feat: Add IT Support catalog and related migrations, seeders, and email templates

- Created migration to add 'group_label' to 'product_type_fields' table.
- Implemented ItSupportCatalogSeeder to populate IT Support features and tiers.
- Added ProductCategorySeeder for initial product categories.
- Developed ProductMockupSeeder for mockup products in various categories.
- Introduced ProductTypeFieldSeeder to define fields for different product types.
- Created email templates for VPS service information and service renewal reminders.
This commit is contained in:
baodev0
2026-08-26 16:19:38 +07:00
parent 382b7c0ef8
commit c917e3bf5e
47 changed files with 2992 additions and 1759 deletions
@@ -10,7 +10,7 @@ use App\Jobs\Mail\SendInformationVirtualMachine;
use App\Models\Invoice;
use App\Models\ModuleVmware;
use App\Models\Service;
use App\Models\Setting;
use App\Services\VirtualMachine\VmCredentialsEmailDataBuilder;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
@@ -72,30 +72,8 @@ class SendVmCredentialsEmailJob implements ShouldQueue
// ── [3] Build email payload ───────────────────────────────────────────
$setting = Setting::where('key', 'setting')->first();
$settingValue = $setting ? json_decode((string) $setting->value) : null;
$months = (int) ($orderItem?->months ?? 0);
$osGroupName = $vm->os?->osGroup?->name ?? '';
$isWindows = str_contains(strtolower($osGroupName), 'windows');
$osUsername = $isWindows ? 'Administrator' : 'root';
$emailData = $this->safeUtf8([
'company_name' => $settingValue->company ?? 'Thế Giới Số',
'company_logo' => $settingValue->logo ?? '',
'client_name' => $customer->fullname ?? '',
'product_name' => $orderItem?->getProductAttribute()?->name ?? 'Cloud VPS',
'product_billing' => $this->billingLabel($months),
'product_price' => $orderItem ? number_format((float) $orderItem->price, 0, ',', '.') : 'N/A',
'service_host' => $vm->ip ?? 'N/A',
'service_username' => $osUsername,
'service_port' => (string) ($vm->port ?? '22'),
'service_password' => $vm->plain_password ?? '(xem tai khoan quan ly)',
'os_name' => $vm->os ? ($osGroupName . ' ' . $vm->os->version) : 'Unknown OS',
'service_due_exp' => $vm->next_due_date
? date('d/m/Y', (int) $vm->next_due_date)
: 'N/A',
]);
$months = (int) ($orderItem?->months ?? 0);
$emailData = app(VmCredentialsEmailDataBuilder::class)->build($vm, $orderItem);
// PDF is generated inside the mail job — never pass binary blobs through queue payload
$invoice = Invoice::where('order_id', $vm->order_id)->first();
@@ -123,7 +101,7 @@ class SendVmCredentialsEmailJob implements ShouldQueue
'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 ?? '',
'username' => $osUsername,
'username' => $emailData['service_username'],
'password' => $vm->plain_password ?? '',
]);
@@ -204,26 +182,4 @@ class SendVmCredentialsEmailJob implements ShouldQueue
default => ($months ?? 0) . ' Thang',
};
}
/**
* Sanitize tất cả string trong array thành UTF-8 hợp lệ.
* Loại bỏ ký tự binary/invalid trước khi đẩy vào queue (tránh JSON encode lỗi).
*/
private function safeUtf8(array $data): array
{
return array_map(function ($value) {
if (!is_string($value)) return $value;
// Nếu đã là UTF-8 hợp lệ → giữ nguyên
if (mb_check_encoding($value, 'UTF-8')) return $value;
// Thử convert từ encoding khác sang UTF-8
$converted = mb_convert_encoding($value, 'UTF-8', mb_detect_encoding($value, ['UTF-8', 'ISO-8859-1', 'Windows-1252'], true) ?: 'ISO-8859-1');
// Nếu vẫn invalid → strip ký tự lỗi
return mb_check_encoding($converted, 'UTF-8')
? $converted
: preg_replace('/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]|[^\x09\x0A\x0D\x20-\x{10FFFF}]/u', '', $value);
}, $data);
}
}