fix(order): 订单详情兜底查询,配送表查空回退待处理表,待处理详情固定先查 dispatch 再兜底 current,避免表位流转后详情落空

This commit is contained in:
liufumingren 2026-09-03 17:00:53 +08:00
parent 66ea0c4c36
commit 007babb6c6
3 changed files with 68 additions and 8 deletions

View File

@ -1831,6 +1831,11 @@ class OrderBaseService extends MainService {
/**
* 查询订单详情。
*
* 兜底查询:当表位类型为配送表(dispatch)且查询不到订单时,
* 自动回退到待处理表(current)再查询一次,避免订单在配送表与
* 待处理表之间流转后详情查询落空。
*
* @param {Object} data 请求体。
* @return {Promise<Object>} 订单头、商品明细和运单信息。
*/
@ -1849,18 +1854,30 @@ class OrderBaseService extends MainService {
}
const orderId = orderIds[0];
const orderModel = await this.getOrderModelByTableType(tableType, warehouseId);
const orderWhere = this.buildOrderWhere([ orderId ], warehouseId);
const order = await orderModel.findOne({
// 实际使用的表位类型:配送表(dispatch)查询不到时兜底查询待处理表(current)
let actualTableType = tableType;
let orderModel = await this.getOrderModelByTableType(actualTableType, warehouseId);
let order = await orderModel.findOne({
where: orderWhere,
raw: true,
});
if (!order && actualTableType === 'dispatch') {
actualTableType = 'current';
orderModel = await this.getOrderModelByTableType(actualTableType, warehouseId);
order = await orderModel.findOne({
where: orderWhere,
raw: true,
});
}
if (!order) {
throw new Error('订单不存在或不属于当前仓库');
}
const orderItemsModel = await this.getOrderItemsModelByTableType(tableType, warehouseId);
const orderItemsModel = await this.getOrderItemsModelByTableType(actualTableType, warehouseId);
const orderItems = await orderItemsModel.findAll({
where: {
order_id: orderId,

View File

@ -694,6 +694,10 @@ class PendingOrderService extends OrderBaseService {
* 仅返回订单头、商品明细与运单信息;
* 待处理详情不再返回 logs 字段,也不触发操作日志查询。
*
* 兜底查询:忽略请求中的 tableType 等表位参数,
* 固定先查询配送表(dispatch),查询不到时回退到待处理表(current)再查询一次,
* 避免订单在配送表与待处理表之间流转后详情查询落空。
*
* @param {Object} data 请求体。
* @return {Promise<Object>} 订单头、商品明细和运单信息。
*/
@ -701,7 +705,6 @@ class PendingOrderService extends OrderBaseService {
const requestData = this.isPlainObject(data) ? data : {};
const warehouseId = this.getWarehouseId();
const orderIds = this.normalizeOrderIds(requestData);
const tableType = this.resolveOrderTableType(requestData);
if (orderIds.length === 0) {
throw new Error('订单ID不能为空');
@ -712,18 +715,30 @@ class PendingOrderService extends OrderBaseService {
}
const orderId = orderIds[0];
const orderModel = await this.getOrderModelByTableType(tableType, warehouseId);
const orderWhere = this.buildOrderWhere([ orderId ], warehouseId);
const order = await orderModel.findOne({
// 忽略传入的 tableType:固定先查配送表(dispatch),查不到再兜底待处理表(current)
let actualTableType = 'dispatch';
let orderModel = await this.getOrderModelByTableType(actualTableType, warehouseId);
let order = await orderModel.findOne({
where: orderWhere,
raw: true,
});
if (!order) {
actualTableType = 'current';
orderModel = await this.getOrderModelByTableType(actualTableType, warehouseId);
order = await orderModel.findOne({
where: orderWhere,
raw: true,
});
}
if (!order) {
throw new Error('订单不存在或不属于当前仓库');
}
const orderItemsModel = await this.getOrderItemsModelByTableType(tableType, warehouseId);
const orderItemsModel = await this.getOrderItemsModelByTableType(actualTableType, warehouseId);
const orderItems = await orderItemsModel.findAll({
where: {
order_id: orderId,
@ -6005,6 +6020,7 @@ ${numbered}`;
* 执行批量解除拦截后台任务。
*
* 直接对给定订单ID数组,将 intercept_status 更新为 'none',并写入操作日志 ORDER_INTERCEPT_CANCEL。
* 同时释放订单对应的拦截锁定库存(intercept_locked_quantity 回落到可用数量,失败不阻断主流程)。
* 仅处理当前仓库上下文内的订单。
*
* @param {Object} params 任务参数。
@ -6172,6 +6188,10 @@ ${numbered}`;
);
}
// 注意:解除拦截不操作拦截锁定数量字段——业务上「拦截→取消拦截」两个环节均不动库存口径,
// 拦截锁定数量仅在库内拦截确定(confirmIntercept/interceptScan)时占用,
// 其回落由后续特定的入库处理链路统一接管,取消拦截环节不做释放。
// 写入操作日志 ORDER_INTERCEPT_CANCEL
const logPayloads = chunkRows.map(row => {
const orderId = Number(row.id || 0);

View File

@ -17,6 +17,9 @@ function createHarness(storeId = 100321) {
},
},
},
model: {
Picking: undefined,
},
logger: {
warn() {},
},
@ -39,6 +42,26 @@ function createHarness(storeId = 100321) {
};
},
},
stockWarehouse: {
async getStockDetails() {
return [
{
id: 7,
item_code: 'ITEM-7',
item_name: '测试商品',
sku_property: '',
quantity: 10,
locked_quantity: 0,
is_batch_mgmt: 'N',
is_shelf_life_mgmt: 'N',
is_images: 'N',
store_id: storeId,
packing_requirements: '',
stock_unit: '',
},
];
},
},
},
},
};
@ -58,7 +81,7 @@ function createHarness(storeId = 100321) {
service.getOrderItemsModelByTableType = async () => ({
async findAll(args) {
calls.findOrderItemsArgs = args;
return [{ id: 1, order_id: 99 }];
return [{ id: 1, order_id: 99, stock_id: 7 }];
},
});