396 lines
18 KiB
PHP
396 lines
18 KiB
PHP
<?php
|
|
|
|
namespace Database\Seeders;
|
|
|
|
use App\Models\Customer;
|
|
use App\Models\Department;
|
|
use App\Models\Feedback;
|
|
use App\Models\FeedbackChannel;
|
|
use App\Models\Product;
|
|
use App\Models\User;
|
|
use Illuminate\Database\Seeder;
|
|
use Spatie\Permission\Models\Role;
|
|
|
|
class AfterSalesSeeder extends Seeder
|
|
{
|
|
public function run(): void
|
|
{
|
|
Role::create(['name' => 'admin']);
|
|
Role::create(['name' => 'manager']);
|
|
Role::create(['name' => 'staff']);
|
|
|
|
$admin = User::create([
|
|
'name' => 'Admin',
|
|
'email' => 'admin@minicrm.local',
|
|
'password' => bcrypt('password'),
|
|
'role' => 'admin',
|
|
]);
|
|
$admin->assignRole('admin');
|
|
|
|
$manager = User::create([
|
|
'name' => 'Manager',
|
|
'email' => 'manager@minicrm.local',
|
|
'password' => bcrypt('password'),
|
|
'role' => 'manager',
|
|
]);
|
|
$manager->assignRole('manager');
|
|
|
|
$staff = User::create([
|
|
'name' => 'Staff',
|
|
'email' => 'staff@minicrm.local',
|
|
'password' => bcrypt('password'),
|
|
'role' => 'staff',
|
|
]);
|
|
$staff->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]);
|
|
|
|
$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'],
|
|
];
|
|
|
|
foreach ($channels as $channel) {
|
|
FeedbackChannel::create($channel);
|
|
}
|
|
|
|
$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'],
|
|
];
|
|
|
|
foreach ($products as $product) {
|
|
Product::create($product);
|
|
}
|
|
|
|
$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'],
|
|
];
|
|
|
|
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,
|
|
'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,
|
|
'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,
|
|
'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,
|
|
'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,
|
|
'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();
|
|
|
|
\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ộ.',
|
|
]);
|
|
|
|
\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.',
|
|
]);
|
|
|
|
\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.',
|
|
]);
|
|
|
|
\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,
|
|
'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.',
|
|
]);
|
|
|
|
\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.',
|
|
]);
|
|
|
|
$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,
|
|
],
|
|
];
|
|
|
|
foreach ($feedbacks as $feedback) {
|
|
Feedback::create($feedback);
|
|
}
|
|
|
|
$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'],
|
|
];
|
|
|
|
foreach ($tags as $tag) {
|
|
\App\Models\FeedbackTag::create($tag);
|
|
}
|
|
|
|
$allFeedback = Feedback::all();
|
|
$allTags = \App\Models\FeedbackTag::all();
|
|
|
|
$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]);
|
|
|
|
\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.',
|
|
'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.',
|
|
]);
|
|
|
|
\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.',
|
|
'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.',
|
|
'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,
|
|
'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'),
|
|
]);
|
|
|
|
$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'),
|
|
]);
|
|
|
|
$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'),
|
|
]);
|
|
}
|
|
}
|