fix(独立进货): 信用校验修在**最底层** —— 录单页预检接口不再报"客户 __INDEPENDENT_INBOUND__ 不存在,无法下单"
CI / server typecheck + tests (push) Canceled after 0s
CI / web typecheck + tests + miniprogram syntax (push) Canceled after 0s
CI / eslint (观察项,C7 骨架) (push) Canceled after 0s
CI / npm audit (critical 硬拦) (push) Canceled after 0s

开发者强刷后仍报该提示。全仓只有一处产生这句话(`customerBudgetService.checkCustomerCredit`),
逐一排查调用链后定位到真正的入口:

  录单页提交前会调 `assertCustomerCanOrderApi` →
  `GET /workflow/finance/customer/:customerCode/can-order`(financeRoutes)
  → `checkCustomerOrderBudget` → `checkCustomerCredit` → 403「客户 X 不存在,无法下单」

  我此前只放行了 submit 服务层 / 小程序预算接口 / MCP 工具 —— **录单页的预检接口没覆盖**,
  所以强刷照样报错(这与"后端没重载"无关:进程 08:55 已重载)。

改法:把哨兵放行下沉到**唯一底层函数** `checkCustomerCredit`
(覆盖所有包装与接口:submit 服务、can-order 预检、mobile 预算、MCP、财务页);
真实客户口径完全不变(仍只有"客户不存在"才 block —— 冻结口径)。

真库实测(走界面同一条接口):
  · `GET /api/workflow/finance/customer/__INDEPENDENT_INBOUND__/can-order` ⇒ 200 {"allowed":true,...}(原 403)
  · 对照真实客户 MAIN_BR002 ⇒ 200 allowed(校验逻辑照旧)
  · `POST /api/workflow/orders/submit`(哨兵)⇒ success(上一轮已验证)

测试:independentInbound 21 例(新增 2 例钉住底层放行 + 预检链路);全量 0 新增失败。
This commit is contained in:
Ubuntu
2026-10-13 09:01:34 +08:00
parent f2f95456bf
commit 45c24fe171
2 changed files with 43 additions and 0 deletions
@@ -1,4 +1,5 @@
import { pool } from '../db';
import { isIndependentInboundCustomer } from './independentInbound';
export type CreditCheckLevel = 'ok' | 'block';
@@ -23,6 +24,25 @@ export async function checkCustomerCredit(
FROM customers WHERE customer_code = $1`,
[customerCode]
);
/**
* 「独立进货」哨兵客户(2026-10-12 开发者):它不是真实客户、也不产生应收
* ⇒ **不参与信用/预算校验**,直接放行。
* ⚠️ 必须修在**这一层**:录单页提交前会调 `GET /workflow/finance/customer/:code/can-order`
* (`checkCustomerOrderBudget` 包装 → 本函数),只改 submit 服务层挡不住它 —— 开发者截图报障的就是这条。
* 「信用不拦单、唯一 block 是客户不存在」这条冻结口径对**真实客户**完全不变。
*/
if (isIndependentInboundCustomer(customerCode)) {
return {
allowed: true,
level: 'ok',
message: '',
creditFrozen: false,
creditLimit: 0,
usedBudget: 0,
orderAmount: Math.max(0, Number(orderAmount) || 0),
projectedUsed: Math.max(0, Number(orderAmount) || 0),
} as CustomerCreditCheck;
}
const orderAmt = Math.max(0, Number(orderAmount) || 0);
const base = {
creditFrozen: false,
+23
View File
@@ -179,6 +179,29 @@ describe('③b 结构上零销售:录单写 0 售价、零价闸门对哨兵
});
});
describe('③c 信用校验:修在**最底层**函数上(否则录单页的预检接口仍报"客户不存在")', () => {
const budget = svc('src/services/customerBudgetService.ts');
it('checkCustomerCredit 对哨兵直接返回 allowed(覆盖所有包装/接口)', () => {
const idx = budget.indexOf('export async function checkCustomerCredit');
expect(idx).toBeGreaterThan(-1);
const body = budget.slice(idx, idx + 1600);
expect(body).toContain('isIndependentInboundCustomer(customerCode)');
expect(body).toContain("level: 'ok'");
// 必须在查 customers 之后仍无条件放行(真实客户逻辑不变)
expect(body).toContain('FROM customers WHERE customer_code = $1');
// 冻结口径:真实客户仍只有"不存在"才 block
expect(budget).toContain('不存在,无法下单');
});
it('录单页提交前预检接口链路存在(GET /finance/customer/:code/can-order → checkCustomerOrderBudget)', () => {
const routes = svc('src/modules/workflow/routes/financeRoutes.ts');
expect(routes).toContain("'/finance/customer/:customerCode/can-order'");
expect(routes).toContain('checkCustomerOrderBudget');
expect(budget).toContain('export async function checkCustomerOrderBudget');
});
});
describe('④ 不计入销售(口径谓词统一,成本口径不动)', () => {
it('统一谓词来自 new 模块', () => {
expect(sentinel).toContain('export function salesVisibleOrderSql');