insert([ 'company_id' => 1, 'warehouse_provider' => '新增仓储方', 'warehouse' => '新增仓储方主仓', 'warehouse_short_name' => '新仓简称', 'created_at' => $now, 'updated_at' => $now, ]); $target = DB::connection('business_mirror')->table('store_receipt_product_cost_rows'); $target->insert([ $this->row('mapped-september', '2026-09-01', '新增仓储方 ', '旧简称', $now), $this->row('unmapped-september', '2026-09-01', '未映射仓储方', '保持简称', $now), $this->row('mapped-august', '2026-08-01', '新增仓储方', '八月旧简称', $now), ]); $this->artisan('store-receipt:product-cost:sync', [ 'month' => '2026-09', '--remap-warehouses-only' => true, ])->assertExitCode(Command::SUCCESS); $mapped = DB::connection('business_mirror')->table('store_receipt_product_cost_rows') ->where('row_key', 'mapped-september')->first(); $this->assertSame('新仓简称', $mapped->warehouse_short_name); $this->assertSame('SKU-mapped-september', $mapped->product_code); $this->assertSame(2.0, (float) $mapped->product_quantity); $this->assertSame(12.0, (float) $mapped->unit_price); $this->assertSame(24.0, (float) $mapped->product_cost); $this->assertSame('保留原备注', $mapped->remark); $this->assertSame( '保持简称', DB::connection('business_mirror')->table('store_receipt_product_cost_rows') ->where('row_key', 'unmapped-september')->value('warehouse_short_name'), ); $this->assertSame( '八月旧简称', DB::connection('business_mirror')->table('store_receipt_product_cost_rows') ->where('row_key', 'mapped-august')->value('warehouse_short_name'), ); } /** @return array */ private function row( string $rowKey, string $reportMonth, string $warehouse, string $warehouseShortName, mixed $now, ): array { return [ 'report_month' => $reportMonth, 'row_key' => $rowKey, 'platform' => '京东账单', 'occurred_date' => $reportMonth, 'store_name' => '测试店铺', 'online_order_no' => 'ORDER-' . $rowKey, 'warehouse' => $warehouse, 'warehouse_short_name' => $warehouseShortName, 'product_code' => 'SKU-' . $rowKey, 'product_quantity' => 2, 'unit_price' => 12, 'product_cost' => 24, 'remark' => '保留原备注', 'imported_at' => $now, ]; } }