问题:哨兵客户 __RETAIL__ 会出现在小程序客户列表,但小程序走普通下单 (服务层无 RETAIL 分支),而自动推进又显式排除散客 ⇒ 单子容易卡在流程里。 新增 POST /mobile/order-entry/retail-orders:录单角色 + 客户范围校验, 与 Web 同源调 submitRetailOrder(entryChannel=MP,不校验下单时间窗口)。 小程序选中散客后:不要求配送日期、不做预算校验、只允许已建档商品, 成功后提示到「订单管理」点「确认扣除并完结」;界面加「只扣库存」提示。 普通录单行为逐字不变。
102 lines
4.8 KiB
TypeScript
102 lines
4.8 KiB
TypeScript
/**
|
|
* 小程序录单:散客(`__RETAIL__`)与 Web 对齐 —— 走零售口径,不走普通下单。
|
|
*
|
|
* 设计:`docs/design/20261021-小程序散客录单对齐Web零售口径.md`
|
|
*
|
|
* 问题(改前):哨兵客户「散客录单」会出现在小程序客户列表里(`listOrderEntryCustomers` 未排除),
|
|
* 但小程序提交走 `/mobile/order-entry/orders`(普通下单)⇒ 单子进分配/配送链路,而
|
|
* `orderAutoAdvanceService` 又把 `__RETAIL__` 排除在自动推进之外 ⇒ 容易卡住。
|
|
*
|
|
* 钉住四件事:
|
|
* ① 后端新接口与 Web `POST /orders/retail` **同源**(都调 `submitRetailOrder`);
|
|
* ② 小程序选中散客后走零售接口,且不再要求配送日期、不做预算校验;
|
|
* ③ 散客单只支持已建档商品(缺 sku_code 前端先拦、后端同口径再拦);
|
|
* ④ 成功后提示去「订单管理」点「确认扣除并完结」(完结链路已在 20261015 实现)。
|
|
*/
|
|
import { readFileSync } from 'node:fs';
|
|
import { describe, expect, it } from 'vitest';
|
|
|
|
const mobileOrderRoutes = readFileSync(
|
|
new URL('../src/routes/mobile/mobileOrderRoutes.ts', import.meta.url),
|
|
'utf8'
|
|
);
|
|
const retailService = readFileSync(
|
|
new URL('../src/services/retailOrderService.ts', import.meta.url),
|
|
'utf8'
|
|
);
|
|
const requestSrc = readFileSync(new URL('../../miniprogram/utils/request.js', import.meta.url), 'utf8');
|
|
const panelJs = readFileSync(
|
|
new URL('../../miniprogram/components/order-entry-panel/index.js', import.meta.url),
|
|
'utf8'
|
|
);
|
|
const panelWxml = readFileSync(
|
|
new URL('../../miniprogram/components/order-entry-panel/index.wxml', import.meta.url),
|
|
'utf8'
|
|
);
|
|
|
|
describe('后端:散客录单接口与 Web 同源', () => {
|
|
it('新增 POST /mobile/order-entry/retail-orders,调 submitRetailOrder', () => {
|
|
expect(mobileOrderRoutes).toContain("router.post('/order-entry/retail-orders'");
|
|
expect(mobileOrderRoutes).toContain(
|
|
"import { submitRetailOrder } from '../../services/retailOrderService'"
|
|
);
|
|
expect(mobileOrderRoutes).toContain('await submitRetailOrder({');
|
|
// 渠道标记 MP,便于区分 Web/小程序
|
|
expect(mobileOrderRoutes).toContain("entryChannel: 'MP'");
|
|
});
|
|
|
|
it('沿用录单权限与客户可见范围校验,分公司从散客行解析', () => {
|
|
expect(mobileOrderRoutes).toContain("requireMobileRole(req, 'order_entry')");
|
|
expect(mobileOrderRoutes).toContain('await assertOrderEntryCustomerAccess(RETAIL_CUSTOMER_CODE, scope)');
|
|
expect(mobileOrderRoutes).toContain(
|
|
'await resolveOrderBranchForEntry(scope, RETAIL_CUSTOMER_CODE)'
|
|
);
|
|
expect(mobileOrderRoutes).toContain('RETAIL_CUSTOMER_CODE');
|
|
});
|
|
|
|
it('零售服务本身就是建单即全额抵扣(不分配、无配送),不另写一套', () => {
|
|
expect(retailService).toContain('export async function submitRetailOrder');
|
|
expect(retailService).toContain('ensureRetailCustomer');
|
|
});
|
|
});
|
|
|
|
describe('小程序:选中散客后走零售口径', () => {
|
|
it('请求层有 submitRetailOrderEntry 并指向新接口', () => {
|
|
expect(requestSrc).toContain('function submitRetailOrderEntry(payload)');
|
|
expect(requestSrc).toContain("'/mobile/order-entry/retail-orders'");
|
|
expect(requestSrc).toContain(' submitRetailOrderEntry,');
|
|
});
|
|
|
|
it('面板识别散客并单独分支提交(不走普通下单)', () => {
|
|
expect(panelJs).toContain("const RETAIL_CUSTOMER_CODE = '__RETAIL__';");
|
|
expect(panelJs).toContain('function isRetailCustomer(customer)');
|
|
expect(panelJs).toContain('retailMode: isRetailCustomer(customer)');
|
|
expect(panelJs).toContain('if (retail) {');
|
|
expect(panelJs).toContain('await submitRetailOrderEntry({');
|
|
// 普通下单仍存在,散客分支在其之前 return
|
|
expect(panelJs).toContain('await submitOrderEntryOrderWithConfirm({');
|
|
});
|
|
|
|
it('散客不要求配送日期、不做预算校验(与 Web 一致)', () => {
|
|
expect(panelJs).toMatch(/if \(!retail\) \{\r?\n\s*if \(!this\.data\.deliveryDate\)/);
|
|
expect(panelJs).toContain('if (!retail && this.data.budgetBlocked)');
|
|
expect(panelJs).toContain('if (!customer || isRetailCustomer(customer))');
|
|
});
|
|
|
|
it('散客单只支持已建档商品:缺 sku_code 先拦下来说清楚', () => {
|
|
expect(panelJs).toContain('散客单只支持已建档商品');
|
|
expect(panelJs).toContain('missingRows');
|
|
});
|
|
|
|
it('成功后提示去订单管理点「确认扣除并完结」,并清空草稿', () => {
|
|
expect(panelJs).toContain("title: '散客单已创建'");
|
|
expect(panelJs).toContain('确认扣除并完结');
|
|
expect(panelJs).toContain('this.resetDraftForm();');
|
|
});
|
|
|
|
it('界面给出与 Web 同义的「只扣库存」提示', () => {
|
|
expect(panelWxml).toContain('wx:if="{{retailMode}}"');
|
|
expect(panelWxml).toContain('只扣库存:无采购、无分拣、无配送;库存不足会拦住');
|
|
});
|
|
});
|