From 6354a6d8dc9a50a37ea31c5b77086b72f89ff231 Mon Sep 17 00:00:00 2001 From: liufumingren Date: Thu, 3 Sep 2026 17:03:56 +0800 Subject: [PATCH] =?UTF-8?q?fix(stockTransaction):=20keyword=20=E6=97=A0?= =?UTF-8?q?=E5=8C=B9=E9=85=8D=E5=95=86=E5=93=81=E6=97=B6=E6=9D=A1=E4=BB=B6?= =?UTF-8?q?=E7=BD=AE=E7=A9=BA=E9=98=B2=E5=85=A8=E8=A1=A8=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E6=B5=81=E6=B0=B4=EF=BC=8C=E8=B4=A7=E4=B8=BB=E6=A8=A1=E5=BC=8F?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E8=A1=A5=E5=85=85=20mode=3Dstore=20=E5=85=A5?= =?UTF-8?q?=E5=8F=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/service/systemMethods/stock/transaction.js | 1 + app/service/systems/stock_transaction.js | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/app/service/systemMethods/stock/transaction.js b/app/service/systemMethods/stock/transaction.js index 006b3be..1c06b0e 100644 --- a/app/service/systemMethods/stock/transaction.js +++ b/app/service/systemMethods/stock/transaction.js @@ -166,6 +166,7 @@ class StockTransactionMethodService extends MainService { orderId, sort: sortOption, pagination, + mode: 'store', }); return this.success('ok', result); diff --git a/app/service/systems/stock_transaction.js b/app/service/systems/stock_transaction.js index 2e0f6e7..918201d 100644 --- a/app/service/systems/stock_transaction.js +++ b/app/service/systems/stock_transaction.js @@ -433,18 +433,27 @@ class StockTransactionService extends Service { ? rawStockIds.map(item => Number(item)).filter(item => Number.isInteger(item) && item > 0) : []; const normalizedKeyword = String(keyword || '').trim(); + let keywordResolvedEmpty = false; if (normalizedKeyword && resolvedStockIds.length === 0) { const isStoreMode = mode === 'store'; const primaryDimCol = isStoreMode ? 'store_id' : 'warehouse_id'; const primaryDimVal = isStoreMode ? Number(storeId) : Number(warehouseId); if (primaryDimVal > 0) { resolvedStockIds = await this._resolveKeywordToStockIds(normalizedKeyword, primaryDimCol, primaryDimVal); + if (resolvedStockIds.length === 0) { + // keyword 无匹配商品,避免退化为查询全部流水 + keywordResolvedEmpty = true; + } } } const whereClauses = []; const replacements = {}; + if (keywordResolvedEmpty) { + whereClauses.push('1 = 0'); + } + // 数据范围限定:仓库侧或货主侧 if (warehouseId !== undefined && warehouseId !== null) { whereClauses.push('t.warehouse_id = :warehouseId'); @@ -686,12 +695,17 @@ class StockTransactionService extends Service { ? rawStockIds.map(item => Number(item)).filter(item => Number.isInteger(item) && item > 0) : []; const normalizedKeyword = String(keyword || '').trim(); + let keywordResolvedEmpty = false; if (normalizedKeyword && resolvedStockIds.length === 0) { const isStoreMode = mode === 'store'; const primaryDimCol = isStoreMode ? 'store_id' : 'warehouse_id'; const primaryDimVal = isStoreMode ? Number(storeId) : Number(warehouseId); if (primaryDimVal > 0) { resolvedStockIds = await this._resolveKeywordToStockIds(normalizedKeyword, primaryDimCol, primaryDimVal); + if (resolvedStockIds.length === 0) { + // keyword 无匹配商品,避免退化为导出全部流水 + keywordResolvedEmpty = true; + } } } @@ -699,6 +713,10 @@ class StockTransactionService extends Service { const whereClauses = []; const replacements = {}; + if (keywordResolvedEmpty) { + whereClauses.push('1 = 0'); + } + // 数据范围限定 if (warehouseId !== undefined && warehouseId !== null) { whereClauses.push('t.warehouse_id = :warehouseId');