From a7e7b067eb58fe52dd2ed77c3e5d11ded38cd846 Mon Sep 17 00:00:00 2001 From: limeng <1131177064@qq.com> Date: Sat, 28 Nov 2026 12:27:14 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=8F=91=E8=B4=A7=E5=8C=85?= =?UTF-8?q?=E8=A3=B9=E5=95=86=E5=93=81=E3=80=81=E6=95=B0=E9=87=8F=E3=80=81?= =?UTF-8?q?=E4=BD=93=E7=A7=AF=E4=B8=8E=E6=8D=A2=E5=8D=95=E5=90=8C=E6=AD=A5?= =?UTF-8?q?=20(#1545)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/jushuitan.php | 11 +-- .../Jushuitan/ShippingReplicaSynchronizer.php | 85 +++++++++++-------- .../ShippingReplicaSynchronizerTest.php | 76 ++++++++++++++++- 3 files changed, 124 insertions(+), 48 deletions(-) diff --git a/config/jushuitan.php b/config/jushuitan.php index 5878cee4..6660334d 100644 --- a/config/jushuitan.php +++ b/config/jushuitan.php @@ -38,17 +38,8 @@ return [ 'retry_sleep_ms' => (int) env('JST_RETRY_SLEEP_MS', 1000), ], - // 发货数据「导出明细」体积口径(对齐工作平台 OmsDataDay:明细体积默认 = 数量 × 长×宽×高)。 - // 依据:工作平台 9.1-9.16 导出明细,非代发仓 8421/8421 行乘数量;代发仓走简尚线路快递的不乘数量。 - // 合并口径体积不受此影响(单独存 m_volume_cm3)。 + // 发货明细统一按单件尺寸体积 × 实发数量;合并优先使用出库视图已汇总的体积。 'detail_volume' => [ - // 这些发货仓的明细体积不乘数量(工厂代发虚拟仓) - 'no_qty_warehouses' => ['常州简尚家居有限公司'], - // 上述仓库中,用这些标准承运商发货时仍乘数量 - 'qty_carriers_in_no_qty_warehouses' => [ - '中通快运', '韵达快递', '申通E物流', '安能物流', '邮政电商标快', '邮政快递包裹POSTB', - '壹米滴答', '百世物流', '德邦快递', '中通速递', '圆通速递', - ], // 这些快递的明细体积一律为 0 'zero_volume_expresses' => ['白云韵达-天猫亿家达', '中通礼品单'], ], diff --git a/modules/EcommerceFinance/Services/Jushuitan/ShippingReplicaSynchronizer.php b/modules/EcommerceFinance/Services/Jushuitan/ShippingReplicaSynchronizer.php index 9d59c302..b526d044 100644 --- a/modules/EcommerceFinance/Services/Jushuitan/ShippingReplicaSynchronizer.php +++ b/modules/EcommerceFinance/Services/Jushuitan/ShippingReplicaSynchronizer.php @@ -44,7 +44,7 @@ class ShippingReplicaSynchronizer ]; private const PRESERVED_CONTACT_FIELDS = ['receiver_name', 'receiver_mobile', 'receiver_phone']; private const REFRESHED_PACKAGE_FIELDS = [ - 'trade_no', 'express_name1', 'warehouse_name', 'shop_name', 'platform', 'pay_time', 'ship_time', + 'express_no', 'trade_no', 'express_name1', 'warehouse_name', 'shop_name', 'platform', 'pay_time', 'ship_time', 'receiver_state', 'receiver_city', 'receiver_district', ]; private const PRESERVED_ITEM_FIELDS = ['finished_barcode', 'finished_name', 'finished_supplier']; @@ -199,6 +199,8 @@ class ShippingReplicaSynchronizer throw new InvalidArgumentException('跳过运费仅支持指定起止日期的历史补录。'); } $this->skipFreight = $skipFreight; + // Only an explicit date window is a replacement run. The regular incremental + // path keeps its existing fast upsert semantics and does not rescan old parcels. $this->replaceWindow = (bool) $windowed; $this->packagesProcessed = 0; $this->packagesWithoutItems = 0; @@ -635,7 +637,7 @@ class ShippingReplicaSynchronizer continue; } $ph = implode(',', array_fill(0, count($chunk), '?')); - $sql = "SELECT o_id, l_id, send_date, status, labels FROM rpt.jst_Orders om WHERE om.o_id IN ({$ph})"; + $sql = "SELECT o_id, l_id, send_date, status, labels, shop_name FROM rpt.jst_Orders om WHERE om.o_id IN ({$ph})"; foreach ($this->selectWithReconnect($sql, $chunk) as $row) { $oid = (string) ($row['o_id'] ?? ''); if ($oid === '') { @@ -646,6 +648,7 @@ class ShippingReplicaSynchronizer $this->orderMetadata[$oid] = [ 'l_id' => $row['l_id'] ?? null, 'send_date' => $row['send_date'] ?? null, + 'shop_name' => $row['shop_name'] ?? null, 'status' => in_array($st, ['Cancelled', 'Split', 'Merged'], true) ? $st : null, 'online' => $this->excludedByLabel($row['labels'] ?? null), ]; @@ -668,6 +671,9 @@ class ShippingReplicaSynchronizer if (($row['jo_send'] ?? '') === '' && ($metadata['send_date'] ?? '') !== '') { $row['jo_send'] = $metadata['send_date']; } + if (trim((string) ($row['shop_name'] ?? '')) === '' && ! empty($metadata['shop_name'])) { + $row['shop_name'] = $metadata['shop_name']; + } // 订单状态/标签:取消/拆分/合并 与 订单级"线上发货"标签的排除判断用 if (($row['jo_status'] ?? '') === '' && ($metadata['status'] ?? '') !== '') { $row['jo_status'] = $metadata['status']; @@ -1149,6 +1155,8 @@ class ShippingReplicaSynchronizer 'l' => null, 'w' => null, 'h' => null, 'vol' => null, 'weight' => null, 'supplier' => null, ]; $it['qty'] = $qty; + // A purchase-out correction changes quantity; discard the old view total. + unset($it['vol'], $it['mvol'], $it['volume_is_total']); $out[] = $it; } @@ -1377,7 +1385,7 @@ class ShippingReplicaSynchronizer $syntheticSkuIds = []; foreach ($items as $idx => $it) { $first = ($idx === 0); - $sk = (! empty($it['sku']) && isset($skus[(string) $it['sku']])) ? $skus[(string) $it['sku']] : []; + $sk = $skus[mb_strtolower(trim((string) ($it['sku'] ?? '')))] ?? []; $skuSid = (int) ($it['id'] ?? ($pkgId * 100 + $idx)); if (($it['id'] ?? null) === null) { $syntheticSkuIds[$skuSid] = true; @@ -1393,7 +1401,7 @@ class ShippingReplicaSynchronizer /** * 导出明细体积(对齐工作平台 OmsDataDay):默认 数量×长×宽×高; - * 代发仓(配置)且非标准承运商 → 长×宽×高;特定快递 → 0;无尺寸 → 空。 + * 特定虚拟快递 → 0;无尺寸 → 空。仓库和承运商不再改变数量倍率。 */ private function detailVolume(mixed $L, mixed $W, mixed $H, float $qty, string $warehouse, string $express): ?float { @@ -1409,10 +1417,7 @@ class ShippingReplicaSynchronizer return null; } $unit = $l * $w * $h; - $noQty = in_array(trim($warehouse), (array) ($cfg['no_qty_warehouses'] ?? []), true) - && ! in_array($express, (array) ($cfg['qty_carriers_in_no_qty_warehouses'] ?? []), true); - - return round($noQty ? $unit : $unit * max($qty, 1), 4); + return round($unit * max($qty, 0), 4); } /** 组装一件明细行。包裹级字段(实称重量/运费)仅首件携带。 */ @@ -1443,7 +1448,12 @@ class ShippingReplicaSynchronizer $L = ($it['l'] ?? null) ?: ($sk['l'] ?? null); $W = ($it['w'] ?? null) ?: ($sk['w'] ?? null); $H = ($it['h'] ?? null) ?: ($sk['h'] ?? null); - $vol = ($it['vol'] ?? null) ? round((float) $it['vol'], 4) : (($L && $W && $H) ? round((float) $L * (float) $W * (float) $H, 4) : null); + $detailVol = $this->detailVolume($L, $W, $H, $qty, (string) ($pkg['warehouse_name'] ?: ($it['warehouse'] ?? '')), (string) ($pkg['express_name1'] ?? '')); + // The view carries a parcel total, while a split combo part carries a unit volume. + // Keep an explicit total once; multiply unit volumes by the shipped quantity. + $vol = isset($it['vol']) + ? round((float) $it['vol'] * (($it['volume_is_total'] ?? false) ? 1 : max($qty, 0)), 4) + : $detailVol; $pkgWeight = (float) ($pkg['weight'] ?? 0) ?: null; $freightW = (float) ($f['w'] ?? 0); @@ -1479,7 +1489,7 @@ class ShippingReplicaSynchronizer 'length_cm' => $L, 'width_cm' => $W, 'height_cm' => $H, - 'volume_cm3' => $this->detailVolume($L, $W, $H, $qty, (string) ($pkg['warehouse_name'] ?: ($it['warehouse'] ?? '')), (string) ($pkg['express_name1'] ?? '')), + 'volume_cm3' => $detailVol, 'm_name' => $this->wpText($it['mname'] ?? null), 'm_volume_cm3' => isset($it['mvol']) ? round((float) $it['mvol'], 4) : $vol, 'm_length_cm' => $it['ml'] ?? null, @@ -1782,10 +1792,8 @@ class ShippingReplicaSynchronizer /** * 包裹实发商品: * 1. 出库单实发商品(发货数据视图); - * 2. 多包裹订单:聚水潭运费明细里本快递单号的商品; - * 3. 内部订单(o_id)商品; - * 4. 运费明细里本快递单号的商品(单包裹订单); - * 5. 交易单号整单商品。 + * 2. 聚水潭运费明细里本快递单号的商品; + * 3. 没有出库单且没有多包裹证据时,才使用内部订单/交易单号商品。 * * 运费明细(fys_jstFreightCostDetail)按 交易单号+快递单号 记录每个包裹的 sku。工厂代发仓等找不到出库单的包裹, * 内部订单/交易单号商品是整单口径,多包裹时会把同订单其它包裹的商品挂到本单号上 @@ -1803,10 +1811,12 @@ class ShippingReplicaSynchronizer $tk = ltrim(trim($tracking), '@'); $packageSkus = ($so !== '' && $tk !== '') ? ($this->fysPackageSkus[$so . '|' . $tk] ?? []) : []; $multiPackage = ($this->fysSoTrackCount[$so] ?? 0) > 1; - if ($oid !== '' && ! empty($byOid[$oid]) && ! ($multiPackage && $packageSkus !== [])) { - return $byOid[$oid]; - } if ($packageSkus === []) { + // An identified outbound package without item detail must remain incomplete. + // Whole-order lines may describe a different parcel or the original full item. + if ($io !== '' || $multiPackage) { + return []; + } return $this->itemsFor($byOid, $bySo, $dws, $oid, $so); } @@ -2127,6 +2137,9 @@ class ShippingReplicaSynchronizer if ($logisticId !== '' && ! empty($ioMap['byL'][$logisticId])) { return (string) $ioMap['byL'][$logisticId]; } + if ($logisticId !== '') { + return ''; // A different parcel on the same order is not a match. + } if ($oid !== '' && ! empty($ioMap['byO'][$oid])) { return (string) $ioMap['byO'][$oid]; } @@ -2263,7 +2276,7 @@ class ShippingReplicaSynchronizer 'id' => null, 'sku' => $a['sku'], 'iid' => null, 'shopid' => $a['shopid'], 'name' => $a['name'], 'qty' => $qty, 'amount' => null, 'warehouse' => $a['wh'], - 'l' => $a['l'], 'w' => $a['w'], 'h' => $a['h'], 'vol' => $vol, + 'l' => $a['l'], 'w' => $a['w'], 'h' => $a['h'], 'vol' => $vol, 'volume_is_total' => true, 'weight' => $a['weight'], 'supplier' => $a['supplier'], ]; } @@ -2605,12 +2618,18 @@ class ShippingReplicaSynchronizer foreach ($packageRows as &$packageRow) { $skuId = (int) $packageRow['sku_source_id']; $oldItem = $previousItems[$id][$skuId] ?? null; + $barcodeKey = mb_strtolower(trim((string) ($packageRow['barcode'] ?? ''))); + if (isset($syntheticSkuIds[$id][$skuId]) && $oldItem !== null + && mb_strtolower(trim((string) ($oldItem['barcode'] ?? ''))) !== $barcodeKey) { + // Synthetic IDs depend on row order, which the upstream view does not promise. + // Match the amount by barcode before deciding whether an update is unsafe. + $oldItem = null; + } if ($packageRow['amount'] !== null) { unset($unmatchedOldAmounts[$skuId]); continue; } if ($oldItem === null || $oldItem['amount'] === null) { - $barcodeKey = mb_strtolower(trim((string) ($packageRow['barcode'] ?? ''))); if ($barcodeKey !== '' && isset($oldAmountByBarcode[$barcodeKey])) { [$matchedOldSkuId, $matchedAmount] = $oldAmountByBarcode[$barcodeKey]; $packageRow['amount'] = $matchedAmount; @@ -2619,16 +2638,8 @@ class ShippingReplicaSynchronizer } continue; } - if (isset($syntheticSkuIds[$id][$skuId])) { - $oldBarcode = trim((string) $oldItem['barcode']); - $newBarcode = trim((string) ($packageRow['barcode'] ?? '')); - if ($oldBarcode === '' || $newBarcode === '' || $oldBarcode !== $newBarcode) { - $unsafeAmount = true; - break; - } - } $packageRow['amount'] = $oldItem['amount']; - unset($unmatchedOldAmounts[$skuId]); + unset($unmatchedOldAmounts[$skuId], $oldAmountByBarcode[$barcodeKey]); } unset($packageRow); if (! $unsafeAmount && $unmatchedOldAmounts !== []) { @@ -2670,6 +2681,10 @@ class ShippingReplicaSynchronizer foreach (self::PRESERVED_PACKAGE_FIELDS as $field) { $packageRows[0][$field] = $previous[$id][$field] ?? null; } + if (! empty($previous[$id]['express_no']) && ! empty($packageRows[0]['express_no']) + && ltrim($previous[$id]['express_no'], '@') !== ltrim($packageRows[0]['express_no'], '@')) { + $packageRows[0]['front_no'] = $previous[$id]['express_no']; + } foreach (self::PRESERVED_CONTACT_FIELDS as $field) { if (($packageRows[0][$field] ?? null) === null || $packageRows[0][$field] === '') { $packageRows[0][$field] = $previous[$id][$field] ?? null; @@ -2683,7 +2698,7 @@ class ShippingReplicaSynchronizer } array_push($rows, ...$packageRows); } - $this->refreshRetainedPackages($refresh); + $this->refreshRetainedPackages($refresh, $previous); if ($replaceIds === []) { return; } @@ -2752,7 +2767,7 @@ class ShippingReplicaSynchronizer } $ph = implode(',', array_fill(0, count($chunk), '?')); foreach ($this->selectWithReconnect("SELECT sku_id, l, w, h, pack_volume, weight, supplier_name, name, i_id FROM rpt.jst_sku WHERE sku_id IN ({$ph})", $chunk) as $r) { - $out[(string) $r['sku_id']] = [ + $out[mb_strtolower(trim((string) $r['sku_id']))] = [ 'l' => $r['l'] ?? null, 'w' => $r['w'] ?? null, 'h' => $r['h'] ?? null, 'vol' => $r['pack_volume'] ?? null, 'weight' => $r['weight'] ?? null, 'supplier' => $r['supplier_name'] ?? null, @@ -2893,7 +2908,7 @@ class ShippingReplicaSynchronizer } /** 因商品/金额无法安全替换而保留的旧包裹:包裹级字段(省市区、快递、仓库、店铺等)仍按本次上游刷新,商品与金额不动。 */ - private function refreshRetainedPackages(array $refresh): void + private function refreshRetainedPackages(array $refresh, array $previous): void { foreach ($refresh as $id => $new) { $set = []; @@ -2903,6 +2918,10 @@ class ShippingReplicaSynchronizer $set[$field] = $v; } } + $oldTracking = trim((string) ($previous[$id]['express_no'] ?? '')); + if ($oldTracking !== '' && isset($set['express_no']) && ltrim($oldTracking, '@') !== ltrim($set['express_no'], '@')) { + $set['front_no'] = $oldTracking; + } if ($set !== []) { $this->db->table('jst_oms_shipping')->where('source_id', (int) $id)->update($set); } @@ -2912,9 +2931,7 @@ class ShippingReplicaSynchronizer private function withPreservedFreight(array $payload, array $previous): array { $payload = $this->withPreservedCharges($payload, $previous); - if (! empty($previous['express_no'])) { - $payload['express_no'] = $previous['express_no']; - } + // Preserving freight must not restore the old tracking number after a waybill change. $payload['express_name2'] = $previous['express_name2'] ?? $payload['express_name2']; return $payload; diff --git a/tests/Unit/EcommerceFinance/ShippingReplicaSynchronizerTest.php b/tests/Unit/EcommerceFinance/ShippingReplicaSynchronizerTest.php index f5f4ce0a..fc957069 100644 --- a/tests/Unit/EcommerceFinance/ShippingReplicaSynchronizerTest.php +++ b/tests/Unit/EcommerceFinance/ShippingReplicaSynchronizerTest.php @@ -31,7 +31,7 @@ class ShippingReplicaSynchronizerTest extends TestCase if (str_contains($sql, 'FROM rpt.jst_Orders om WHERE om.o_id IN')) { $orderMetadataQueries[] = [$sql, $bindings]; - return [['o_id' => 'order-1', 'l_id' => 'order-tracking', 'send_date' => '2026-09-02 12:00:00']]; + return [['o_id' => 'order-1', 'l_id' => 'order-tracking', 'send_date' => '2026-09-02 12:00:00', 'shop_name' => '供销店铺']]; } if (str_contains($sql, 'FROM rpt.jst_Orders o WHERE o.status =')) { return []; @@ -54,6 +54,7 @@ class ShippingReplicaSynchronizerTest extends TestCase $row = DB::connection('business_mirror')->table('jst_oms_shipping')->where('source_id', 5000)->sole(); $this->assertSame('order-tracking', $row->express_no); $this->assertSame('2026-09-02 12:00:00', $row->ship_time); + $this->assertSame('供销店铺', $row->shop_name); } public function test_windowed_outbound_lookup_preloads_date_range_and_reuses_cache_without_in_queries(): void @@ -510,14 +511,15 @@ class ShippingReplicaSynchronizerTest extends TestCase ->where('dataset_key', 'jst.sctrade.freight.20260901000000-20260905000000')->value('status')); $this->assertSame('partial', (new ShippingOrderRepository())->syncStatus()['code']); $existing = $db->table('jst_oms_shipping')->where('source_id', 5000)->first(); - $this->assertSame('existing-tracking', $existing->express_no); + $this->assertSame('new-tracking', $existing->express_no); + $this->assertSame('existing-tracking', $existing->front_no); $this->assertSame('existing-express', $existing->express_name2); $this->assertEquals(12.34, $existing->freight); $this->assertEquals(13.45, $existing->settle_freight); $this->assertEquals(1.2, $existing->weight_kg); $this->assertEquals(1.3, $existing->settle_weight_kg); $weightOnly = $db->table('jst_oms_shipping')->where('source_id', 6000)->first(); - $this->assertSame('weight-only-tracking', $weightOnly->express_no); + $this->assertSame('new-weight-tracking', $weightOnly->express_no); $this->assertNull($weightOnly->freight); $this->assertEquals(4.5, $weightOnly->settle_weight_kg); $new = $db->table('jst_oms_shipping')->where('source_id', 4000)->first(); @@ -1184,7 +1186,8 @@ class ShippingReplicaSynchronizerTest extends TestCase $this->assertFalse($label->invoke($sync, '线上发货,云仓订单')); $volume = new \ReflectionMethod($sync, 'detailVolume'); $this->assertSame(120.0, $volume->invoke($sync, 10, 3, 2, 2.0, '普通仓', '中通速递')); - $this->assertSame(60.0, $volume->invoke($sync, 10, 3, 2, 2.0, '常州简尚家居有限公司', '自送')); + $this->assertSame(120.0, $volume->invoke($sync, 10, 3, 2, 2.0, '常州简尚家居有限公司', '自送')); + $this->assertSame(0.0, $volume->invoke($sync, 10, 3, 2, 0.0, '普通仓', '中通速递')); $this->assertNull($volume->invoke($sync, 0, 3, 2, 2.0, '普通仓', '中通速递')); $this->assertSame(0.0, $volume->invoke($sync, 10, 3, 2, 2.0, '普通仓', '中通礼品单')); } @@ -1778,6 +1781,71 @@ class ShippingReplicaSynchronizerTest extends TestCase $this->assertSame('简尚-POP仓', $wh($build->invoke($sync, $pkg('京东快递', ''), $it + ['warehouse' => '简尚-POP仓'], [], [], true, '1/1', now(), false))); } + public function test_reordered_shipped_items_update_zero_quantity_and_match_old_amounts_by_barcode(): void + { + $db = DB::connection('business_mirror'); + $db->table('jst_oms_shipping')->insert([ + ['source_id' => 5000, 'sku_source_id' => 500000, 'express_no' => 'OLD', 'barcode' => 'part-b', 'qty' => 0, 'amount' => 25], + ['source_id' => 5000, 'sku_source_id' => 500001, 'express_no' => 'OLD', 'barcode' => 'PART-A', 'qty' => 0, 'amount' => 10], + ]); + $factory = $this->createMock(UpstreamReadOnlyQueryFactory::class); + $factory->method('forSource')->willReturn($this->createMock(UpstreamReadOnlyQuery::class)); + $sync = new ShippingReplicaSynchronizer($factory); + $replacement = new \ReflectionProperty($sync, 'replacementPackages'); + $replacement->setValue($sync, [5000 => [ + ['source_id' => 5000, 'sku_source_id' => 500000, 'express_no' => 'NEW', 'barcode' => 'part-a', 'qty' => 2, 'amount' => null, + 'receiver_name' => null, 'receiver_mobile' => null, 'receiver_phone' => null, + 'freight' => null, 'settle_freight' => null, 'weight_kg' => null, 'settle_weight_kg' => null], + ['source_id' => 5000, 'sku_source_id' => 500001, 'express_no' => 'NEW', 'barcode' => 'part-b', 'qty' => 3, 'amount' => null, + 'receiver_name' => null, 'receiver_mobile' => null, 'receiver_phone' => null, + 'freight' => null, 'settle_freight' => null, 'weight_kg' => null, 'settle_weight_kg' => null], + ]]); + (new \ReflectionProperty($sync, 'replacementHasItems'))->setValue($sync, [5000 => true]); + (new \ReflectionProperty($sync, 'replacementSyntheticSkuIds'))->setValue($sync, [5000 => [500000 => true, 500001 => true]]); + (new \ReflectionProperty($sync, 'replacementFromView'))->setValue($sync, [5000 => true]); + (new \ReflectionMethod($sync, 'flushReplacements'))->invoke($sync); + $rows = $db->table('jst_oms_shipping')->orderBy('sku_source_id')->get(); + $this->assertSame([2, 3], $rows->pluck('qty')->all()); + $this->assertEquals([10, 25], $rows->pluck('amount')->all()); + $this->assertSame(['NEW', 'NEW'], $rows->pluck('express_no')->all()); + $this->assertSame(0, (new \ReflectionProperty($sync, 'packagesRetainedForUnmatchedAmount'))->getValue($sync)); + } + + public function test_merged_volume_multiplies_unit_fallbacks_but_does_not_multiply_view_totals(): void + { + $factory = $this->createMock(UpstreamReadOnlyQueryFactory::class); + $factory->method('forSource')->willReturn($this->createMock(UpstreamReadOnlyQuery::class)); + $sync = new ShippingReplicaSynchronizer($factory); + $build = new \ReflectionMethod($sync, 'buildRow'); + $pkg = array_fill_keys(['tracking', 'so_id', 'express_name1', 'ship_time', 'pay_time', 'shop_name', 'platform', + 'dis_co_name', 'warehouse_name', 'r_state', 'r_city', 'r_district', 'r_address', 'r_name', 'r_mobile', 'r_phone', 'buyer_memo'], null); + $item = ['qty' => 3, 'l' => 10, 'w' => 5, 'h' => 2]; + foreach ([$item, $item + ['vol' => 100], $item + ['vol' => 300, 'volume_is_total' => true]] as $input) { + $row = $build->invoke($sync, $pkg, $input, [], [], true, '1/1', now(), false); + $this->assertSame(300.0, $row['volume_cm3']); + $this->assertSame(300.0, $row['m_volume_cm3']); + } + $combo = $build->invoke($sync, $pkg, $item + ['vol' => 100, 'mvol' => 240], [], [], true, '1/2', now(), false); + $this->assertSame(300.0, $combo['volume_cm3']); + $this->assertSame(240.0, $combo['m_volume_cm3']); + } + + public function test_package_specific_goods_override_single_order_goods_and_missing_outbound_stays_incomplete(): void + { + $factory = $this->createMock(UpstreamReadOnlyQueryFactory::class); + $factory->method('forSource')->willReturn($this->createMock(UpstreamReadOnlyQuery::class)); + $sync = new ShippingReplicaSynchronizer($factory); + $method = new \ReflectionMethod($sync, 'packageItems'); + $order = ['O' => [['sku' => 'whole-chair', 'qty' => 1]]]; + (new \ReflectionProperty($sync, 'fysPackageSkus'))->setValue($sync, ['S|TRACK' => ['chair-screw' => 2]]); + $items = $method->invoke($sync, '', [], $order, [], [], 'O', 'S', 'TRACK'); + $this->assertSame(['chair-screw'], array_column($items, 'sku')); + $this->assertSame([2], array_column($items, 'qty')); + $this->assertSame([], $method->invoke($sync, 'IO', [], $order, [], [], 'O', 'S', 'NO-DETAIL')); + $map = ['byL' => [], 'byLO' => [], 'byO' => ['O' => 'OTHER-PARCEL']]; + $this->assertSame('', (new \ReflectionMethod($sync, 'ioFor'))->invoke($sync, $map, 'TRACK', 'O')); + } + private function setScanBatchLimit(ShippingReplicaSynchronizer $synchronizer, string $property, int $limit): void { $reflection = new \ReflectionProperty($synchronizer, $property);