Chinh sua giao dien phu hop tailwind css va upload
Some checks failed
Tests / PHP 8.3 (push) Has been cancelled
Tests / PHP 8.4 (push) Has been cancelled
Tests / PHP 8.5 (push) Has been cancelled

This commit is contained in:
2026-05-05 09:25:28 +00:00
parent 8c6b71cb8a
commit fb1f82e1a0
12 changed files with 834 additions and 466 deletions

View File

@@ -2,396 +2,453 @@
namespace Database\Seeders;
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;
use App\Models\FeedbackChannel;
use App\Models\FeedbackInteraction;
use App\Models\FeedbackTag;
use App\Models\Handover;
use App\Models\Product;
use App\Models\ProductService;
use App\Models\TicketTransferLog;
use App\Models\User;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
use Spatie\Permission\Models\Role;
class AfterSalesSeeder extends Seeder
{
public function run(): void
{
// ============================================================
// 1. ROLES & PERMISSIONS
// ============================================================
Role::create(['name' => 'admin']);
Role::create(['name' => 'manager']);
Role::create(['name' => 'staff']);
$this->call(PermissionSeeder::class);
// ============================================================
// 2. USERS (5 users)
// ============================================================
$admin = User::create([
'name' => 'Admin',
'name' => 'Nguyễn Quản Trị',
'email' => 'admin@minicrm.local',
'password' => bcrypt('password'),
'role' => 'admin',
]);
$admin->assignRole('admin');
$manager = User::create([
'name' => 'Manager',
$managerCskh = User::create([
'name' => 'Trần Minh Manager',
'email' => 'manager@minicrm.local',
'password' => bcrypt('password'),
'role' => 'manager',
]);
$manager->assignRole('manager');
$managerCskh->assignRole('manager');
$staff = User::create([
'name' => 'Staff',
$managerKt = User::create([
'name' => 'Lê Văn Kỹ Thuật',
'email' => 'manager.kt@minicrm.local',
'password' => bcrypt('password'),
'role' => 'manager',
]);
$managerKt->assignRole('manager');
$staffA = User::create([
'name' => 'Phạm Thị Nhân Viên',
'email' => 'staff@minicrm.local',
'password' => bcrypt('password'),
'role' => 'staff',
]);
$staff->assignRole('staff');
$staffA->assignRole('staff');
$depCskh = Department::create(['name' => 'Phòng CSKH', 'manager_id' => $manager->id]);
$depKythuat = Department::create(['name' => 'Phòng Kỹ thuật', 'manager_id' => $admin->id]);
$depKetoan = Department::create(['name' => 'Phòng Kế toán', 'manager_id' => null]);
$depPhaply = Department::create(['name' => 'Phòng Pháp lý', 'manager_id' => null]);
$staffB = User::create([
'name' => 'Hoàng Văn Phụ',
'email' => 'staff.b@minicrm.local',
'password' => bcrypt('password'),
'role' => 'staff',
]);
$staffB->assignRole('staff');
$channels = [
['name' => 'Email', 'slug' => 'email', 'icon' => 'heroicon-o-envelope', 'color' => '#3b82f6'],
['name' => 'Zalo', 'slug' => 'zalo', 'icon' => 'heroicon-o-chat-bubble-left', 'color' => '#10b981'],
['name' => 'Phone', 'slug' => 'phone', 'icon' => 'heroicon-o-phone', 'color' => '#f59e0b'],
['name' => 'Document', 'slug' => 'document', 'icon' => 'heroicon-o-document-text', 'color' => '#8b5cf6'],
['name' => 'In Person', 'slug' => 'in-person', 'icon' => 'heroicon-o-user', 'color' => '#ec4899'],
];
// ============================================================
// 3. DEPARTMENTS (4 departments)
// ============================================================
$deptCskh = Department::create(['name' => 'Phòng Chăm sóc Khách hàng', 'manager_id' => $managerCskh->id]);
$deptKt = Department::create(['name' => 'Phòng Kỹ thuật', 'manager_id' => $managerKt->id]);
$deptKtoan = Department::create(['name' => 'Phòng Kế toán', 'manager_id' => null]);
$deptPhaply = Department::create(['name' => 'Phòng Pháp lý', 'manager_id' => null]);
foreach ($channels as $channel) {
FeedbackChannel::create($channel);
}
// ============================================================
// 4. FEEDBACK CHANNELS (5 channels)
// ============================================================
$chEmail = FeedbackChannel::create(['name' => 'Email', 'slug' => 'email', 'icon' => 'heroicon-o-envelope', 'color' => '#3b82f6']);
$chZalo = FeedbackChannel::create(['name' => 'Zalo', 'slug' => 'zalo', 'icon' => 'heroicon-o-chat-bubble-left', 'color' => '#10b981']);
$chPhone = FeedbackChannel::create(['name' => 'Điện thoại', 'slug' => 'phone', 'icon' => 'heroicon-o-phone', 'color' => '#f59e0b']);
$chWalkin = FeedbackChannel::create(['name' => 'Trực tiếp', 'slug' => 'walk-in', 'icon' => 'heroicon-o-user', 'color' => '#ec4899']);
$chApp = FeedbackChannel::create(['name' => 'Ứng dụng', 'slug' => 'app', 'icon' => 'heroicon-o-device-phone-mobile', 'color' => '#8b5cf6']);
$products = [
['name' => 'Sunrise Apartment A1', 'description' => 'Luxury apartment in District 1, 3 bedrooms, river view', 'status' => 'active'],
['name' => 'Sunrise Apartment A2', 'description' => 'Premium apartment in District 1, 2 bedrooms, city view', 'status' => 'active'],
['name' => 'Green Valley Villa', 'description' => 'Standalone villa with private garden and pool', 'status' => 'active'],
['name' => 'Ocean Tower Office', 'description' => 'High-end office space in central business district', 'status' => 'sold_out'],
['name' => 'Park Hill Townhouse', 'description' => 'Modern townhouse near the park, 4 bedrooms', 'status' => 'inactive'],
];
// ============================================================
// 5. PRODUCTS (6 products)
// ============================================================
$p1 = Product::create(['name' => 'Sunrise Apartment A101', 'description' => 'Căn hộ 3PN, tầng 10, view sông, nội thất cao cấp', 'status' => 'active']);
$p2 = Product::create(['name' => 'Sunrise Apartment A202', 'description' => 'Căn hộ 2PN, tầng 20, view thành phố', 'status' => 'active']);
$p3 = Product::create(['name' => 'Green Valley Villa V05', 'description' => 'Biệt thự đơn lập, hồ bơi riêng, sân vườn 200m²', 'status' => 'active']);
$p4 = Product::create(['name' => 'Ocean Tower Office O12', 'description' => 'Văn phòng hạng A, tầng 12, trung tâm Q1', 'status' => 'sold_out']);
$p5 = Product::create(['name' => 'Park Hill Townhouse T08', 'description' => 'Nhà phố liền kề, 4PN, gần công viên', 'status' => 'active']);
$p6 = Product::create(['name' => 'Sunrise Apartment B305', 'description' => 'Căn hộ Studio, tầng 3, phù hợp đầu tư cho thuê', 'status' => 'inactive']);
foreach ($products as $product) {
Product::create($product);
}
// ============================================================
// 6. CUSTOMERS (6 customers)
// ============================================================
$c1 = Customer::create(['name' => 'Nguyễn Văn An', 'email' => 'nguyenvanan@gmail.com', 'phone' => '0909123456', 'address' => 'Quận 1, TP.HCM', 'status' => 'active']);
$c2 = Customer::create(['name' => 'Trần Thị Bình', 'email' => 'tranthibinh@gmail.com', 'phone' => '0918234567', 'address' => 'Quận 7, TP.HCM', 'status' => 'active']);
$c3 = Customer::create(['name' => 'Lê Hoàng Dũng', 'email' => 'lehoangdung@gmail.com', 'phone' => '0927345678', 'address' => 'Quận 2, TP.HCM', 'status' => 'active']);
$c4 = Customer::create(['name' => 'Phạm Minh Châu', 'email' => 'phamminhchau@gmail.com', 'phone' => '0936456789', 'address' => 'Bình Thạnh, TP.HCM', 'status' => 'active']);
$c5 = Customer::create(['name' => 'Hoàng Thị Mai', 'email' => 'hoangthimai@gmail.com', 'phone' => '0945567890', 'address' => 'Quận 9, TP.HCM', 'status' => 'active']);
$c6 = Customer::create(['name' => 'Đỗ Văn Phúc', 'email' => 'dovanphuc@gmail.com', 'phone' => '0954678901', 'address' => 'Thủ Đức, TP.HCM', 'status' => 'inactive']);
$customers = [
['name' => 'Nguyen Van A', 'email' => 'nguyenvana@example.com', 'phone' => '0909123456', 'address' => 'Hanoi'],
['name' => 'Tran Thi B', 'email' => 'tranthib@example.com', 'phone' => '0918234567', 'address' => 'Ho Chi Minh City'],
['name' => 'Le Van C', 'email' => 'levanc@example.com', 'phone' => '0927345678', 'address' => 'Da Nang'],
['name' => 'Pham Thi D', 'email' => 'phamthid@example.com', 'phone' => '0936456789', 'address' => 'Can Tho'],
];
// ============================================================
// 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']);
foreach ($customers as $customerData) {
Customer::create($customerData);
}
$customers = Customer::all();
$products = Product::where('status', 'active')->get();
$channels = FeedbackChannel::all();
$customers[0]->products()->attach($products[0]->id, ['purchase_date' => '2024-01-15']);
$customers[0]->products()->attach($products[1]->id, ['purchase_date' => '2024-06-01']);
$customers[1]->products()->attach($products[0]->id, ['purchase_date' => '2024-03-20']);
$customers[2]->products()->attach($products[2]->id, ['purchase_date' => '2024-09-10']);
$customers[3]->products()->attach($products[1]->id, ['purchase_date' => '2025-01-05']);
$customers[3]->products()->attach($products[2]->id, ['purchase_date' => '2025-02-15']);
$contract1 = \App\Models\Contract::create([
'product_id' => $products[0]->id,
'customer_id' => $customers[0]->id,
'type' => \App\Enums\ContractType::SALE->value,
'start_date' => '2024-01-15',
'status' => \App\Enums\ContractStatus::ACTIVE->value,
// ============================================================
// 8. CONTRACTS (6 contracts)
// ============================================================
$contract1 = Contract::create([
'product_id' => $p1->id, 'customer_id' => $c1->id,
'type' => ContractType::SALE->value,
'start_date' => '2024-01-15', 'end_date' => null,
'status' => ContractStatus::ACTIVE->value,
'signed_status' => 'Đã ký',
]);
$contract2 = \App\Models\Contract::create([
'product_id' => $products[1]->id,
'customer_id' => $customers[0]->id,
'type' => \App\Enums\ContractType::LEASE->value,
'start_date' => '2024-06-01',
'end_date' => '2026-06-01',
'status' => \App\Enums\ContractStatus::ACTIVE->value,
$contract2 = Contract::create([
'product_id' => $p2->id, 'customer_id' => $c1->id,
'type' => ContractType::LEASE->value,
'start_date' => '2024-06-01', 'end_date' => '2026-06-01',
'status' => ContractStatus::ACTIVE->value,
'signed_status' => 'Đã ký',
]);
$contract3 = \App\Models\Contract::create([
'product_id' => $products[0]->id,
'customer_id' => $customers[1]->id,
'type' => \App\Enums\ContractType::SALE->value,
'start_date' => '2024-03-20',
'status' => \App\Enums\ContractStatus::ACTIVE->value,
$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,
'signed_status' => 'Đã ký',
]);
$contract4 = \App\Models\Contract::create([
'product_id' => $products[2]->id,
'customer_id' => $customers[2]->id,
'type' => \App\Enums\ContractType::BCC->value,
'start_date' => '2024-09-10',
'end_date' => '2029-09-10',
'status' => \App\Enums\ContractStatus::ACTIVE->value,
$contract4 = Contract::create([
'product_id' => $p3->id, 'customer_id' => $c3->id,
'type' => ContractType::BCC->value,
'start_date' => '2024-09-10', 'end_date' => '2029-09-10',
'status' => ContractStatus::ACTIVE->value,
'signed_status' => 'Đang chờ ký',
]);
$contract5 = \App\Models\Contract::create([
'product_id' => $products[1]->id,
'customer_id' => $customers[3]->id,
'type' => \App\Enums\ContractType::LEASE->value,
'start_date' => '2025-01-05',
'end_date' => '2026-01-05',
'status' => \App\Enums\ContractStatus::EXPIRED->value,
$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,
'start_date' => '2024-11-01', 'end_date' => null,
'status' => ContractStatus::ACTIVE->value,
'signed_status' => 'Đã ký',
]);
$customerProduct1 = \App\Models\CustomerProduct::where('customer_id', $customers[0]->id)->where('product_id', $products[0]->id)->first();
$customerProduct2 = \App\Models\CustomerProduct::where('customer_id', $customers[0]->id)->where('product_id', $products[1]->id)->first();
$customerProduct3 = \App\Models\CustomerProduct::where('customer_id', $customers[1]->id)->where('product_id', $products[0]->id)->first();
// ============================================================
// 9. 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.']);
Handover::create(['product_id' => $p2->id, 'customer_id' => $c1->id, 'handover_date' => null, 'status' => HandoverStatus::READY->value, 'remark' => 'Căn hộ đã hoàn thiện, chờ khách xác nhận lịch bàn giao.']);
Handover::create(['product_id' => $p3->id, 'customer_id' => $c3->id, 'handover_date' => '2024-10-01', 'status' => HandoverStatus::SCHEDULED->value, 'remark' => 'Đã hẹn lịch 10h sáng ngày 01/10/2024.']);
Handover::create(['product_id' => $p5->id, 'customer_id' => $c4->id, 'handover_date' => null, 'status' => HandoverStatus::NOT_READY->value, 'remark' => 'Đang hoàn thiện nội thất, dự kiến đủ điều kiện sau 2 tuần.']);
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.']);
\App\Models\Handover::create([
'product_id' => $products[0]->id,
'customer_id' => $customers[0]->id,
'handover_date' => '2024-02-15',
'status' => \App\Enums\HandoverStatus::HANDED_OVER->value,
'remark' => 'Đã bàn giao đầy đủ chìa khóa và thẻ căn hộ.',
]);
// ============================================================
// 10. 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.']);
ProductService::create(['product_id' => $p2->id, 'service_type' => ServiceType::MANAGEMENT_FEE->value, 'status' => 'pending', 'actual_collection_date' => null, 'remark' => 'Chưa thu phí quản lý quý 1/2025.']);
ProductService::create(['product_id' => $p3->id, 'service_type' => ServiceType::SELF_BUSINESS->value, 'status' => 'active', 'actual_collection_date' => '2024-10-01', 'remark' => 'Dịch vụ cho thuê hồ bơi và BBQ khu Villa.']);
ProductService::create(['product_id' => $p5->id, 'service_type' => ServiceType::GRATITUDE->value, 'status' => 'cancelled', 'actual_collection_date' => null, 'remark' => 'KH từ chối nhận quà, chuyển sang đợt sau.']);
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.']);
\App\Models\Handover::create([
'product_id' => $products[0]->id,
'customer_id' => $customers[1]->id,
'handover_date' => '2024-04-20',
'status' => \App\Enums\HandoverStatus::HANDED_OVER->value,
'remark' => 'Đã bàn giao, còn thiếu sổ bảo hành nội thất.',
]);
// ============================================================
// 11. 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']);
$tagWarranty = FeedbackTag::create(['name' => 'Bảo hành', 'slug' => 'warranty', 'color' => '#10b981']);
$tagMaintenance = FeedbackTag::create(['name' => 'Bảo trì', 'slug' => 'maintenance', 'color' => '#8b5cf6']);
$tagComplaint = FeedbackTag::create(['name' => 'Phàn nàn', 'slug' => 'complaint', 'color' => '#ef4444']);
$tagSuggestion = FeedbackTag::create(['name' => 'Đề xuất', 'slug' => 'suggestion', 'color' => '#06b6d4']);
\App\Models\Handover::create([
'product_id' => $products[1]->id,
'customer_id' => $customers[0]->id,
'status' => \App\Enums\HandoverStatus::READY->value,
'remark' => 'Căn hộ đã hoàn thiện, chờ khách xác nhận lịch bàn giao.',
]);
// ============================================================
// 12. FEEDBACKS (8 feedbacks - various statuses)
// ============================================================
\App\Models\Handover::create([
'product_id' => $products[2]->id,
'customer_id' => $customers[2]->id,
'handover_date' => '2024-10-01',
'status' => \App\Enums\HandoverStatus::SCHEDULED->value,
'remark' => 'Đã hẹn lịch 10h sáng ngày 01/10/2024.',
]);
\App\Models\Handover::create([
'product_id' => $products[1]->id,
'customer_id' => $customers[3]->id,
'status' => \App\Enums\HandoverStatus::NOT_READY->value,
'remark' => 'Đang hoàn thiện nội thất, dự kiến đủ điều kiện sau 2 tuần.',
]);
\App\Models\ProductService::create([
'product_id' => $products[0]->id,
'service_type' => \App\Enums\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.',
]);
\App\Models\ProductService::create([
'product_id' => $products[0]->id,
'service_type' => \App\Enums\ServiceType::GRATITUDE->value,
'status' => 'completed',
'actual_collection_date' => '2024-06-15',
'remark' => 'Quà tri ân khách hàng dịp sinh nhật BQL.',
]);
\App\Models\ProductService::create([
'product_id' => $products[1]->id,
'service_type' => \App\Enums\ServiceType::MANAGEMENT_FEE->value,
// 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,
'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',
'content' => 'Sau trận mưa lớn ngày 25/04, trần phòng khách xuất hiện vết nước và nhỏ giọt. Đề nghị kiểm tra và sửa chữa khẩn cấp.',
'status' => 'pending',
'remark' => 'Chưa thu phí quản lý quý 1/2025.',
]);
\App\Models\ProductService::create([
'product_id' => $products[2]->id,
'service_type' => \App\Enums\ServiceType::SELF_BUSINESS->value,
'status' => 'active',
'actual_collection_date' => '2024-10-01',
'remark' => 'Dịch vụ cho thuê hồ bơi và BBQ khu Villa.',
// 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,
'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',
'content' => 'Tôi muốn nâng cấp từ 1 chỗ đậu xe lên 2 chỗ. Vui lòng tư vấn giá cả và thủ tục.',
'status' => 'processing',
]);
\App\Models\ProductService::create([
'product_id' => $products[1]->id,
'service_type' => \App\Enums\ServiceType::GRATITUDE->value,
'status' => 'cancelled',
'remark' => 'KH từ chối nhận quà, chuyển sang đợt sau.',
// 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,
'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',
'content' => 'Điều hòa Panasonic Inverter 1.5HP trong phòng ngủ chính phát ra tiếng ồn lớn và không làm mát hiệu quả. Đã vệ sinh lưới lọc nhưng không cải thiện.',
'status' => 'resolved',
]);
$feedbacks = [
[
'customer_id' => $customers[0]->id,
'customer_product_id' => $customerProduct1->id,
'contract_id' => $contract1->id,
'feedback_channel_id' => $channels->firstWhere('slug', 'email')->id,
'title' => 'Leaking ceiling in living room',
'content' => 'I noticed water stains on the ceiling of the living room after heavy rain. Please send someone to inspect and fix.',
'status' => 'pending',
'assigned_to' => $staff->id,
'current_department_id' => $depCskh->id,
],
[
'customer_id' => $customers[0]->id,
'customer_product_id' => $customerProduct2->id,
'contract_id' => $contract2->id,
'feedback_channel_id' => $channels->firstWhere('slug', 'phone')->id,
'title' => 'Request for parking slot upgrade',
'content' => 'I would like to upgrade from one parking slot to two. Please advise on availability and pricing.',
'status' => 'processing',
'assigned_to' => $manager->id,
'current_department_id' => $depCskh->id,
],
[
'customer_id' => $customers[1]->id,
'customer_product_id' => $customerProduct3->id,
'contract_id' => $contract3->id,
'feedback_channel_id' => $channels->firstWhere('slug', 'zalo')->id,
'title' => 'AC not cooling properly',
'content' => 'The air conditioner in the master bedroom is making loud noises and not cooling effectively.',
'status' => 'resolved',
'assigned_to' => $staff->id,
'current_department_id' => $depKythuat->id,
],
[
'customer_id' => $customers[2]->id,
'customer_product_id' => null,
'contract_id' => null,
'feedback_channel_id' => $channels->firstWhere('slug', 'document')->id,
'title' => 'General feedback on community services',
'content' => 'I suggest improving the garbage collection schedule to twice a day instead of once. Also, the security guard shift changes could be more organized.',
'status' => 'pending',
'assigned_to' => null,
'current_department_id' => $depCskh->id,
],
[
'customer_id' => $customers[3]->id,
'customer_product_id' => \App\Models\CustomerProduct::where('customer_id', $customers[3]->id)->where('product_id', $products[1]->id)->first()->id,
'contract_id' => $contract5->id,
'feedback_channel_id' => $channels->firstWhere('slug', 'email')->id,
'title' => 'Kitchen cabinet hinge broken',
'content' => 'One of the kitchen cabinet hinges is broken. It is still under warranty, please arrange replacement.',
'status' => 'closed',
'assigned_to' => $staff->id,
'current_department_id' => $depKythuat->id,
],
];
// Feedback 4: Pending - Góp ý cải thiện dịch vụ
$fb4 = Feedback::create([
'customer_id' => $c3->id, 'customer_product_id' => null, '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',
'content' => 'Tôi đề xuất tăng tần suất thu gom rác lên 2 lần/ngày (hiện tại 1 lần). Khu vực hành lang tầng 3 thường xuyên có mùi khó chịu vào buổi chiều.',
'status' => 'pending',
]);
foreach ($feedbacks as $feedback) {
Feedback::create($feedback);
}
// Feedback 5: Closed - Bản lề tủ bếp
$cp5 = CustomerProduct::where('customer_id', $c4->id)->where('product_id', $p2->id)->first();
$fb5 = Feedback::create([
'customer_id' => $c4->id, 'customer_product_id' => $cp5->id, 'contract_id' => $contract5->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',
'content' => 'Bản lề cánh tủ bếp trên bị gãy, không đóng được. Còn trong thời gian bảo hành, đề nghị thay thế.',
'status' => 'closed',
]);
$tags = [
['name' => 'Leaking', 'slug' => 'leaking', 'color' => '#3b82f6'],
['name' => 'Electrical', 'slug' => 'electrical', 'color' => '#f59e0b'],
['name' => 'Warranty', 'slug' => 'warranty', 'color' => '#10b981'],
['name' => 'Maintenance', 'slug' => 'maintenance', 'color' => '#8b5cf6'],
['name' => 'Service Request', 'slug' => 'service-request', 'color' => '#ec4899'],
];
// 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,
'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',
'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',
]);
foreach ($tags as $tag) {
\App\Models\FeedbackTag::create($tag);
}
// Feedback 7: Resolved - Hợp đồng thuê
$fb7 = Feedback::create([
'customer_id' => $c4->id, 'customer_product_id' => null, 'contract_id' => $contract5->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ê',
'content' => 'Hợp đồng thuê căn hộ A202 sẽ hết hạn vào 01/2026. Tôi muốn gia hạn thêm 2 năm, vui lòng tư vấn thủ tục và giá thuê mới.',
'status' => 'resolved',
]);
$allFeedback = Feedback::all();
$allTags = \App\Models\FeedbackTag::all();
// Feedback 8: Pending - Phàn nàn về tiếng ồn
$fb8 = Feedback::create([
'customer_id' => $c2->id, 'customer_product_id' => $cp3->id, 'contract_id' => $contract3->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',
'content' => 'Căn hộ tầng trên thường xuyên gây tiếng ồn sau 22h, ảnh hưởng đến giấc ngủ gia đình tôi. Đã phản ánh 2 lần nhưng chưa được giải quyết.',
'status' => 'pending',
]);
$allFeedback[0]->tags()->attach([$allTags[0]->id, $allTags[3]->id]);
$allFeedback[1]->tags()->attach([$allTags[4]->id]);
$allFeedback[2]->tags()->attach([$allTags[1]->id, $allTags[2]->id]);
$allFeedback[3]->tags()->attach([$allTags[3]->id]);
$allFeedback[4]->tags()->attach([$allTags[2]->id, $allTags[3]->id]);
// ============================================================
// 13. TAG ATTACHMENTS
// ============================================================
$fb1->tags()->attach([$tagLeaking->id, $tagMaintenance->id]);
$fb2->tags()->attach([$tagSuggestion->id]);
$fb3->tags()->attach([$tagElectrical->id, $tagWarranty->id]);
$fb4->tags()->attach([$tagSuggestion->id]);
$fb5->tags()->attach([$tagWarranty->id, $tagMaintenance->id]);
$fb6->tags()->attach([$tagElectrical->id, $tagComplaint->id]);
$fb7->tags()->attach([$tagSuggestion->id]);
$fb8->tags()->attach([$tagComplaint->id]);
\App\Models\FeedbackInteraction::create([
'feedback_id' => $allFeedback[0]->id,
'user_id' => $admin->id,
'type' => 'note',
'content' => 'Feedback received via Email. Assigned to Staff for initial handling.',
// ============================================================
// 14. FEEDBACK INTERACTIONS (12 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ý.',
'changes' => ['status' => ['old' => null, 'new' => 'pending']],
]);
\App\Models\FeedbackInteraction::create([
'feedback_id' => $allFeedback[0]->id,
'user_id' => $staff->id,
'type' => 'note',
'content' => 'Contacted customer via phone. Scheduled inspection for next Tuesday. Customer agreed.',
FeedbackInteraction::create([
'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.',
]);
\App\Models\FeedbackInteraction::create([
'feedback_id' => $allFeedback[2]->id,
'user_id' => $staff->id,
'type' => 'status_change',
'content' => 'Technician visited site on 2024-06-10. AC repaired. Customer confirmed cooling is now normal.',
// 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']],
]);
\App\Models\FeedbackInteraction::create([
'feedback_id' => $allFeedback[1]->id,
'user_id' => $manager->id,
'type' => 'note',
'content' => 'Parking upgrade available. Sent quotation via email. Waiting for customer confirmation.',
]);
\App\Models\FeedbackInteraction::create([
'feedback_id' => $allFeedback[4]->id,
'user_id' => $staff->id,
'type' => 'status_change',
'content' => 'Replacement hinge installed on 2025-03-01. All kitchen cabinets now working properly.',
// 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']],
]);
\App\Models\TicketTransferLog::create([
'feedback_id' => $allFeedback[2]->id,
'from_department_id' => $depCskh->id,
'to_department_id' => $depKythuat->id,
'sender_id' => $manager->id,
// 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.',
]);
FeedbackInteraction::create([
'feedback_id' => $fb6->id, 'user_id' => $staffA->id, 'type' => 'status_change',
'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ý.',
'changes' => ['assignment' => ['old' => 'Chưa phân công', 'new' => 'Hoàng Văn Phụ']],
]);
FeedbackInteraction::create([
'feedback_id' => $fb7->id, 'user_id' => $staffB->id, 'type' => 'status_change',
'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)
// ============================================================
TicketTransferLog::create([
'feedback_id' => $fb3->id,
'from_department_id' => $deptCskh->id,
'to_department_id' => $deptKt->id,
'sender_id' => $managerCskh->id,
'reason' => 'Vấn đề kỹ thuật về điều hòa, cần Phòng Kỹ thuật kiểm tra và xử lý.',
]);
$disk = \Illuminate\Support\Facades\Storage::disk('local');
$disk->put('feedback-attachments/ac_repair_report.pdf', '%PDF-1.4 Demo report content');
\App\Models\FeedbackAttachment::create([
'uuid' => \Illuminate\Support\Str::uuid(),
'feedback_id' => $allFeedback[2]->id,
'user_id' => $staff->id,
'name' => 'ac_repair_report.pdf',
'path' => 'feedback-attachments/ac_repair_report.pdf',
'disk' => 'local',
'collection' => 'proof_of_resolution',
'mime_type' => 'application/pdf',
'size' => $disk->size('feedback-attachments/ac_repair_report.pdf'),
TicketTransferLog::create([
'feedback_id' => $fb7->id,
'from_department_id' => $deptCskh->id,
'to_department_id' => $deptPhaply->id,
'sender_id' => $managerCskh->id,
'reason' => 'Yêu cầu gia hạn hợp đồng thuộc thẩm quyền Phòng Pháp lý.',
]);
$disk->put('feedback-attachments/ceiling_photo.jpg', 'dummy-jpeg-content');
\App\Models\FeedbackAttachment::create([
'uuid' => \Illuminate\Support\Str::uuid(),
'feedback_id' => $allFeedback[0]->id,
'user_id' => $staff->id,
'name' => 'ceiling_photo.jpg',
'path' => 'feedback-attachments/ceiling_photo.jpg',
'disk' => 'local',
'collection' => 'customer_evidence',
'mime_type' => 'image/jpeg',
'size' => $disk->size('feedback-attachments/ceiling_photo.jpg'),
]);
// ============================================================
// 16. FEEDBACK ATTACHMENTS (6 attachments - public disk)
// ============================================================
$disk = Storage::disk('public');
$disk->put('feedback-attachments/replaced_hinge_photo.png', 'dummy-png-content');
\App\Models\FeedbackAttachment::create([
'uuid' => \Illuminate\Support\Str::uuid(),
'feedback_id' => $allFeedback[4]->id,
'user_id' => $staff->id,
'name' => 'replaced_hinge_photo.png',
'path' => 'feedback-attachments/replaced_hinge_photo.png',
'disk' => 'local',
'collection' => 'proof_of_resolution',
'mime_type' => 'image/png',
'size' => $disk->size('feedback-attachments/replaced_hinge_photo.png'),
// 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/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
FeedbackAttachment::create([
'uuid' => (string) Str::uuid(),
'feedback_id' => $fb3->id, 'user_id' => $staffA->id,
'name' => 'bao-cao-kiem-tra-dieu-hoa.pdf',
'path' => 'feedback-attachments/bao-cao-kiem-tra-dieu-hoa.pdf',
'disk' => 'public', 'collection' => 'proof_of_resolution',
'mime_type' => 'application/pdf', 'size' => $disk->size('feedback-attachments/bao-cao-kiem-tra-dieu-hoa.pdf'),
]);
FeedbackAttachment::create([
'uuid' => (string) Str::uuid(),
'feedback_id' => $fb1->id, 'user_id' => $staffA->id,
'name' => 'anh-tran-ro-ri.jpg',
'path' => 'feedback-attachments/anh-tran-ro-ri.jpg',
'disk' => 'public', 'collection' => 'customer_evidence',
'mime_type' => 'image/jpeg', 'size' => $disk->size('feedback-attachments/anh-tran-ro-ri.jpg'),
]);
FeedbackAttachment::create([
'uuid' => (string) Str::uuid(),
'feedback_id' => $fb5->id, 'user_id' => $staffB->id,
'name' => 'anh-ban-le-hong.png',
'path' => 'feedback-attachments/anh-ban-le-hong.png',
'disk' => 'public', 'collection' => 'proof_of_resolution',
'mime_type' => 'image/png', 'size' => $disk->size('feedback-attachments/anh-ban-le-hong.png'),
]);
FeedbackAttachment::create([
'uuid' => (string) Str::uuid(),
'feedback_id' => $fb2->id, 'user_id' => $managerCskh->id,
'name' => 'bao-gia-nang-cap.pdf',
'path' => 'feedback-attachments/bao-gia-nang-cap.pdf',
'disk' => 'public', 'collection' => 'general',
'mime_type' => 'application/pdf', 'size' => $disk->size('feedback-attachments/bao-gia-nang-cap.pdf'),
]);
FeedbackAttachment::create([
'uuid' => (string) Str::uuid(),
'feedback_id' => $fb7->id, 'user_id' => $staffB->id,
'name' => 'phu-luc-hop-dong.pdf',
'path' => 'feedback-attachments/phu-luc-hop-dong.pdf',
'disk' => 'public', 'collection' => 'proof_of_resolution',
'mime_type' => 'application/pdf', 'size' => $disk->size('feedback-attachments/phu-luc-hop-dong.pdf'),
]);
FeedbackAttachment::create([
'uuid' => (string) Str::uuid(),
'feedback_id' => $fb6->id, 'user_id' => $staffA->id,
'name' => 'anh-o-cam-hu.jpg',
'path' => 'feedback-attachments/anh-o-cam-hu.jpg',
'disk' => 'public', 'collection' => 'customer_evidence',
'mime_type' => 'image/jpeg', 'size' => $disk->size('feedback-attachments/anh-o-cam-hu.jpg'),
]);
}
}