WMS_MAIN/app/service/qimenMethods/deliveryorder.js
liufumingren e76a6e3fa4 fix(order): 奇门/openapi 查单与取消接口跨分表查单
新增 app/lib/order_lookup.js 共享辅助函数(preloadOrderModels/findOrderAcrossTables/
findOrderByCodeAcrossTables),按 current→dispatch→history→outsourced 顺序命中即停;
模型预取置于事务外(工厂首次获取可能执行 DDL 隐式提交),事务内查询支持透传行锁。

改造 4 处接口:
- qimen deliveryorder.query / openapi deliveryorder.query:跨表查单,
  订单流转到配送/历史表后不再误报"未找到订单"(避免货主误判重推);
- qimen order.cancel / openapi order.cancel:跨表查找,命中非 current 表
  且 status=cancel 时幂等返回取消成功,其余情况返回"未找到对应的订单"。

回归验证(真实网关,脚本在 test/ 不入库):
- openapi:query 命中 dispatch、cancel 幂等成功、不存在单号报错
- qimen:同 4 场景全部符合预期
2026-09-20 22:12:35 +08:00

60 lines
2.0 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'use strict';
const MainService = require('../main');
const { findOrderByCodeAcrossTables } = require('../../lib/order_lookup');
class deliveryorderServer extends MainService {
async query(data) {
const orderCode = String(data?.request?.orderCode || '').trim();
if (!orderCode) {
return this.fail('订单号不能为空');
}
// 跨表查找:订单可能已流转到 dispatch/history/outsourced,仅查 current 会误报未找到
const { order } = await findOrderByCodeAcrossTables(this.ctx, this.warehouseId, {
delivery_order_code: orderCode,
});
const totalLines = 0;
if (order) {
return this.success('成功', {
totalLines,
deliveryOrder: {
deliveryOrderCode: order.delivery_order_code,
deliveryOrderId: order.delivery_order_code,
warehouseCode: order.warehouse_code,
orderType: order.order_type,
status: order.status,
orderConfirmTime: order.order_confirm_time,
operatorCode: 0,
operatorName: '',
operateTime: order.update_at,
},
packages: {
package: {},
},
orderLines: [],
});
}
return this.fail('未找到订单');
}
async create(data) {
const info = this.getInfo();
const res = await this.ctx.service.systems.deliveryOrder.addOrder(data, info, 'QM');
if (res.success) {
return this.success(res.message, {
createTime: this.app.formatDate(new Date()),
// addOrder 成功返回 data.orderId,兼容历史字段 deliveryOrderId
deliveryOrderId: (res.data && (res.data.orderId || res.data.deliveryOrderId)) || '',
warehouseCode: info.warehouseCode,
logisticsCode: (res.data && res.data.logisticsCode) || '',
});
}
return this.fail(res.message, { createTime: this.app.formatDate(new Date()) });
}
async batchcreate() {
return this.fail('批量创建接口未完善');
}
}
module.exports = deliveryorderServer;