feat(客户自提): 「是否取货」客户级开关 + 分拣完毕进「待取货」+ 管理员确认取货结案
开发者需求:「客户列表加一个按钮,是否取货(客户自己来拿货、不走配送)」;
二次澄清采纳方案乙:「还是待取货,旁边留一个按钮,客户取货后点完成就结案」;
逐条确认:权限给管理员 / 不生成配送单(和主系统发过来的类似)/ 取货在订单列表点按钮。
后端:
- 迁移 20261049:只加两列 customers.is_self_pickup / orders.self_pickup(NOT NULL DEFAULT false ⇒
存量行为完全不变),逐 schema + tenant_template 幂等;不新建表、不动 tenant_business_tables()。
- 录单快照:建单 INSERT 里用子查询带出客户开关(改客户开关不影响已有单)。
⚠️ 子查询必须用独立参数 $13:否则 PG 报 `inconsistent types deduced for parameter $4`
($4 在 VALUES 推断 text、在 customers.customer_code=$4 推断 varchar;::text 转换救不了)——
本地实测复现(PREPARE)+ 修复后验证。
- 不生成配送任务:ensureDeliveryTaskForOrder 第四道守卫(在 pool.connect() 之前)。
- 拦发车:tryAdvanceOrderToDelivering 对自提单抛 400 self_pickup_no_delivery;
位置在 status>=60 / <50 两条早退之后(避免打断 orderStatusReconcileService 的周期性调用)。
- 配送管理列表不再显示自提单:nonSelfPickupOrderSql 加在 6 处查询。
- 回退器不再把自提单从 50 打回 30(demotePrematureInspectionStatus 的 UPDATE 加条件)。
- 确认取货接口 POST /workflow/orders/:orderCode/self-pickup-complete(仅管理员,
requireAdminRole + 复用既有权限码):只允许自提单 + 只允许停在 50 + 已 90 幂等;
走 completeOrderWithoutDriverDelivery(settleInventory:true) ⇒ 不新增状态边、不动状态链;
全段在租户上下文内(orders 为 FORCE RLS);写审计。
- 客户开关走领域接口 POST /workflow/customers/:customerCode/self-pickup(仅管理员 + 审计),
而不是前端通用网关直写 —— gatewayWriteBoundary 守卫禁止新增 /api/data 写入点(实测被拦下后改正)。
前端:
- 客户列表新增「是否取货」列 + 开关(仅管理员;走领域接口;在途锁)。
- 订单列表:50 的自提单显示「待取货」(与主系统免入库区分来源),管理员见「确认取货」按钮
(在途锁、成功/失败提示、刷新)。
- 三语文案(开关列、按钮、提示)。
测试:server/tests/selfPickup.test.ts 8 例(迁移只加列、快照、两道守卫及其相对位置、列表派生、
接口管理员鉴权、服务状态机、状态链未改)。
回归:定向子集 23 文件/170 用例,8 个失败**全部为基线既有**;网关边界守卫 4/4 通过(修好新引入的
写入点数超标);两端 tsc 0 错误。全量后端 26 failed files,其中 weighInspectionMergeSimilar 的
2 例为 5s 测试超时(机器负载高、时快时慢,非本次改动)。
This commit is contained in:
@@ -8,10 +8,47 @@ import {
|
||||
deleteCustomer,
|
||||
} from '../../../services/customerOps';
|
||||
import { getWorkflowCtx, requireWorkflowPermission } from '../context';
|
||||
import { requireAdminRole } from '../context';
|
||||
import { getGeoProvider, isValidLatLng } from '../../../services/geoProvider';
|
||||
|
||||
/** 客户模块 workflow API */
|
||||
export function mountCustomerWorkflowRoutes(router: Router): void {
|
||||
/**
|
||||
* 客户「是否取货」(自提)开关 —— 2026-10-15 需求。
|
||||
*
|
||||
* **仅管理员**;写 `customers.is_self_pickup`(只影响之后新建的订单)。
|
||||
* 走本领域接口而不是前端通用网关:`gatewayWriteBoundary` 守卫禁止新增 /api/data 写入点。
|
||||
*/
|
||||
router.post('/customers/:customerCode/self-pickup', authMiddleware, async (req: AuthRequest, res: Response) => {
|
||||
try {
|
||||
const ctx = await getWorkflowCtx(req);
|
||||
requireWorkflowPermission(ctx, ['customer_manage']);
|
||||
requireAdminRole(ctx, '仅管理员可设置客户「是否取货」');
|
||||
const customerCode = String(req.params.customerCode || '').trim();
|
||||
if (!customerCode) {
|
||||
return res.status(400).json({ error: 'invalid_request', error_description: '缺少客户编码' });
|
||||
}
|
||||
const branchCode = String(ctx?.branchCode || '').trim();
|
||||
if (!branchCode) {
|
||||
return res.status(400).json({ error: 'branch_required', error_description: '请选择当前操作分公司' });
|
||||
}
|
||||
const { setCustomerSelfPickup } = await import('../../../services/selfPickupCustomerService');
|
||||
const data = await setCustomerSelfPickup({
|
||||
customerCode,
|
||||
enabled: req.body?.enabled === true,
|
||||
branchCode,
|
||||
operatorId: req.userId || null,
|
||||
operatorRole: (ctx?.roles || []).join(',') || null,
|
||||
});
|
||||
return res.json({ data });
|
||||
} catch (error: any) {
|
||||
return res.status(error?.status || 500).json({
|
||||
error: error?.code || 'server_error',
|
||||
error_description: error?.message || '设置客户取货方式失败',
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
router.post('/customers/geocode-address', authMiddleware, async (req: AuthRequest, res: Response) => {
|
||||
try {
|
||||
const ctx = await getWorkflowCtx(req);
|
||||
|
||||
@@ -603,6 +603,40 @@ router.get('/orders/:orderCode/main-system-prep-facts', authMiddleware, async (r
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* 客户自提「确认取货」⇒ 结案(2026-10-15 开发者需求「是否取货」)。
|
||||
*
|
||||
* · **仅管理员**(开发者:权限给到管理员);
|
||||
* · 订单须为**自提单**(`orders.self_pickup`,录单时从客户主数据快照)且停在 **50「待取货」**
|
||||
* (分拣完毕 = 出库 = 扣库存之后才是"客户可来拿货");已 90 幂等返回;
|
||||
* · 收口复用无配送结案入口(30/50 → 90)⇒ **不新增状态边、不动状态链**;
|
||||
* · 结案照常按实收冻结计划量、生成结算单、补扣缺失出库;动作写审计(谁、何时)。
|
||||
*/
|
||||
router.post('/orders/:orderCode/self-pickup-complete', authMiddleware, async (req: AuthRequest, res: Response) => {
|
||||
try {
|
||||
const ctx = await getWorkflowCtx(req);
|
||||
requireWorkflowPermission(ctx, ['order_manage', 'order_edit', 'order_status_update']);
|
||||
requireAdminRole(ctx, '仅管理员可确认客户自提取货');
|
||||
const orderCode = String(req.params.orderCode || '').trim();
|
||||
if (!orderCode) {
|
||||
return res.status(400).json({ error: 'invalid_request', error_description: '缺少订单号' });
|
||||
}
|
||||
const { selfPickupComplete } = await import('../../../services/selfPickupService');
|
||||
const data = await selfPickupComplete({
|
||||
orderCode,
|
||||
branchCode: getEffectiveBranchCode(ctx!, readOperatingBranchCode(req)) || ctx?.branchCode || null,
|
||||
operatorId: req.userId || null,
|
||||
operatorRole: (ctx?.roles || []).join(',') || null,
|
||||
});
|
||||
return res.json({ data });
|
||||
} catch (error: any) {
|
||||
return res.status(error?.status || 500).json({
|
||||
error: error?.code || 'server_error',
|
||||
error_description: error?.message || '确认取货失败',
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
router.post('/orders/:orderCode/main-system-prep-facts/refresh', authMiddleware, async (req: AuthRequest, res: Response) => {
|
||||
try {
|
||||
const ctx = await getWorkflowCtx(req);
|
||||
|
||||
Reference in New Issue
Block a user