From 8c5ec8b34fa4635b3658a3248fcefcf20f906558 Mon Sep 17 00:00:00 2001 From: renshen <1005457301@qq.com> Date: Sat, 24 Oct 2026 20:44:43 +0800 Subject: [PATCH] =?UTF-8?q?=E5=95=86=E5=93=81=E5=88=A9=E6=B6=A6=E9=95=9C?= =?UTF-8?q?=E5=83=8F=EF=BC=9A7=20=E6=9C=88=E5=89=8D=E4=B8=8E=E5=8F=AA?= =?UTF-8?q?=E6=9C=89=E8=B4=B9=E7=94=A8=E8=A1=8C=E7=9A=84=E5=8E=86=E5=8F=B2?= =?UTF-8?q?=E8=AE=A2=E5=8D=95=E5=9B=9E=E9=80=80=E5=AF=BC=E5=85=A5=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=20(#525)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/order_after_sales_cost.php | 4 +++ .../Repositories/GoodsProfitAfsRepository.php | 31 ++++++++++++++----- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/config/order_after_sales_cost.php b/config/order_after_sales_cost.php index 43ef00f4..b35e110f 100644 --- a/config/order_after_sales_cost.php +++ b/config/order_after_sales_cost.php @@ -10,6 +10,10 @@ */ return [ + // 聚水潭「商品利润 → 订单售后费用数据」原表可靠覆盖的起始日期: + // 更早月份在原表里不完整(例如 6 月订单只有费用行、没有组件/成本),走导入文件。 + 'goods_profit_from' => '2026-07-01', + 'headers' => [ '内部订单号' => 'internal_order_no', '线上订单号' => 'online_order_no', diff --git a/modules/EcommerceFinance/Repositories/GoodsProfitAfsRepository.php b/modules/EcommerceFinance/Repositories/GoodsProfitAfsRepository.php index 3961d9b6..951420d2 100644 --- a/modules/EcommerceFinance/Repositories/GoodsProfitAfsRepository.php +++ b/modules/EcommerceFinance/Repositories/GoodsProfitAfsRepository.php @@ -184,15 +184,22 @@ class GoodsProfitAfsRepository // 只按单号(不限日期)查询:原表命中该单就用原表,否则交给导入历史数据兜底。 if ($from === '' && $to === '' && $orderNo !== '') { + $dateColumn = $columns['order_time'] ?? null; + foreach ($this->orderNumberFields($orderNo) as $field) { if (! isset($columns[$field])) { continue; } - if ($this->connection()->table(self::MAIN_TABLE) - ->where($columns[$field], 'like', $orderNo . '%') - ->limit(1) - ->exists()) { + $query = $this->connection()->table(self::MAIN_TABLE) + ->where($columns[$field], 'like', $orderNo . '%'); + + // 只有带订单时间的行才是完整明细;只有费用行的历史订单交给导入数据。 + if ($dateColumn !== null) { + $query->whereNotNull($dateColumn)->where($dateColumn, '<>', ''); + } + + if ($query->limit(1)->exists()) { return true; } } @@ -200,6 +207,12 @@ class GoodsProfitAfsRepository return false; } + $start = (string) config('order_after_sales_cost.goods_profit_from', '2026-07-01'); + + if ($start !== '' && $from !== '' && $from < $start) { + return false; + } + // “是否覆盖”只看日期范围,不掺业务筛选:筛选条件由 paginate 应用, // 筛不到就该显示空结果,而不是回退到旧订单镜像(否则筛选会被忽略)。 if ($from === '' && $to === '') { @@ -212,15 +225,17 @@ class GoodsProfitAfsRepository $expression = $this->dateExpression($columns['order_time']); $range = $this->connection()->table(self::MAIN_TABLE) - ->selectRaw("MIN({$expression}) as min_time, MAX({$expression}) as max_time") + ->selectRaw("MAX({$expression}) as max_time") ->first(); - if (! $range || $range->min_time === null) { + if (! $range || $range->max_time === null) { return false; } - return ($from === '' || substr((string) $range->min_time, 0, 10) <= $from) - && ($to === '' || substr((string) $range->max_time, 0, 10) >= $to); + // 起始日受 goods_profit_from 约束,结束日按原表实际最大日期判断(今天往往晚于最后一次同步)。 + $anchor = $from !== '' ? $from : $to; + + return $anchor === '' || substr((string) $range->max_time, 0, 10) >= $anchor; } /**