diff --git a/backend/app/lib/orderCallback.js b/backend/app/lib/orderCallback.js index 85bf702..a4a96f2 100644 --- a/backend/app/lib/orderCallback.js +++ b/backend/app/lib/orderCallback.js @@ -578,7 +578,7 @@ async function confirmOutbound(ctx, { principalId, warehouseId, data }) { } // 确认摘要(含运单号/物流公司)与状态、库存同事务写入 summaryResult = await applyOutboundConfirmSummary(ctx, order, payload, packages, lines, { transaction, express: expressResult.first }); - await order.update({ status: 4, stock_deducted: 1 }, { transaction }); + await order.update({ status: 4, stock_deducted: 1, stock_locked: 0 }, { transaction }); await transaction.commit(); } catch (err) { await transaction.rollback(); @@ -950,8 +950,8 @@ async function cancelOrder(ctx, { principalId, warehouseId, data }) { return { ok: true, message: 'ok', data: { bill_id: order.id, bill_no: order.bill_no, bill_type: billType, status: 9, already_cancelled: true } }; } - // 出库单已推送(3)且未扣减库存:取消时释放锁定库存 - if (billType === 2 && order.status === 3 && !order.stock_deducted) { + // 出库单已推送(3)、或推送未成功但已锁定库存(stock_locked=1)且未扣减库存:取消时释放锁定库存 + if (billType === 2 && (order.status === 3 || Number(order.stock_locked) === 1) && !order.stock_deducted) { const items = await ctx.model.StockItem.findAll({ where: { bill_type: 2, bill_id: order.id, product_id: { [ctx.app.Sequelize.Op.ne]: null } }, attributes: [ 'product_id', 'code', 'name', 'quantity', 'inventory_type' ], @@ -977,7 +977,7 @@ async function cancelOrder(ctx, { principalId, warehouseId, data }) { transaction, }); } - await order.update({ status: 9 }, { transaction }); + await order.update({ status: 9, stock_locked: 0 }, { transaction }); await transaction.commit(); } catch (err) { await transaction.rollback();