Version 2.0

This commit is contained in:
2026-05-12 09:23:05 +00:00
parent f2bc048219
commit f1b68e5e78
34 changed files with 564 additions and 283 deletions

View File

@@ -2,13 +2,13 @@
namespace Database\Seeders;
use App\Enums\ContractCategory;
use App\Enums\ContractStatus;
use App\Enums\ContractType;
use App\Enums\HandoverStatus;
use App\Enums\ServiceType;
use App\Models\Contract;
use App\Models\Customer;
use App\Models\CustomerProduct;
use App\Models\Department;
use App\Models\Feedback;
use App\Models\FeedbackAttachment;
@@ -119,65 +119,62 @@ class AfterSalesSeeder extends Seeder
$c6 = Customer::create(['name' => 'Đỗ Văn Phúc', 'email' => 'dovanphuc@gmail.com', 'phone' => '0954678901', 'address' => 'Thủ Đức, TP.HCM', 'status' => 'inactive']);
// ============================================================
// 7. CUSTOMER-PRODUCT pivots
// ============================================================
$c1->products()->attach($p1->id, ['purchase_date' => '2024-01-15']);
$c1->products()->attach($p2->id, ['purchase_date' => '2024-06-01']);
$c2->products()->attach($p1->id, ['purchase_date' => '2024-03-20']);
$c3->products()->attach($p3->id, ['purchase_date' => '2024-09-10']);
$c4->products()->attach($p2->id, ['purchase_date' => '2025-01-05']);
$c4->products()->attach($p5->id, ['purchase_date' => '2025-02-15']);
$c5->products()->attach($p5->id, ['purchase_date' => '2024-11-01']);
$c6->products()->attach($p6->id, ['purchase_date' => '2023-06-15']);
// ============================================================
// 8. CONTRACTS (6 contracts)
// 7. CONTRACTS (V2: category + representative)
// ============================================================
$contract1 = Contract::create([
'product_id' => $p1->id, 'customer_id' => $c1->id,
'type' => ContractType::SALE->value,
'category' => ContractCategory::OWNERSHIP->value,
'type' => ContractType::PURCHASE->value,
'start_date' => '2024-01-15', 'end_date' => null,
'status' => ContractStatus::ACTIVE->value,
'signed_status' => 'Đã ký',
'representative_name' => 'Nguyễn Thị Hoa',
'representative_phone' => '0901000111',
'representative_email' => 'hoant@example.com',
]);
$contract2 = Contract::create([
'product_id' => $p2->id, 'customer_id' => $c1->id,
'type' => ContractType::LEASE->value,
'category' => ContractCategory::BUSINESS->value,
'type' => ContractType::RENTAL->value,
'start_date' => '2024-06-01', 'end_date' => '2026-06-01',
'status' => ContractStatus::ACTIVE->value,
'signed_status' => 'Đã ký',
]);
$contract3 = Contract::create([
'product_id' => $p1->id, 'customer_id' => $c2->id,
'type' => ContractType::SALE->value,
'start_date' => '2024-03-20', 'end_date' => null,
'status' => ContractStatus::ACTIVE->value,
'product_id' => $p2->id, 'customer_id' => $c4->id,
'category' => ContractCategory::BUSINESS->value,
'type' => ContractType::RENTAL->value,
'start_date' => '2025-01-05', 'end_date' => '2026-01-05',
'status' => ContractStatus::EXPIRED->value,
'signed_status' => 'Đã ký',
]);
$contract4 = Contract::create([
'product_id' => $p3->id, 'customer_id' => $c3->id,
'category' => ContractCategory::BUSINESS->value,
'type' => ContractType::BCC->value,
'start_date' => '2024-09-10', 'end_date' => '2029-09-10',
'status' => ContractStatus::ACTIVE->value,
'signed_status' => 'Đang chờ ký',
]);
$contract5 = Contract::create([
'product_id' => $p2->id, 'customer_id' => $c4->id,
'type' => ContractType::LEASE->value,
'start_date' => '2025-01-05', 'end_date' => '2026-01-05',
'status' => ContractStatus::EXPIRED->value,
'signed_status' => 'Đã ký',
]);
$contract6 = Contract::create([
'product_id' => $p5->id, 'customer_id' => $c5->id,
'type' => ContractType::SALE->value,
'category' => ContractCategory::OWNERSHIP->value,
'type' => ContractType::PURCHASE->value,
'start_date' => '2024-11-01', 'end_date' => null,
'status' => ContractStatus::ACTIVE->value,
'signed_status' => 'Đã ký',
]);
$contract6 = Contract::create([
'product_id' => $p1->id, 'customer_id' => $c2->id,
'category' => ContractCategory::OWNERSHIP->value,
'type' => ContractType::PURCHASE->value,
'start_date' => '2024-03-20', 'end_date' => '2024-12-31',
'status' => ContractStatus::LIQUIDATED->value,
'signed_status' => 'Đã ký',
]);
// ============================================================
// 9. HANDOVERS (6 handovers)
// 8. HANDOVERS (6 handovers)
// ============================================================
Handover::create(['product_id' => $p1->id, 'customer_id' => $c1->id, 'handover_date' => '2024-02-15', 'status' => HandoverStatus::HANDED_OVER->value, 'remark' => 'Đã bàn giao đầy đủ chìa khóa, thẻ từ và sổ bảo hành.']);
Handover::create(['product_id' => $p1->id, 'customer_id' => $c2->id, 'handover_date' => '2024-04-20', 'status' => HandoverStatus::HANDED_OVER->value, 'remark' => 'Đã bàn giao, khách yêu cầu kiểm tra lại hệ thống nước nóng.']);
@@ -187,7 +184,7 @@ class AfterSalesSeeder extends Seeder
Handover::create(['product_id' => $p5->id, 'customer_id' => $c5->id, 'handover_date' => '2025-01-15', 'status' => HandoverStatus::HANDED_OVER->value, 'remark' => 'Bàn giao thành công, khách hài lòng với chất lượng.']);
// ============================================================
// 10. PRODUCT SERVICES (6 services)
// 9. PRODUCT SERVICES (6 services)
// ============================================================
ProductService::create(['product_id' => $p1->id, 'service_type' => ServiceType::MANAGEMENT_FEE->value, 'status' => 'active', 'actual_collection_date' => '2024-03-01', 'remark' => 'Phí quản lý hàng tháng 5.000.000 VND/căn.']);
ProductService::create(['product_id' => $p1->id, 'service_type' => ServiceType::GRATITUDE->value, 'status' => 'completed', 'actual_collection_date' => '2024-06-15', 'remark' => 'Quà tri ân khách hàng nhân dịp khai trương tiện ích mới.']);
@@ -197,7 +194,7 @@ class AfterSalesSeeder extends Seeder
ProductService::create(['product_id' => $p5->id, 'service_type' => ServiceType::MANAGEMENT_FEE->value, 'status' => 'active', 'actual_collection_date' => '2025-02-01', 'remark' => 'Phí quản lý hàng tháng 3.500.000 VND/căn.']);
// ============================================================
// 11. FEEDBACK TAGS (6 tags)
// 10. FEEDBACK TAGS (6 tags)
// ============================================================
$tagLeaking = FeedbackTag::create(['name' => 'Rò rỉ', 'slug' => 'leaking', 'color' => '#3b82f6']);
$tagElectrical = FeedbackTag::create(['name' => 'Điện nước', 'slug' => 'electrical', 'color' => '#f59e0b']);
@@ -207,13 +204,12 @@ class AfterSalesSeeder extends Seeder
$tagSuggestion = FeedbackTag::create(['name' => 'Đề xuất', 'slug' => 'suggestion', 'color' => '#06b6d4']);
// ============================================================
// 12. FEEDBACKS (8 feedbacks - various statuses)
// 11. FEEDBACKS (8 feedbacks - V2: no customer_product_id, use contract_id)
// ============================================================
// Feedback 1: Pending - Trần rò rỉ
$cp1 = CustomerProduct::where('customer_id', $c1->id)->where('product_id', $p1->id)->first();
$fb1 = Feedback::create([
'customer_id' => $c1->id, 'customer_product_id' => $cp1->id, 'contract_id' => $contract1->id,
'customer_id' => $c1->id, 'contract_id' => $contract1->id,
'feedback_channel_id' => $chEmail->id, 'assigned_to' => $staffA->id,
'current_department_id' => $deptCskh->id,
'title' => 'Trần nhà bị rò rỉ nước mưa',
@@ -222,9 +218,8 @@ class AfterSalesSeeder extends Seeder
]);
// Feedback 2: Processing - Nâng cấp chỗ đậu xe
$cp2 = CustomerProduct::where('customer_id', $c1->id)->where('product_id', $p2->id)->first();
$fb2 = Feedback::create([
'customer_id' => $c1->id, 'customer_product_id' => $cp2->id, 'contract_id' => $contract2->id,
'customer_id' => $c1->id, 'contract_id' => $contract2->id,
'feedback_channel_id' => $chPhone->id, 'assigned_to' => $managerCskh->id,
'current_department_id' => $deptCskh->id,
'title' => 'Yêu cầu nâng cấp chỗ đậu xe',
@@ -233,9 +228,8 @@ class AfterSalesSeeder extends Seeder
]);
// Feedback 3: Resolved - Điều hòa hỏng
$cp3 = CustomerProduct::where('customer_id', $c2->id)->where('product_id', $p1->id)->first();
$fb3 = Feedback::create([
'customer_id' => $c2->id, 'customer_product_id' => $cp3->id, 'contract_id' => $contract3->id,
'customer_id' => $c2->id, 'contract_id' => $contract6->id,
'feedback_channel_id' => $chZalo->id, 'assigned_to' => $staffA->id,
'current_department_id' => $deptKt->id, 'is_escalated' => false,
'title' => 'Điều hòa phòng ngủ chính không mát',
@@ -243,9 +237,9 @@ class AfterSalesSeeder extends Seeder
'status' => 'resolved',
]);
// Feedback 4: Pending - Góp ý cải thiện dịch vụ
// Feedback 4: Pending - Góp ý cải thiện dịch vụ (general)
$fb4 = Feedback::create([
'customer_id' => $c3->id, 'customer_product_id' => null, 'contract_id' => null,
'customer_id' => $c3->id, 'contract_id' => null,
'feedback_channel_id' => $chApp->id, 'assigned_to' => null,
'current_department_id' => $deptCskh->id,
'title' => 'Đề xuất cải thiện dịch vụ vệ sinh',
@@ -253,10 +247,9 @@ class AfterSalesSeeder extends Seeder
'status' => 'pending',
]);
// Feedback 5: Closed - Bản lề tủ bếp
$cp5 = CustomerProduct::where('customer_id', $c4->id)->where('product_id', $p2->id)->first();
// Feedback 5: Closed - Bản lề tủ bếp (vẫn ref contract đã expired)
$fb5 = Feedback::create([
'customer_id' => $c4->id, 'customer_product_id' => $cp5->id, 'contract_id' => $contract5->id,
'customer_id' => $c4->id, 'contract_id' => $contract3->id,
'feedback_channel_id' => $chEmail->id, 'assigned_to' => $staffB->id,
'current_department_id' => $deptKt->id,
'title' => 'Bản lề tủ bếp bị gãy',
@@ -265,19 +258,18 @@ class AfterSalesSeeder extends Seeder
]);
// Feedback 6: Processing - Ổ cắm điện hư
$cp6 = CustomerProduct::where('customer_id', $c5->id)->where('product_id', $p5->id)->first();
$fb6 = Feedback::create([
'customer_id' => $c5->id, 'customer_product_id' => $cp6->id, 'contract_id' => $contract6->id,
'customer_id' => $c5->id, 'contract_id' => $contract5->id,
'feedback_channel_id' => $chPhone->id, 'assigned_to' => $staffA->id,
'current_department_id' => $deptKt->id, 'is_escalated' => true,
'title' => 'Ổ c插座 điện phòng bếp bị hư, có mùi khét',
'title' => 'Ổ cắm điện phòng bếp bị hư, có mùi khét',
'content' => 'Ổ cắm điện cạnh bồn rửa chén bị hư, phát ra mùi khét khi cắm thiết bị. Đây là vấn đề an toàn, cần xử lý gấp.',
'status' => 'processing',
]);
// Feedback 7: Resolved - Hợp đồng thuê
$fb7 = Feedback::create([
'customer_id' => $c4->id, 'customer_product_id' => null, 'contract_id' => $contract5->id,
'customer_id' => $c4->id, 'contract_id' => $contract3->id,
'feedback_channel_id' => $chWalkin->id, 'assigned_to' => $staffB->id,
'current_department_id' => $deptPhaply->id,
'title' => 'Hỏi về gia hạn hợp đồng thuê',
@@ -285,9 +277,9 @@ class AfterSalesSeeder extends Seeder
'status' => 'resolved',
]);
// Feedback 8: Pending - Phàn nàn về tiếng ồn
// Feedback 8: Pending - Phàn nàn tiếng ồn
$fb8 = Feedback::create([
'customer_id' => $c2->id, 'customer_product_id' => $cp3->id, 'contract_id' => $contract3->id,
'customer_id' => $c2->id, 'contract_id' => $contract6->id,
'feedback_channel_id' => $chZalo->id, 'assigned_to' => $staffB->id,
'current_department_id' => $deptCskh->id,
'title' => 'Phàn nàn về tiếng ồn từ tầng trên',
@@ -296,7 +288,7 @@ class AfterSalesSeeder extends Seeder
]);
// ============================================================
// 13. TAG ATTACHMENTS
// 12. TAG ATTACHMENTS
// ============================================================
$fb1->tags()->attach([$tagLeaking->id, $tagMaintenance->id]);
$fb2->tags()->attach([$tagSuggestion->id]);
@@ -308,10 +300,8 @@ class AfterSalesSeeder extends Seeder
$fb8->tags()->attach([$tagComplaint->id]);
// ============================================================
// 14. FEEDBACK INTERACTIONS (12 interactions)
// 13. FEEDBACK INTERACTIONS
// ============================================================
// FB1: Tạo mới + ghi chú
FeedbackInteraction::create([
'feedback_id' => $fb1->id, 'user_id' => $admin->id, 'type' => 'note',
'content' => 'Tiếp nhận phản ánh qua Email. Giao cho nhân viên Phạm Thị xử lý.',
@@ -321,28 +311,20 @@ class AfterSalesSeeder extends Seeder
'feedback_id' => $fb1->id, 'user_id' => $staffA->id, 'type' => 'note',
'content' => 'Đã liên hệ khách hàng qua điện thoại. Lên lịch kiểm tra vào thứ Ba tuần sau.',
]);
// FB2: Phân công
FeedbackInteraction::create([
'feedback_id' => $fb2->id, 'user_id' => $managerCskh->id, 'type' => 'note',
'content' => 'Đã gửi báo giá nâng cấp chỗ đậu xe qua email. Chờ khách xác nhận.',
]);
// FB3: Xử lý xong
FeedbackInteraction::create([
'feedback_id' => $fb3->id, 'user_id' => $staffA->id, 'type' => 'status_change',
'content' => 'Kỹ thuật viên đã kiểm tra và thay thế block điều hòa ngày 10/06. Khách hàng xác nhận hoạt động bình thường.',
'changes' => ['status' => ['old' => 'processing', 'new' => 'resolved']],
]);
// FB5: Đóng phiếu
FeedbackInteraction::create([
'feedback_id' => $fb5->id, 'user_id' => $staffB->id, 'type' => 'status_change',
'content' => 'Đã thay thế bản lề mới ngày 01/03. Tất cả tủ bếp hoạt động bình thường.',
'changes' => ['status' => ['old' => 'processing', 'new' => 'closed']],
]);
// FB6: Đang xử lý + ghi chú khẩn cấp
FeedbackInteraction::create([
'feedback_id' => $fb6->id, 'user_id' => $staffA->id, 'type' => 'note',
'content' => 'Đã cử kỹ thuật viên khẩn cấp đến kiểm tra. Yêu cầu khách không sử dụng ổ cắm cho đến khi sửa xong.',
@@ -352,8 +334,6 @@ class AfterSalesSeeder extends Seeder
'content' => 'Kỹ thuật viên đã kiểm tra, phát hiện dây điện bị hở. Đang chờ vật tư thay thế.',
'changes' => ['status' => ['old' => 'pending', 'new' => 'processing']],
]);
// FB7: Phân công + chuyển phòng ban
FeedbackInteraction::create([
'feedback_id' => $fb7->id, 'user_id' => $managerCskh->id, 'type' => 'assignment',
'content' => 'Chuyển yêu cầu gia hạn hợp đồng sang Phòng Pháp lý.',
@@ -364,15 +344,13 @@ class AfterSalesSeeder extends Seeder
'content' => 'Đã soạn thảo phụ lục hợp đồng gia hạn. Đang chờ khách hàng ký.',
'changes' => ['status' => ['old' => 'processing', 'new' => 'resolved']],
]);
// FB8: Ghi chú
FeedbackInteraction::create([
'feedback_id' => $fb8->id, 'user_id' => $staffB->id, 'type' => 'note',
'content' => 'Đã liên hệ ban quản lý tòa nhà để xác minh thông tin. BQL cho biết sẽ nhắc nhở cư dân tầng trên.',
]);
// ============================================================
// 15. TICKET TRANSFER LOGS (2 transfers)
// 14. TICKET TRANSFER LOGS
// ============================================================
TicketTransferLog::create([
'feedback_id' => $fb3->id,
@@ -390,17 +368,15 @@ class AfterSalesSeeder extends Seeder
]);
// ============================================================
// 16. FEEDBACK ATTACHMENTS (6 attachments - public disk)
// 15. FEEDBACK ATTACHMENTS
// ============================================================
$disk = Storage::disk('public');
// Tạo file mẫu trên public disk
$disk->put('feedback-attachments/bao-cao-kiem-tra-dieu-hoa.pdf', '%PDF-1.4 Mẫu báo cáo kiểm tra điều hòa - Demo');
$disk->put('feedback-attachments/anh-tran-ro-ri.jpg', str_repeat('x', 1000)); // dummy image
$disk->put('feedback-attachments/anh-ban-le-hong.png', str_repeat('y', 1200)); // dummy image
$disk->put('feedback-attachments/anh-tran-ro-ri.jpg', str_repeat('x', 1000));
$disk->put('feedback-attachments/anh-ban-le-hong.png', str_repeat('y', 1200));
$disk->put('feedback-attachments/bao-gia-nang-cap.pdf', '%PDF-1.4 Báo giá nâng cấp chỗ đậu xe - Demo');
$disk->put('feedback-attachments/phu-luc-hop-dong.pdf', '%PDF-1.4 Phụ lục hợp đồng gia hạn - Demo');
$disk->put('feedback-attachments/anh-o-cam-hu.jpg', str_repeat('z', 800)); // dummy image
$disk->put('feedback-attachments/anh-o-cam-hu.jpg', str_repeat('z', 800));
FeedbackAttachment::create([
'uuid' => (string) Str::uuid(),