From dcc401f50a1e28359573f845802fb8b42d8ddcbc Mon Sep 17 00:00:00 2001 From: limeng <1131177064@qq.com> Date: Wed, 2 Dec 2026 11:07:39 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=A7=8D=E8=8F=9C=E6=8D=9F=E8=80=97?= =?UTF-8?q?=E8=AF=86=E5=88=AB=E6=8B=8DA+B=E5=8F=8A=E6=8C=87=E5=AE=9A?= =?UTF-8?q?=E6=9D=A1=E7=A0=81=E5=85=8D=E6=89=A3=20(#1637)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/PlantingLossCalculator.php | 33 +++++++++-- .../planting-loss.blade.php | 6 +- .../Business/PlantingWorkOrderPagesTest.php | 4 +- .../PlantingLossCalculatorTest.php | 55 +++++++++++++++++++ 4 files changed, 87 insertions(+), 11 deletions(-) diff --git a/modules/EcommerceFinance/Services/PlantingLossCalculator.php b/modules/EcommerceFinance/Services/PlantingLossCalculator.php index 4eb94ad16..fbc6967cd 100644 --- a/modules/EcommerceFinance/Services/PlantingLossCalculator.php +++ b/modules/EcommerceFinance/Services/PlantingLossCalculator.php @@ -16,6 +16,7 @@ use Modules\EcommerceFinance\Repositories\ShippingOrderRepository; * 2. 用线上订单号去匹配发货数据(jst_oms_shipping)中 M-1、M 两个月发货的交易单号,匹配到的保留; * 3. 任务备注或卖家备注写了“拍A发B”或“拍A发A”的不扣款,不论是否匹配到发货都单独列出发给运营; * 4. 实际只发了「信誉订单虚拟条码」「透明挂钩」这类商品的不扣款; + * XF001-JX、DF- 开头条码仅免对应商品,混合发货的普通商品仍计算扣款; * 5. 其余匹配到的作为扣款项,扣款金额 = Σ 发货商品成本价 × 数量 + 该订单在发货数据中的运费(2026-10-19 更正), * 成本价按发货条形码(=商品编码)取普通商品资料。未匹配到发货的不计入种菜损耗。 */ @@ -86,13 +87,13 @@ class PlantingLossCalculator return substr($window['from'], 0, 7) . '~' . $month; } - /** 命中的免扣字样(拍A发B / 拍A发A),未命中返回 null。全角、大小写、空格均兼容。 */ + /** 命中的免扣字样(拍A发B / 拍A发A / 拍A+B),未命中返回 null。全角、大小写、空格均兼容。 */ public static function exemptionKeyword(string ...$remarks): ?string { foreach ($remarks as $remark) { $text = mb_strtoupper((string) preg_replace('/\s+/u', '', mb_convert_kana($remark, 'as'))); - if (preg_match('/拍A发([AB])/u', $text, $match) === 1) { - return '拍A发' . $match[1]; + if (preg_match('/拍A发[AB]|拍A\+B(?![A-Z0-9])/u', $text, $match) === 1) { + return $match[0]; } } @@ -101,6 +102,9 @@ class PlantingLossCalculator public static function isFreeGoods(string $barcode, string $productName): bool { + if (self::isExemptBarcode($barcode)) { + return true; + } foreach (self::FREE_GOODS_KEYWORDS as $keyword) { if (str_contains($productName, $keyword) || str_contains($barcode, $keyword)) { return true; @@ -110,6 +114,14 @@ class PlantingLossCalculator return false; } + /** 只免该商品,不触发虚拟条码的整单免扣规则。 */ + public static function isExemptBarcode(string $barcode): bool + { + $code = strtoupper(trim($barcode)); + + return $code === 'XF001-JX' || str_starts_with($code, 'DF-'); + } + public static function isVirtualOrderItem(string $barcode, string $productName): bool { $code = strtoupper(trim($barcode)); @@ -139,7 +151,7 @@ class PlantingLossCalculator */ public function rows(string $month): array { - $key = 'planting-loss:rows:v3:' . $month; + $key = 'planting-loss:rows:v4:' . $month; $cached = Cache::get($key); if (is_array($cached)) { return $cached; @@ -178,6 +190,7 @@ class PlantingLossCalculator $deductLines = []; $missingCost = []; $cents = 0; + $exemptBarcodes = []; $virtualOrder = false; foreach ($shipment['lines'] ?? [] as $line) { if (self::isVirtualOrderItem($line['barcode'], $line['product_name'])) { @@ -186,6 +199,9 @@ class PlantingLossCalculator } foreach ($virtualOrder ? [] : ($shipment['lines'] ?? []) as $line) { if (self::isFreeGoods($line['barcode'], $line['product_name'])) { + if (self::isExemptBarcode($line['barcode'])) { + $exemptBarcodes[$line['barcode']] = true; + } continue; } $cost = $costs[$line['barcode']] ?? null; @@ -215,14 +231,19 @@ class PlantingLossCalculator // 拍A发B/拍A发A 不论是否匹配到发货都单独列出发给运营(2026-10-20 财务确认);匹配发货只用于挑出真实发货的单。 $keyword = self::exemptionKeyword((string) $row['task_remark'], (string) $row['seller_remark']); + $exemptionBasis = '备注含“' . $keyword . '”' . ($keyword === '拍A+B' ? '(按拍A发B处理)' : '') + . ($shipment === null ? '(未匹配到发货)' : ''); [$result, $basis] = match (true) { - $keyword !== null => [self::RESULT_EXEMPT, '备注含“' . $keyword . '”' . ($shipment === null ? '(未匹配到发货)' : '')], + $keyword !== null => [self::RESULT_EXEMPT, $exemptionBasis], $shipment === null => [self::RESULT_UNMATCHED, self::shippingLabel($month) . ' 发货数据中无此交易单号'], $virtualOrder => [self::RESULT_FREE_GOODS, '发货含信誉订单虚拟条码/透明挂钩,整单不扣款'], - $deductLines === [] => [self::RESULT_FREE_GOODS, '只发了虚拟条码/透明挂钩/无实物商品'], + $deductLines === [] => [self::RESULT_FREE_GOODS, $exemptBarcodes !== [] ? '只发了免扣条码/无实物商品' : '只发了虚拟条码/透明挂钩/无实物商品'], $missingText !== '' => [self::RESULT_DEDUCT, $missingText . ',扣款金额未含缺失部分'], default => [self::RESULT_DEDUCT, '已匹配发货,按成本价×数量+运费扣款'], }; + if ($exemptBarcodes !== [] && $keyword === null && ! $virtualOrder) { + $basis .= ';免扣条码:' . implode('、', array_keys($exemptBarcodes)); + } $row['loss_result'] = $result; $row['loss_basis'] = $basis; diff --git a/resources/views/business/pages/billing-transactions/planting-loss.blade.php b/resources/views/business/pages/billing-transactions/planting-loss.blade.php index 5eaaf4ac1..398eb1eda 100644 --- a/resources/views/business/pages/billing-transactions/planting-loss.blade.php +++ b/resources/views/business/pages/billing-transactions/planting-loss.blade.php @@ -13,7 +13,7 @@ @endphp
{{ $plantingFilters['month'] }} 月种菜报销明细(完成时间 {{ substr($plantingWindow['from'], 0, 10) }} 至 {{ \Illuminate\Support\Carbon::parse($plantingWindow['to'])->subDay()->format('Y-m-d') }})的线上订单号,匹配 {{ $shippingLabel }} 发货数据(发货时间 {{ substr($plantingShippingWindow['from'], 0, 10) }} 至 {{ \Illuminate\Support\Carbon::parse($plantingShippingWindow['to'])->subDay()->format('Y-m-d') }})中的交易单号。任务备注或卖家备注写了“拍A发B / 拍A发A”的(不论是否匹配到发货)、以及匹配到的单中只发了信誉订单虚拟条码/透明挂钩的不扣款,其余按发货商品成本价×数量+该单运费扣款。
+{{ $plantingFilters['month'] }} 月种菜报销明细(完成时间 {{ substr($plantingWindow['from'], 0, 10) }} 至 {{ \Illuminate\Support\Carbon::parse($plantingWindow['to'])->subDay()->format('Y-m-d') }})的线上订单号,匹配 {{ $shippingLabel }} 发货数据(发货时间 {{ substr($plantingShippingWindow['from'], 0, 10) }} 至 {{ \Illuminate\Support\Carbon::parse($plantingShippingWindow['to'])->subDay()->format('Y-m-d') }})中的交易单号。任务备注或卖家备注写了“拍A发B / 拍A发A / 拍A+B”的(不论是否匹配到发货)、以及匹配到的单中只发了信誉订单虚拟条码/透明挂钩的不扣款,XF001-JX、DF- 开头条码仅免对应商品,混合发货的普通商品继续扣款;其余按发货商品成本价×数量+该单运费扣款。
-① 取该月种菜报销明细:工单类型“种菜报销”、状态“已完成”,完成时间 M 月 2 日 00:00 至次月 1 日 23:59:59(与「种菜报销」页同一口径)。② 用线上订单号(交易单号)精确匹配「快递应付 → 发货数据」中发货时间在上月 1 日至本月末的交易单号,匹配到的保留,同一单多个包裹/商品合并为一行。③ 任务备注或卖家备注写了“拍A发B”或“拍A发A”(不区分全半角、大小写和空格)的不做扣款,不论是否匹配到发货都单独列出,「导出拍A发B(发运营)」按种菜报销字段导出。④ 发货数据里该交易单号下出现“信誉订单虚拟条码”(X00006/X00002)或透明挂钩(条形码 GG 开头)的整单不扣款(同单号下的其它商品视为合并发货的别的订单);只发了“无实物”商品的也不扣款。⑤ 其余匹配到的为扣款项:扣款金额 = Σ 发货条形码(商品编码)在「普通商品资料」中的成本价 × 发货数量 + 该订单在「发货数据」中的运费合计;普通商品资料里没有成本价(空或 0)的商品、发货数据里运费为空的订单分别标为“成本价缺失”“运费缺失”,缺失部分不计入扣款金额,补齐后自动重算。未匹配到发货的单不计入种菜损耗,仅供核对。
① 取该月种菜报销明细:工单类型“种菜报销”、状态“已完成”,完成时间 M 月 2 日 00:00 至次月 1 日 23:59:59(与「种菜报销」页同一口径)。② 用线上订单号(交易单号)精确匹配「快递应付 → 发货数据」中发货时间在上月 1 日至本月末的交易单号,匹配到的保留,同一单多个包裹/商品合并为一行。③ 任务备注或卖家备注写了“拍A发B”“拍A发A”或“拍A+B”(按拍A发B处理,不区分全半角、大小写和空格)的不做扣款,不论是否匹配到发货都单独列出,「导出拍A发B(发运营)」按种菜报销字段导出。④ 发货数据里该交易单号下出现“信誉订单虚拟条码”(X00006/X00002)或透明挂钩(条形码 GG 开头)的整单不扣款(同单号下的其它商品视为合并发货的别的订单);只发了“无实物”商品的也不扣款。⑤ 发货条码 XF001-JX 和 DF- 开头条码免对应商品成本(不区分大小写),混合发货的普通商品继续按成本价和既有订单运费计算;仅有免扣商品的整单不扣款。⑥ 其余匹配到的为扣款项:扣款金额 = Σ 发货条形码(商品编码)在「普通商品资料」中的成本价 × 发货数量 + 该订单在「发货数据」中的运费合计;普通商品资料里没有成本价(空或 0)的商品、发货数据里运费为空的订单分别标为“成本价缺失”“运费缺失”,缺失部分不计入扣款金额,补齐后自动重算。未匹配到发货的单不计入种菜损耗,仅供核对。