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
+92
View File
@@ -0,0 +1,92 @@
<?php
namespace App\Exports;
use App\Models\Product;
use Illuminate\Support\Collection;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
use Maatwebsite\Excel\Concerns\WithEvents;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithMapping;
use Maatwebsite\Excel\Events\AfterSheet;
final class ProductsExport implements FromCollection, WithHeadings, WithMapping, WithEvents, ShouldAutoSize
{
public function collection(): Collection
{
return Product::query()
->with(['category', 'pricings', 'operatingSystems'])
->orderBy('id')
->get();
}
public function headings(): array
{
return [
'ID', 'UUID', 'Tên sản phẩm', 'Slug', 'Ảnh đại diện', 'Loại sản phẩm',
'ID danh mục', 'Danh mục', 'ID gói dịch vụ', 'CPU', 'RAM', 'Ổ đĩa',
'Băng thông', 'Số tên miền', 'Phí khởi tạo', 'Giá thấp nhất', 'Loại thanh toán',
'Tiền tệ', 'Giá tháng', 'Giá quý', 'Giá 6 tháng', 'Giá năm', 'Giá 2 năm',
'Giá 3 năm', 'Giá một lần', 'Tính năng', 'Đang hoạt động', 'ID hệ điều hành',
'ID máy chủ module', 'ID datastore module', 'Ngày tạo', 'Ngày cập nhật',
];
}
public function map($product): array
{
$prices = $product->pricings->keyBy('billing_cycle');
$hasOneTime = $prices->has('one_time');
$hasRecurring = $prices->keys()->contains(fn ($cycle) => $cycle !== 'one_time');
return [
$product->id,
$product->uuid,
$product->name,
$product->slug,
$product->thumbnail,
$product->product_type,
$product->product_categories_id,
$product->category?->name,
$product->service_plan_id,
$product->cpu,
$product->ram,
$product->disk,
$product->bandwidth,
$product->domain_count,
$product->setup_fee,
$prices->min('price'),
$hasOneTime && !$hasRecurring ? 'Một lần' : 'Định kỳ',
$prices->first()?->currency ?? 'VND',
$prices->get('monthly')?->price,
$prices->get('quarterly')?->price,
$prices->get('semi_annually')?->price,
$prices->get('annually')?->price,
$prices->get('biennially')?->price,
$prices->get('triennially')?->price,
$prices->get('one_time')?->price,
$product->features ? json_encode($product->features, JSON_UNESCAPED_UNICODE) : null,
$product->is_active ? 'Có' : 'Không',
$product->operatingSystems->pluck('id')->implode(', '),
$product->module_host_id,
$product->module_datastore_id,
optional($product->created_at)->format('Y-m-d H:i:s'),
optional($product->updated_at)->format('Y-m-d H:i:s'),
];
}
public function registerEvents(): array
{
return [
AfterSheet::class => function (AfterSheet $event): void {
$sheet = $event->sheet->getDelegate();
$sheet->freezePane('A2');
$sheet->setAutoFilter($sheet->calculateWorksheetDimension());
$sheet->getStyle('A1:AF1')->getFont()->setBold(true)->getColor()->setARGB('FFFFFFFF');
$sheet->getStyle('A1:AF1')->getFill()->setFillType('solid')->getStartColor()->setARGB('FF1677FF');
$sheet->getStyle('A1:AF1')->getAlignment()->setVertical('center');
$sheet->getRowDimension(1)->setRowHeight(24);
},
];
}
}