diff --git a/app/service/systemMethods/order/wave.js b/app/service/systemMethods/order/wave.js index 9ee9968..94d6f5c 100644 --- a/app/service/systemMethods/order/wave.js +++ b/app/service/systemMethods/order/wave.js @@ -986,6 +986,8 @@ class WaveService extends OrderBaseService { intercept_status: 'none', lock_status: 'none', wave_id: 0, + // 波次抓取不抓取 B2B 订单(NULL 视为非 B2B,兼容存量行) + is_b2b: { [Op.or]: [{ [Op.is]: null }, 'N' ] }, }; const itemPartType = String(structure.item_part_type || '').trim(); @@ -2913,6 +2915,8 @@ class WaveService extends OrderBaseService { intercept_status: 'none', lock_status: 'none', wave_id: 0, + // 波次抓取不抓取 B2B 订单(NULL 视为非 B2B,兼容存量行) + is_b2b: { [Op.or]: [{ [Op.is]: null }, 'N' ] }, }; if (storeId > 0) { @@ -3167,6 +3171,8 @@ class WaveService extends OrderBaseService { intercept_status: 'none', lock_status: 'none', wave_id: 0, + // 波次抓取不抓取 B2B 订单(NULL 视为非 B2B,兼容存量行) + is_b2b: { [Op.or]: [{ [Op.is]: null }, 'N' ] }, }; if (storeId > 0) { @@ -3431,6 +3437,8 @@ class WaveService extends OrderBaseService { intercept_status: 'none', lock_status: 'none', wave_id: 0, + // 波次抓取不抓取 B2B 订单(NULL 视为非 B2B,兼容存量行) + is_b2b: { [Op.or]: [{ [Op.is]: null }, 'N' ] }, }; if (storeId > 0) { @@ -3734,6 +3742,7 @@ class WaveService extends OrderBaseService { AND o.outbound_status != 'padding' AND o.intercept_status = 'none' AND o.lock_status = 'none' + AND (o.is_b2b IS NULL OR o.is_b2b = 'N') WHERE m.warehouse_id = :warehouseId AND m.strategy_id = :strategyId ORDER BY o.id ASC @@ -3975,6 +3984,7 @@ class WaveService extends OrderBaseService { AND o.outbound_status != 'padding' AND o.intercept_status = 'none' AND o.lock_status = 'none' + AND (o.is_b2b IS NULL OR o.is_b2b = 'N') INNER JOIN ( SELECT src.items_hash AS structure_key${groupKeyExtra}, @@ -3990,6 +4000,7 @@ class WaveService extends OrderBaseService { AND src.outbound_status != 'padding' AND src.intercept_status = 'none' AND src.lock_status = 'none' + AND (src.is_b2b IS NULL OR src.is_b2b = 'N') GROUP BY src.items_hash${requireSameExpress ? `, ${expressExpr('src')}` : ''} ) same_structure ON same_structure.structure_key = o.items_hash${joinKeyExtra} @@ -4077,6 +4088,7 @@ class WaveService extends OrderBaseService { AND o.outbound_status != 'padding' AND o.intercept_status = 'none' AND o.lock_status = 'none' + AND (o.is_b2b IS NULL OR o.is_b2b = 'N') INNER JOIN ( SELECT src.items_hash AS structure_key${groupKeyExtra}, @@ -4092,6 +4104,7 @@ class WaveService extends OrderBaseService { AND src.outbound_status != 'padding' AND src.intercept_status = 'none' AND src.lock_status = 'none' + AND (src.is_b2b IS NULL OR src.is_b2b = 'N') GROUP BY src.items_hash${requireSameExpress ? `, ${expressExpr('src')}` : ''} ) same_structure ON same_structure.structure_key = o.items_hash${joinKeyExtra} @@ -6943,6 +6956,8 @@ class WaveService extends OrderBaseService { intercept_status: 'none', lock_status: 'none', print_status: { [Op.ne]: 'fin' }, + // 波次策略扫描不扫描 B2B 订单(NULL 视为非 B2B,兼容存量行) + is_b2b: { [Op.or]: [{ [Op.is]: null }, 'N' ] }, }; if (!forceRescan) { @@ -7502,6 +7517,7 @@ class WaveService extends OrderBaseService { intercept_status: 'none', lock_status: 'none', print_status: { [Op.ne]: 'fin' }, + is_b2b: { [Op.or]: [{ [Op.is]: null }, 'N' ] }, [Op.or]: [ { wave_strategy_version: { [Op.ne]: currentVersion } }, { wave_strategy_version: { [Op.is]: null } }, @@ -8188,6 +8204,8 @@ class WaveService extends OrderBaseService { step: { [Op.in]: [ 1, 2, 3 ] }, status: { [Op.ne]: 'cancel' }, outbound_status: { [Op.ne]: 'padding' }, + // 波次抓取不抓取 B2B 订单(NULL 视为非 B2B,兼容存量行) + is_b2b: { [Op.or]: [{ [Op.is]: null }, 'N' ] }, [Op.or]: candidateWhereList, }, raw: true, @@ -8276,7 +8294,7 @@ class WaveService extends OrderBaseService { try { const orderRows = await orderModel.findAll({ - attributes: [ 'id', 'wave_id', 'wave_no', 'step', 'status', 'outbound_status', 'items_hash', 'items', 'logistics_name', 'intercept_status', 'lock_status' ], + attributes: [ 'id', 'wave_id', 'wave_no', 'step', 'status', 'outbound_status', 'items_hash', 'items', 'logistics_name', 'intercept_status', 'lock_status', 'is_b2b' ], where: { id: { [Op.in]: normalizedIds }, }, @@ -8305,6 +8323,12 @@ class WaveService extends OrderBaseService { .map(row => Number(row && row.id || 0)) .filter(id => Number.isInteger(id) && id > 0)) ] .sort((a, b) => a - b); + // B2B 订单不参与波次抓取(NULL 视为非 B2B,兼容存量行) + const excludedB2bOrderIds = [ ...new Set(normalizedOrderRows + .filter(row => String(row && row.is_b2b || '').trim() === 'Y') + .map(row => Number(row && row.id || 0)) + .filter(id => Number.isInteger(id) && id > 0)) ] + .sort((a, b) => a - b); const fetchableRows = normalizedOrderRows.filter(row => { const orderId = Number(row && row.id || 0); @@ -8328,6 +8352,11 @@ class WaveService extends OrderBaseService { return false; } + // B2B 订单不允许抓取波次 + if (String(row && row.is_b2b || '').trim() === 'Y') { + return false; + } + return true; }); @@ -8349,6 +8378,7 @@ class WaveService extends OrderBaseService { excluded_existing_wave_order_ids: excludedExistingWaveOrderIds, excluded_intercepted_order_ids: excludedInterceptedOrderIds, excluded_locked_order_ids: excludedLockedOrderIds, + excluded_b2b_order_ids: excludedB2bOrderIds, skipped_order_ids: skippedOrderIds, not_found_order_ids: notFoundOrderIds, }); @@ -8467,6 +8497,7 @@ class WaveService extends OrderBaseService { excluded_existing_wave_order_ids: excludedExistingWaveOrderIds, excluded_intercepted_order_ids: excludedInterceptedOrderIds, excluded_locked_order_ids: excludedLockedOrderIds, + excluded_b2b_order_ids: excludedB2bOrderIds, skipped_order_ids: skippedOrderIds, not_found_order_ids: notFoundOrderIds, }); @@ -11858,6 +11889,7 @@ class WaveService extends OrderBaseService { AND o.outbound_status != 'padding' AND o.intercept_status = 'none' AND o.lock_status = 'none' + AND (o.is_b2b IS NULL OR o.is_b2b = 'N') AND (:createdBefore IS NULL OR o.create_at < :createdBefore) INNER JOIN ( SELECT @@ -11874,6 +11906,7 @@ class WaveService extends OrderBaseService { AND src.outbound_status != 'padding' AND src.intercept_status = 'none' AND src.lock_status = 'none' + AND (src.is_b2b IS NULL OR src.is_b2b = 'N') GROUP BY ${structureExpr('src')}${groupKeyExtra} ) same_structure ON same_structure.structure_key = ${structureExpr('o')}${joinKeyExtra} @@ -12152,6 +12185,8 @@ class WaveService extends OrderBaseService { step: { [Op.ne]: 0 }, status: { [Op.ne]: 'cancel' }, outbound_status: { [Op.ne]: 'padding' }, + // 尾部兜底:候选筛选后再次排除 B2B 订单(NULL 视为非 B2B,兼容存量行) + is_b2b: { [Op.or]: [{ [Op.is]: null }, 'N' ] }, }, raw: true, transaction, @@ -12402,6 +12437,7 @@ class WaveService extends OrderBaseService { AND o.outbound_status != 'padding' AND o.intercept_status = 'none' AND o.lock_status = 'none' + AND (o.is_b2b IS NULL OR o.is_b2b = 'N') AND ${structureExpr('o')} IN (:structureKeys)${expressCondition} ORDER BY o.id ASC `, {