From ad0b6d43d33dba6f9d9304441cd27e2bb35f35fb Mon Sep 17 00:00:00 2001 From: chenxi Date: Thu, 5 Nov 2026 14:56:02 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=A4=84=E7=90=86=E5=95=86=E5=93=81?= =?UTF-8?q?=E6=88=90=E6=9C=AC=E5=8D=A0=E4=BD=8D=E8=A1=8C=E5=92=8C=E6=8B=BC?= =?UTF-8?q?=E6=8E=A5=E7=BB=84=E5=90=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Commands/SyncStoreReceiptProductCost.php | 27 +++++++++-- docs/商品成本占位行规则清单.md | 4 +- .../Unit/StoreReceiptProductCostLineTest.php | 48 +++++++++++++++++++ 3 files changed, 74 insertions(+), 5 deletions(-) diff --git a/app/Console/Commands/SyncStoreReceiptProductCost.php b/app/Console/Commands/SyncStoreReceiptProductCost.php index 49b9378d..f25c1dc6 100644 --- a/app/Console/Commands/SyncStoreReceiptProductCost.php +++ b/app/Console/Commands/SyncStoreReceiptProductCost.php @@ -74,6 +74,14 @@ class SyncStoreReceiptProductCost extends Command 'JIAXIANGJIANCAIJIAJUZIZHUANG964A', 'YUNFEI', 'BCJ', + '信息说明', + 'GG003-SZ', + '10237635142166', + '10237635142167', + '10228923011349', + '10230781002185', + '10230781002760', + '10230780802455', ]; /** 组合装条码前缀;条码结构为「前缀-组件条码-数量-组件条码-数量」。 */ @@ -3044,6 +3052,10 @@ class SyncStoreReceiptProductCost extends Command // 2) 种菜商品整行排除,不尝试把它替换成去掉「种菜」前缀后的正式编码。 foreach ($unique as $key => $row) { $sku = mb_strtoupper(trim((string) $row['sku'])); + if (in_array($sku, self::EXCLUDED_SKUS, true)) { + unset($unique[$key]); + continue; + } if (! self::isPlantingSku($sku)) { continue; } @@ -3087,8 +3099,8 @@ class SyncStoreReceiptProductCost extends Command } // 4) 上游有些平台组合会同时返回「+ 拼接父行」和多条组件行。 - // 只有同一订单、outer_oi_id、shop_sku_id 下至少有两条组件,且组件金额 - // 合计与父行一致时,父行才是可确认的汇总占位,才允许排除。 + // 同一订单、outer_oi_id、shop_sku_id 下至少有两条组件,或存在一条可完整解析为 + // 多个组件的 MKH-/ZH- 结构子行,且合计金额与父行一致时,才允许排除父行。 $plusParents = []; $plusComponents = []; foreach ($unique as $key => $row) { @@ -3103,12 +3115,21 @@ class SyncStoreReceiptProductCost extends Command $plusComponents[$groupKey]['rows'] = ($plusComponents[$groupKey]['rows'] ?? 0) + 1; $plusComponents[$groupKey]['amount'] = ($plusComponents[$groupKey]['amount'] ?? 0.0) + (float) $row['amount']; + if (count(self::expandComboSku((string) $row['sku'], (float) $row['qty'])) >= 2) { + $plusComponents[$groupKey]['structured_rows'] + = ($plusComponents[$groupKey]['structured_rows'] ?? 0) + 1; + } } foreach ($plusParents as $key => $groupKey) { $component = $plusComponents[$groupKey] ?? null; + $hasComponentDetail = $component !== null + && ( + $component['rows'] >= 2 + || ($component['rows'] === 1 && ($component['structured_rows'] ?? 0) === 1) + ); if ( $component !== null - && $component['rows'] >= 2 + && $hasComponentDetail && abs(round((float) $component['amount'], 2) - round((float) $unique[$key]['amount'], 2)) <= 0.01 ) { $stats['plus_parent_excluded_rows']++; diff --git a/docs/商品成本占位行规则清单.md b/docs/商品成本占位行规则清单.md index 24eec4d1..77e3cc11 100644 --- a/docs/商品成本占位行规则清单.md +++ b/docs/商品成本占位行规则清单.md @@ -20,7 +20,7 @@ store-receipt:product-cost:sync YYYY-MM --remap-warehouses-only 1. 业绩明细只取收入金额非空且不为 0 的账单行。 2. 种菜金额非空,或种菜标签为「种菜报销 / 种菜未报销」的账单行整行排除。 -3. 商品编码为 `TCXJ`、`FUWU`、`AZF`、`DF-PJZY0001`、`JIAXIANGJIANCAIJIAJUZIZHUANG964A`、`YUNFEI`、`BCJ` 的订单行全局排除;组合装拆出的这些编码同样排除。 +3. 商品编码为 `TCXJ`、`FUWU`、`AZF`、`DF-PJZY0001`、`JIAXIANGJIANCAIJIAJUZIZHUANG964A`、`YUNFEI`、`BCJ`、`信息说明`、`GG003-SZ`、`10237635142166`、`10237635142167`、`10228923011349`、`10230781002185`、`10230781002760`、`10230780802455` 的订单行全局排除;组合装拆出的这些编码同样排除。 4. 商品编码以「种菜」开头的订单行整行排除,不尝试去掉前缀后计价。 5. 发货仓库以 `配件-` 开头时整仓排除,不核算商品成本;发货仓库为「常州简尚家居有限公司」「简尚-苏州福利品仓」「简尚-自动发货仓」时也排除,仅「常州简尚家居有限公司」中以 `DF-` 开头的商品行例外保留。 6. 完成上述过滤后,再执行占位行去重、组合装展开、叶子行和已取消订单处理。 @@ -31,7 +31,7 @@ store-receipt:product-cost:sync YYYY-MM --remap-warehouses-only | 类型 | 识别条件 | 自动处理 | 无法唯一确认时 | | --- | --- | --- | --- | | 平台数字编码 | 同一订单、同一 `shop_i_id` 已有内部商品编码,当前编码为纯数字 | 数字平台占位行不参与成本 | 没有内部兄弟行时进入待核验 | -| 加号组合父行 | 同一订单、`outer_oi_id`、`shop_sku_id` 下至少两条组件,组件金额合计与父行一致 | 剔除带 `+` 的组合父行,只保留组件 | 保留父行待核验 | +| 加号组合父行 | 同一订单、`outer_oi_id`、`shop_sku_id` 下至少两条组件,或一条可完整解析为多个组件的 `MKH-` / `ZH-` 结构子行,组件金额合计与父行一致 | 剔除带 `+` 的组合父行,只保留组件 | 保留父行待核验 | | 中文后缀别名 | 占位编码以白名单后缀结尾,当前白名单仅「非」;必须同数据源、平台、店铺、订单、子订单、`shop_sku_id`、`shop_i_id`、仓库 | 正式编码与占位编码各唯一,且数量和金额完全一致时,保留正式编码、剔除占位行 | 任一关系不唯一或数量、金额不一致,两个编码都保留 | | 父子前缀占位 | 同一订单内只有一个严格扩展编码的子商品,且平台商品、规格、子订单和仓库一致 | 数量、金额一致时剔除较短父行,保留明细编码,例如 `CTG022516` 类父行 | 多子编码或任一字段不一致时保留父行 | | 中文「组合」主行 | 商品编码包含中文「组合」;同一 `o_id` 下,组件 `src_combine_sku_id` 指向源组合装编码;没有显式标记时,组件须与主行 `outer_oi_id + shop_sku_id + shop_i_id` 一致 | 组件金额合计与组包总额误差≤0.01 元时剔除主行,只计组件 | 非零主行找不到组件或金额不一致时保留主行待核验,组件暂不计成本 | diff --git a/tests/Unit/StoreReceiptProductCostLineTest.php b/tests/Unit/StoreReceiptProductCostLineTest.php index b1cf720b..87f22114 100644 --- a/tests/Unit/StoreReceiptProductCostLineTest.php +++ b/tests/Unit/StoreReceiptProductCostLineTest.php @@ -419,6 +419,54 @@ class StoreReceiptProductCostLineTest extends TestCase $this->assertContains('GBGJ-A+V01+GBGJ-B+V01', array_column($lines, 'sku')); } + public function test_plus_parent_is_removed_when_single_structured_mkh_child_matches(): void + { + [$lines, , , $plusParents] = $this->costLines([ + $this->row( + 'plus-parent', + 'DNZ038522N1280V01+GBGJ-DNZ038401N1440V01', + '993830851777', + 1, + 1161, + ), + $this->row( + 'structured-child', + 'MKH-DNZ038522N1280V01-1-GBGJ-DNZ038401N1440V01-1', + '993830851777', + 1, + 1161, + ), + ]); + + $this->assertSame(1, $plusParents); + $this->assertSame( + ['DNZ038522N1280V01', 'GBGJ-DNZ038401N1440V01'], + array_column($lines, 'sku'), + ); + } + + public function test_confirmed_non_product_placeholder_codes_are_excluded(): void + { + $codes = [ + '信息说明', + 'GG003-SZ', + '10237635142166', + '10237635142167', + '10228923011349', + '10230781002185', + '10230781002760', + '10230780802455', + ]; + $rows = []; + foreach ($codes as $index => $code) { + $rows[] = $this->row('placeholder-' . $index, $code, '3200000000000', 1, 100); + } + + [$lines] = $this->costLines($rows); + + $this->assertSame([], $lines); + } + public function test_non_numeric_variant_parent_is_removed_when_quantity_and_amount_match(): void { [$lines, $placeholders, $bundles, $plusParents, $variantParents] = $this->costLines([