feat: add GeneratesUniqueSlug class for unique slug generation

feat: create PostCategoryFactory for generating post category data

feat: create PostFactory for generating post data

feat: add retry_requested_at column to services table

feat: add vcenter provisioning fields to products table

feat: add module_host_id to os table

feat: create email_notification_templates table for email templates

feat: add scenario and format fields to template table

feat: add admin fields to transactions table

fix: update ticket table columns and types

feat: add uuid to ticket table and backfill existing records

fix: make ticket_reply user_id nullable

feat: create notifications table for user notifications

fix: make ticket uuid nullable

feat: create post_categories table for blog categories

feat: create posts table for blog posts

feat: add invoice email template for PDF generation
This commit is contained in:
baodev0
2026-05-25 15:39:42 +07:00
parent a31d238135
commit 520f21cb11
73 changed files with 4682 additions and 440 deletions
@@ -205,17 +205,28 @@ class RetryProvisioningOrchestrator implements ShouldQueue
/**
* Resolve vcenter from DB chain:
* Path 1: order_items.os_id → os → osGroup → host → datacenter → vcenter
* Path 2: invoices → invoice_items → product_id → os_product → os → osGroup → host → datacenter → vcenter
* Path 3: module_vmware with same order_id (partial provisioning)
* Path 1a: order_items.os_id → os.host → datacenter → vcenter (ưu tiên: host gán trực tiếp trên OS)
* Path 1b: order_items.os_id → os → osGroup → host → datacenter → vcenter
* Path 2a: invoices → product → os_product → os.host → datacenter → vcenter
* Path 2b: invoices → product → os_product → os → osGroup → host → datacenter → vcenter
* Path 3: module_vmware with same order_id (partial provisioning)
*/
private function resolveVcenter(OrderItem $item, Telegram $telegram): ?VcenterModel
{
if ($item->os_id) {
$os = Os::with('osGroup.host.datacenter.vCenter')->find($item->os_id);
$os = Os::with(['host.datacenter.vCenter', 'osGroup.host.datacenter.vCenter'])->find($item->os_id);
// Path 1a: host gán trực tiếp trên OS
$vcenter = $os?->host?->datacenter?->vCenter;
if ($vcenter) {
Log::info('resolveVcenter: found via os.host chain', ['os_id' => $item->os_id, 'vcenter_id' => $vcenter->id]);
return $vcenter;
}
// Path 1b: host qua osGroup (cũ)
$vcenter = $os?->osGroup?->host?->datacenter?->vCenter;
if ($vcenter) {
Log::info('resolveVcenter: found via os → osGroup chain', ['vcenter_id' => $vcenter->id]);
Log::info('resolveVcenter: found via os → osGroup chain', ['os_id' => $item->os_id, 'vcenter_id' => $vcenter->id]);
return $vcenter;
}
}
@@ -229,10 +240,19 @@ class RetryProvisioningOrchestrator implements ShouldQueue
->first();
if ($osRecord) {
$os = Os::with('osGroup.host.datacenter.vCenter')->find($osRecord->os_id);
$os = Os::with(['host.datacenter.vCenter', 'osGroup.host.datacenter.vCenter'])->find($osRecord->os_id);
// Path 2a: host gán trực tiếp trên OS
$vcenter = $os?->host?->datacenter?->vCenter;
if ($vcenter) {
Log::info('resolveVcenter: found via invoice → os.host chain', ['vcenter_id' => $vcenter->id]);
return $vcenter;
}
// Path 2b: host qua osGroup
$vcenter = $os?->osGroup?->host?->datacenter?->vCenter;
if ($vcenter) {
Log::info('resolveVcenter: found via invoice_items → os_product chain', ['vcenter_id' => $vcenter->id]);
Log::info('resolveVcenter: found via invoice → os → osGroup chain', ['vcenter_id' => $vcenter->id]);
return $vcenter;
}
}
@@ -80,24 +80,22 @@ class SendVmCredentialsEmailJob implements ShouldQueue
$isWindows = str_contains(strtolower($osGroupName), 'windows');
$osUsername = $isWindows ? 'Administrator' : 'root';
$emailData = [
$emailData = $this->safeUtf8([
'company_name' => $settingValue->company ?? 'Thế Giới Số',
'company_logo' => $settingValue->logo ?? '',
'client_name' => $customer->fullname ?? '',
'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' => $vm->port,
'service_password' => $vm->plain_password ?? '(xem tài khoản quản lý)',
'os_name' => $vm->os
? ($osGroupName . ' ' . $vm->os->version)
: 'Unknown OS',
'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',
];
]);
// PDF is generated inside the mail job — never pass binary blobs through queue payload
$invoice = Invoice::where('order_id', $vm->order_id)->first();
@@ -198,12 +196,34 @@ class SendVmCredentialsEmailJob implements ShouldQueue
private function billingLabel(?int $months): string
{
return match ($months) {
1 => 'Hàng tháng',
3 => '3 Tháng',
6 => '6 Tháng',
12 => 'Hàng năm',
24 => '2 Năm',
default => ($months ?? 0) . ' Tháng',
1 => 'Hang thang',
3 => '3 Thang',
6 => '6 Thang',
12 => 'Hang nam',
24 => '2 Nam',
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);
}
}