Init: Hoan thanh kien truc V3 va Filament UI
This commit is contained in:
1
database/.gitignore
vendored
Normal file
1
database/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
*.sqlite*
|
||||
29
database/factories/ContractFactory.php
Normal file
29
database/factories/ContractFactory.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Contract;
|
||||
use App\Models\Product;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class ContractFactory extends Factory
|
||||
{
|
||||
protected $model = Contract::class;
|
||||
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'product_id' => Product::factory(),
|
||||
'contract_number' => 'HDMB-' . $this->faker->unique()->numberBetween(10000, 99999),
|
||||
'contract_type' => 'HĐMB',
|
||||
'signing_date' => $this->faker->date(),
|
||||
'status' => 'Đang hiệu lực',
|
||||
'total_value' => fn (array $attributes) => Product::find($attributes['product_id'])->total_price,
|
||||
'paid_amount' => function (array $attributes) {
|
||||
$total = Product::find($attributes['product_id'])->total_price;
|
||||
return $this->faker->randomFloat(2, 0, $total);
|
||||
},
|
||||
'transfer_order' => 0,
|
||||
];
|
||||
}
|
||||
}
|
||||
28
database/factories/CustomerFactory.php
Normal file
28
database/factories/CustomerFactory.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Customer;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class CustomerFactory extends Factory
|
||||
{
|
||||
protected $model = Customer::class;
|
||||
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'full_name' => $this->faker->name(),
|
||||
'cmnd_cccd' => $this->faker->unique()->numerify('0##########'),
|
||||
'phone' => $this->faker->phoneNumber(),
|
||||
'email' => $this->faker->unique()->safeEmail(),
|
||||
'address' => [
|
||||
'street' => $this->faker->streetAddress(),
|
||||
'ward' => 'Phường ' . $this->faker->numberBetween(1, 15),
|
||||
'district' => 'Quận ' . $this->faker->numberBetween(1, 12),
|
||||
'city' => $this->faker->city(),
|
||||
],
|
||||
'dob' => $this->faker->date(),
|
||||
];
|
||||
}
|
||||
}
|
||||
43
database/factories/ProductFactory.php
Normal file
43
database/factories/ProductFactory.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Product;
|
||||
use App\Models\Project;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class ProductFactory extends Factory
|
||||
{
|
||||
protected $model = Product::class;
|
||||
|
||||
public function definition(): array
|
||||
{
|
||||
$type = $this->faker->randomElement(['LAND', 'APARTMENT']);
|
||||
$area = $this->faker->randomFloat(2, 50, 200);
|
||||
$pricePerUnit = $this->faker->numberBetween(20, 100) * 1000000; // 20M to 100M VND
|
||||
|
||||
$customData = match ($type) {
|
||||
'LAND' => [
|
||||
'frontage' => $this->faker->numberBetween(1, 3),
|
||||
'road_width' => $this->faker->numberBetween(6, 30),
|
||||
],
|
||||
'APARTMENT' => [
|
||||
'block' => $this->faker->randomElement(['A', 'B', 'C']),
|
||||
'floor' => $this->faker->numberBetween(2, 30),
|
||||
'view' => $this->faker->randomElement(['Hồ bơi', 'Công viên', 'Thành phố']),
|
||||
],
|
||||
};
|
||||
|
||||
return [
|
||||
'project_id' => Project::factory(),
|
||||
'product_type' => $type,
|
||||
'code' => 'STH-' . $this->faker->unique()->numberBetween(1000, 9999),
|
||||
'area' => $area,
|
||||
'price_per_unit' => $pricePerUnit,
|
||||
'total_price' => $area * $pricePerUnit,
|
||||
'custom_data' => $customData,
|
||||
'status' => 'Đang mở bán',
|
||||
'red_book_status' => 'Chưa có dữ liệu',
|
||||
];
|
||||
}
|
||||
}
|
||||
20
database/factories/ProjectFactory.php
Normal file
20
database/factories/ProjectFactory.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Project;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class ProjectFactory extends Factory
|
||||
{
|
||||
protected $model = Project::class;
|
||||
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'name' => 'Khu đô thị HQLand ' . $this->faker->unique()->city(),
|
||||
'type' => $this->faker->randomElement(['Khu đô thị', 'Chung cư', 'Đất nền phân lô']),
|
||||
'address' => $this->faker->address(),
|
||||
];
|
||||
}
|
||||
}
|
||||
45
database/factories/UserFactory.php
Normal file
45
database/factories/UserFactory.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* @extends Factory<User>
|
||||
*/
|
||||
class UserFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* The current password being used by the factory.
|
||||
*/
|
||||
protected static ?string $password;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'name' => fake()->name(),
|
||||
'email' => fake()->unique()->safeEmail(),
|
||||
'email_verified_at' => now(),
|
||||
'password' => static::$password ??= Hash::make('password'),
|
||||
'remember_token' => Str::random(10),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the model's email address should be unverified.
|
||||
*/
|
||||
public function unverified(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'email_verified_at' => null,
|
||||
]);
|
||||
}
|
||||
}
|
||||
43
database/migrations/0001_01_01_000000_create_users_table.php
Normal file
43
database/migrations/0001_01_01_000000_create_users_table.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('users', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name');
|
||||
$table->string('email')->unique();
|
||||
$table->timestamp('email_verified_at')->nullable();
|
||||
$table->string('password');
|
||||
$table->rememberToken();
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
Schema::create('password_reset_tokens', function (Blueprint $table) {
|
||||
$table->string('email')->primary();
|
||||
$table->string('token');
|
||||
$table->timestamp('created_at')->nullable();
|
||||
});
|
||||
|
||||
Schema::create('sessions', function (Blueprint $table) {
|
||||
$table->string('id')->primary();
|
||||
$table->foreignId('user_id')->nullable()->index();
|
||||
$table->string('ip_address', 45)->nullable();
|
||||
$table->text('user_agent')->nullable();
|
||||
$table->longText('payload');
|
||||
$table->integer('last_activity')->index();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('users');
|
||||
Schema::dropIfExists('password_reset_tokens');
|
||||
Schema::dropIfExists('sessions');
|
||||
}
|
||||
};
|
||||
29
database/migrations/0001_01_01_000001_create_cache_table.php
Normal file
29
database/migrations/0001_01_01_000001_create_cache_table.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('cache', function (Blueprint $table) {
|
||||
$table->string('key')->primary();
|
||||
$table->mediumText('value');
|
||||
$table->integer('expiration');
|
||||
});
|
||||
|
||||
Schema::create('cache_locks', function (Blueprint $table) {
|
||||
$table->string('key')->primary();
|
||||
$table->string('owner');
|
||||
$table->integer('expiration');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('cache');
|
||||
Schema::dropIfExists('cache_locks');
|
||||
}
|
||||
};
|
||||
51
database/migrations/0001_01_01_000002_create_jobs_table.php
Normal file
51
database/migrations/0001_01_01_000002_create_jobs_table.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('jobs', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('queue')->index();
|
||||
$table->longText('payload');
|
||||
$table->unsignedTinyInteger('attempts');
|
||||
$table->unsignedInteger('reserved_at')->nullable();
|
||||
$table->unsignedInteger('available_at');
|
||||
$table->unsignedInteger('created_at');
|
||||
});
|
||||
|
||||
Schema::create('job_batches', function (Blueprint $table) {
|
||||
$table->string('id')->primary();
|
||||
$table->string('name');
|
||||
$table->integer('total_jobs');
|
||||
$table->integer('pending_jobs');
|
||||
$table->integer('failed_jobs');
|
||||
$table->longText('failed_job_ids');
|
||||
$table->mediumText('options')->nullable();
|
||||
$table->integer('cancelled_at')->nullable();
|
||||
$table->integer('created_at');
|
||||
$table->integer('finished_at')->nullable();
|
||||
});
|
||||
|
||||
Schema::create('failed_jobs', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('uuid')->unique();
|
||||
$table->text('connection');
|
||||
$table->text('queue');
|
||||
$table->longText('payload');
|
||||
$table->longText('exception');
|
||||
$table->timestamp('failed_at')->useCurrent();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('jobs');
|
||||
Schema::dropIfExists('job_batches');
|
||||
Schema::dropIfExists('failed_jobs');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
return new class extends Migration {
|
||||
public function up(): void {
|
||||
Schema::create('projects', function (Blueprint $table) {
|
||||
$table->uuid('id')->primary();
|
||||
$table->string('name');
|
||||
$table->string('type');
|
||||
$table->string('address')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
public function down(): void { Schema::dropIfExists('projects'); }
|
||||
};
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
return new class extends Migration {
|
||||
public function up(): void {
|
||||
Schema::create('products', function (Blueprint $table) {
|
||||
$table->uuid('id')->primary();
|
||||
$table->foreignUuid('project_id')->constrained('projects')->cascadeOnDelete();
|
||||
$table->string('product_type');
|
||||
$table->string('code')->unique();
|
||||
$table->decimal('area', 10, 2);
|
||||
$table->decimal('price_per_unit', 15, 2)->nullable();
|
||||
$table->decimal('total_price', 15, 2);
|
||||
$table->jsonb('custom_data')->nullable(); // Chứa thông tin tầng, view, hướng...
|
||||
$table->string('status')->default('Đang mở bán');
|
||||
$table->string('red_book_status')->default('Chưa có dữ liệu');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
public function down(): void { Schema::dropIfExists('products'); }
|
||||
};
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
return new class extends Migration {
|
||||
public function up(): void {
|
||||
Schema::create('customers', function (Blueprint $table) {
|
||||
$table->uuid('id')->primary();
|
||||
$table->string('cmnd_cccd')->unique();
|
||||
$table->string('full_name');
|
||||
$table->string('phone')->nullable();
|
||||
$table->string('email')->nullable();
|
||||
$table->jsonb('address')->nullable(); // Lưu cấu trúc: số nhà, phường, quận...
|
||||
$table->date('dob')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
public function down(): void { Schema::dropIfExists('customers'); }
|
||||
};
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
return new class extends Migration {
|
||||
public function up(): void {
|
||||
Schema::create('contracts', function (Blueprint $table) {
|
||||
$table->uuid('id')->primary();
|
||||
$table->foreignUuid('product_id')->constrained('products')->cascadeOnDelete();
|
||||
$table->integer('transfer_order')->default(0);
|
||||
$table->string('contract_type')->default('HĐMB');
|
||||
$table->string('contract_number')->unique();
|
||||
$table->date('signing_date')->nullable();
|
||||
$table->string('status')->default('Đang hiệu lực');
|
||||
$table->decimal('total_value', 15, 2);
|
||||
$table->decimal('paid_amount', 15, 2)->default(0);
|
||||
// Cột ảo tự động tính số tiền còn lại, dev không cần query tính toán
|
||||
$table->decimal('remaining_amount', 15, 2)->virtualAs('total_value - paid_amount');
|
||||
$table->jsonb('metadata')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
public function down(): void { Schema::dropIfExists('contracts'); }
|
||||
};
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
return new class extends Migration {
|
||||
public function up(): void {
|
||||
Schema::create('contract_customers', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignUuid('contract_id')->constrained('contracts')->cascadeOnDelete();
|
||||
$table->foreignUuid('customer_id')->constrained('customers')->cascadeOnDelete();
|
||||
$table->string('role')->default('CHỦ SH 1'); // Đồng sở hữu
|
||||
$table->integer('transfer_order')->default(0);
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
public function down(): void { Schema::dropIfExists('contract_customers'); }
|
||||
};
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
return new class extends Migration {
|
||||
public function up(): void {
|
||||
Schema::create('appendices', function (Blueprint $table) {
|
||||
$table->uuid('id')->primary();
|
||||
$table->foreignUuid('contract_id')->constrained('contracts')->cascadeOnDelete();
|
||||
$table->foreignUuid('product_id')->constrained('products')->cascadeOnDelete();
|
||||
$table->string('type');
|
||||
$table->integer('apply_from_order')->default(0);
|
||||
$table->date('signing_date')->nullable();
|
||||
$table->jsonb('custom_data')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
public function down(): void { Schema::dropIfExists('appendices'); }
|
||||
};
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
return new class extends Migration {
|
||||
public function up(): void {
|
||||
Schema::create('settlements', function (Blueprint $table) {
|
||||
$table->uuid('id')->primary();
|
||||
$table->foreignUuid('product_id')->constrained('products')->cascadeOnDelete();
|
||||
$table->string('type'); // "MÓNG", "THÂN", "CP THI CÔNG"
|
||||
$table->decimal('temp_value', 15, 2)->default(0);
|
||||
$table->decimal('final_value', 15, 2)->default(0);
|
||||
$table->decimal('difference', 15, 2)->virtualAs('final_value - temp_value');
|
||||
$table->string('red_book_status')->nullable();
|
||||
$table->date('issue_date')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
public function down(): void { Schema::dropIfExists('settlements'); }
|
||||
};
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
return new class extends Migration {
|
||||
public function up(): void {
|
||||
Schema::create('payments', function (Blueprint $table) {
|
||||
$table->uuid('id')->primary();
|
||||
$table->foreignUuid('contract_id')->constrained('contracts')->cascadeOnDelete();
|
||||
$table->string('payment_type');
|
||||
$table->integer('installment_no')->default(1);
|
||||
$table->decimal('amount', 15, 2);
|
||||
$table->date('due_date')->nullable();
|
||||
$table->date('paid_date')->nullable();
|
||||
$table->string('status')->default('PENDING'); // PENDING, PAID, OVERDUE, CANCELLED
|
||||
$table->string('receipt_number')->nullable();
|
||||
$table->jsonb('metadata')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
public function down(): void { Schema::dropIfExists('payments'); }
|
||||
};
|
||||
109
database/seeders/DatabaseSeeder.php
Normal file
109
database/seeders/DatabaseSeeder.php
Normal file
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Models\Project;
|
||||
use App\Models\Product;
|
||||
use App\Models\Customer;
|
||||
use App\Models\Contract;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class DatabaseSeeder extends Seeder
|
||||
{
|
||||
public function run(): void
|
||||
{
|
||||
// 1. Xóa sạch dữ liệu cũ
|
||||
Schema::disableForeignKeyConstraints();
|
||||
Contract::query()->delete();
|
||||
Customer::query()->delete();
|
||||
Product::query()->delete();
|
||||
Project::query()->delete();
|
||||
Schema::enableForeignKeyConstraints();
|
||||
|
||||
// 2. Tạo tài khoản Admin mặc định
|
||||
User::updateOrCreate(
|
||||
['email' => 'admin@phuongtc.com'],
|
||||
[
|
||||
'name' => 'Administrator',
|
||||
'password' => Hash::make('1Qazxsw2@!321'),
|
||||
]
|
||||
);
|
||||
|
||||
// 3. Tạo 1 Dự án cố định và 1 Sản phẩm cố định STH-6535 để test
|
||||
$specialProject = Project::factory()->create(['name' => 'Dự án HQLand Center']);
|
||||
$specialProduct = Product::factory()->create([
|
||||
'project_id' => $specialProject->id,
|
||||
'code' => 'STH-6535',
|
||||
'status' => 'Đang mở bán'
|
||||
]);
|
||||
|
||||
// 4. Tạo thêm các Dự án và Sản phẩm ngẫu nhiên khác
|
||||
Project::factory(2)
|
||||
->has(Product::factory()->count(15), 'products')
|
||||
->create();
|
||||
|
||||
// 5. Tạo 20 Khách hàng
|
||||
Customer::factory(20)->create();
|
||||
|
||||
// 6. Tạo dữ liệu Lịch sử chuyển nhượng cho 10 sản phẩm (bao gồm cả STH-6535)
|
||||
$transferProducts = Product::limit(10)->get();
|
||||
$allCustomers = Customer::all();
|
||||
|
||||
foreach ($transferProducts as $product) {
|
||||
$baseValue = $product->total_price;
|
||||
|
||||
// --- Lần 1: Hợp đồng gốc (Mua từ CĐT) ---
|
||||
$contract1 = Contract::factory()->create([
|
||||
'product_id' => $product->id,
|
||||
'contract_type' => 'HĐMB',
|
||||
'transfer_order' => 1,
|
||||
'total_value' => $baseValue,
|
||||
'status' => 'Đã chuyển nhượng',
|
||||
'signing_date' => now()->subYears(2),
|
||||
]);
|
||||
$allCustomers->random()->contracts()->attach($contract1->id, ['role' => 'CHỦ CŨ', 'transfer_order' => 1]);
|
||||
|
||||
// --- Lần 2: Chuyển nhượng F1 ---
|
||||
$valueF1 = $baseValue * 1.1;
|
||||
$contract2 = Contract::factory()->create([
|
||||
'product_id' => $product->id,
|
||||
'contract_type' => 'VBCN',
|
||||
'transfer_order' => 2,
|
||||
'total_value' => $valueF1,
|
||||
'status' => 'Đã chuyển nhượng',
|
||||
'signing_date' => now()->subYear(),
|
||||
]);
|
||||
$allCustomers->random()->contracts()->attach($contract2->id, ['role' => 'CHỦ CŨ', 'transfer_order' => 2]);
|
||||
|
||||
// --- Lần 3: Chủ hiện tại (Sở hữu cuối cùng) ---
|
||||
$valueFinal = $valueF1 * 1.1;
|
||||
$contract3 = Contract::factory()->create([
|
||||
'product_id' => $product->id,
|
||||
'contract_type' => 'VBCN',
|
||||
'transfer_order' => 0,
|
||||
'total_value' => $valueFinal,
|
||||
'status' => 'Đang hiệu lực',
|
||||
'signing_date' => now(),
|
||||
]);
|
||||
$allCustomers->random()->contracts()->attach($contract3->id, ['role' => 'CHỦ SỞ HỮU', 'transfer_order' => 0]);
|
||||
|
||||
// Cập nhật trạng thái sản phẩm cuối cùng
|
||||
$product->update(['status' => 'Đã bán', 'total_price' => $valueFinal]);
|
||||
}
|
||||
|
||||
// 7. Tạo thêm 5 hợp đồng lẻ cho các sản phẩm còn lại để đa dạng hóa
|
||||
$remainingProducts = Product::where('status', 'Đang mở bán')->inRandomOrder()->limit(5)->get();
|
||||
foreach ($remainingProducts as $product) {
|
||||
$contract = Contract::factory()->create([
|
||||
'product_id' => $product->id,
|
||||
'transfer_order' => 0,
|
||||
'total_value' => $product->total_price,
|
||||
]);
|
||||
$allCustomers->random()->contracts()->attach($contract->id, ['role' => 'CHỦ SỞ HỮU', 'transfer_order' => 0]);
|
||||
$product->update(['status' => 'Đã bán']);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user