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

@@ -5,7 +5,6 @@ namespace App\Console\Commands;
use App\Services\ActivityLogger;
use App\Models\Contract;
use App\Models\Customer;
use App\Models\CustomerProduct;
use App\Models\Feedback;
use App\Models\FeedbackInteraction;
use App\Models\Handover;
@@ -22,7 +21,7 @@ class ImportCskh extends Command
{file_path : Path to CSV/Excel file}
{--dry-run : Analyze only, do not write to database}';
protected $description = 'Import dữ liệu CSKH từ file Excel/CSV vào database relational';
protected $description = 'Import dữ liệu CSKH từ file Excel/CSV vào database relational (V2)';
private int $statsProducts = 0;
private int $statsCustomers = 0;
@@ -123,11 +122,6 @@ class ImportCskh extends Command
return self::SUCCESS;
}
private function isMetaRow(array $row): bool
{
return $this->getMetaRowReason($row) !== null;
}
private function getMetaRowReason(array $row): ?string
{
$code = $row['Mã căn hộ'] ?? '';
@@ -210,8 +204,6 @@ class ImportCskh extends Command
$product = $this->findOrCreateProduct($productCode);
$customer = $this->findOrCreateCustomer($customerName);
$this->ensureCustomerProduct($product, $customer);
$this->processContracts($row, $product, $customer);
$this->processHandover($row, $product, $customer);
$this->processServices($row, $product);
@@ -250,14 +242,6 @@ class ImportCskh extends Command
return $c;
}
private function ensureCustomerProduct(Product $product, Customer $customer): void
{
CustomerProduct::firstOrCreate([
'customer_id' => $customer->id,
'product_id' => $product->id,
]);
}
private function processContracts(array $row, Product $product, Customer $customer): void
{
$leaseValue = $row['HỢP ĐỒNG THUÊ'] ?? null;
@@ -265,14 +249,16 @@ class ImportCskh extends Command
if (! empty($leaseStr) && ! is_numeric($leaseStr) && $leaseStr !== 'Tình trạng') {
$exists = Contract::where('product_id', $product->id)
->where('customer_id', $customer->id)
->where('type', 'lease')
->where('category', 'business')
->where('type', 'rental')
->exists();
if (! $exists) {
Contract::create([
'product_id' => $product->id,
'customer_id' => $customer->id,
'type' => 'lease',
'category' => 'business',
'type' => 'rental',
'status' => 'active',
]);
$this->statsContracts++;
@@ -284,6 +270,7 @@ class ImportCskh extends Command
if (! empty($bccStr) && ! is_numeric($bccStr) && $bccStr !== 'Tình trạng HĐ') {
$exists = Contract::where('product_id', $product->id)
->where('customer_id', $customer->id)
->where('category', 'business')
->where('type', 'bcc')
->exists();
@@ -291,6 +278,7 @@ class ImportCskh extends Command
Contract::create([
'product_id' => $product->id,
'customer_id' => $customer->id,
'category' => 'business',
'type' => 'bcc',
'status' => 'active',
'signed_status' => $bccStr,
@@ -386,20 +374,15 @@ class ImportCskh extends Command
$title = 'Ticket từ dữ liệu lịch sử';
$customerProduct = CustomerProduct::where('customer_id', $customer->id)
->where('product_id', $product->id)
->first();
$feedback = Feedback::firstOrCreate(
[
'customer_id' => $customer->id,
'customer_product_id' => $customerProduct?->id,
'contract_id' => $activeContract?->id,
'title' => $title,
],
[
'content' => $content,
'status' => 'pending',
'contract_id' => $activeContract?->id,
'feedback_channel_id' => 1,
]
);
@@ -429,9 +412,6 @@ class ImportCskh extends Command
}
}
/**
* Parse the PHP DateTime JSON format: {"date":"2021-06-09 00:00:00.000000","timezone_type":3,"timezone":"UTC"}
*/
private function parseHandoverDate(mixed $value): ?string
{
if (empty($value)) {