From 3e7c9a7a10cc16f223c4a8dcd0b92f5ca4e7c2ae Mon Sep 17 00:00:00 2001 From: liufumingren Date: Sun, 9 Aug 2026 00:23:42 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20docs=20=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=20JS=20=E5=A4=B1=E6=95=88=20+=20=E5=85=A5=E5=BA=93=20?= =?UTF-8?q?locked=5Fquantity=20=E6=B5=81=E6=B0=B4=E8=A1=A5=E5=85=A8=20+=20?= =?UTF-8?q?stock=5Fstore=20=E6=9F=A5=E8=AF=A2=E6=9D=A1=E4=BB=B6=E8=A1=A5?= =?UTF-8?q?=E5=85=A8=20is=5Fvalid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. docs.js: 修复模板字面量中 '\n' 被服务端解释为换行符导致客户端 JS SyntaxError,所有交互功能失效(搜索/发送按钮) 2. inbound_direct_log.js: batch_no 修正为 effectiveBatchNo;storage 表更新时补全 before_locked_quantity/after_locked_quantity;新增 stock_id 归属校验 3. stock_store.js: 多处查询/更新补全 is_valid='Y' 过滤条件,避免软删除/失效数据泄露或误操作 4. storage/entry.js: 入库完成时补全 storage 表 before_locked_quantity/after_locked_quantity 流水字段 --- app/controller/docs.js | 2 +- app/service/systems/inbound_direct_log.js | 16 +++++++++++++++- app/service/systems/stock_store.js | 14 +++++++++++++- app/service/systems/storage/entry.js | 8 ++++++++ 4 files changed, 37 insertions(+), 3 deletions(-) diff --git a/app/controller/docs.js b/app/controller/docs.js index 9fcc600..7967b14 100644 --- a/app/controller/docs.js +++ b/app/controller/docs.js @@ -2043,7 +2043,7 @@ Content-Type: application/json }).then(function(res) { return res.text().then(function(txt) { return { status: res.status, body: txt }; }); }).then(function(r) { - resultEl.textContent = 'HTTP ' + r.status + '\n' + r.body; + resultEl.textContent = 'HTTP ' + r.status + '\\n' + r.body; resultEl.className = r.status === 200 ? 'req-result success' : 'req-result error'; }).catch(function(err) { resultEl.textContent = '推送失败: ' + err.message; diff --git a/app/service/systems/inbound_direct_log.js b/app/service/systems/inbound_direct_log.js index 9062369..49556a1 100644 --- a/app/service/systems/inbound_direct_log.js +++ b/app/service/systems/inbound_direct_log.js @@ -1042,7 +1042,7 @@ class InboundDirectLogService extends Service { where: { space_id: spaceId, stock_id: stockId, - batch_no: batchNo, + batch_no: effectiveBatchNo, inventory_type: inventoryType, is_enabled: 1, delete_at: null, @@ -1054,10 +1054,20 @@ class InboundDirectLogService extends Service { let sId = null; let sBeforeQty = 0; let sAfterQty = 0; + let sBeforeLockedQty = 0; + let sAfterLockedQty = 0; if (sRecord) { + if (Number(sRecord.stock_id) !== Number(stockId)) { + throw new Error( + `入库库存归属冲突: storage_id=${sRecord.id} 当前 stock_id=${sRecord.stock_id}, ` + + `本次入库 stock_id=${stockId}, space_id=${spaceId}, batch_no=${effectiveBatchNo}` + ); + } sBeforeQty = Number(sRecord.quantity) || 0; sAfterQty = sBeforeQty + qty; + sBeforeLockedQty = Number(sRecord.locked_quantity) || 0; + sAfterLockedQty = sBeforeLockedQty; await ctx.model.Storage.update({ quantity: app.Sequelize.literal(`quantity + ${qty}`), @@ -1077,6 +1087,8 @@ class InboundDirectLogService extends Service { } else { sBeforeQty = 0; sAfterQty = qty; + sBeforeLockedQty = 0; + sAfterLockedQty = 0; const createdStorage = await ctx.model.Storage.create({ warehouse_id: warehouseId, @@ -1114,6 +1126,8 @@ class InboundDirectLogService extends Service { quantity: qty, before_quantity: sBeforeQty, after_quantity: sAfterQty, + before_locked_quantity: sBeforeLockedQty, + after_locked_quantity: sAfterLockedQty, batch_no: effectiveBatchNo, inventory_type: inventoryType, order_type: 'entry_order', diff --git a/app/service/systems/stock_store.js b/app/service/systems/stock_store.js index 9e377e4..aedcf07 100644 --- a/app/service/systems/stock_store.js +++ b/app/service/systems/stock_store.js @@ -1437,6 +1437,7 @@ class stockStoreService extends Service { warehouse_id: warehouseId, store_id: sourceData.store_id, deleted_at: null, + is_valid: 'Y', }, attributes: [ 'id' ], raw: true, @@ -1548,6 +1549,7 @@ class stockStoreService extends Service { goods_code: sourceData.goods_code, warehouse_id: warehouseId, is_valid: 'Y', + deleted_at: null, }, attributes: [ 'id' ], raw: true, @@ -2557,7 +2559,8 @@ class stockStoreService extends Service { where: { id: { [Op.in]: ids }, warehouse_id: warehouseId, - delete_at: null, + deleted_at: null, + is_valid: 'Y', }, attributes: [ 'id' ], }); @@ -2784,6 +2787,8 @@ class stockStoreService extends Service { } else { const StockWarehouseWhere = { warehouse_id: warehouseId, + deleted_at: null, + is_valid: 'Y', }; const StockStoreWhere = {}; if (store_id) { @@ -2905,6 +2910,7 @@ class stockStoreService extends Service { where: { warehouse_id: warehouseId, deleted_at: null, + is_valid: 'Y', id: warehouse_stock, }, attributes: [ @@ -2985,6 +2991,7 @@ class stockStoreService extends Service { where: { warehouse_id: warehouseId, deleted_at: null, + is_valid: 'Y', id, }, attributes: [ @@ -3078,6 +3085,7 @@ class stockStoreService extends Service { where: { id, deleted_at: null, + is_valid: 'Y', warehouse_id: ctx.user.store_id, }, transaction, @@ -3325,6 +3333,7 @@ class stockStoreService extends Service { store_id: owner_id, warehouse_id, deleted_at: null, + is_valid: 'Y', }; if (item_id) { @@ -3370,6 +3379,7 @@ class stockStoreService extends Service { [Op.and]: [ { id: { [Op.in]: ids } }, { deleted_at: null }, + { is_valid: 'Y' }, ], }; @@ -3678,6 +3688,7 @@ class stockStoreService extends Service { const whereCondition = { warehouse_id: warehouseId, deleted_at: null, + is_valid: 'Y', }; // 如果有传入store_id,则添加store_id条件 @@ -3923,6 +3934,7 @@ class stockStoreService extends Service { id: stock_id, warehouse_id: warehouseId, deleted_at: null, + is_valid: 'Y', }, attributes: [ 'id', 'item_code', 'item_name', 'sku_property', 'stock_unit', 'quantity', 'locked_quantity' ], raw: true, diff --git a/app/service/systems/storage/entry.js b/app/service/systems/storage/entry.js index add9722..260a70a 100644 --- a/app/service/systems/storage/entry.js +++ b/app/service/systems/storage/entry.js @@ -1553,10 +1553,14 @@ class EntryService extends Service { let storageId = null; let storageBeforeQty = 0; let storageAfterQty = 0; + let storageBeforeLockedQty = 0; + let storageAfterLockedQty = 0; if (storageRecord) { storageBeforeQty = Number(storageRecord.quantity) || 0; storageAfterQty = storageBeforeQty + planQty; + storageBeforeLockedQty = Number(storageRecord.locked_quantity) || 0; + storageAfterLockedQty = storageBeforeLockedQty; await ctx.model.Storage.update({ quantity: app.Sequelize.literal(`quantity + ${planQty}`), @@ -1573,6 +1577,8 @@ class EntryService extends Service { } else { storageBeforeQty = 0; storageAfterQty = planQty; + storageBeforeLockedQty = 0; + storageAfterLockedQty = 0; const createdStorage = await ctx.model.Storage.create({ warehouse_id: warehouseId, @@ -1608,6 +1614,8 @@ class EntryService extends Service { quantity: planQty, before_quantity: storageBeforeQty, after_quantity: storageAfterQty, + before_locked_quantity: storageBeforeLockedQty, + after_locked_quantity: storageAfterLockedQty, batch_no: batchNo, inventory_type: inventoryType, order_type: 'entry_order',