From 5329aa8003df27daf4c7807af8f35f513fb79674 Mon Sep 17 00:00:00 2001 From: liufumingren Date: Mon, 14 Sep 2026 01:00:20 +0800 Subject: [PATCH] =?UTF-8?q?fix(backend):=20=E5=87=BA=E5=BA=93=E5=8D=95?= =?UTF-8?q?=E7=A1=AE=E8=AE=A4/=E5=8F=96=E6=B6=88=E6=97=B6=E5=90=8C?= =?UTF-8?q?=E6=AD=A5=E6=B8=85=E7=A9=BA=20stock=5Flocked?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - stockout.confirm 完成出库时置 stock_locked=0(与 stock_deducted 同步) - order.cancel 回调:单据已推送(3)、或推送未成功但已锁定库存(stock_locked=1),且尚未扣减时释放锁定并置 0 --- backend/app/lib/orderCallback.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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();