diff --git a/database/migrations/2026_07_21_000000_create_business_finance_tables.php b/database/migrations/2026_07_21_000000_create_business_finance_tables.php index 85edb3e6..a39b0703 100644 --- a/database/migrations/2026_07_21_000000_create_business_finance_tables.php +++ b/database/migrations/2026_07_21_000000_create_business_finance_tables.php @@ -11,7 +11,7 @@ return new class extends Migration // 1. 店铺后台税务数据 $this->createOrValidate('ak_biz_tax_data', ['id', 'company_id', 'company_name', 'real_ship_revenue', 'final_tax_revenue', 'period', 'created_at', 'updated_at'], function (Blueprint $table) { $table->id(); - $table->foreignId('company_id')->constrained('companies')->cascadeOnDelete(); + $table->unsignedInteger('company_id')->index(); $table->string('company_name')->default('')->comment('公司名称'); $table->decimal('real_ship_revenue', 18, 2)->default(0)->comment('公司真实发货业绩'); $table->decimal('zhongcai_revenue', 18, 2)->default(0)->comment('公司种菜业绩'); @@ -29,7 +29,7 @@ return new class extends Migration // 2. 财务SW规划表 $this->createOrValidate('ak_biz_sw_planning', ['id', 'company_id', 'company_name', 'final_tax_revenue', 'profit', 'period', 'created_at', 'updated_at'], function (Blueprint $table) { $table->id(); - $table->foreignId('company_id')->constrained('companies')->cascadeOnDelete(); + $table->unsignedInteger('company_id')->index(); $table->string('company_name')->default(''); $table->decimal('final_tax_revenue', 18, 2)->default(0)->comment('最终报税业绩'); $table->decimal('product_cost', 18, 2)->default(0)->comment('商品成本'); @@ -45,7 +45,7 @@ return new class extends Migration // 3. 实际SW统计表(多级表头,扁平化存储) $this->createOrValidate('biz_sw_actual', ['id', 'company_id', 'region', 'company_name', 'total_revenue', 'tax_burden_rate', 'created_at', 'updated_at'], function (Blueprint $table) { $table->id(); - $table->foreignId('company_id')->constrained('companies')->cascadeOnDelete(); + $table->unsignedInteger('company_id')->index(); $table->string('region')->default('')->comment('区域'); $table->string('company_type')->default('')->comment('公司类型'); $table->string('contact_person')->default('')->comment('对接人'); @@ -103,7 +103,7 @@ return new class extends Migration // 4. 公司店铺数据 $this->createOrValidate('biz_company_stores', ['id', 'company_id', 'company_name', 'store_name', 'store_revenue', 'company_revenue', 'period', 'created_at', 'updated_at'], function (Blueprint $table) { $table->id(); - $table->foreignId('company_id')->constrained('companies')->cascadeOnDelete(); + $table->unsignedInteger('company_id')->index(); $table->string('company_name')->default('')->comment('公司名称'); $table->string('store_name')->default('')->comment('店铺名称'); $table->decimal('store_revenue', 18, 2)->default(0)->comment('店铺业绩'); @@ -117,7 +117,7 @@ return new class extends Migration // 5. 店铺变更统计表 $this->createOrValidate('ak_biz_store_changes', ['id', 'company_id', 'store_name', 'change_date', 'previous_entity', 'created_at', 'updated_at'], function (Blueprint $table) { $table->id(); - $table->foreignId('company_id')->constrained('companies')->cascadeOnDelete(); + $table->unsignedInteger('company_id')->index(); $table->string('store_name')->default('')->comment('店铺名称'); $table->string('store_entity')->default('')->comment('店铺主体'); $table->date('change_date')->nullable()->comment('变更时间'); @@ -129,7 +129,7 @@ return new class extends Migration // 6. 发票基础信息+发票数据报表 $this->createOrValidate('ak_biz_invoice_basic', ['id', 'company_id', 'store_name', 'invoice_issuer', 'invoice_limit', 'period', 'created_at', 'updated_at'], function (Blueprint $table) { $table->id(); - $table->foreignId('company_id')->constrained('companies')->cascadeOnDelete(); + $table->unsignedInteger('company_id')->index(); $table->string('store_name')->default('')->comment('店铺名称'); $table->string('store_entity')->default('')->comment('店铺主体'); $table->string('invoice_issuer')->default('')->comment('开票员'); @@ -143,7 +143,7 @@ return new class extends Migration // 7. 店铺后台开票 $this->createOrValidate('ak_biz_store_invoice', ['id', 'company_id', 'store', 'seller_name', 'invoice_amount', 'invoice_type', 'invoice_date', 'created_at', 'updated_at'], function (Blueprint $table) { $table->id(); - $table->foreignId('company_id')->constrained('companies')->cascadeOnDelete(); + $table->unsignedInteger('company_id')->index(); $table->string('store')->default('')->comment('店铺'); $table->string('seller_name')->default('')->comment('销售方名称'); $table->string('seller_tax_no')->default('')->comment('销售方税号'); @@ -159,7 +159,7 @@ return new class extends Migration // 8. 资金预测表(月度资金收支预算表) $this->createOrValidate('ak_biz_fund_forecast', ['id', 'company_id', 'period', 'actual_period', 'income_total_budget', 'expense_total_actual', 'net_balance_actual', 'created_at', 'updated_at'], function (Blueprint $table) { $table->id(); - $table->foreignId('company_id')->constrained('companies')->cascadeOnDelete(); + $table->unsignedInteger('company_id')->index(); $table->string('period')->default('')->comment('预算填报月份'); $table->string('actual_period')->default('')->comment('实际填报月份'); // 收入明细 @@ -213,7 +213,7 @@ return new class extends Migration // 9. 店铺收款账户信息 $this->createOrValidate('ak_biz_store_receiving_accounts', ['id', 'company_id', 'platform', 'store_name', 'wallet_no', 'account_number', 'bank_name', 'created_at', 'updated_at'], function (Blueprint $table) { $table->id(); - $table->foreignId('company_id')->constrained('companies')->cascadeOnDelete(); + $table->unsignedInteger('company_id')->index(); $table->string('platform')->default('')->comment('店铺平台'); $table->string('store_name')->default('')->comment('店铺名称'); $table->string('wallet_no')->default('')->comment('钱包号'); @@ -230,7 +230,7 @@ return new class extends Migration // 10. 银行账户信息 $this->createOrValidate('ak_biz_bank_accounts', ['id', 'company_id', 'account_name', 'account_type', 'bank_account', 'bank_name', 'auditor_login_password', 'created_at', 'updated_at'], function (Blueprint $table) { $table->id(); - $table->foreignId('company_id')->constrained('companies')->cascadeOnDelete(); + $table->unsignedInteger('company_id')->index(); $table->string('account_name')->default('')->comment('账户名称'); $table->string('account_type')->default('')->comment('账户类型:基本户/一般户/个人账户/个人微信/个人支付宝'); $table->string('bank_account')->default('')->comment('银行账号'); @@ -245,7 +245,7 @@ return new class extends Migration // 11. 快递收款系统 $this->createOrValidate('ak_biz_express_receiving', ['id', 'company_id', 'express_name', 'receiving_type', 'receiving_name', 'account_number', 'bank_name', 'created_at', 'updated_at'], function (Blueprint $table) { $table->id(); - $table->foreignId('company_id')->constrained('companies')->cascadeOnDelete(); + $table->unsignedInteger('company_id')->index(); $table->string('express_name')->default('')->comment('快递名称'); $table->string('receiving_type')->default('')->comment('收款类型:对公/个人'); $table->string('receiving_name')->default('')->comment('收款名称'); diff --git a/tests/Feature/Business/BusinessMigrationCompatibilityTest.php b/tests/Feature/Business/BusinessMigrationCompatibilityTest.php index 02afafde..7f1d1f34 100644 --- a/tests/Feature/Business/BusinessMigrationCompatibilityTest.php +++ b/tests/Feature/Business/BusinessMigrationCompatibilityTest.php @@ -115,7 +115,7 @@ class BusinessMigrationCompatibilityTest extends TestCase { Schema::create('ak_biz_tax_data', function (Blueprint $table) { $table->id(); - $table->foreignId('company_id'); + $table->unsignedInteger('company_id'); $table->string('company_name')->default(''); $table->decimal('real_ship_revenue', 18, 2)->default(0); $table->decimal('final_tax_revenue', 18, 2)->default(0);