[ 'driver' => 'sqlite', 'database' => ':memory:', 'prefix' => '', ], 'upstream_mirrors.connection' => 'business_mirror', 'cache.default' => 'array', 'upstream_mirrors.datasets' => [ InstallationFeeSummaryRepository::MAIN_DATASET => [ 'source_key' => 'jiansun', 'schema' => 'dbo', 'object' => 'install_view', 'target' => 'fixture_install_view', 'keys' => ['Id'], ], InstallationFeeSummaryRepository::ITEM_DATASET => [ 'source_key' => 'jiansun', 'schema' => 'dbo', 'object' => 'install_item', 'target' => 'fixture_install_item', 'keys' => ['Id'], ], ], ]); DB::purge('business_mirror'); Cache::flush(); $schema = Schema::connection('business_mirror'); $schema->create('business_mirror_table_states', function (Blueprint $table): void { $table->string('dataset_key')->primary(); $table->dateTime('initial_completed_at')->nullable(); }); $schema->create('fixture_install_view', function (Blueprint $table): void { $table->integer('Id'); $table->string('SourceGuid'); $table->dateTime('ShipTIme')->nullable(); $table->string('shop_name')->nullable(); $table->string('installCompanyName')->nullable(); $table->string('costWay')->nullable(); }); $schema->create('fixture_install_item', function (Blueprint $table): void { $table->integer('Id'); $table->string('guid'); $table->decimal('settleItemAmount', 18, 4)->nullable(); }); foreach ([InstallationFeeSummaryRepository::MAIN_DATASET, InstallationFeeSummaryRepository::ITEM_DATASET] as $dataset) { DB::connection('business_mirror')->table('business_mirror_table_states')->insert([ 'dataset_key' => $dataset, 'initial_completed_at' => '2026-09-01 00:00:00', ]); } $mirror = DB::connection('business_mirror'); $mirror->table('fixture_install_view')->insert([ ['Id' => 1, 'SourceGuid' => 'A', 'ShipTIme' => '2026-09-01 10:00:00', 'shop_name' => '店铺A', 'installCompanyName' => '万师傅', 'costWay' => null], ['Id' => 2, 'SourceGuid' => 'A', 'ShipTIme' => '2026-09-02 10:00:00', 'shop_name' => '店铺A', 'installCompanyName' => '万师傅', 'costWay' => null], ['Id' => 3, 'SourceGuid' => 'B', 'ShipTIme' => '2026-09-03 10:00:00', 'shop_name' => '店铺A', 'installCompanyName' => '万师傅', 'costWay' => '银行转账'], ['Id' => 4, 'SourceGuid' => 'C', 'ShipTIme' => '2026-08-31 23:59:59', 'shop_name' => '店铺C', 'installCompanyName' => '鲁班到家', 'costWay' => null], ['Id' => 5, 'SourceGuid' => 'D', 'ShipTIme' => '2026-09-04 10:00:00', 'shop_name' => null, 'installCompanyName' => ' ', 'costWay' => ' '], ]); $mirror->table('fixture_install_item')->insert([ ['Id' => 10, 'guid' => 'A', 'settleItemAmount' => 100], ['Id' => 11, 'guid' => 'A', 'settleItemAmount' => 25], ['Id' => 12, 'guid' => 'B', 'settleItemAmount' => 50], ['Id' => 13, 'guid' => 'C', 'settleItemAmount' => 999], ['Id' => 14, 'guid' => 'D', 'settleItemAmount' => 10], ]); $this->repository = new InstallationFeeSummaryRepository( new GenericBusinessMirrorRepository(app('db')), new BusinessMirrorDatasetRegistry(), ); } public function test_summary_and_details_use_shipment_month_and_settlement_detail_amount(): void { $summary = $this->repository->summary('2026-09'); $this->assertTrue($summary['ready']); $this->assertSame(185.0, $summary['total']); $this->assertSame(4, $summary['row_count']); $details = $this->repository->details('2026-09'); $this->assertTrue($details['ready']); $this->assertSame(185.0, $details['total']); $this->assertSame([ ['store_name' => '店铺A', 'installation_company' => '万师傅', 'payment_channel' => '包安装', 'amount' => 125.0], ['store_name' => '店铺A', 'installation_company' => '万师傅', 'payment_channel' => '不包安装', 'amount' => 50.0], ['store_name' => '未填写店铺', 'installation_company' => '未填写安装公司', 'payment_channel' => '包安装', 'amount' => 10.0], ], $details['rows']); } public function test_invalid_month_is_rejected(): void { $this->expectException(\InvalidArgumentException::class); $this->repository->summary('2026-13'); } }