[ 'driver' => 'sqlite', 'database' => ':memory:', 'prefix' => '', ], 'upstream_mirrors.connection' => 'business_mirror', ]); DB::purge('business_mirror'); $this->createSchema(); $this->seedRows(); } public function test_it_maps_confirmed_and_finished_purchase_rows_and_keeps_missing_orders(): void { $result = app(DingOnlineDaifaPriceMirrorRepository::class)->paginate([], 1, 25); $this->assertSame(2, $result['total']); $this->assertSame(2, $result['summary']['purchase_count']); $this->assertSame(0.0, $result['summary']['daifa_amount']); $confirmed = collect($result['data'])->firstWhere('purchase_order_id', 907329); $this->assertSame('110212448119316609', $confirmed['shop_trade_no']); $this->assertSame('得物-米客米家家居旗舰店', $confirmed['shop_name']); $this->assertSame('霸州市亚锦五金制品厂', $confirmed['supplier_name']); $this->assertSame('DF-C1ZDY000202', $confirmed['material_no']); $this->assertSame(1.0, $confirmed['ship_qty']); $this->assertSame(19.3, $confirmed['daifa_amount']); $this->assertSame('采购单管理', $confirmed['tag']); $this->assertSame('已确认', $confirmed['status_label']); $this->assertTrue($confirmed['order_matched']); $missing = collect($result['data'])->firstWhere('purchase_order_id', 907330); $this->assertNotNull($missing); $this->assertSame('', $missing['shop_trade_no']); $this->assertFalse($missing['order_matched']); } public function test_purchase_filters_apply_to_page_and_export_with_the_same_scope(): void { $filters = [ 'status' => 'CONFIRMED', 'shop_name' => '得物-米客米家家居旗舰店', 'supplier_name' => '亚锦', 'material_no' => 'DF-C1ZDY000202', ]; $repository = app(DingOnlineDaifaPriceMirrorRepository::class); $page = $repository->paginate($filters, 1, 25); $export = iterator_to_array($repository->exportRows($filters)); $this->assertSame(1, $page['total']); $this->assertSame([907329], array_column($page['data'], 'purchase_order_id')); $this->assertSame([907329], array_column($export, 'purchase_order_id')); } private function createSchema(): void { $schema = Schema::connection('business_mirror'); $schema->create('business_mirror_table_states', function (Blueprint $table): void { $table->string('dataset_key')->primary(); $table->string('status'); $table->dateTime('initial_completed_at')->nullable(); $table->dateTime('last_succeeded_at')->nullable(); }); $schema->create('product_purchase_price_sync_states', function (Blueprint $table): void { $table->string('dataset_key')->primary(); $table->string('status'); $table->unsignedTinyInteger('projection_version')->default(1); $table->dateTime('initial_completed_at')->nullable(); $table->dateTime('last_succeeded_at')->nullable(); }); $schema->create('product_purchase_price_mirror_rows', function (Blueprint $table): void { $table->unsignedBigInteger('item_id')->primary(); $table->unsignedBigInteger('purchase_order_id'); $table->unsignedBigInteger('source_order_no')->nullable(); $table->string('supplier_name')->nullable(); $table->string('sku_id')->nullable(); $table->string('style_id')->nullable(); $table->decimal('quantity', 20, 4)->nullable(); $table->decimal('unit_price', 20, 4)->nullable(); $table->string('document_status')->nullable(); $table->text('labels')->nullable(); $table->dateTime('document_created_at')->nullable(); $table->dateTime('finished_at')->nullable(); $table->dateTime('purchase_updated_at'); }); $schema->create('ops_jst_orders', function (Blueprint $table): void { $table->unsignedBigInteger('Id')->primary(); $table->unsignedBigInteger('o_id')->index(); $table->string('so_id')->nullable(); $table->string('shop_name')->nullable(); }); } private function seedRows(): void { $db = DB::connection('business_mirror'); $db->table('business_mirror_table_states')->insert([ 'dataset_key' => 'operations_replica.rpt.jst_Orders', 'status' => 'succeeded', 'initial_completed_at' => '2026-09-20 00:00:00', 'last_succeeded_at' => '2026-09-22 16:40:00', ]); $db->table('product_purchase_price_sync_states')->insert([ 'dataset_key' => ProductPurchasePriceMirrorRepository::DATASET_KEY, 'status' => 'succeeded', 'projection_version' => ProductPurchasePriceMirrorRepository::CURRENT_PROJECTION_VERSION, 'initial_completed_at' => '2026-09-22 17:30:00', 'last_succeeded_at' => '2026-09-22 17:35:11', ]); $db->table('ops_jst_orders')->insert([ 'Id' => 1, 'o_id' => 9416447, 'so_id' => '110212448119316609', 'shop_name' => '得物-米客米家家居旗舰店', ]); $db->table('product_purchase_price_mirror_rows')->insert([ [ 'item_id' => 1, 'purchase_order_id' => 907329, 'source_order_no' => 9416447, 'supplier_name' => '霸州市亚锦五金制品厂', 'sku_id' => 'DF-C1ZDY000202', 'quantity' => 1, 'unit_price' => 19.3, 'document_status' => 'Confirmed', 'document_created_at' => '2026-09-22 16:30:03', 'purchase_updated_at' => '2026-09-22 16:30:04', ], [ 'item_id' => 2, 'purchase_order_id' => 907330, 'source_order_no' => 9999999, 'supplier_name' => '待匹配供应商', 'sku_id' => 'SKU-FINISHED', 'quantity' => 2, 'unit_price' => 8.5, 'document_status' => 'Finished', 'document_created_at' => '2026-09-22 17:00:00', 'purchase_updated_at' => '2026-09-22 17:01:00', ], [ 'item_id' => 3, 'purchase_order_id' => 896492, 'source_order_no' => 9416447, 'supplier_name' => '霸州市亚锦五金制品厂', 'sku_id' => 'DF-C1ZDY000202', 'quantity' => 1, 'unit_price' => 19.3, 'document_status' => 'Cancelled', 'document_created_at' => '2026-09-17 16:15:04', 'purchase_updated_at' => '2026-09-17 16:15:05', ], ]); } }