feat(auto-outbound): 自动出库改为「开关 + 规则数组」,支持多条规则与跨天放行

- subject_config 新增 auto_outbound_enabled(默认 false);auto_outbound_rules 由对象改为数组,
  每项仅含 require_pack / require_weigh / require_sync / exclude_same_day_outbound /
  same_day_outbound_deadline_time / same_day_outbound_release_time
- 固定基线:已复核(recheck_status=fin)+ 已分配储位(storage_status=fin);已打印、已拣货不再校验
- 规则内 AND、规则间 OR(任一命中即出库);空数组不出库且不告警
- 旧对象结构不再兼容:读路径按默认(关闭)处理,写路径返回 400 提示重新配置
- 放行时间支持跨天 00:00~47:59(27:00 = 次日 03:00);按订单复核时间所在北京日计算未放行窗口
- 定时任务与手动触发统一走新规则;自动出库写入操作日志 ORDER_AUTO_OUTBOUND
- 同步 methods/system.json、methods/changes/system.json 与 AI_METHOD_ROUTING.md

涉及接口:setting.warehouse.getSettings / getFieldMeta / saveSettings、outbound.autoOutbound
This commit is contained in:
liufumingren 2026-10-16 05:27:30 +08:00
parent e602d205b2
commit fdec622f2d
9 changed files with 658 additions and 297 deletions

View File

@ -621,8 +621,8 @@ rg "class .*Service|module.exports" app/service/qimenMethods
- buildOperationLogData, buildBusinessLogWhere, formatOperationLogRows, createOperationLog, createOperationLogs, queryLogsByBusinessType, queryStockLogs, queryOrderLogs, queryAllOrderLogs, queryAllLogsByBusinessType, queryReceivingLogs, queryEntryOrderLogs, queryStockoutLogs, getMessageDetail
- app/service/systems/order_async.js (9)
- finalizeSuccessfulQimenSync, syncQmOrders, syncManualOrders, flushDeferredOrderSyncNotices, syncApiOrders, syncStockoutOrders, buildStockoutConfirmRequest, notifyStockoutExternal, resolveOpenApiAppByStore
- app/service/systems/order_auto_outbound.js (11)
- getEnabledAutoOutboundWarehouses, normalizeSubjectConfigForAutoOutbound, buildAutoOutboundWhere, findAutoOutboundOrders, buildSameDayOutboundCutoffUtc, resolveSameDayTime, resolveSameDayReleaseTime, buildSameDayReleaseUtc, findOrderIdsWithWeigh, processWarehouseAutoOutbound, executeAutoOutbound
- app/service/systems/order_auto_outbound.js (17)
- getEnabledAutoOutboundWarehouses, isAutoOutboundEnabled, resolveAutoOutboundRules, normalizeSubjectConfigForAutoOutbound, buildAutoOutboundWhere, findAutoOutboundOrderIds, resolveSameDayTime, resolveSameDayDeadlineTime, resolveSameDayReleaseTime, buildBeijingDayStartUtc, buildSameDayOutboundHoldWindows, buildSameDayOutboundRecheckCondition, findOrderIdsWithWeigh, processWarehouseAutoOutbound, writeAutoOutboundOperationLogs, buildAutoOutboundRuleSummary, executeAutoOutbound
- app/service/systems/order_delivery_archive.js (16)
- getArchiveDefaults, buildArchiveOptions, buildArchiveThresholds, normalizeWarehouseIds, listDispatchWarehouseIds, getArchiveModels, buildCandidateWhere, buildQueryOptions, buildHistoryOrderRow, buildHistoryItemRow, getArchiveErrorInfo, rollbackQuietly, archiveDispatchBatch, archiveDispatchOrdersForWarehouse, resolveFailureCursor, archiveDispatchOrdersToHistory
- app/service/systems/order_delivery_migration.js (15)

View File

@ -96,6 +96,7 @@ module.exports = {
ORDER_RETURN_RECEIVED: '退回收到',
ORDER_LOCK: '订单锁定',
ORDER_UNLOCK: '订单解锁',
ORDER_AUTO_OUTBOUND: '自动出库',
// 库存管理
STORAGE_TRANSFER_LOCATION: '库位调拨',

View File

@ -31,18 +31,17 @@ module.exports = app => {
const DEFAULT_SAME_DAY_OUTBOUND_DEADLINE_TIME = '06:00';
const DEFAULT_SAME_DAY_OUTBOUND_RELEASE_TIME = '22:00';
const DEFAULT_AUTO_OUTBOUND_RULES = Object.freeze({
enabled: false,
require_recheck: true,
require_pack: true,
require_weigh: true,
require_sync: true,
require_print: true,
require_pick: true,
exclude_same_day_outbound: true,
same_day_outbound_deadline_time: '06:00',
same_day_outbound_release_time: '22:00',
});
// 自动出库开关:独立字段,默认关闭
const DEFAULT_AUTO_OUTBOUND_ENABLED = false;
// 自动出库规则:数组,默认空数组(空数组 = 不出库任何订单);每项规则独立判断,任一命中即出库
const DEFAULT_AUTO_OUTBOUND_RULES = Object.freeze([]);
/**
* 获取自动出库规则默认值(新数组,避免共享冻结数组引用)。
*
* @return {Array<Object>} 默认自动出库规则数组。
*/
const getDefaultAutoOutboundRules = () => [];
const DEFAULT_CUTOFF_ORDER_TIME = '18:00';
const CUTOFF_ORDER_TIME_MIN = '00:00';
@ -107,6 +106,7 @@ module.exports = app => {
stock_static_hours: 168,
return_unpack_max_record_minutes: 5,
inventory_warning_rules: DEFAULT_INVENTORY_WARNING_RULES,
auto_outbound_enabled: DEFAULT_AUTO_OUTBOUND_ENABLED,
auto_outbound_rules: DEFAULT_AUTO_OUTBOUND_RULES,
cutoff_order_enabled: 1,
cutoff_order_time: DEFAULT_CUTOFF_ORDER_TIME,
@ -193,61 +193,106 @@ module.exports = app => {
};
/**
* 规范化 HH:mm 时间文本。
* 缺省或格式非法时回退指定默认值。
* 规范化 HH:mm 时间文本(支持跨天:小时最大 maxHour)。
* 缺省或格式非法(含超出 maxHour)时回退指定默认值。
*
* @param {string|undefined|null} value 原始时间文本。
* @param {string} defaultValue 默认 HH:mm。
* @param {number} [maxHour=23] 允许的最大小时(放开时间用 47,表示可跨到次日)。
* @return {string} 规范化后的 HH:mm 文本。
*/
const normalizeHourMinuteTime = (value, defaultValue) => {
const normalizeHourMinuteTime = (value, defaultValue, maxHour = 23) => {
if (value === undefined || value === null || value === '') {
return defaultValue;
}
const text = String(value).trim();
return /^([01]\d|2[0-3]):[0-5]\d$/.test(text) ? text : defaultValue;
const match = /^(\d{1,2}):([0-5]\d)$/.exec(text);
if (!match || Number(match[1]) > maxHour) {
return defaultValue;
}
return `${String(Number(match[1])).padStart(2, '0')}:${match[2]}`;
};
/**
* 将 HH:mm 文本解析为总分钟数(用于时间先后比较)。
* 将 HH:mm 文本解析为总分钟数(支持跨天,用于时间先后比较)。
*
* @param {string} timeText HH:mm 文本。
* @param {string} timeText HH:mm 文本(小时可超过 23)。
* @return {number} 总分钟数。
*/
const parseHourMinuteToMinutes = timeText => {
const match = /^(\d{2}):(\d{2})$/.exec(String(timeText || '').trim());
const match = /^(\d{1,2}):(\d{2})$/.exec(String(timeText || '').trim());
if (!match) return 0;
return Number(match[1]) * 60 + Number(match[2]);
};
/**
* 规范化「允许当天出库最后时间」配置(HH:mm)。
* 规范化「允许当天出库最后时间」配置(HH:mm,当天内 00:00~23:59)。
* 缺省或格式非法时回退默认 06:00。
*
* @param {string|undefined|null} value 原始时间文本。
* @return {string} 规范化后的 HH:mm 文本。
*/
const normalizeSameDayOutboundDeadlineTime = value => normalizeHourMinuteTime(value, DEFAULT_SAME_DAY_OUTBOUND_DEADLINE_TIME);
const normalizeSameDayOutboundDeadlineTime = value => normalizeHourMinuteTime(value, DEFAULT_SAME_DAY_OUTBOUND_DEADLINE_TIME, 23);
/**
* 规范化「当天放开时间」配置(HH:mm)。
* 规范化「放行时间」配置(HH:mm,支持跨天 00:00~47:59,如 27:00 = 次日 03:00)。
* 缺省或格式非法时回退默认 22:00。
*
* @param {string|undefined|null} value 原始时间文本。
* @return {string} 规范化后的 HH:mm 文本。
*/
const normalizeSameDayOutboundReleaseTime = value => normalizeHourMinuteTime(value, DEFAULT_SAME_DAY_OUTBOUND_RELEASE_TIME);
const normalizeSameDayOutboundReleaseTime = value => normalizeHourMinuteTime(value, DEFAULT_SAME_DAY_OUTBOUND_RELEASE_TIME, 47);
/**
* 规范化自动化出库规则配置。
* 确保 enabled/require_recheck/require_pack/require_weigh/require_sync/require_print/require_pick 等字段存在且类型正确。
* 规范化单条自动出库规则。
* 字段:require_pack(需已打包) / require_weigh(需已称重) / require_sync(需已同步)
* / exclude_same_day_outbound(不出库当天订单) / same_day_outbound_deadline_time
* / same_day_outbound_release_time。
* 三个 require_* 沿用「非 false 即 true(缺省开启)」口径;非对象项、时间越界抛错。
*
* @param {Object|undefined|null} rawRules 原始自动化出库规则。
* @return {Object} 规范化后的自动化出库规则对象。
* @param {Object} rawRule 原始单条规则。
* @param {number} index 规则下标(用于报错定位)。
* @return {Object} 规范化后的单条规则。
*/
const normalizeAutoOutboundRule = (rawRule, index) => {
const basePath = `subject_config.auto_outbound_rules[${index}]`;
if (!rawRule || typeof rawRule !== 'object' || Array.isArray(rawRule)) {
throw new Error(`${basePath} 必须是对象`);
}
const sameDayOutboundDeadlineTime = normalizeSameDayOutboundDeadlineTime(rawRule.same_day_outbound_deadline_time);
const sameDayOutboundReleaseTime = normalizeSameDayOutboundReleaseTime(rawRule.same_day_outbound_release_time);
// 保存时校验:允许当天出库最后时间不能大于当天放开时间
if (parseHourMinuteToMinutes(sameDayOutboundDeadlineTime) > parseHourMinuteToMinutes(sameDayOutboundReleaseTime)) {
throw new Error(`自动出库规则第 ${index + 1} 条:允许当天出库最后时间不能大于当天放开时间`);
}
return {
require_pack: rawRule.require_pack !== false,
require_weigh: rawRule.require_weigh !== false,
require_sync: rawRule.require_sync !== false,
exclude_same_day_outbound: normalizeBooleanFlag(
rawRule.exclude_same_day_outbound,
`${basePath}.exclude_same_day_outbound`
) !== false,
same_day_outbound_deadline_time: sameDayOutboundDeadlineTime,
same_day_outbound_release_time: sameDayOutboundReleaseTime,
};
};
/**
* 规范化自动出库规则数组。
* 旧版本的对象结构(含 enabled/require_recheck/require_print/require_pick)不兼容:
* 一律按默认(空数组)处理,需重新配置。
*
* @param {Array|Object|string|undefined|null} rawRules 原始自动出库规则。
* @return {Array<Object>} 规范化后的自动出库规则数组。
*/
const normalizeAutoOutboundRules = rawRules => {
if (rawRules === undefined || rawRules === null || rawRules === '') {
return { ...DEFAULT_AUTO_OUTBOUND_RULES };
return [];
}
let parsed = rawRules;
@ -255,34 +300,15 @@ module.exports = app => {
try {
parsed = JSON.parse(parsed);
} catch (error) {
return { ...DEFAULT_AUTO_OUTBOUND_RULES };
return [];
}
}
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
return { ...DEFAULT_AUTO_OUTBOUND_RULES };
if (!Array.isArray(parsed)) {
return [];
}
const sameDayOutboundDeadlineTime = normalizeSameDayOutboundDeadlineTime(parsed.same_day_outbound_deadline_time);
const sameDayOutboundReleaseTime = normalizeSameDayOutboundReleaseTime(parsed.same_day_outbound_release_time);
// 保存时校验:允许当天出库最后时间不能大于当天放开时间
if (parseHourMinuteToMinutes(sameDayOutboundDeadlineTime) > parseHourMinuteToMinutes(sameDayOutboundReleaseTime)) {
throw new Error('自动出库规则:允许当天出库最后时间不能大于当天放开时间');
}
return {
enabled: normalizeBooleanFlag(parsed.enabled, 'auto_outbound_rules.enabled') === true,
require_recheck: parsed.require_recheck !== false,
require_pack: parsed.require_pack !== false,
require_weigh: parsed.require_weigh !== false,
require_sync: parsed.require_sync !== false,
require_print: parsed.require_print !== false,
require_pick: parsed.require_pick !== false,
exclude_same_day_outbound: normalizeBooleanFlag(parsed.exclude_same_day_outbound, 'auto_outbound_rules.exclude_same_day_outbound') !== false,
same_day_outbound_deadline_time: sameDayOutboundDeadlineTime,
same_day_outbound_release_time: sameDayOutboundReleaseTime,
};
return parsed.map((rule, index) => normalizeAutoOutboundRule(rule, index));
};
/**
@ -454,6 +480,7 @@ module.exports = app => {
return {
...DEFAULT_SUBJECT_CONFIG,
inventory_warning_rules: getDefaultInventoryWarningRules(),
auto_outbound_rules: getDefaultAutoOutboundRules(),
};
}
@ -650,6 +677,10 @@ module.exports = app => {
}
normalized.inventory_warning_rules = normalizeInventoryWarningRules(parsed.inventory_warning_rules);
normalized.auto_outbound_enabled = normalizeBooleanFlag(
parsed.auto_outbound_enabled,
'subject_config.auto_outbound_enabled'
) === true;
normalized.auto_outbound_rules = normalizeAutoOutboundRules(parsed.auto_outbound_rules);
normalized.receiving_pending_inbound_notice = normalizeReceivingPendingInboundNotice(
parsed.receiving_pending_inbound_notice
@ -947,6 +978,7 @@ module.exports = app => {
Store.DEFAULT_INVENTORY_WARNING_RULES = DEFAULT_INVENTORY_WARNING_RULES;
Store.DEFAULT_SUBJECT_CONFIG = DEFAULT_SUBJECT_CONFIG;
Store.normalizeSubjectConfig = normalizeSubjectConfig;
Store.normalizeAutoOutboundRules = normalizeAutoOutboundRules;
// 实例方法:检查商家是否启用
Store.prototype.isEnabled = function() {

View File

@ -2,20 +2,22 @@
/**
* 自动化出库定时任务。
* 每分钟在单 worker 中扫描一次:当订单满足仓库配置的自动化出库条件时,
* 自动标记出库并将订单状态更新为已完成。
* 每分钟在单 worker 中扫描一次:当订单满足仓库配置的自动化出库规则时,
* 自动标记出库并将订单状态更新为已完成,同时写入订单操作日志(ORDER_AUTO_OUTBOUND)。
*
* 出库条件(由仓库 subject_config.auto_outbound_rules 控制):
* 1. 已复核:recheck_status = 'fin'
* 2. 已打包:pack_status = 'fin'
* 3. 已称重:wms_order_express.weighing_weight > 0
* 4. 已同步:sync_status = 'fin'
* 5. 已打印:print_status = 'fin'
* 6. 已拣货:pick_status = 'fin'
* 开关与规则(仓库 subject_config):
* - auto_outbound_enabled:是否启用,默认 false(关闭);
* - auto_outbound_rules:规则数组(空数组时不自动出库),每项规则独立判断,任一命中即出库。
*
* 各条件是否必须可由仓库配置独立控制。
* 固定基线条件:已复核(recheck_status='fin')+ 已分配储位(storage_status='fin'),
* 未复核订单一律不自动出库。
*
* 当天订单限制(exclude_same_day_outbound,默认 true):
* 单条规则可选条件(仅校验这三项):
* 1. 已打包:pack_status = 'fin'(require_pack)
* 2. 已称重:wms_order_express.weighing_weight > 0(require_weigh)
* 3. 已同步:sync_status = 'fin'(require_sync)
*
* 当天订单限制(exclude_same_day_outbound,默认 true,按规则独立生效):
* 开启时,在当天放开时间(same_day_outbound_release_time,默认北京时间 22:00)前,
* 北京时间当天「允许当天出库最后时间」(same_day_outbound_deadline_time,默认 06:00)
* 起复核(recheck_time)的订单不自动出库;

View File

@ -24,14 +24,13 @@ class OutboundService extends MainService {
/**
* 手动触发自动化出库扫描。
*
* 扫描当前仓库下满足自动化出库条件的订单并执行出库操作。
* 条件由仓库 subject_config.auto_outbound_rules 控制:
* - recheck_status = 'fin'(已复核)
* - pack_status = 'fin'(已打包)
* - wms_order_express.weighing_weight > 0(已称重)
* - sync_status = 'fin'(已同步)
* - print_status = 'fin'(已打印)
* - pick_status = 'fin'(已拣货)
* 扫描当前仓库下满足自动化出库规则的订单并执行出库操作(任一规则命中即出库)。
* 开关与规则由仓库 subject_config 控制:
* - auto_outbound_enabled:是否启用(默认关闭);
* - auto_outbound_rules:规则数组(空数组时不执行),每项仅校验:
* require_pack(pack_status='fin')/ require_weigh(wms_order_express.weighing_weight>0)
* / require_sync(sync_status='fin')。
* 固定基线条件:已复核(recheck_status='fin')+ 已分配储位(storage_status='fin')。
*
* @param {Object} data 请求参数。
* @param {number} [data.warehouseId] 指定仓库ID,不传则使用当前用户上下文仓库。
@ -71,13 +70,19 @@ class OutboundService extends MainService {
}
}
const autoOutboundRules = subjectConfig && subjectConfig.auto_outbound_rules;
const orderAutoOutboundService = ctx.service.systems.orderAutoOutbound;
if (!autoOutboundRules || !autoOutboundRules.enabled) {
if (!orderAutoOutboundService.isAutoOutboundEnabled(subjectConfig)) {
throw new Error('当前仓库未启用自动化出库');
}
const result = await ctx.service.systems.orderAutoOutbound.processWarehouseAutoOutbound(
const autoOutboundRules = orderAutoOutboundService.resolveAutoOutboundRules(subjectConfig);
if (autoOutboundRules.length === 0) {
throw new Error('当前仓库未配置自动化出库规则');
}
const result = await orderAutoOutboundService.processWarehouseAutoOutbound(
warehouseId,
autoOutboundRules
);

View File

@ -8,22 +8,35 @@ const OUTBOUND_STEP = 4;
const ORDER_STATUS_FINISHED = 'finished';
const MAX_BATCH_SIZE = 500;
const STORAGE_STATUS_FIN = 'fin';
const RECHECK_STATUS_FIN = 'fin';
const DAY_MS = 24 * 3600 * 1000;
const BEIJING_OFFSET_MS = 8 * 3600 * 1000;
// 出库操作日志编码(app/dict/businessDict.js OPERATION_CODE)
const AUTO_OUTBOUND_OPERATION_CODE = 'ORDER_AUTO_OUTBOUND';
// 定时任务无用户上下文,按系统操作人记录
const AUTO_OUTBOUND_OPERATOR = Object.freeze({ id: null, name: '系统' });
/**
* 订单自动化出库服务。
* 当订单满足仓库配置的自动化出库规则时,自动标记出库并完成订单。
*
* 当仓库开启 auto_outbound_enabled 且配置了 auto_outbound_rules(数组,任一命中即出库)时,
* 自动将满足条件的订单标记为出库并将订单状态更新为已完成。
* 规则前置条件固定为「已复核」(recheck_status=fin)+「已分配储位」(storage_status=fin)。
*/
class OrderAutoOutboundService extends MainService {
/**
* 获取所有启用了自动化出库的仓库配置。
* 获取所有启用了自动化出库且配置了规则的仓库。
*
* @return {Promise<Array<{storeId: number, warehouseId: number, rules: Object}>>} 仓库配置列表。
* 自动出库配置以仓库为单位生效(wms_store.id 即 warehouse_id),
* 处理范围仅限当前仓库,不再扩散到该货主签约的外部合同仓。
*
* @return {Promise<Array<{storeId: number, warehouseId: number, rules: Array<Object>}>>} 仓库配置列表。
*/
async getEnabledAutoOutboundWarehouses() {
const { app } = this;
const { Store, StoreWarehouse } = app.model;
const { Store } = app.model;
if (!Store || !StoreWarehouse) {
if (!Store) {
return [];
}
@ -39,48 +52,68 @@ class OrderAutoOutboundService extends MainService {
const result = [];
for (const store of stores) {
const subjectConfig = this.normalizeSubjectConfigForAutoOutbound(store.subject_config);
const autoOutboundRules = subjectConfig && subjectConfig.auto_outbound_rules;
if (!autoOutboundRules || !autoOutboundRules.enabled) {
if (!this.isAutoOutboundEnabled(store.subject_config)) {
continue;
}
const contracts = await StoreWarehouse.findAll({
where: {
store_id: store.id,
auth_status: 2,
},
attributes: [ 'warehouse_id' ],
raw: true,
});
const rules = this.resolveAutoOutboundRules(store.subject_config);
// 空数组表示不出库任何订单,直接跳过(无需告警)
if (rules.length === 0) {
continue;
}
// 始终将 store.id 自身的仓库加入扫描(store.id 即 warehouse_id)
const scannedWarehouseIds = new Set();
result.push({
storeId: store.id,
warehouseId: store.id,
rules: autoOutboundRules,
rules,
});
scannedWarehouseIds.add(store.id);
// 追加外部合同中的仓库(去重)
for (const contract of contracts) {
const contractWarehouseId = contract.warehouse_id;
if (!scannedWarehouseIds.has(contractWarehouseId)) {
result.push({
storeId: store.id,
warehouseId: contractWarehouseId,
rules: autoOutboundRules,
});
scannedWarehouseIds.add(contractWarehouseId);
}
}
}
return result;
}
/**
* 判断仓库是否启用自动出库(subject_config.auto_outbound_enabled)。
*
* @param {Object|string|null|undefined} rawConfig subject_config 原始值。
* @return {boolean} 是否启用。
*/
isAutoOutboundEnabled(rawConfig) {
const subjectConfig = this.normalizeSubjectConfigForAutoOutbound(rawConfig);
const enabled = subjectConfig && subjectConfig.auto_outbound_enabled;
return enabled === true || enabled === 1 || enabled === '1' || enabled === 'true';
}
/**
* 解析自动出库规则数组(复用 Store 模型归一化,补齐缺省字段)。
* 旧对象结构或非法规则一律按空数组处理(空数组 = 不出库任何订单)。
*
* @param {Object|string|null|undefined} rawConfig subject_config 原始值。
* @return {Array<Object>} 规则数组。
*/
resolveAutoOutboundRules(rawConfig) {
const subjectConfig = this.normalizeSubjectConfigForAutoOutbound(rawConfig);
const rules = subjectConfig && subjectConfig.auto_outbound_rules;
const storeModel = this.app && this.app.model && this.app.model.Store;
if (storeModel && typeof storeModel.normalizeAutoOutboundRules === 'function') {
try {
return storeModel.normalizeAutoOutboundRules(rules);
} catch (error) {
this.ctx.logger.warn(`[auto-outbound] 自动出库规则配置非法,已按空规则处理: ${error.message}`);
return [];
}
}
if (!Array.isArray(rules)) {
return [];
}
return rules.filter(rule => rule && typeof rule === 'object' && !Array.isArray(rule));
}
/**
* 规范化 subject_config,支持字符串 JSON 和对象两种格式。
*
@ -108,186 +141,262 @@ class OrderAutoOutboundService extends MainService {
}
/**
* 构造自动化出库的订单查询条件。
* 根据配置规则组合各状态字段的 WHERE 条件。
* 构造单条自动化出库规则的订单查询条件。
*
* 基础条件(所有规则固定):已复核(recheck_status='fin')+ 已分配储位(storage_status='fin')
* + 未出库(outbound_status='none')+ 状态非 cancel/error/finished。
*
* @param {Object} rule 自动化出库规则(单条),支持字段:
* - {boolean} [rule.require_pack] 是否要求已打包(pack_status='fin')
* - {boolean} [rule.require_sync] 是否要求已同步(sync_status='fin')
* - {boolean} [rule.exclude_same_day_outbound] 是否不出库当天复核订单(默认 true);
* 开启后按「复核时间所在北京日 D」判定:
* recheck_time < D + deadline(默认 06:00)的订单不受影响;
* recheck_time ≥ D + deadline 的订单在 now < D + release(默认 22:00)前不出库,到达后放行。
* release 支持跨天(最大 47:59),如 27:00 表示次日 03:00 放行;
* recheck_time 为 null 的订单不受限制。
* - {string} [rule.same_day_outbound_deadline_time] 允许当天出库最后时间(HH:mm,默认 '06:00',当天内)。
* - {string} [rule.same_day_outbound_release_time] 放行时间(HH:mm,默认 '22:00',支持 00:00~47:59)。
* 常用组合:deadline='00:00' + release='23:59' → 当天复核的订单当天不出库,过了零点全部出库;
* deadline='00:00' + release='27:00' → 到次日 03:00 才全部出库。
* 注:require_weigh(已称重)涉及 wms_order_express,由调用方通过订单ID 子集约束,不在此处拼装。
*
* @param {Object} rules 自动化出库规则,包含以下可选字段:
* - {boolean} [rules.require_recheck] 是否要求已复核(recheck_status='fin')
* - {boolean} [rules.require_pack] 是否要求已打包(pack_status='fin')
* - {boolean} [rules.require_sync] 是否要求已同步(sync_status='fin')
* - {boolean} [rules.require_print] 是否要求已打印(print_status='fin')
* - {boolean} [rules.require_pick] 是否要求已拣货(pick_status='fin')
* - {boolean} [rules.exclude_same_day_outbound] 是否不出库当天复核订单(默认 true);
* 为 true 时,在到达当天放开时间(same_day_outbound_release_time,默认北京时间 22:00)前,
* 北京时间当天「允许当天出库最后时间」(same_day_outbound_deadline_time,默认 06:00)起复核(recheck_time)的订单当天不参与自动出库;
* recheck_time 早于该最后时间或为 null 的订单不受影响;
* 到达放开时间后当天复核订单恢复自动出库。
* - {string} [rules.same_day_outbound_deadline_time] 允许当天出库最后时间(HH:mm,默认 '06:00'),
* 复核时间早于该时间的订单不受「不出库当天订单」开启的影响。
* - {string} [rules.same_day_outbound_release_time] 当天放开时间(HH:mm,默认 '22:00'),
* 仅在 exclude_same_day_outbound 为 true 时生效。
* @return {Object} Sequelize where 条件对象。
*/
buildAutoOutboundWhere(rules) {
buildAutoOutboundWhere(rule) {
const safeRule = rule && typeof rule === 'object' ? rule : {};
const where = {
outbound_status: 'none',
status: {
[Op.notIn]: [ 'cancel', 'error', 'finished' ],
},
storage_status: STORAGE_STATUS_FIN,
// 未复核订单一律不自动出库(固定基线)
recheck_status: RECHECK_STATUS_FIN,
};
if (rules.require_recheck) {
where.recheck_status = 'fin';
}
// 开启「不出库当天订单」(默认开启)时:当天到达放开时间(默认北京时间 22:00)前,
// 排除当天「允许当天出库最后时间」(默认 06:00)起复核的订单(recheck_time 为 null 不排除);
// 到达放开时间后不再限制当天复核订单,当天即可出库。
// 开启「不出库当天订单」(默认开启)时:按复核时间所在北京日计算未放行窗口,
// 未放行窗口内的订单(recheck_time ∈ [D+deadline, D+24h) 且 now < D+release)不自动出库。
// 注意:应用按 UTC 读写 DATETIME,recheck_time 存储为 UTC 时刻,边界需按北京时间(UTC+8)换算。
if (rules.exclude_same_day_outbound !== false) {
const now = new Date();
const releaseUtc = this.buildSameDayReleaseUtc(now, rules.same_day_outbound_release_time);
if (now.getTime() < releaseUtc.getTime()) {
const sameDayCutoffUtc = this.buildSameDayOutboundCutoffUtc(now, rules.same_day_outbound_deadline_time);
where.recheck_time = {
[Op.or]: [
{ [Op.lt]: sameDayCutoffUtc },
{ [Op.is]: null },
],
};
if (safeRule.exclude_same_day_outbound !== false) {
const recheckCondition = this.buildSameDayOutboundRecheckCondition(new Date(), safeRule);
if (recheckCondition) {
where.recheck_time = recheckCondition;
}
}
if (rules.require_pack) {
if (safeRule.require_pack) {
where.pack_status = 'fin';
}
if (rules.require_sync) {
if (safeRule.require_sync) {
where.sync_status = 'fin';
}
if (rules.require_print) {
where.print_status = 'fin';
}
if (rules.require_pick) {
where.pick_status = 'fin';
}
return where;
}
/**
* 获取仓库下满足自动化出库条件的订单ID列表。
* 扫描仓库下命中任一自动出库规则的订单ID。
*
* 逐条规则查询(规则内条件 AND),命中即纳入结果;订单ID 去重并保留首个命中的规则下标。
* 需要称重的规则先取称重订单ID(同仓库只查一次,跨规则复用)。
*
* @param {number} warehouseId 仓库ID。
* @param {Object} rules 自动化出库规则。
* @param {number} [limit=MAX_BATCH_SIZE] 单次扫描上限。
* @return {Promise<Array<{id: number}>>} 订单ID列表。
* @param {Array<Object>} rules 自动化出库规则数组。
* @param {number} [limit=MAX_BATCH_SIZE] 单次扫描上限(按仓库汇总)。
* @return {Promise<{orderIds: Array<number>, ruleIndexById: Map<number, number>}>} 命中订单ID与规则下标映射。
*/
async findAutoOutboundOrders(warehouseId, rules, limit = MAX_BATCH_SIZE) {
async findAutoOutboundOrderIds(warehouseId, rules, limit = MAX_BATCH_SIZE) {
const { ctx } = this;
const factory = ctx.model && ctx.model.OrderDeliveryFactory;
const emptyResult = { orderIds: [], ruleIndexById: new Map() };
if (!factory || typeof factory.getCurrentModel !== 'function') {
return [];
return emptyResult;
}
const orderModel = await factory.getCurrentModel(warehouseId);
if (!orderModel) {
return [];
return emptyResult;
}
const where = this.buildAutoOutboundWhere(rules);
const ruleList = Array.isArray(rules) ? rules : [];
const orderIds = [];
const ruleIndexById = new Map();
let weighOrderIds = null;
if (rules.require_weigh) {
const orderIdsWithWeigh = await this.findOrderIdsWithWeigh(warehouseId);
if (orderIdsWithWeigh.length === 0) {
return [];
for (let index = 0; index < ruleList.length; index += 1) {
const remaining = limit - orderIds.length;
if (remaining <= 0) {
break;
}
const rule = ruleList[index] && typeof ruleList[index] === 'object' ? ruleList[index] : {};
const where = this.buildAutoOutboundWhere(rule);
if (rule.require_weigh) {
if (weighOrderIds === null) {
weighOrderIds = await this.findOrderIdsWithWeigh(warehouseId);
}
if (weighOrderIds.length === 0) {
continue;
}
where.id = { [Op.in]: weighOrderIds };
}
const orders = await orderModel.findAll({
where,
attributes: [ 'id' ],
limit: remaining,
raw: true,
});
for (const order of orders) {
const orderId = Number(order && order.id);
if (!Number.isFinite(orderId) || orderId <= 0 || ruleIndexById.has(orderId)) {
continue;
}
ruleIndexById.set(orderId, index);
orderIds.push(orderId);
}
where.id = { [Op.in]: orderIdsWithWeigh };
}
const orders = await orderModel.findAll({
where,
attributes: [ 'id' ],
limit,
raw: true,
});
return orders;
return { orderIds, ruleIndexById };
}
/**
* 计算「允许当天出库最后时间」边界(UTC 时刻)。
* 解析 HH:mm 时间配置为小时/分钟,支持跨天(小时可超过 23)。
* 缺省、格式非法或超出 maxHour 时回退指定默认值。
*
* 边界为北京时间当天配置时刻(默认 06:00,UTC+8):
* - recheck_time(UTC 存储)早于该边界 → 不受「不出库当天订单」开启影响,当天允许自动出库;
* - recheck_time 晚于或等于该边界 → 在到达当天放开时间前不自动出库,
* 到达放开时间(默认 22:00)后放开。
*
* 用 UTC 显式换算,不依赖 Node 进程时区(生产服务器 TZ 可能与北京时间不一致)。
*
* @param {Date} [now] 当前时刻(用于计算“今天”,默认 new Date())。
* @param {string} [timeText] 允许当天出库最后时间(HH:mm,默认 '06:00')。
* @return {Date} 北京时间当天该时刻对应的 UTC Date。
*/
buildSameDayOutboundCutoffUtc(now = new Date(), timeText) {
const DAY_MS = 24 * 3600 * 1000;
const BEIJING_OFFSET_MS = 8 * 3600 * 1000;
const { hour, minute } = this.resolveSameDayTime(timeText, 6, 0);
// 当前时刻换算为北京时刻后,取北京当天 0 点的毫秒基准
const beijingNowMs = now.getTime() + BEIJING_OFFSET_MS;
const beijingMidnightMs = Math.floor(beijingNowMs / DAY_MS) * DAY_MS;
return new Date(beijingMidnightMs + hour * 3600 * 1000 + minute * 60 * 1000 - BEIJING_OFFSET_MS);
}
/**
* 解析 HH:mm 时间配置为小时/分钟,缺省或格式非法时回退指定默认值。
*
* @param {string} [timeText] 时间文本,如 '22:00'。
* @param {string} [timeText] 时间文本,如 '22:00'、'27:00'(= 次日 03:00)。
* @param {number} defaultHour 默认小时。
* @param {number} defaultMinute 默认分钟。
* @param {number} [maxHour=23] 允许的最大小时(放开时间支持 47,表示可跨到次日)。
* @return {{hour: number, minute: number}} 小时与分钟。
*/
resolveSameDayTime(timeText, defaultHour, defaultMinute) {
resolveSameDayTime(timeText, defaultHour, defaultMinute, maxHour = 23) {
const text = typeof timeText === 'string' ? timeText.trim() : '';
const match = /^([01]\d|2[0-3]):([0-5]\d)$/.exec(text);
const match = /^(\d{1,2}):([0-5]\d)$/.exec(text);
if (!match) {
return { hour: defaultHour, minute: defaultMinute };
}
return { hour: Number(match[1]), minute: Number(match[2]) };
const hour = Number(match[1]);
if (hour > maxHour) {
return { hour: defaultHour, minute: defaultMinute };
}
return { hour, minute: Number(match[2]) };
}
/**
* 解析「当天放开时间」配置为小时/分钟(HH:mm)。
* 缺省或格式非法时回退默认 22:00。
* 解析「允许当天出库最后时间」(当天内,最大 23:59;缺省/非法回退 06:00)。
*
* @param {string} [timeText] 时间文本,如 '22:00'。
* @param {string} [timeText] 时间文本。
* @return {{hour: number, minute: number}} 小时与分钟。
*/
resolveSameDayDeadlineTime(timeText) {
return this.resolveSameDayTime(timeText, 6, 0, 23);
}
/**
* 解析「放行时间」(支持跨天,最大 47:59;27:00 = 次日 03:00;缺省/非法回退 22:00)。
*
* @param {string} [timeText] 时间文本。
* @return {{hour: number, minute: number}} 小时与分钟。
*/
resolveSameDayReleaseTime(timeText) {
return this.resolveSameDayTime(timeText, 22, 0);
return this.resolveSameDayTime(timeText, 22, 0, 47);
}
/**
* 计算北京时间当天「放开时间」对应的 UTC Date。
* 计算北京时间「当天 00:00」对应的 UTC 时刻。
*
* 仅在开启「不出库当天订单」时使用:当前时刻早于该边界时,
* 当天最后时间之后复核的订单不自动出库;晚于或等于该边界时放开。
* 用 UTC 显式换算,不依赖 Node 进程时区(生产服务器 TZ 可能与北京时间不一致)。
*
* @param {Date} [now] 当前时刻(默认 new Date())。
* @param {string} [timeText] 放开时间(HH:mm,默认 22:00)。
* @return {Date} 北京时间当天放开时间对应的 UTC Date。
* @return {Date} 北京时间当天 0 点对应的 UTC Date。
*/
buildSameDayReleaseUtc(now = new Date(), timeText) {
const DAY_MS = 24 * 3600 * 1000;
const BEIJING_OFFSET_MS = 8 * 3600 * 1000;
const { hour, minute } = this.resolveSameDayReleaseTime(timeText);
buildBeijingDayStartUtc(now = new Date()) {
const beijingNowMs = now.getTime() + BEIJING_OFFSET_MS;
const beijingMidnightMs = Math.floor(beijingNowMs / DAY_MS) * DAY_MS;
return new Date(beijingMidnightMs + hour * 3600 * 1000 + minute * 60 * 1000 - BEIJING_OFFSET_MS);
return new Date(beijingMidnightMs - BEIJING_OFFSET_MS);
}
/**
* 计算「不出库当天订单」的未放行窗口(按**复核时间所在北京日**对齐,支持跨天)。
*
* 口径(第 D 天复核的订单,D 为复核时间的北京日):
* - recheck_time < D + deadline → 不受限制(豁免,照常出库);
* - recheck_time ≥ D + deadline 且 now < D + release → 未放行,不出库;
* - now ≥ D + release → 放行(照常出库)。
*
* 由于 release 最大 47:59,复核日只可能是「今天」或「昨天」,故返回至多两个窗口。
*
* @param {Date} now 当前时刻。
* @param {Object} rule 自动化出库规则(单条)。
* @return {Array<{start: number, end: number}>} 未放行窗口(UTC 毫秒区间,已合并相邻/重叠)。
*/
buildSameDayOutboundHoldWindows(now, rule) {
const safeRule = rule && typeof rule === 'object' ? rule : {};
const release = this.resolveSameDayReleaseTime(safeRule.same_day_outbound_release_time);
const deadline = this.resolveSameDayDeadlineTime(safeRule.same_day_outbound_deadline_time);
const releaseMs = (release.hour * 60 + release.minute) * 60000;
const deadlineMs = (deadline.hour * 60 + deadline.minute) * 60000;
const todayStartMs = this.buildBeijingDayStartUtc(now).getTime();
const windows = [];
for (const dayOffset of [ -1, 0 ]) {
const dayStartMs = todayStartMs + dayOffset * DAY_MS;
if (now.getTime() >= dayStartMs + releaseMs) {
continue; // 该复核日的放行时刻已到
}
windows.push({ start: dayStartMs + deadlineMs, end: dayStartMs + DAY_MS });
}
windows.sort((a, b) => a.start - b.start);
const merged = [];
for (const window of windows) {
const last = merged[merged.length - 1];
if (last && window.start <= last.end) {
last.end = Math.max(last.end, window.end);
} else {
merged.push({ ...window });
}
}
return merged;
}
/**
* 生成「不出库当天订单」对 recheck_time 的查询约束(允许集 = 未放行窗口的补集 + NULL)。
*
* 返回 null 表示当前时刻没有任何未放行窗口(即完全不限制)。
*
* @param {Date} now 当前时刻。
* @param {Object} rule 自动化出库规则(单条)。
* @return {Object|null} Sequelize 条件对象或 null。
*/
buildSameDayOutboundRecheckCondition(now, rule) {
const windows = this.buildSameDayOutboundHoldWindows(now, rule);
if (windows.length === 0) {
return null;
}
const ranges = [];
let cursor = null;
for (const window of windows) {
if (cursor === null) {
ranges.push({ [Op.lt]: new Date(window.start) });
} else if (window.start > cursor) {
ranges.push({ [Op.gte]: new Date(cursor), [Op.lt]: new Date(window.start) });
}
cursor = cursor === null ? window.end : Math.max(cursor, window.end);
}
ranges.push({ [Op.gte]: new Date(cursor) });
// recheck_time 为 null 的订单不受限制(既有口径)
ranges.push({ [Op.is]: null });
return { [Op.or]: ranges };
}
/**
@ -321,8 +430,11 @@ class OrderAutoOutboundService extends MainService {
/**
* 对指定仓库执行单次自动化出库扫描与执行。
*
* 按规则逐条扫描(任一规则命中即出库),订单ID 去重后一次性更新,
* 并对本次出库订单写入操作日志(写日志失败仅告警,不影响出库主流程)。
*
* @param {number} warehouseId 仓库ID。
* @param {Object} rules 自动化出库规则。
* @param {Array<Object>} rules 自动化出库规则数组。
* @return {Promise<{warehouseId: number, processedCount: number, errorMessage: string|null}>} 执行结果。
*/
async processWarehouseAutoOutbound(warehouseId, rules) {
@ -334,13 +446,8 @@ class OrderAutoOutboundService extends MainService {
};
try {
const orders = await this.findAutoOutboundOrders(warehouseId, rules);
const { orderIds, ruleIndexById } = await this.findAutoOutboundOrderIds(warehouseId, rules);
if (!orders || orders.length === 0) {
return result;
}
const orderIds = orders.map(order => Number(order.id)).filter(Boolean);
if (orderIds.length === 0) {
return result;
}
@ -371,6 +478,8 @@ class OrderAutoOutboundService extends MainService {
ctx.logger.info(
`[auto-outbound] 仓库 ${warehouseId} 自动化出库 ${result.processedCount} 条订单,订单ID: ${orderIds.join(',')}`
);
await this.writeAutoOutboundOperationLogs(warehouseId, orderIds, rules, ruleIndexById);
}
} catch (error) {
result.errorMessage = error.message;
@ -380,6 +489,83 @@ class OrderAutoOutboundService extends MainService {
return result;
}
/**
* 写入自动出库订单操作日志(business_type=order,operation_code=ORDER_AUTO_OUTBOUND)。
*
* 日志写入失败仅告警,不影响出库主流程。
*
* @param {number} warehouseId 仓库ID。
* @param {Array<number>} orderIds 本次出库的订单ID列表。
* @param {Array<Object>} rules 自动化出库规则数组。
* @param {Map<number, number>} ruleIndexById 订单ID → 命中规则下标。
* @return {Promise<void>} 无返回值。
*/
async writeAutoOutboundOperationLogs(warehouseId, orderIds, rules, ruleIndexById) {
const { ctx } = this;
const operationLogService = ctx.service
&& ctx.service.systems
&& ctx.service.systems.operationLog;
if (!operationLogService || typeof operationLogService.createOperationLogs !== 'function') {
return;
}
const ruleList = Array.isArray(rules) ? rules : [];
const payloads = orderIds.map(orderId => {
const ruleIndex = ruleIndexById && typeof ruleIndexById.get === 'function' && ruleIndexById.has(orderId)
? ruleIndexById.get(orderId)
: -1;
const rule = ruleIndex >= 0 ? ruleList[ruleIndex] : null;
return {
businessType: 'order',
businessId: orderId,
operationCode: AUTO_OUTBOUND_OPERATION_CODE,
operator: AUTO_OUTBOUND_OPERATOR,
extras: {
warehouseId,
message: ruleIndex >= 0
? `自动出库(命中规则${ruleIndex + 1}:${this.buildAutoOutboundRuleSummary(rule)})`
: '自动出库',
},
};
});
try {
await operationLogService.createOperationLogs(payloads);
} catch (error) {
ctx.logger.warn(
`[auto-outbound] 仓库 ${warehouseId} 写入自动出库操作日志失败,不影响出库: ${error.message}`
);
}
}
/**
* 生成规则条件摘要(用于操作日志 message)。
*
* @param {Object} rule 自动化出库规则。
* @return {string} 规则摘要文本。
*/
buildAutoOutboundRuleSummary(rule) {
const safeRule = rule && typeof rule === 'object' ? rule : {};
const conditions = [];
if (safeRule.require_pack) {
conditions.push('需已打包');
}
if (safeRule.require_weigh) {
conditions.push('需已称重');
}
if (safeRule.require_sync) {
conditions.push('需已同步');
}
if (safeRule.exclude_same_day_outbound !== false) {
conditions.push('不出库当天订单');
}
return conditions.length > 0 ? conditions.join('、') : '无附加条件';
}
/**
* 执行全局自动化出库扫描。
* 遍历所有启用了自动化出库的仓库,对每个仓库扫描并执行符合条件的订单出库。

View File

@ -220,24 +220,28 @@ const WAREHOUSE_SETTING_FIELDS = Object.freeze([
required: false,
description: '可配置多个库存预警项,每项包含 name、key、expire_days、tip_text',
}),
Object.freeze({
key: 'auto_outbound_enabled',
name: '启用自动出库',
type: 'flag',
default: false,
required: false,
description: '是否启用自动出库,默认 false(关闭)。开启后按 auto_outbound_rules 中的规则扫描订单并自动标记出库',
}),
Object.freeze({
key: 'auto_outbound_rules',
name: '自动出库规则',
type: 'object',
default: Object.freeze({ enabled: false, require_recheck: true, require_pack: true, require_weigh: true, require_sync: true, require_print: true, require_pick: true, exclude_same_day_outbound: true, same_day_outbound_deadline_time: '06:00', same_day_outbound_release_time: '22:00' }),
type: 'array',
default: [],
required: false,
description: '满足条件自动标记出库。全部条件满足时自动标记待出库',
description: '自动出库规则数组,每项规则独立判断,订单满足任意一条规则即自动出库;空数组时不自动出库。规则前置条件固定为「已复核」(recheck_status=fin)+「已分配储位」(storage_status=fin),未复核订单一律不自动出库',
item_keys: Object.freeze([
Object.freeze({ key: 'enabled', name: '启用', type: 'flag', required: true, description: '是否启用自动出库' }),
Object.freeze({ key: 'require_recheck', name: '需已复核', type: 'flag', required: false, description: '是否要求 recheck_status=fin' }),
Object.freeze({ key: 'require_pack', name: '需已打包', type: 'flag', required: false, description: '是否要求 pack_status=fin' }),
Object.freeze({ key: 'require_weigh', name: '需已称重', type: 'flag', required: false, description: '是否要求 weighing_weight>0' }),
Object.freeze({ key: 'require_sync', name: '需已同步', type: 'flag', required: false, description: '是否要求 sync_status=fin' }),
Object.freeze({ key: 'require_print', name: '需已打印', type: 'flag', required: false, description: '是否要求 print_status=fin' }),
Object.freeze({ key: 'require_pick', name: '需已拣货', type: 'flag', required: false, description: '是否要求 pick_status=fin' }),
Object.freeze({ key: 'exclude_same_day_outbound', name: '不出库当天订单', type: 'flag', required: false, default: true, description: '开启后,在当天放开时间前,「允许当天出库最后时间」之后复核的订单不自动出库,到达当天放开时间后恢复' }),
Object.freeze({ key: 'same_day_outbound_deadline_time', name: '允许当天出库最后时间', type: 'string', required: false, default: '06:00', maxLength: 5, min: '00:00', max: '23:59', description: '复核时间早于该时间的订单不受「不出库当天订单」开启的影响,格式 HH:mm,不能大于当天放开时间' }),
Object.freeze({ key: 'same_day_outbound_release_time', name: '当天放开时间', type: 'string', required: false, default: '22:00', maxLength: 5, min: '00:00', max: '23:59', description: '开启「不出库当天订单」时,当天到达该时间后不再限制当天复核订单的自动出库,格式 HH:mm' }),
Object.freeze({ key: 'require_pack', name: '需已打包', type: 'flag', required: false, default: true, description: '是否要求已打包(pack_status=fin),默认 true' }),
Object.freeze({ key: 'require_weigh', name: '需已称重', type: 'flag', required: false, default: true, description: '是否要求已称重(weighing_weight>0),默认 true' }),
Object.freeze({ key: 'require_sync', name: '需已同步', type: 'flag', required: false, default: true, description: '是否要求已同步(sync_status=fin),默认 true' }),
Object.freeze({ key: 'exclude_same_day_outbound', name: '不出库当天订单', type: 'flag', required: false, default: true, description: '开启后,按订单复核时间所在日计算:复核时间在「允许当天出库最后时间」之后的订单,需等到该复核日的「放行时间」才自动出库;复核时间早于该最后时间、或为空的订单不受影响' }),
Object.freeze({ key: 'same_day_outbound_deadline_time', name: '允许当天出库最后时间', type: 'string', required: false, default: '06:00', maxLength: 5, min: '00:00', max: '23:59', description: '复核时间早于该时间的订单不受「不出库当天订单」影响,格式 HH:mm(当天内 00:00~23:59),不能大于放行时间。想表达「当天复核的订单全天不出库」时设为 00:00' }),
Object.freeze({ key: 'same_day_outbound_release_time', name: '放行时间', type: 'string', required: false, default: '22:00', maxLength: 5, min: '00:00', max: '47:59', description: '到达该时刻后,该复核日被限制的订单放行。格式 HH:mm,支持跨天 00:00~47:59(24:00 之后的数字表示次日,如 27:00 = 次日 03:00)。常用:23:59 = 当天不放、过了零点出库;27:00 = 到次日 03:00 才出库' }),
]),
}),
Object.freeze({
@ -823,6 +827,27 @@ class SettingWarehouseService extends Service {
await this.validateDefaultLocation(nextPatch.default_location_id, warehouseId);
}
// 自动出库规则必须是数组(旧的对象结构已废弃):写路径显式报错,避免被静默重置为默认值
if (Object.prototype.hasOwnProperty.call(nextPatch, 'auto_outbound_rules')) {
const rawAutoOutboundRules = nextPatch.auto_outbound_rules;
if (rawAutoOutboundRules !== undefined && rawAutoOutboundRules !== null && rawAutoOutboundRules !== '') {
let parsedAutoOutboundRules = rawAutoOutboundRules;
if (typeof parsedAutoOutboundRules === 'string') {
try {
parsedAutoOutboundRules = JSON.parse(parsedAutoOutboundRules);
} catch (error) {
parsedAutoOutboundRules = null;
}
}
if (!Array.isArray(parsedAutoOutboundRules)) {
throw this.createError(
'subject_config.auto_outbound_rules 必须是数组(每项包含 require_pack/require_weigh/require_sync 等字段),旧对象结构已废弃,请重新配置',
400
);
}
}
}
const nextPatchForMerge = {
...nextPatch,
};

View File

@ -1,4 +1,120 @@
[
{
"version": "0.3.301",
"date": "2026-10-16",
"type": "updated",
"summary": "自动出库「不出库当天订单」支持跨天放行:放行时间放开到 00:00~47:59(27:00 = 次日 03:00),限制窗口改为按订单复核时间所在日计算",
"methods": [
"setting.warehouse.getSettings",
"setting.warehouse.saveSettings"
],
"notes": [
"语义变更(原实现按「当前日」计算窗口,跨天时会提前放行,且放行时间只支持 00:00~23:59):新口径按**订单复核时间所在北京日 D**计算 —— recheck_time < D + 允许当天出库最后时间 的订单不受影响;recheck_time ≥ D + 最后时间 的订单在 now < D + 放行时间 前不出库,到达后放行。",
"字段范围:same_day_outbound_release_time 放开到 00:00~47:59(24:00 之后的数字表示次日,例如 27:00 = 次日 03:00;48:00 等超限值回退默认 22:00);same_day_outbound_deadline_time 仍限当天内 00:00~23:59。",
"典型配置:① 当天复核的订单当天不出、过零点出库 → deadline=00:00 + release=23:59;② 到次日 03:00 才出库 → deadline=00:00 + release=27:00;③ 当天 20:00 后复核的次日 05:00 放行 → deadline=20:00 + release=29:00。",
"recheck_time 为 NULL 的订单仍不受该限制(既有口径);字段名 same_day_outbound_release_time 未变,仅中文名与语义说明调整(getFieldMeta 中显示名改为「放行时间」)。",
"验证:本地隔离测试仓真实库走查 12 个场景全通过(含 S6a 当天/ S6b 次日 02:00 未放行 / S6c 次日 04:00 放行 / S6d 次日复核仍受限),脚本 test/auto_outbound_local_test_warehouse.cjs;单测 30 例通过(含跨天窗口补集断言)。",
"文档变更范围:methods/system.json 的 setting.warehouse.getSettings 响应、setting.warehouse.saveSettings 入参中 exclude_same_day_outbound / same_day_outbound_deadline_time / same_day_outbound_release_time 三条描述 + method 描述;根版本 0.3.300 → 0.3.301、updatedAt 2026-10-16;methods/changes/system.json 新增本条(插入数组首位)。"
]
},
{
"version": "0.3.300",
"date": "2026-10-16",
"type": "updated",
"summary": "自动出库当天限制的时间口径补充:时间字段仅支持 00:00~23:59(不支持 24:00),「当天不出库、过零点全部出库」用 deadline=00:00 + release=23:59",
"methods": [
"setting.warehouse.getSettings",
"setting.warehouse.saveSettings"
],
"notes": [
"背景:业务希望「未打包订单当天不出库,过了零点(24:00)后全部出库」。现有 same_day_outbound_deadline_time / same_day_outbound_release_time 只支持 HH:mm 且范围 00:00~23:59,写 24:00 会被回退成默认值。",
"推荐配置:exclude_same_day_outbound=true + same_day_outbound_deadline_time=00:00 + same_day_outbound_release_time=23:59 —— 当天 00:00 之后复核的订单全天不出库,到达 23:59 后(含次日凌晨,cutoff 前移到次日 00:00 使前一日复核订单自动放行)全部出库。",
"附带说明:recheck_time 为 NULL 的订单不受该限制(既有口径);已打包等其它规则若关闭 exclude_same_day_outbound 则不受影响。",
"本地真实库走查(隔离临时仓 990001,8 个场景全通过):S1/S2 当天限制与放开时刻、S3 deadline 06:00→03:00 边界、S4a/S4b release 06:00 前后、S5a/S5b/S5c deadline=00:00+release=23:59 的当天/23:59/次日三个时点。测试脚本 test/auto_outbound_local_test_warehouse.cjs(不入库)。",
"文档变更范围:methods/system.json 的 setting.warehouse.getSettings 响应、setting.warehouse.saveSettings 入参两条字段描述 + method 描述;根版本 0.3.299 → 0.3.300、updatedAt 2026-10-16;methods/changes/system.json 新增本条(插入数组首位)。"
]
},
{
"version": "0.3.299",
"date": "2026-10-16",
"type": "updated",
"summary": "仓库设置自动出库配置重构:开关拆分为 auto_outbound_enabled,auto_outbound_rules 改为规则数组(仅校验打包/称重/同步,任一命中即出库,固定要求已复核),移除复核/打印/拣货校验",
"methods": [
"setting.warehouse.getSettings",
"setting.warehouse.getFieldMeta",
"setting.warehouse.saveSettings"
],
"notes": [
"变更内容:subject_config 新增 auto_outbound_enabled(flag,默认 false);auto_outbound_rules 由对象改为数组,每项字段为 require_pack/require_weigh/require_sync/exclude_same_day_outbound/same_day_outbound_deadline_time/same_day_outbound_release_time,规则内条件 AND、规则间 OR(任一命中即出库),空数组表示不出库任何订单。",
"固定前置条件:所有规则均要求已复核(recheck_status=fin)与已分配储位(storage_status=fin),未复核订单一律不自动出库;不再校验已打印(print_status)与已拣货(pick_status)。",
"不兼容变更:旧对象结构(含 enabled/require_recheck/require_print/require_pick)一律按默认(关闭 + 空规则)处理,需重新配置;saveSettings 保存非数组时返回 400(不静默重置)。",
"处理范围:自动出库配置以仓库为单位生效(wms_store.id 即 warehouse_id),仅扫描该仓库自身订单,不再扩展到货主签约的外部合同仓。",
"出库操作日志:自动出库成功更新后按订单写入 wms_operation_log(business_type=order,operation_code=ORDER_AUTO_OUTBOUND,operator=系统,message 形如「自动出库(命中规则1:需已打包、需已称重)」);写日志失败仅告警不影响出库。",
"代码依据:app/model/store.js(默认值与 normalizeAutoOutboundRules)、app/service/systems/order_auto_outbound.js(getEnabledAutoOutboundWarehouses/isAutoOutboundEnabled/resolveAutoOutboundRules/buildAutoOutboundWhere/findAutoOutboundOrderIds/processWarehouseAutoOutbound/writeAutoOutboundOperationLogs)、app/service/systemMethods/outbound.js、app/service/systems/setting/warehouse.js(WAREHOUSE_SETTING_FIELDS + saveSettings 数组校验)、app/dict/businessDict.js(ORDER_AUTO_OUTBOUND)。",
"验证:单测 test/auto_outbound_rules_v2.test.cjs(23 用例通过,含配置归一化/条件拼装/多规则命中去重/操作日志/字段元信息/保存校验);ESLint 0 错误。",
"文档变更范围:methods/system.json 的 setting.warehouse.getSettings 响应、setting.warehouse.getFieldMeta、setting.warehouse.saveSettings 入参三处;根版本 0.3.298 → 0.3.299、updatedAt 2026-10-16;methods/changes/system.json 新增本条(插入数组首位)。"
]
},
{
"version": "0.3.298",
"date": "2026-10-14",
"type": "added",
"summary": "小程序用户须知增加系统默认版本:首次授权时自动写入作为第一版(0.3.297 → 0.3.298)",
"methods": [
"wechat.getUserAgreementText"
],
"notes": [
"变更内容:wms_wechat_agreement_version 新增系统级种子行 appid='system'(系统默认须知模板,迁移 20261014100000 开发+生产执行);首次授权的小程序(handleAuthCallback 与 authorized/updateauthorized 事件的 create 分支)自动复制该内容为第一版(systems/wechat.js#ensureDefaultAgreementVersion,幂等:已有任意版本则跳过)。",
"系统默认内容可在 wms_wechat_agreement_version 中 appid='system' 的行直接修改(后续授权的小程序复制新内容);已授权但无版本的小程序不会自动回填(如需回填另行处理)。",
"代码依据:app/service/systems/wechat.js 新增 SYSTEM_AGREEMENT_APPID 常量与 ensureDefaultAgreementVersion;app/controller/wechatOpen.js 两处 create 分支调用。",
"文档变更范围:methods/system.json 的 wechat.getUserAgreementText 一条(description 补系统默认版本说明);根版本 0.3.297 → 0.3.298、updatedAt 2026-10-14;methods/changes/system.json 新增本条(插入数组首位);其余 method 未改动。"
]
},
{
"version": "0.3.297",
"date": "2026-10-14",
"type": "updated",
"summary": "wechat.getTemplateList 移除 Redis 缓存,改为每次实时拉取微信(0.3.296 → 0.3.297)",
"methods": [
"wechat.getTemplateList"
],
"notes": [
"变更内容:移除 wechat:template:list:normal 的 Redis 缓存读写(cacheGet/cacheSet),每次调用直接 GET wxa/gettemplatelist 实时拉取;响应移除 from_cache 字段。",
"背景:模板缓存 24h → 5 分钟仍反复遇到旧列表问题,用户要求彻底移除缓存。",
"代码依据:app/service/systems/wechat.js#getTemplateList 移除 CACHE_KEY/CACHE_TTL_SECONDS 与缓存分支;systemMethods/wechat.js JSDoc 同步。",
"文档变更范围:methods/system.json 的 wechat.getTemplateList 一条(description 改实时拉取、response 移除 from_cache);根版本 0.3.296 → 0.3.297、updatedAt 2026-10-14;methods/changes/system.json 新增本条(插入数组首位);其余 method 未改动。"
]
},
{
"version": "0.3.296",
"date": "2026-10-13",
"type": "updated",
"summary": "wechat.getTemplateList 模板缓存 TTL 24h → 5 分钟(0.3.295 → 0.3.296)",
"methods": [
"wechat.getTemplateList"
],
"notes": [
"变更内容:模板列表 Redis 缓存 TTL 由 24 小时(24*3600)改为 5 分钟(5*60),模板更新后最多 5 分钟即可在列表接口看到最新模板。",
"背景:2026-10-13 生产模板库变更后列表仍命中旧缓存,用户要求缩短缓存时间。",
"代码依据:app/service/systems/wechat.js#getTemplateList CACHE_TTL_SECONDS 24*3600 → 5*60;JSDoc 同步;systemMethods/wechat.js JSDoc 同步。",
"文档变更范围:methods/system.json 的 wechat.getTemplateList 一条(description 缓存 24h → 5 分钟);根版本 0.3.295 → 0.3.296、updatedAt 2026-10-13;methods/changes/system.json 新增本条(插入数组首位);其余 method 未改动。"
]
},
{
"version": "0.3.295",
"date": "2026-10-13",
"type": "fixed",
"summary": "wechat.commit 模板 ID 校验放开 0:普通模板库模板 ID 从 0 开始(0.3.294 → 0.3.295)",
"methods": [
"wechat.commit"
],
"notes": [
"变更内容:template_id 校验由「正整数(>0)」改为「非负整数(≥0)」,错误提示同步改为「template_id 必须为非负整数」;普通模板库第一个模板的 template_id 为 0(微信官方 wxa/commit 请求示例即 \"template_id\": \"0\"),此前模板库唯一模板 template_id=0 无法提交。",
"背景:2026-10-13 生产模板库仅一个模板(template_id=0),调用 wechat.commit 被本服务校验拦截。",
"代码依据:app/service/systems/wechat.js#commit 校验条件 <=0 → <0;本地未新增测试(0 的边界由现有 list.find 匹配覆盖),ESLint 0 错误。",
"文档变更范围:methods/system.json 的 wechat.commit 一条(params.template_id.description 补 0 合法说明、errors 补非负整数校验提示);根版本 0.3.294 → 0.3.295、updatedAt 2026-10-13;methods/changes/system.json 新增本条(插入数组首位);其余 method 未改动。"
]
},
{
"version": "0.3.294",
"date": "2026-10-13",

View File

@ -1,8 +1,8 @@
{
"module": "system",
"description": "系统接口标准入口,method 对应系统内置方法,全部使用 POST 请求,参数统一放在 body 内",
"version": "0.3.294",
"updatedAt": "2026-10-13",
"version": "0.3.301",
"updatedAt": "2026-10-16",
"headers": [
{
"name": "platform",
@ -15326,7 +15326,7 @@
"list": [
{
"method": "setting.warehouse.getSettings",
"description": "获取当前登录仓库的 subject_config;subject_config 新增大团购打包系数 big_group_pack_coefficient(数字,默认 3,单位秒/单,必须大于 0,用于 workbench 大团购波次打包时长闸门与倒计时);新增散单称重是否需要打包 single_weigh_require_pack(flag 布尔,默认 false 关闭;开启后散单称重(订单波次范围 wave_scope 非 1 大团购/3 小团购)前必须已打包完成 pack_status=fin,未打包时拒绝称重并返回错误)",
"description": "获取当前登录仓库的 subject_config;subject_config 新增大团购打包系数 big_group_pack_coefficient(数字,默认 3,单位秒/单,必须大于 0,用于 workbench 大团购波次打包时长闸门与倒计时);新增散单称重是否需要打包 single_weigh_require_pack(flag 布尔,默认 false 关闭;开启后散单称重(订单波次范围 wave_scope 非 1 大团购/3 小团购)前必须已打包完成 pack_status=fin,未打包时拒绝称重并返回错误);本次调整自动出库配置:新增 subject_config.auto_outbound_enabled(flag,默认 false 关闭);subject_config.auto_outbound_rules 由对象改为数组(每项仅校验 require_pack/require_weigh/require_sync,任一规则命中即出库;固定前置条件为已复核 recheck_status=fin 与已分配储位 storage_status=fin),移除 rules.enabled 与 require_recheck/require_print/require_pick 字段;本次文档补充「不出库当天订单」的时间口径:时间字段范围 00:00~23:59(不支持 24:00),常用组合为 允许当天出库最后时间=00:00 + 当天放开时间=23:59 表示「当天复核的订单全天不出库、过了零点后全部出库」;本次补充「不出库当天订单」的跨天口径:按订单复核时间所在日计算,放行时间支持 00:00~47:59(27:00 = 次日 03:00 放行)",
"isNeedAuth": false,
"isNeedLogin": true,
"headers": [
@ -15357,23 +15357,17 @@
"required": true,
"description": "是否启用外部快递编码;默认 false(关闭)。开启后允许按外部系统传入的快递编码进行处理(如无匹配仍以业务校验为准)"
},
{
"name": "subject_config.auto_outbound_enabled",
"type": "boolean",
"required": true,
"description": "是否启用自动出库(flag),默认 false(关闭);开启后按 auto_outbound_rules 中的规则扫描订单并自动标记出库"
},
{
"name": "subject_config.auto_outbound_rules",
"type": "object",
"type": "array",
"required": true,
"description": "自动出库规则配置。全部条件满足时自动标记待出库"
},
{
"name": "subject_config.auto_outbound_rules.enabled",
"type": "boolean",
"required": true,
"description": "是否启用自动出库,默认 false"
},
{
"name": "subject_config.auto_outbound_rules.require_recheck",
"type": "boolean",
"required": true,
"description": "是否要求已复核(recheck_status=fin),默认 true"
"description": "自动出库规则数组,每项规则独立判断,订单满足任意一条规则即自动出库;空数组时不自动出库。所有规则的固定前置条件为「已复核」(recheck_status=fin)与「已分配储位」(storage_status=fin),未复核订单一律不自动出库。旧版本的对象结构(含 enabled/require_recheck/require_print/require_pick)已废弃不再兼容,保存为非数组时返回 400"
},
{
"name": "subject_config.auto_outbound_rules.require_pack",
@ -15385,7 +15379,7 @@
"name": "subject_config.auto_outbound_rules.require_weigh",
"type": "boolean",
"required": true,
"description": "是否要求已称重(weighing_weight>0),默认 true"
"description": "是否要求已称重(wms_order_express.weighing_weight>0),默认 true"
},
{
"name": "subject_config.auto_outbound_rules.require_sync",
@ -15394,16 +15388,22 @@
"description": "是否要求已同步(sync_status=fin),默认 true"
},
{
"name": "subject_config.auto_outbound_rules.require_print",
"name": "subject_config.auto_outbound_rules.exclude_same_day_outbound",
"type": "boolean",
"required": true,
"description": "是否要求已打印(print_status=fin),默认 true"
"description": "是否不出库当天复核订单(flag),默认 true;开启后按订单复核时间所在日计算:复核时间在「允许当天出库最后时间」之后的订单,需等到该复核日的「放行时间」才自动出库;复核时间早于该最后时间、或为空的订单不受影响"
},
{
"name": "subject_config.auto_outbound_rules.require_pick",
"type": "boolean",
"name": "subject_config.auto_outbound_rules.same_day_outbound_deadline_time",
"type": "string",
"required": true,
"description": "是否要求已拣货(pick_status=fin),默认 true"
"description": "允许当天出库最后时间(HH:mm,默认 06:00,当天内 00:00~23:59);复核时间早于该时间的订单不受「不出库当天订单」影响,不能大于放行时间。想表达「当天复核的订单全天不出库」时设为 00:00"
},
{
"name": "subject_config.auto_outbound_rules.same_day_outbound_release_time",
"type": "string",
"required": true,
"description": "放行时间(HH:mm,默认 22:00,支持跨天 00:00~47:59:24:00 之后的数字表示次日,如 27:00 = 次日 03:00);到达该时刻后,该复核日被限制的订单放行。常用:23:59 = 当天不放、过了零点出库;27:00 = 到次日 03:00 才出库"
},
{
"name": "subject_config.sender_name",
@ -15591,7 +15591,7 @@
},
{
"method": "setting.warehouse.getFieldMeta",
"description": "获取仓库设置字段元信息;本次 list 新增「大团购打包系数」(key=big_group_pack_coefficient,type=number,default=3,min=0.1,单位秒/单,用于大团购波次打包时长闸门与倒计时);本次新增「散单称重是否需要打包」(key=single_weigh_require_pack,type=flag,default=false,required=false,开启后散单称重(wave_scope 非 1 大团购/3 小团购)前必须已打包完成 pack_status=fin)",
"description": "获取仓库设置字段元信息;本次 list 新增「大团购打包系数」(key=big_group_pack_coefficient,type=number,default=3,min=0.1,单位秒/单,用于大团购波次打包时长闸门与倒计时);本次新增「散单称重是否需要打包」(key=single_weigh_require_pack,type=flag,default=false,required=false,开启后散单称重(wave_scope 非 1 大团购/3 小团购)前必须已打包完成 pack_status=fin);本次新增「启用自动出库」(key=auto_outbound_enabled,type=flag,default=false,required=false);「自动出库规则」(key=auto_outbound_rules)由 object 调整为 array(default=[],item_keys 仅含 require_pack/require_weigh/require_sync/exclude_same_day_outbound/same_day_outbound_deadline_time/same_day_outbound_release_time)",
"isNeedAuth": false,
"isNeedLogin": true,
"headers": [
@ -15676,7 +15676,7 @@
},
{
"method": "setting.warehouse.saveSettings",
"description": "修改仓库设置并清理指定仓库缓存(subject_config 支持部分字段更新,本次新增 subject_config.single_weigh_require_pack);本次文档补漏 subject_config.big_group_pack_coefficient 入参说明(对齐 getSettings/getFieldMeta 与代码实现)",
"description": "修改仓库设置并清理指定仓库缓存(subject_config 支持部分字段更新,本次新增 subject_config.single_weigh_require_pack);本次文档补漏 subject_config.big_group_pack_coefficient 入参说明(对齐 getSettings/getFieldMeta 与代码实现);本次调整自动出库配置:新增 subject_config.auto_outbound_enabled(flag,默认 false);subject_config.auto_outbound_rules 改为数组(每项仅校验 require_pack/require_weigh/require_sync,任一命中即出库;固定前置条件为已复核 + 已分配储位),非数组(旧对象结构)保存时返回 400;本次文档补充 same_day_outbound_deadline_time / same_day_outbound_release_time 的范围(00:00~23:59,不支持 24:00)与常用组合(00:00 + 23:59 = 当天不放、过零点全部出库);本次补充 same_day_outbound_release_time 支持跨天(00:00~47:59,27:00 = 次日 03:00)与 same_day_outbound_deadline_time 仍限当天内(00:00~23:59)",
"isNeedAuth": false,
"isNeedLogin": true,
"headers": [
@ -15717,25 +15717,18 @@
"description": "是否启用外部快递编码;默认 false(关闭)。开启后允许按外部系统传入的快递编码进行处理(如无匹配仍以业务校验为准)"
},
{
"name": "subject_config.auto_outbound_rules",
"type": "object",
"name": "subject_config.auto_outbound_enabled",
"type": "boolean",
"required": false,
"source": "body.subject_config",
"description": "自动出库规则配置。全部条件满足时自动标记待出库"
"description": "是否启用自动出库(flag),默认 false(关闭);开启后按 auto_outbound_rules 中的规则扫描订单并自动标记出库"
},
{
"name": "subject_config.auto_outbound_rules.enabled",
"type": "boolean",
"name": "subject_config.auto_outbound_rules",
"type": "array",
"required": false,
"source": "body.subject_config.auto_outbound_rules",
"description": "是否启用自动出库,默认 false"
},
{
"name": "subject_config.auto_outbound_rules.require_recheck",
"type": "boolean",
"required": false,
"source": "body.subject_config.auto_outbound_rules",
"description": "是否要求已复核(recheck_status=fin),默认 true"
"source": "body.subject_config",
"description": "自动出库规则数组,每项规则独立判断,订单满足任意一条规则即自动出库;空数组时不自动出库。所有规则的固定前置条件为「已复核」(recheck_status=fin)与「已分配储位」(storage_status=fin),未复核订单一律不自动出库。旧版本的对象结构(含 enabled/require_recheck/require_print/require_pick)已废弃不再兼容,保存为非数组时返回 400"
},
{
"name": "subject_config.auto_outbound_rules.require_pack",
@ -15749,7 +15742,7 @@
"type": "boolean",
"required": false,
"source": "body.subject_config.auto_outbound_rules",
"description": "是否要求已称重(weighing_weight>0),默认 true"
"description": "是否要求已称重(wms_order_express.weighing_weight>0),默认 true"
},
{
"name": "subject_config.auto_outbound_rules.require_sync",
@ -15759,18 +15752,25 @@
"description": "是否要求已同步(sync_status=fin),默认 true"
},
{
"name": "subject_config.auto_outbound_rules.require_print",
"name": "subject_config.auto_outbound_rules.exclude_same_day_outbound",
"type": "boolean",
"required": false,
"source": "body.subject_config.auto_outbound_rules",
"description": "是否要求已打印(print_status=fin),默认 true"
"description": "是否不出库当天复核订单(flag),默认 true;开启后按订单复核时间所在日计算:复核时间在「允许当天出库最后时间」之后的订单,需等到该复核日的「放行时间」才自动出库;复核时间早于该最后时间、或为空的订单不受影响"
},
{
"name": "subject_config.auto_outbound_rules.require_pick",
"type": "boolean",
"name": "subject_config.auto_outbound_rules.same_day_outbound_deadline_time",
"type": "string",
"required": false,
"source": "body.subject_config.auto_outbound_rules",
"description": "是否要求已拣货(pick_status=fin),默认 true"
"description": "允许当天出库最后时间(HH:mm,默认 06:00,当天内 00:00~23:59);复核时间早于该时间的订单不受「不出库当天订单」影响,不能大于放行时间。想表达「当天复核的订单全天不出库」时设为 00:00"
},
{
"name": "subject_config.auto_outbound_rules.same_day_outbound_release_time",
"type": "string",
"required": false,
"source": "body.subject_config.auto_outbound_rules",
"description": "放行时间(HH:mm,默认 22:00,支持跨天 00:00~47:59:24:00 之后的数字表示次日,如 27:00 = 次日 03:00);到达该时刻后,该复核日被限制的订单放行。常用:23:59 = 当天不放、过了零点出库;27:00 = 到次日 03:00 才出库"
},
{
"name": "subject_config.sender_name",
@ -47610,7 +47610,7 @@
"type": "string",
"required": false,
"source": "body.where",
"description": "退回收件运单号(模糊搜索,传 {operator:'like',value} 或直接值)"
"description": "退回收件运单号(模糊搜索,传 {operator:'like',value} 或直接值;value 为数组时多值 OR 包含匹配)"
},
{
"name": "where.scan_date",
@ -47816,7 +47816,7 @@
"type": "object",
"required": false,
"source": "body",
"description": "查询条件,语义与 returnReceived.list 的 where 一致(支持 {operator,value} 标准结构或直接值;字段含 waybill_code 模糊、scan_date/created_at/updated_at 范围、scanner_id/scanner_name/store_id/order_express_id/order_id/return_received_task_id 等值、is_original_return 是否原单退回);禁止传入 warehouse_id/warehouseId(服务端注入)"
"description": "查询条件,语义与 returnReceived.list 的 where 一致(支持 {operator,value} 标准结构或直接值;字段含 waybill_code 模糊(like 支持数组多值 OR 包含)、scan_date/created_at/updated_at 范围、scanner_id/scanner_name/store_id/order_express_id/order_id/return_received_task_id 等值、is_original_return 是否原单退回);禁止传入 warehouse_id/warehouseId(服务端注入)"
},
{
"name": "sort",
@ -49748,7 +49748,7 @@
"type": "string",
"required": false,
"source": "body.where",
"description": "运单号(模糊搜索,传 {operator:'like',value} 或直接值)"
"description": "运单号(模糊搜索,传 {operator:'like',value} 或直接值;value 为数组时多值 OR 包含匹配)"
},
{
"name": "where.store_id",
@ -52814,7 +52814,7 @@
},
{
"method": "wechat.getUserAgreementText",
"description": "获取小程序用户须知富文本(免登录):传入 appId(小程序 AppID),从副表 wms_wechat_agreement_version 拉取最新版本(id 自增即最新);Redis 缓存 24 小时(key wechat:userAgreement:{appid}),有缓存直接使用缓存;无版本返回错误",
"description": "获取小程序用户须知富文本(免登录):传入 appId(小程序 AppID),从副表 wms_wechat_agreement_version 拉取最新版本(id 自增即最新);Redis 缓存 24 小时(key wechat:userAgreement:{appid}),有缓存直接使用缓存;无版本返回错误(新授权小程序会自动写入系统默认须知作为第一版)",
"isNeedAuth": false,
"isNeedLogin": false,
"headers": [],
@ -53300,7 +53300,7 @@
},
{
"method": "wechat.getTemplateList",
"description": "获取小程序模板库列表(需登录):只拉取普通模板(template_type=0,GET wxa/gettemplatelist + component_access_token),Redis 缓存 24h(key wechat:template:list:normal);有缓存直接返回(from_cache=true),无缓存拉取后写入缓存",
"description": "获取小程序模板库列表(需登录):只拉取普通模板(template_type=0,GET wxa/gettemplatelist + component_access_token),每次实时拉取不缓存",
"isNeedAuth": false,
"isNeedLogin": true,
"headers": [
@ -53318,12 +53318,6 @@
"type": "array",
"required": true,
"description": "模板信息列表(create_time/user_version/user_desc/template_id/draft_id/source_miniprogram_appid/source_miniprogram/template_type 等)"
},
{
"name": "from_cache",
"type": "boolean",
"required": true,
"description": "是否来自缓存"
}
],
"errors": [
@ -53352,7 +53346,7 @@
"type": "number",
"required": true,
"source": "body",
"description": "代码库中的代码模板 ID(getTemplateList 获取)"
"description": "代码库中的代码模板 ID(getTemplateList 获取,允许 0:普通模板库模板 ID 从 0 开始,0 表示第一个模板)"
}
],
"response": [
@ -53390,7 +53384,7 @@
"errors": [
{
"code": "400",
"message": "未识别仓库/未授权小程序/未授权权限集 18/模板不存在或缺少版本号/代码描述/上传失败(微信 errcode 透传:85014 模板不存在、9402202 并发限制等)"
"message": "template_id 必须为非负整数/未识别仓库/未授权小程序/未授权权限集 18/模板不存在或缺少版本号/代码描述/上传失败(微信 errcode 透传:85014 模板不存在、9402202 并发限制等)"
}
]
},