'sqlite', 'piaoju.cookie' => 'isLogin=1; u_sso_token=test-session', 'piaoju.api_base_url' => 'https://api.erp321.com', ]); Schema::dropIfExists('piaoju_seller_quota_snapshots'); Schema::create('piaoju_seller_quota_snapshots', function (Blueprint $table): void { $table->bigIncrements('id'); $table->string('seller_key', 64)->unique(); $table->string('seller_name', 191); $table->string('tax_number', 64)->nullable(); $table->boolean('seller_status')->nullable(); $table->string('auth_status', 32)->nullable(); $table->string('auth_status_desc', 64)->nullable(); $table->decimal('invoice_limit', 18, 2)->nullable(); $table->dateTime('invoice_limit_updated_at')->nullable(); $table->dateTime('source_fetched_at'); $table->dateTime('synced_at'); $table->timestamps(); }); } public function test_it_replaces_the_shared_mirror_with_ticket_union_seller_quotas(): void { Http::fake([ 'https://api.erp321.com/fp/fms/company/seller/page' => Http::response([ 'code' => '0000', 'data' => [ [ 'id' => 101, 'sellerName' => '甲公司', 'taxNumber' => '91320000TEST000001', 'status' => true, 'authStatus' => 'AUTHENTICATED', 'authStatusDesc' => '已授权', 'invoiceLimit' => 128963.91, 'invoiceLimitUpdated' => '2026-11-18 13:30:07', ], [ 'id' => 102, 'sellerName' => '乙公司', 'taxNumber' => '91320000TEST000002', 'status' => true, 'authStatus' => 'AUTHENTICATED', 'authStatusDesc' => '已授权', 'invoiceLimit' => -100, 'invoiceLimitUpdated' => '2026-11-18 13:51:43', ], ], 'total' => 2, ]), ]); $this->artisan('piaoju:sync-invoice-quotas') ->expectsOutput('票聚销方额度同步完成:2 条。') ->assertSuccessful(); $this->assertDatabaseHas('piaoju_seller_quota_snapshots', [ 'seller_key' => '91320000TEST000001', 'seller_name' => '甲公司', 'invoice_limit' => 128963.91, ], 'sqlite'); $this->assertDatabaseHas('piaoju_seller_quota_snapshots', [ 'seller_key' => '91320000TEST000002', 'seller_name' => '乙公司', 'invoice_limit' => -100, ], 'sqlite'); } public function test_failed_sync_keeps_the_previous_mirror(): void { DB::connection('sqlite')->table('piaoju_seller_quota_snapshots')->insert([ 'seller_key' => 'old-1', 'seller_name' => '旧主体', 'invoice_limit' => 500, 'source_fetched_at' => '2026-11-18 13:00:00', 'synced_at' => '2026-11-18 13:00:01', 'created_at' => '2026-11-18 13:00:01', 'updated_at' => '2026-11-18 13:00:01', ]); Http::fake([ 'https://api.erp321.com/fp/fms/company/seller/page' => Http::response([ 'code' => -1, 'msg' => '未登录', ]), ]); $this->artisan('piaoju:sync-invoice-quotas') ->expectsOutput('票聚销方额度同步失败,已保留上一版镜像。') ->assertFailed(); $this->assertDatabaseHas('piaoju_seller_quota_snapshots', [ 'seller_key' => 'old-1', 'seller_name' => '旧主体', ], 'sqlite'); } }