From 6cbfe27afcd808b27f872fb83bb35ea46332b06c Mon Sep 17 00:00:00 2001 From: "j.jiang" Date: Mon, 26 Oct 2026 17:36:20 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=89=A9=E5=8C=96=E7=8A=B6=E6=80=81?= =?UTF-8?q?=E5=90=8C=E6=97=B6=E6=A0=A1=E9=AA=8C=E7=A9=BA=E5=80=BC=EF=BC=8C?= =?UTF-8?q?=E5=85=BC=E5=AE=B9=E5=B0=9A=E6=9C=AA=E9=83=A8=E7=BD=B2=E6=96=B0?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E7=9A=84=E5=90=8C=E6=AD=A5=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 状态表标记已物化、但旧版本同步代码重刷账期时不写物化列,会留下 NULL 导致页面把未物化行当成 0 差额。现在读取状态时同时检查该账期是否还有 has_difference 为 NULL 的行,有则回退实时规则表达式(缓存 10 分钟)。 --- .../StoreReceiptDifferenceMaterialization.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/app/Business/StoreReceiptDifferenceMaterialization.php b/app/Business/StoreReceiptDifferenceMaterialization.php index 285f9bc8..a07609db 100644 --- a/app/Business/StoreReceiptDifferenceMaterialization.php +++ b/app/Business/StoreReceiptDifferenceMaterialization.php @@ -133,7 +133,18 @@ class StoreReceiptDifferenceMaterialization ->where('report_month', $month) ->first(); - return $row !== null && (string) ($row->rule_version ?? '') === self::ruleVersion(); + if ($row === null || (string) ($row->rule_version ?? '') !== self::ruleVersion()) { + return false; + } + + // 过渡期保护:尚未部署新代码的同步任务重刷账期时不会写物化列, + // 一旦出现 NULL 就回退实时口径,避免页面把未物化的行当成 0 差额。 + return ! DB::connection(self::connection()) + ->table(self::TABLE) + ->where('report_month', $month) + ->whereNull(self::HAS_DIFFERENCE_COLUMN) + ->limit(1) + ->exists(); }); }