feat: email gửi tay/nhắc gia hạn, gói hosting, sửa dữ liệu sản phẩm

- Gửi email theo template cho 1 khách, tab lịch sử email, nhắc gia hạn dịch vụ hàng loạt
- Mail lưu from/bcc/sent_by; mẫu MARKETING và mẫu cũ trong TemplateSeeder
- Gói hosting: giới hạn, trạng thái, lấy plan Plesk qua CLI gateway
- Backfill payment_method và ngày đơn hàng còn thiếu
- Bổ sung field CPU/RAM/Disk/Băng thông cho loại sản phẩm vps và cloud

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
baodev0
2026-10-09 11:32:05 +07:00
co-authored by Claude Opus 5.5
parent 8651dde6b1
commit 30898ea46f
59 changed files with 1771 additions and 108 deletions
@@ -0,0 +1,91 @@
<?php
namespace App\Services\Product;
use App\Models\ProductCategories;
use Illuminate\Support\Facades\DB;
final class ProductCategorySampleService
{
/**
* Fill missing metadata on known groups and create missing sample groups.
* Existing administrator-entered values are never overwritten.
*
* @return array{created: int, updated: int}
*/
public function seed(): array
{
$definitions = [
['slug' => 'vps', 'name' => 'VPS', 'type' => 'vps', 'sort_order' => 10, 'billing_cycles' => $this->recurringCycles()],
['slug' => 'hosting', 'name' => 'Hosting', 'type' => 'hosting', 'sort_order' => 20, 'billing_cycles' => $this->recurringCycles()],
['slug' => 'cloud-storage', 'name' => 'Cloud Storage', 'type' => 'cloud', 'sort_order' => 30, 'billing_cycles' => $this->recurringCycles()],
['slug' => 'email', 'name' => 'Email', 'type' => 'email', 'sort_order' => 40, 'billing_cycles' => $this->recurringCycles()],
['slug' => 'hardware', 'name' => 'Hardware', 'type' => 'hardware', 'sort_order' => 50, 'billing_cycles' => ['one_time']],
['slug' => 'thiet-ke-website', 'name' => 'Thiết kế website', 'type' => 'web_design', 'sort_order' => 60, 'billing_cycles' => ['one_time']],
['slug' => 'it-support', 'name' => 'IT Support', 'type' => 'it_support', 'sort_order' => 70, 'billing_cycles' => ['monthly', 'annually', 'one_time']],
['slug' => 'domain', 'name' => 'Tên miền Việt Nam', 'type' => 'domain', 'sort_order' => 75, 'billing_cycles' => ['annually']],
['slug' => 'other', 'name' => 'Other', 'type' => 'addon', 'sort_order' => 80, 'billing_cycles' => ['one_time']],
];
return DB::transaction(function () use ($definitions): array {
$created = 0;
$updated = 0;
foreach ($definitions as $definition) {
$group = ProductCategories::withTrashed()->firstOrNew(['slug' => $definition['slug']]);
$isNew = ! $group->exists;
if ($isNew) {
$group->fill([
...$definition,
'parent_id' => null,
'is_active' => true,
]);
} else {
foreach (['type', 'billing_cycles'] as $field) {
if (blank($group->{$field})) {
$group->{$field} = $definition[$field];
}
}
}
if ($isNew || $group->isDirty()) {
$group->save();
$isNew ? $created++ : $updated++;
}
if ($group->trashed()) {
$group->restore();
$updated++;
}
}
ProductCategories::query()
->whereNotNull('type')
->whereNull('billing_cycles')
->get()
->each(function (ProductCategories $group) use (&$updated): void {
$group->billing_cycles = $this->cyclesForType($group->type);
$group->save();
$updated++;
});
return compact('created', 'updated');
});
}
private function cyclesForType(string $type): array
{
return match ($type) {
'hardware', 'web_design', 'addon' => ['one_time'],
'domain' => ['annually'],
'it_support' => ['monthly', 'annually', 'one_time'],
default => $this->recurringCycles(),
};
}
private function recurringCycles(): array
{
return ['monthly', 'quarterly', 'semi_annually', 'annually', 'biennially', 'triennially'];
}
}