feat(admin): improve payments and server settings
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Jobs\Mail\Admin;
|
||||
|
||||
use App\Mail\Admin\AdminPaymentReceived;
|
||||
use App\Models\Setting;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
||||
class AdminPaymentReceivedJob implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
public int $tries = 3;
|
||||
public int $timeout = 60;
|
||||
|
||||
public function __construct(public readonly array $data) {}
|
||||
|
||||
public function handle(): void
|
||||
{
|
||||
$setting = Setting::where('key', 'setting')->first();
|
||||
$values = $setting ? json_decode((string) $setting->value, true) : [];
|
||||
$adminEmail = $values['admin_email'] ?? null;
|
||||
|
||||
if (!$adminEmail) {
|
||||
Log::warning('AdminPaymentReceivedJob: admin_email not configured in settings.');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
Mail::to($adminEmail)->send(new AdminPaymentReceived([
|
||||
...$this->data,
|
||||
'company_name' => $values['company'] ?? config('app.name'),
|
||||
]));
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('AdminPaymentReceivedJob: failed to send email.', [
|
||||
'reference' => $this->data['reference'] ?? null,
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
namespace App\Jobs\VirtualMachine\Provision;
|
||||
|
||||
use App\Http\Services\Telegram;
|
||||
use App\Enums\Product\ProductBillingCycle;
|
||||
use App\Jobs\Mail\Admin\AdminOrderNotificationJob;
|
||||
use App\Jobs\Mail\SendInformationVirtualMachine;
|
||||
use App\Models\Invoice;
|
||||
@@ -97,7 +98,7 @@ class SendVmCredentialsEmailJob implements ShouldQueue
|
||||
'order_num' => $order?->order_num ?? $order?->id ?? 'N/A',
|
||||
'product_name' => $orderItem?->getProductAttribute()?->name ?? 'Cloud VPS',
|
||||
'product_type' => 'Cloud VPS',
|
||||
'billing_cycle' => $this->billingLabel($months),
|
||||
'billing_cycle' => ProductBillingCycle::vietnameseLabelForMonths($months),
|
||||
'total' => $orderItem?->price ?? 0,
|
||||
'created_at' => $order?->created_at?->format('d/m/Y H:i:s') ?? now()->format('d/m/Y H:i:s'),
|
||||
'ip' => $vm->ip ?? '',
|
||||
@@ -171,15 +172,4 @@ class SendVmCredentialsEmailJob implements ShouldQueue
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────
|
||||
|
||||
private function billingLabel(?int $months): string
|
||||
{
|
||||
return match ($months) {
|
||||
1 => 'Hang thang',
|
||||
3 => '3 Thang',
|
||||
6 => '6 Thang',
|
||||
12 => 'Hang nam',
|
||||
24 => '2 Nam',
|
||||
default => ($months ?? 0) . ' Thang',
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
namespace App\Jobs\VirtualMachine\Rebuild;
|
||||
|
||||
use App\Http\Services\Telegram;
|
||||
use App\Enums\Product\ProductBillingCycle;
|
||||
use App\Jobs\Mail\Admin\AdminOrderNotificationJob;
|
||||
use App\Jobs\Mail\Customer\VmRebuildFailedJob;
|
||||
use App\Jobs\Mail\SendInformationVirtualMachine;
|
||||
@@ -157,7 +158,7 @@ final class RebuildFinalizeJob implements ShouldQueue
|
||||
'company_logo' => $settingValue->logo ?? '',
|
||||
'client_name' => $vm->customer->fullname ?? '',
|
||||
'product_name' => $orderItem?->getProductAttribute()?->name ?? 'Cloud VPS',
|
||||
'product_billing' => $this->billingLabel($months),
|
||||
'product_billing' => ProductBillingCycle::vietnameseLabelForMonths($months),
|
||||
'product_price' => $orderItem ? number_format((float) $orderItem->price, 0, ',', '.') : 'N/A',
|
||||
'service_host' => $vm->ip ?? 'N/A',
|
||||
'service_username' => $osUsername,
|
||||
@@ -180,7 +181,7 @@ final class RebuildFinalizeJob implements ShouldQueue
|
||||
'order_num' => $vm->order?->order_num ?? $vm->order?->id ?? 'N/A',
|
||||
'product_name' => ($orderItem?->getProductAttribute()?->name ?? 'Cloud VPS') . ' (Rebuild)',
|
||||
'product_type' => 'Cloud VPS Rebuild',
|
||||
'billing_cycle' => $this->billingLabel($months),
|
||||
'billing_cycle' => ProductBillingCycle::vietnameseLabelForMonths($months),
|
||||
'total' => $orderItem?->price ?? 0,
|
||||
'created_at' => now()->format('d/m/Y H:i:s'),
|
||||
'ip' => $vm->ip ?? '',
|
||||
@@ -188,17 +189,4 @@ final class RebuildFinalizeJob implements ShouldQueue
|
||||
'password' => $vm->plain_password ?? '',
|
||||
]);
|
||||
}
|
||||
|
||||
private function billingLabel(int $months): string
|
||||
{
|
||||
return match ($months) {
|
||||
1 => 'Hang thang',
|
||||
3 => '3 Thang',
|
||||
6 => '6 Thang',
|
||||
12 => 'Hang nam',
|
||||
24 => '2 Nam',
|
||||
default => $months . ' Thang',
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user