Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d86857d473 | ||
|
|
6e6a84101e | ||
|
|
59bc65b443 | ||
|
|
06d0bc8ef8 | ||
|
|
2c615cb4f8 |
@ -77,6 +77,15 @@ module.exports = {
|
|||||||
ORDER_WAVE_AUTO_GROUP: '自动加团',
|
ORDER_WAVE_AUTO_GROUP: '自动加团',
|
||||||
ORDER_WAVE_STRATEGY_FETCH: '策略抓取波次',
|
ORDER_WAVE_STRATEGY_FETCH: '策略抓取波次',
|
||||||
ORDER_WAVE_CLAIM: '领取波次',
|
ORDER_WAVE_CLAIM: '领取波次',
|
||||||
|
ORDER_B2B_CONVERT: '转B2B订单',
|
||||||
|
ORDER_B2B_CANCEL: '取消B2B',
|
||||||
|
ORDER_B2B_SET_URGENT: '设置B2B加急',
|
||||||
|
ORDER_B2B_PREP_START: '备货开始',
|
||||||
|
ORDER_B2B_PREP_CANCEL: '取消备货',
|
||||||
|
ORDER_B2B_PREP_FINISH: '备货完成',
|
||||||
|
ORDER_B2B_PICKUP: 'B2B提货',
|
||||||
|
ORDER_B2B_PICKUP_PLATE: '录入B2B提货车牌',
|
||||||
|
ORDER_B2B_IMAGES: '更新B2B订单图片',
|
||||||
ORDER_CONFIRM_PRINT: '确认打印',
|
ORDER_CONFIRM_PRINT: '确认打印',
|
||||||
ORDER_AUTO_EXPRESS_SKIP: '跳过自动分配快递',
|
ORDER_AUTO_EXPRESS_SKIP: '跳过自动分配快递',
|
||||||
ORDER_PICK_COMPLETE: '拣货完成',
|
ORDER_PICK_COMPLETE: '拣货完成',
|
||||||
|
|||||||
33
app/lib/file_business_types.js
Normal file
33
app/lib/file_business_types.js
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* wms_file_reference.business_type 取值集中定义。
|
||||||
|
*
|
||||||
|
* 文件与业务的关联统一落在 wms_file_reference:business_type 标识业务域,
|
||||||
|
* business_id 为业务主键字符串(如商品ID、盘点记录ID、订单ID),
|
||||||
|
* warehouse_id 做仓库隔离,display_order 控制展示顺序。
|
||||||
|
*
|
||||||
|
* 新增业务域时必须在此登记,避免各服务散落硬编码字符串导致口径漂移。
|
||||||
|
*/
|
||||||
|
const FILE_BUSINESS_TYPE = Object.freeze({
|
||||||
|
/** 商品图片(business_id = wms_stock_warehouse.id) */
|
||||||
|
STOCK: 'stock',
|
||||||
|
/** 盘点作业记录图片(business_id = wms_stock_check_record.id) */
|
||||||
|
STOCK_CHECK_RECORD: 'stock_check_record',
|
||||||
|
/** 收货明细图片(business_id = 收货明细 id) */
|
||||||
|
RECEIVING_ITEM: 'receivingItem',
|
||||||
|
/**
|
||||||
|
* B2B 订单备货留证照片(business_id = wms_order_delivery*.id)。
|
||||||
|
* 仅用于 B2B 订单(is_b2b='Y')的备货留证照片,与普通订单附件隔离。
|
||||||
|
*/
|
||||||
|
B2B_ORDER: 'b2b_order',
|
||||||
|
/**
|
||||||
|
* B2B 订单提货留证照片(business_id = wms_order_delivery*.id)。
|
||||||
|
* 与备货照片(b2b_order)分开存放,便于提货交接留证与客户推送按环节区分。
|
||||||
|
*/
|
||||||
|
B2B_PICKUP: 'b2b_pickup',
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
FILE_BUSINESS_TYPE,
|
||||||
|
};
|
||||||
@ -148,6 +148,11 @@ module.exports = app => {
|
|||||||
allowNull: true,
|
allowNull: true,
|
||||||
comment: '产品编码',
|
comment: '产品编码',
|
||||||
},
|
},
|
||||||
|
goods_description: {
|
||||||
|
type: STRING(255),
|
||||||
|
allowNull: true,
|
||||||
|
comment: '物品描述',
|
||||||
|
},
|
||||||
weight_type: {
|
weight_type: {
|
||||||
type: INTEGER(10),
|
type: INTEGER(10),
|
||||||
allowNull: true,
|
allowNull: true,
|
||||||
|
|||||||
@ -9,7 +9,7 @@
|
|||||||
* @return {Object} Sequelize Model 定义。
|
* @return {Object} Sequelize Model 定义。
|
||||||
*/
|
*/
|
||||||
module.exports = app => {
|
module.exports = app => {
|
||||||
const { BIGINT, STRING, INTEGER, DATE } = app.Sequelize;
|
const { BIGINT, STRING, INTEGER, TINYINT, DATE } = app.Sequelize;
|
||||||
|
|
||||||
const InboxBlock = app.model.define('inbox_block', {
|
const InboxBlock = app.model.define('inbox_block', {
|
||||||
id: {
|
id: {
|
||||||
@ -34,6 +34,12 @@ module.exports = app => {
|
|||||||
allowNull: true,
|
allowNull: true,
|
||||||
comment: '用户ID',
|
comment: '用户ID',
|
||||||
},
|
},
|
||||||
|
is_robot: {
|
||||||
|
type: TINYINT(1),
|
||||||
|
allowNull: false,
|
||||||
|
defaultValue: 0,
|
||||||
|
comment: '是否机器人账号:机器人屏蔽在仓库群同样生效(仓库群默认忽略仅用户级屏蔽)',
|
||||||
|
},
|
||||||
created_at: {
|
created_at: {
|
||||||
type: DATE,
|
type: DATE,
|
||||||
allowNull: false,
|
allowNull: false,
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
*
|
*
|
||||||
* 对应数据库表 `wms_order_b2b`,与发货单(订单)分表 wms_order_delivery_% 一对一,
|
* 对应数据库表 `wms_order_b2b`,与发货单(订单)分表 wms_order_delivery_% 一对一,
|
||||||
* 记录 B2B 订单的备货/提货作业信息:总箱数、提货车牌、备货备注、备货用时、
|
* 记录 B2B 订单的备货/提货作业信息:总箱数、提货车牌、备货备注、备货用时、
|
||||||
* 备货完成时间、是否提货等。
|
* 备货完成时间、备货状态与备货人、是否加急、是否提货等。
|
||||||
*
|
*
|
||||||
* 不分表(不按仓库分表),关联读统一使用 warehouse_id + order_id(分表 id 按仓库
|
* 不分表(不按仓库分表),关联读统一使用 warehouse_id + order_id(分表 id 按仓库
|
||||||
* 各自发号,跨仓可能重叠,故不单独依赖 order_id)。取消 B2B 时物理删除行,不做软删除。
|
* 各自发号,跨仓可能重叠,故不单独依赖 order_id)。取消 B2B 时物理删除行,不做软删除。
|
||||||
@ -59,12 +59,39 @@ module.exports = app => {
|
|||||||
allowNull: true,
|
allowNull: true,
|
||||||
comment: '备货完成时间',
|
comment: '备货完成时间',
|
||||||
},
|
},
|
||||||
|
prep_status: {
|
||||||
|
type: ENUM('none', 'padding', 'fin'),
|
||||||
|
allowNull: false,
|
||||||
|
defaultValue: 'none',
|
||||||
|
comment: '备货状态:none=未开始 padding=备货中 fin=已完成',
|
||||||
|
},
|
||||||
|
prep_operator_id: {
|
||||||
|
type: BIGINT(20).UNSIGNED,
|
||||||
|
allowNull: true,
|
||||||
|
comment: '备货人工号ID(工号,用于同工号校验)',
|
||||||
|
},
|
||||||
|
prep_operator_name: {
|
||||||
|
type: STRING(50),
|
||||||
|
allowNull: true,
|
||||||
|
comment: '备货人姓名',
|
||||||
|
},
|
||||||
|
prep_start_at: {
|
||||||
|
type: DATE,
|
||||||
|
allowNull: true,
|
||||||
|
comment: '备货开始时间',
|
||||||
|
},
|
||||||
is_picked_up: {
|
is_picked_up: {
|
||||||
type: ENUM('Y', 'N'),
|
type: ENUM('Y', 'N'),
|
||||||
allowNull: false,
|
allowNull: false,
|
||||||
defaultValue: 'N',
|
defaultValue: 'N',
|
||||||
comment: '是否提货:Y=已提货 N=未提货',
|
comment: '是否提货:Y=已提货 N=未提货',
|
||||||
},
|
},
|
||||||
|
is_urgent: {
|
||||||
|
type: ENUM('Y', 'N'),
|
||||||
|
allowNull: false,
|
||||||
|
defaultValue: 'N',
|
||||||
|
comment: '是否加急:Y=加急 N=普通',
|
||||||
|
},
|
||||||
picked_up_at: {
|
picked_up_at: {
|
||||||
type: DATE,
|
type: DATE,
|
||||||
allowNull: true,
|
allowNull: true,
|
||||||
@ -93,6 +120,14 @@ module.exports = app => {
|
|||||||
name: 'idx_is_picked_up',
|
name: 'idx_is_picked_up',
|
||||||
fields: [ 'is_picked_up' ],
|
fields: [ 'is_picked_up' ],
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: 'idx_is_urgent',
|
||||||
|
fields: [ 'is_urgent' ],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'idx_prep_status_operator',
|
||||||
|
fields: [ 'prep_status', 'prep_operator_id' ],
|
||||||
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
73
app/model/order_b2b_item.js
Normal file
73
app/model/order_b2b_item.js
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* B2B 订单分箱商品明细。
|
||||||
|
* @param {import('egg').Application} app Egg 应用实例。
|
||||||
|
*/
|
||||||
|
module.exports = app => {
|
||||||
|
const { BIGINT, INTEGER, STRING, DATE } = app.Sequelize;
|
||||||
|
|
||||||
|
return app.model.define('wms_order_b2b_items', {
|
||||||
|
id: {
|
||||||
|
type: BIGINT(20).UNSIGNED,
|
||||||
|
primaryKey: true,
|
||||||
|
autoIncrement: true,
|
||||||
|
allowNull: false,
|
||||||
|
comment: '主键ID',
|
||||||
|
},
|
||||||
|
warehouse_id: {
|
||||||
|
type: BIGINT(20).UNSIGNED,
|
||||||
|
allowNull: false,
|
||||||
|
comment: '仓库ID',
|
||||||
|
},
|
||||||
|
order_id: {
|
||||||
|
type: BIGINT(20).UNSIGNED,
|
||||||
|
allowNull: false,
|
||||||
|
comment: '订单ID',
|
||||||
|
},
|
||||||
|
order_item_id: {
|
||||||
|
type: BIGINT(20).UNSIGNED,
|
||||||
|
allowNull: false,
|
||||||
|
comment: '订单商品明细ID',
|
||||||
|
},
|
||||||
|
box_no: {
|
||||||
|
type: STRING(50),
|
||||||
|
allowNull: false,
|
||||||
|
comment: '箱号',
|
||||||
|
},
|
||||||
|
quantity: {
|
||||||
|
type: INTEGER(11).UNSIGNED,
|
||||||
|
allowNull: false,
|
||||||
|
comment: '该商品在该箱中的数量',
|
||||||
|
},
|
||||||
|
created_at: {
|
||||||
|
type: DATE,
|
||||||
|
allowNull: false,
|
||||||
|
comment: '创建时间',
|
||||||
|
},
|
||||||
|
updated_at: {
|
||||||
|
type: DATE,
|
||||||
|
allowNull: false,
|
||||||
|
comment: '更新时间',
|
||||||
|
},
|
||||||
|
}, {
|
||||||
|
tableName: 'wms_order_b2b_items',
|
||||||
|
comment: 'B2B订单分箱商品明细表',
|
||||||
|
timestamps: false,
|
||||||
|
indexes: [
|
||||||
|
{
|
||||||
|
name: 'uk_warehouse_order_item_box',
|
||||||
|
unique: true,
|
||||||
|
fields: [ 'warehouse_id', 'order_id', 'order_item_id', 'box_no' ],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'idx_warehouse_order',
|
||||||
|
fields: [ 'warehouse_id', 'order_id' ],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'idx_order_item',
|
||||||
|
fields: [ 'order_item_id' ],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
};
|
||||||
@ -101,6 +101,7 @@ module.exports = app => {
|
|||||||
group_order_pack_max_minutes: 40,
|
group_order_pack_max_minutes: 40,
|
||||||
big_group_pack_coefficient: 3,
|
big_group_pack_coefficient: 3,
|
||||||
single_weigh_require_pack: false,
|
single_weigh_require_pack: false,
|
||||||
|
b2b_packing_quantity_check: false,
|
||||||
stock_warning_enabled: false,
|
stock_warning_enabled: false,
|
||||||
stock_warning_quantity: 0,
|
stock_warning_quantity: 0,
|
||||||
stock_static_hours: 168,
|
stock_static_hours: 168,
|
||||||
@ -575,6 +576,13 @@ module.exports = app => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Object.prototype.hasOwnProperty.call(parsed, 'b2b_packing_quantity_check')) {
|
||||||
|
normalized.b2b_packing_quantity_check = normalizeBooleanFlag(
|
||||||
|
parsed.b2b_packing_quantity_check,
|
||||||
|
'subject_config.b2b_packing_quantity_check'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// 是否开启库存预警:默认关闭
|
// 是否开启库存预警:默认关闭
|
||||||
if (Object.prototype.hasOwnProperty.call(parsed, 'stock_warning_enabled')) {
|
if (Object.prototype.hasOwnProperty.call(parsed, 'stock_warning_enabled')) {
|
||||||
normalized.stock_warning_enabled = normalizeBooleanFlag(
|
normalized.stock_warning_enabled = normalizeBooleanFlag(
|
||||||
|
|||||||
@ -8,6 +8,15 @@ const WAREHOUSE_INTERFACE_TYPE_ID = 3;
|
|||||||
/** 历史消息过滤默认阈值:发送时间距今超过 10 分钟视为历史/补推消息,跳过 AI(可用 config.inbox.historyMessageMaxAgeMs 覆盖) */
|
/** 历史消息过滤默认阈值:发送时间距今超过 10 分钟视为历史/补推消息,跳过 AI(可用 config.inbox.historyMessageMaxAgeMs 覆盖) */
|
||||||
const DEFAULT_HISTORY_MESSAGE_MAX_AGE_MS = 10 * 60 * 1000;
|
const DEFAULT_HISTORY_MESSAGE_MAX_AGE_MS = 10 * 60 * 1000;
|
||||||
|
|
||||||
|
/** 屏蔽集合缓存键前缀(v2:纯对象+数组结构,Redis JSON 序列化后可正常回读) */
|
||||||
|
const BLOCK_CACHE_KEY_PREFIX = 'inbox:block:v2:';
|
||||||
|
|
||||||
|
/** 旧版屏蔽集合缓存键前缀(Set 结构,Redis 序列化后恒不命中,仅用于主动失效) */
|
||||||
|
const LEGACY_BLOCK_CACHE_KEY_PREFIX = 'inbox:block:';
|
||||||
|
|
||||||
|
/** 屏蔽集合缓存过期秒数 */
|
||||||
|
const BLOCK_CACHE_TTL_SECONDS = 300;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 站内信内容处理器。
|
* 站内信内容处理器。
|
||||||
* 负责解析入站消息正文,按 source_type 分流处理,
|
* 负责解析入站消息正文,按 source_type 分流处理,
|
||||||
@ -717,10 +726,68 @@ class InboxProcessorService extends Service {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加载仓库维度屏蔽集合(带缓存)。
|
||||||
|
* 缓存值使用「纯对象 + 数组」(Redis 以 JSON 存储,Set 会被序列化成 {} 导致缓存恒不命中),
|
||||||
|
* 读取后转成 Set 便于 O(1) 判定。
|
||||||
|
*
|
||||||
|
* @param {number} warehouseId 仓库ID。
|
||||||
|
* @return {Promise<{pairs: Set<string>, groupAll: Set<string>, users: Set<string>,
|
||||||
|
* robotPairs: Set<string>, robotGroupAll: Set<string>, robotUsers: Set<string>}>} 屏蔽集合。
|
||||||
|
*/
|
||||||
|
async loadBlockSets(warehouseId) {
|
||||||
|
const { ctx } = this;
|
||||||
|
const app = ctx.app;
|
||||||
|
const cacheKey = `${BLOCK_CACHE_KEY_PREFIX}${warehouseId}`;
|
||||||
|
|
||||||
|
const toSets = raw => ({
|
||||||
|
pairs: new Set(raw.pairs || []),
|
||||||
|
groupAll: new Set(raw.groupAll || []),
|
||||||
|
users: new Set(raw.users || []),
|
||||||
|
robotPairs: new Set(raw.robotPairs || []),
|
||||||
|
robotGroupAll: new Set(raw.robotGroupAll || []),
|
||||||
|
robotUsers: new Set(raw.robotUsers || []),
|
||||||
|
});
|
||||||
|
|
||||||
|
const cached = typeof app.getCacheAsync === 'function' ? await app.getCacheAsync(cacheKey) : null;
|
||||||
|
if (cached && Array.isArray(cached.pairs)) return toSets(cached);
|
||||||
|
|
||||||
|
const { InboxBlock } = ctx.model;
|
||||||
|
const rows = await InboxBlock.findAll({
|
||||||
|
attributes: [ 'group_id', 'user_id', 'is_robot' ],
|
||||||
|
where: { warehouse_id: warehouseId },
|
||||||
|
raw: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
const raw = {
|
||||||
|
pairs: [], groupAll: [], users: [],
|
||||||
|
robotPairs: [], robotGroupAll: [], robotUsers: [],
|
||||||
|
};
|
||||||
|
for (const row of rows) {
|
||||||
|
const g = String(row.group_id || '').trim();
|
||||||
|
const u = String(row.user_id || '').trim();
|
||||||
|
if (Number(row.is_robot) === 1) {
|
||||||
|
if (g && u) raw.robotPairs.push(`${g}:${u}`);
|
||||||
|
else if (g) raw.robotGroupAll.push(g);
|
||||||
|
else if (u) raw.robotUsers.push(u);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (g && u) raw.pairs.push(`${g}:${u}`);
|
||||||
|
else if (g) raw.groupAll.push(g);
|
||||||
|
else if (u) raw.users.push(u);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof app.setCacheAsync === 'function') {
|
||||||
|
await app.setCacheAsync(cacheKey, raw, BLOCK_CACHE_TTL_SECONDS);
|
||||||
|
}
|
||||||
|
return toSets(raw);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 加载当前仓库的屏蔽用户ID集合(供 AI 判断真人接管)。
|
* 加载当前仓库的屏蔽用户ID集合(供 AI 判断真人接管)。
|
||||||
* 口径与 isBlocked() 一致:仓库群忽略不带群ID的屏蔽记录(仅带 group_id 的记录才算命中),
|
* 口径与 isBlocked() 一致:仓库群忽略不带群ID的屏蔽记录(仅带 group_id 的记录才算命中),
|
||||||
* 避免货主群/快递群等场景的用户级屏蔽连带把仓库群用户标记为「已屏蔽」。
|
* 避免货主群/快递群等场景的用户级屏蔽连带把仓库群用户标记为「已屏蔽」。
|
||||||
|
* 机器人屏蔽仅用于拦截机器人自身的回灌消息,不参与真人接管判断,故排除。
|
||||||
*
|
*
|
||||||
* @param {number} warehouseId 仓库ID。
|
* @param {number} warehouseId 仓库ID。
|
||||||
* @return {Promise<Set<string>>} 屏蔽用户ID集合。
|
* @return {Promise<Set<string>>} 屏蔽用户ID集合。
|
||||||
@ -732,7 +799,7 @@ class InboxProcessorService extends Service {
|
|||||||
const { InboxBlock } = ctx.model;
|
const { InboxBlock } = ctx.model;
|
||||||
const rows = await InboxBlock.findAll({
|
const rows = await InboxBlock.findAll({
|
||||||
attributes: [ 'group_id', 'user_id' ],
|
attributes: [ 'group_id', 'user_id' ],
|
||||||
where: { warehouse_id: warehouseId },
|
where: { warehouse_id: warehouseId, is_robot: 0 },
|
||||||
raw: true,
|
raw: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -752,13 +819,14 @@ class InboxProcessorService extends Service {
|
|||||||
* - 仅带 user_id 的全局用户屏蔽(`*:用户`)在仓库群内不生效——仓库群是内部群,
|
* - 仅带 user_id 的全局用户屏蔽(`*:用户`)在仓库群内不生效——仓库群是内部群,
|
||||||
* 此类屏蔽多来自货主群/快递群等外部场景,不应连带跳过仓库群消息;
|
* 此类屏蔽多来自货主群/快递群等外部场景,不应连带跳过仓库群消息;
|
||||||
* 仓库群内由机器人发起的屏蔽([屏蔽] 指令)会写入当前群 group_id,故仍按带群ID记录生效。
|
* 仓库群内由机器人发起的屏蔽([屏蔽] 指令)会写入当前群 group_id,故仍按带群ID记录生效。
|
||||||
|
* - 机器人屏蔽(is_robot=1)不受上面的仓库群例外影响:机器人自身回信被桥接回灌成入站消息时
|
||||||
|
* 会形成自问自答死循环,仅带 user_id 的机器人屏蔽按仓库维度全群生效。
|
||||||
* - 无群ID的消息(如私聊)不受此例外影响。
|
* - 无群ID的消息(如私聊)不受此例外影响。
|
||||||
*
|
*
|
||||||
* @return {Promise<boolean>} 是否已屏蔽。
|
* @return {Promise<boolean>} 是否已屏蔽。
|
||||||
*/
|
*/
|
||||||
async isBlocked() {
|
async isBlocked() {
|
||||||
const { ctx } = this;
|
const { ctx } = this;
|
||||||
const app = ctx.app;
|
|
||||||
const groupId = String(ctx.inboxContext?.group_id || '').trim();
|
const groupId = String(ctx.inboxContext?.group_id || '').trim();
|
||||||
const userId = String(ctx.inboxContext?.user_id || '').trim();
|
const userId = String(ctx.inboxContext?.user_id || '').trim();
|
||||||
const warehouseId = Number(ctx.inboxContext?.warehouse_id || 0);
|
const warehouseId = Number(ctx.inboxContext?.warehouse_id || 0);
|
||||||
@ -766,36 +834,20 @@ class InboxProcessorService extends Service {
|
|||||||
if (!groupId && !userId) return false;
|
if (!groupId && !userId) return false;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 1. 尝试从缓存读取屏蔽列表
|
const sets = await this.loadBlockSets(warehouseId);
|
||||||
const cacheKey = `inbox:block:${warehouseId}`;
|
|
||||||
let blockedSet = await app.getCacheAsync(cacheKey);
|
|
||||||
|
|
||||||
if (!blockedSet || !(blockedSet instanceof Set)) {
|
// 1. 机器人屏蔽优先,且不受「仓库群忽略用户级屏蔽」例外影响
|
||||||
// 2. 缓存未命中,查库并填入缓存
|
if (userId && sets.robotUsers.has(userId)) {
|
||||||
const { InboxBlock } = ctx.model;
|
ctx.logger.info(`[inbox processor] 命中机器人屏蔽(按仓库全群生效) user_id=${userId}`);
|
||||||
const rows = await InboxBlock.findAll({
|
return true;
|
||||||
attributes: [ 'group_id', 'user_id' ],
|
|
||||||
where: { warehouse_id: warehouseId },
|
|
||||||
raw: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
blockedSet = new Set();
|
|
||||||
for (const row of rows) {
|
|
||||||
const g = String(row.group_id || '').trim();
|
|
||||||
const u = String(row.user_id || '').trim();
|
|
||||||
if (g && u) blockedSet.add(`${g}:${u}`);
|
|
||||||
if (g && !u) blockedSet.add(`${g}:*`);
|
|
||||||
if (!g && u) blockedSet.add(`*:${u}`);
|
|
||||||
}
|
}
|
||||||
|
if (groupId && userId && sets.robotPairs.has(`${groupId}:${userId}`)) return true;
|
||||||
|
if (groupId && sets.robotGroupAll.has(groupId)) return true;
|
||||||
|
|
||||||
// TTL 5 分钟
|
// 2. 普通屏蔽
|
||||||
await app.setCacheAsync(cacheKey, blockedSet, 300);
|
if (groupId && userId && sets.pairs.has(`${groupId}:${userId}`)) return true;
|
||||||
}
|
if (groupId && sets.groupAll.has(groupId)) return true;
|
||||||
|
if (userId && sets.users.has(userId)) {
|
||||||
// 3. 检查当前消息是否命中屏蔽规则
|
|
||||||
if (groupId && userId && blockedSet.has(`${groupId}:${userId}`)) return true;
|
|
||||||
if (groupId && blockedSet.has(`${groupId}:*`)) return true;
|
|
||||||
if (userId && blockedSet.has(`*:${userId}`)) {
|
|
||||||
// 仓库群忽略不带群ID的用户级屏蔽(见方法注释)
|
// 仓库群忽略不带群ID的用户级屏蔽(见方法注释)
|
||||||
if (groupId && await this.isWarehouseGroup(groupId, warehouseId)) {
|
if (groupId && await this.isWarehouseGroup(groupId, warehouseId)) {
|
||||||
ctx.logger.info(`[inbox processor] 仓库群忽略不带群ID的用户屏蔽 group_id=${groupId} user_id=${userId}`);
|
ctx.logger.info(`[inbox processor] 仓库群忽略不带群ID的用户屏蔽 group_id=${groupId} user_id=${userId}`);
|
||||||
@ -813,16 +865,23 @@ class InboxProcessorService extends Service {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 失效屏蔽缓存,在新增屏蔽记录后调用。
|
* 失效屏蔽缓存,在新增屏蔽记录后调用。
|
||||||
|
* 同时清理旧版 Set 结构的缓存键,避免升级后残留脏缓存。
|
||||||
*
|
*
|
||||||
* @param {number} warehouseId 仓库ID。
|
* @param {number} warehouseId 仓库ID。
|
||||||
* @return {Promise<void>} 无返回值。
|
* @return {Promise<void>} 无返回值。
|
||||||
*/
|
*/
|
||||||
async invalidateBlockCache(warehouseId) {
|
async invalidateBlockCache(warehouseId) {
|
||||||
const { ctx } = this;
|
const { ctx } = this;
|
||||||
|
const keys = [
|
||||||
|
`${BLOCK_CACHE_KEY_PREFIX}${warehouseId}`,
|
||||||
|
`${LEGACY_BLOCK_CACHE_KEY_PREFIX}${warehouseId}`,
|
||||||
|
];
|
||||||
|
for (const key of keys) {
|
||||||
try {
|
try {
|
||||||
await ctx.app.setCacheAsync(`inbox:block:${warehouseId}`, null, 0);
|
await ctx.app.setCacheAsync(key, null, 0);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
ctx.logger.warn(`[inbox processor] 失效屏蔽缓存失败: ${error.message}`);
|
ctx.logger.warn(`[inbox processor] 失效屏蔽缓存失败 key=${key}: ${error.message}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -4,6 +4,7 @@ const MainService = require('../../main');
|
|||||||
const { parseWhereConditions } = require('../../../lib/query_condition_parser');
|
const { parseWhereConditions } = require('../../../lib/query_condition_parser');
|
||||||
const { isInterceptedOrderStatus } = require('../../../lib/intercept_guard');
|
const { isInterceptedOrderStatus } = require('../../../lib/intercept_guard');
|
||||||
const { isLockedOrderStatus } = require('../../../lib/lock_guard');
|
const { isLockedOrderStatus } = require('../../../lib/lock_guard');
|
||||||
|
const { FILE_BUSINESS_TYPE } = require('../../../lib/file_business_types');
|
||||||
|
|
||||||
const DEFAULT_PAGE_SIZE = 20;
|
const DEFAULT_PAGE_SIZE = 20;
|
||||||
const MAX_PAGE_SIZE = 500;
|
const MAX_PAGE_SIZE = 500;
|
||||||
@ -58,6 +59,11 @@ const ORDER_B2B_DETAIL_ATTRIBUTES = Object.freeze([
|
|||||||
'pickup_plate_number',
|
'pickup_plate_number',
|
||||||
'prep_remark',
|
'prep_remark',
|
||||||
'prep_duration_seconds',
|
'prep_duration_seconds',
|
||||||
|
'prep_status',
|
||||||
|
'prep_operator_id',
|
||||||
|
'prep_operator_name',
|
||||||
|
'prep_start_at',
|
||||||
|
'is_urgent',
|
||||||
'is_picked_up',
|
'is_picked_up',
|
||||||
'picked_up_at',
|
'picked_up_at',
|
||||||
'created_at',
|
'created_at',
|
||||||
@ -70,6 +76,11 @@ const ORDER_B2B_DETAIL_EMPTY = Object.freeze({
|
|||||||
pickup_plate_number: null,
|
pickup_plate_number: null,
|
||||||
prep_remark: null,
|
prep_remark: null,
|
||||||
prep_duration_seconds: 0,
|
prep_duration_seconds: 0,
|
||||||
|
prep_status: 'none',
|
||||||
|
prep_operator_id: null,
|
||||||
|
prep_operator_name: null,
|
||||||
|
prep_start_at: null,
|
||||||
|
is_urgent: 'N',
|
||||||
is_picked_up: 'N',
|
is_picked_up: 'N',
|
||||||
picked_up_at: null,
|
picked_up_at: null,
|
||||||
created_at: null,
|
created_at: null,
|
||||||
@ -82,6 +93,10 @@ const ORDER_B2B_DETAIL_FILTER_FIELDS = Object.freeze([
|
|||||||
'pickup_plate_number',
|
'pickup_plate_number',
|
||||||
'prep_remark',
|
'prep_remark',
|
||||||
'prep_duration_seconds',
|
'prep_duration_seconds',
|
||||||
|
'prep_status',
|
||||||
|
'prep_operator_id',
|
||||||
|
'prep_start_at',
|
||||||
|
'is_urgent',
|
||||||
'is_picked_up',
|
'is_picked_up',
|
||||||
'picked_up_at',
|
'picked_up_at',
|
||||||
'created_at',
|
'created_at',
|
||||||
@ -1934,7 +1949,8 @@ class OrderBaseService extends MainService {
|
|||||||
* 不可被请求中的同名字段覆盖(用于 B2B 等固定域列表)。
|
* 不可被请求中的同名字段覆盖(用于 B2B 等固定域列表)。
|
||||||
* @param {boolean} [options.b2bDetailFilter=false] 是否支持用 wms_order_b2b 作业明细字段
|
* @param {boolean} [options.b2bDetailFilter=false] 是否支持用 wms_order_b2b 作业明细字段
|
||||||
* (total_box_count / pickup_plate_number / prep_remark / prep_duration_seconds /
|
* (total_box_count / pickup_plate_number / prep_remark / prep_duration_seconds /
|
||||||
* is_picked_up / picked_up_at / created_at / prep_at)作为筛选条件。
|
* is_urgent / is_picked_up / picked_up_at / created_at / prep_at)作为筛选条件。
|
||||||
|
* @param {boolean} [options.urgentFirst=false] 是否让加急订单(wms_order_b2b.is_urgent='Y')优先排序。
|
||||||
* @return {Promise<Object>} 列表与分页信息。
|
* @return {Promise<Object>} 列表与分页信息。
|
||||||
*/
|
*/
|
||||||
async listByModule(moduleName = 'order', data = {}, options = {}) {
|
async listByModule(moduleName = 'order', data = {}, options = {}) {
|
||||||
@ -2023,7 +2039,11 @@ class OrderBaseService extends MainService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const model = await this.getOrderModel(moduleName, contextWarehouseId);
|
const model = await this.getOrderModel(moduleName, contextWarehouseId);
|
||||||
const order = this.buildListOrder(requestData.sort, moduleName);
|
const baseOrder = this.buildListOrder(requestData.sort, moduleName);
|
||||||
|
const urgentOrder = normalizedOptions.urgentFirst === true
|
||||||
|
? this.buildB2bUrgentFirstOrder(model, contextWarehouseId)
|
||||||
|
: null;
|
||||||
|
const order = urgentOrder ? [ urgentOrder, ...baseOrder ] : baseOrder;
|
||||||
const offset = (page - 1) * pageSize;
|
const offset = (page - 1) * pageSize;
|
||||||
const moduleConfig = this.getModuleConfig(moduleName);
|
const moduleConfig = this.getModuleConfig(moduleName);
|
||||||
const listAttributes = moduleConfig.modelType === 'history'
|
const listAttributes = moduleConfig.modelType === 'history'
|
||||||
@ -2098,16 +2118,103 @@ class OrderBaseService extends MainService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 为订单列表行附加 B2B 作业明细字段(副表 wms_order_b2b)。
|
* 规范化 B2B 作业明细行的输出字段(列表与详情共用)。
|
||||||
|
*
|
||||||
|
* @param {Object|null} detail wms_order_b2b 行。
|
||||||
|
* @return {Object} 统一字段结构;detail 为空时输出空值占位。
|
||||||
|
*/
|
||||||
|
formatB2bDetailFields(detail) {
|
||||||
|
if (!detail) {
|
||||||
|
return { ...ORDER_B2B_DETAIL_EMPTY };
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
total_box_count: Number(detail.total_box_count || 0),
|
||||||
|
pickup_plate_number: detail.pickup_plate_number ?? null,
|
||||||
|
prep_remark: detail.prep_remark ?? null,
|
||||||
|
prep_duration_seconds: Number(detail.prep_duration_seconds || 0),
|
||||||
|
prep_status: String(detail.prep_status || 'none').trim() || 'none',
|
||||||
|
prep_operator_id: detail.prep_operator_id === null || detail.prep_operator_id === undefined
|
||||||
|
? null
|
||||||
|
: Number(detail.prep_operator_id),
|
||||||
|
prep_operator_name: detail.prep_operator_name ?? null,
|
||||||
|
prep_start_at: detail.prep_start_at ?? null,
|
||||||
|
is_urgent: String(detail.is_urgent || 'N').trim() === 'Y' ? 'Y' : 'N',
|
||||||
|
is_picked_up: String(detail.is_picked_up || 'N').trim() === 'Y' ? 'Y' : 'N',
|
||||||
|
picked_up_at: detail.picked_up_at ?? null,
|
||||||
|
created_at: detail.created_at ?? null,
|
||||||
|
prep_at: detail.prep_at ?? null,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询 B2B 订单详情附加信息(副表作业明细 + 备货照片 + 提货照片)。
|
||||||
|
*
|
||||||
|
* 仅对 is_b2b='Y' 的订单返回副表数据:非 B2B 订单返回
|
||||||
|
* { b2b: null, images: [], pickup_images: [] },保持结构稳定。
|
||||||
|
* B2B 订单无副表行时 b2b 输出空值占位(字段结构不变):
|
||||||
|
* images 来自 wms_file_reference(business_type=b2b_order,备货照片),
|
||||||
|
* pickup_images 来自 wms_file_reference(business_type=b2b_pickup,提货照片),
|
||||||
|
* 两者均按 display_order 升序。
|
||||||
|
*
|
||||||
|
* @param {Object} order 订单行(需含 id、is_b2b)。
|
||||||
|
* @param {number|string|null} [warehouseId=null] 仓库ID,缺省取当前上下文。
|
||||||
|
* @return {Promise<{ b2b: (Object|null), images: Array<Object>, pickup_images: Array<Object> }>}
|
||||||
|
* 副表字段、备货照片与提货照片列表。
|
||||||
|
*/
|
||||||
|
async buildB2bDetailExtras(order = {}, warehouseId = null) {
|
||||||
|
const emptyResult = { b2b: null, images: [], pickup_images: [] };
|
||||||
|
const orderId = Number(order && order.id || 0);
|
||||||
|
const normalizedWarehouseId = Number(warehouseId ?? this.getWarehouseId() ?? 0);
|
||||||
|
|
||||||
|
if (String(order && order.is_b2b || '').trim() !== 'Y'
|
||||||
|
|| !Number.isInteger(orderId) || orderId <= 0
|
||||||
|
|| !Number.isInteger(normalizedWarehouseId) || normalizedWarehouseId <= 0) {
|
||||||
|
return emptyResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
const b2bModel = this.ctx.model && this.ctx.model.OrderB2b;
|
||||||
|
let b2bDetail = null;
|
||||||
|
|
||||||
|
if (b2bModel && typeof b2bModel.findOne === 'function') {
|
||||||
|
b2bDetail = await b2bModel.findOne({
|
||||||
|
where: {
|
||||||
|
warehouse_id: normalizedWarehouseId,
|
||||||
|
order_id: orderId,
|
||||||
|
},
|
||||||
|
attributes: [ ...ORDER_B2B_DETAIL_ATTRIBUTES ],
|
||||||
|
raw: true,
|
||||||
|
}) || null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const imageMap = new Map();
|
||||||
|
const pickupImageMap = new Map();
|
||||||
|
await this.attachB2bImages({ prepImageMap: imageMap, pickupImageMap }, [ orderId ], normalizedWarehouseId);
|
||||||
|
|
||||||
|
return {
|
||||||
|
b2b: this.formatB2bDetailFields(b2bDetail),
|
||||||
|
images: imageMap.get(orderId) || [],
|
||||||
|
pickup_images: pickupImageMap.get(orderId) || [],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 为订单列表行附加 B2B 作业明细字段(副表 wms_order_b2b)与订单图片。
|
||||||
*
|
*
|
||||||
* 关联条件固定为 warehouse_id + order_id(分表 id 按仓库发号,不能只按 order_id 关联);
|
* 关联条件固定为 warehouse_id + order_id(分表 id 按仓库发号,不能只按 order_id 关联);
|
||||||
* 无副表行时输出空值占位,保证响应字段结构稳定。附加字段:
|
* 无副表行时输出空值占位,保证响应字段结构稳定。附加字段:
|
||||||
* total_box_count / pickup_plate_number / prep_remark / prep_duration_seconds /
|
* total_box_count / pickup_plate_number / prep_remark / prep_duration_seconds /
|
||||||
* is_picked_up / picked_up_at / created_at(副表创建时间) / prep_at。
|
* prep_status / prep_operator_id / prep_operator_name / prep_start_at /
|
||||||
|
* is_urgent / is_picked_up / picked_up_at / created_at(副表创建时间) / prep_at。
|
||||||
|
*
|
||||||
|
* 同时批量挂载 B2B 订单图片(元素结构统一为 { file_id, url, display_order }):
|
||||||
|
* - images(business_type=b2b_order,备货照片)
|
||||||
|
* - pickup_images(business_type=b2b_pickup,提货照片)
|
||||||
|
* 均按 display_order 升序,无图片输出空数组。
|
||||||
*
|
*
|
||||||
* @param {Array<Object>} list 订单列表行(需含 id)。
|
* @param {Array<Object>} list 订单列表行(需含 id)。
|
||||||
* @param {number|string|null} [warehouseId=null] 仓库ID,缺省取当前上下文。
|
* @param {number|string|null} [warehouseId=null] 仓库ID,缺省取当前上下文。
|
||||||
* @return {Promise<Array<Object>>} 附加 B2B 作业明细后的列表。
|
* @return {Promise<Array<Object>>} 附加 B2B 作业明细与图片后的列表。
|
||||||
*/
|
*/
|
||||||
async attachB2bJobDetail(list = [], warehouseId = null) {
|
async attachB2bJobDetail(list = [], warehouseId = null) {
|
||||||
const rows = Array.isArray(list) ? list : [];
|
const rows = Array.isArray(list) ? list : [];
|
||||||
@ -2118,6 +2225,8 @@ class OrderBaseService extends MainService {
|
|||||||
const normalizedWarehouseId = Number(warehouseId ?? this.getWarehouseId() ?? 0);
|
const normalizedWarehouseId = Number(warehouseId ?? this.getWarehouseId() ?? 0);
|
||||||
const b2bModel = this.ctx.model && this.ctx.model.OrderB2b;
|
const b2bModel = this.ctx.model && this.ctx.model.OrderB2b;
|
||||||
const detailMap = new Map();
|
const detailMap = new Map();
|
||||||
|
const imageMap = new Map();
|
||||||
|
const pickupImageMap = new Map();
|
||||||
|
|
||||||
if (Number.isInteger(normalizedWarehouseId) && normalizedWarehouseId > 0
|
if (Number.isInteger(normalizedWarehouseId) && normalizedWarehouseId > 0
|
||||||
&& b2bModel && typeof b2bModel.findAll === 'function') {
|
&& b2bModel && typeof b2bModel.findAll === 'function') {
|
||||||
@ -2141,29 +2250,138 @@ class OrderBaseService extends MainService {
|
|||||||
detailMap.set(orderId, detail);
|
detailMap.set(orderId, detail);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await this.attachB2bImages({
|
||||||
|
prepImageMap: imageMap,
|
||||||
|
pickupImageMap,
|
||||||
|
}, orderIds, normalizedWarehouseId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return rows.map(row => {
|
return rows.map(row => {
|
||||||
const detail = detailMap.get(Number(row && row.id || 0));
|
const orderId = Number(row && row.id || 0);
|
||||||
if (!detail) {
|
const detail = detailMap.get(orderId);
|
||||||
return { ...row, ...ORDER_B2B_DETAIL_EMPTY };
|
const images = imageMap.get(orderId) || [];
|
||||||
}
|
const pickupImages = pickupImageMap.get(orderId) || [];
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...row,
|
...row,
|
||||||
total_box_count: Number(detail.total_box_count || 0),
|
...this.formatB2bDetailFields(detail),
|
||||||
pickup_plate_number: detail.pickup_plate_number ?? null,
|
images,
|
||||||
prep_remark: detail.prep_remark ?? null,
|
pickup_images: pickupImages,
|
||||||
prep_duration_seconds: Number(detail.prep_duration_seconds || 0),
|
|
||||||
is_picked_up: String(detail.is_picked_up || 'N').trim() === 'Y' ? 'Y' : 'N',
|
|
||||||
picked_up_at: detail.picked_up_at ?? null,
|
|
||||||
created_at: detail.created_at ?? null,
|
|
||||||
prep_at: detail.prep_at ?? null,
|
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量读取 B2B 订单图片并按业务类型分发(一次查询,不做 N+1)。
|
||||||
|
*
|
||||||
|
* 数据源为 wms_file_reference(warehouse_id 隔离)关联 wms_file.file_url,
|
||||||
|
* 同时取 business_type=b2b_order(备货照片)与 b2b_pickup(提货照片),
|
||||||
|
* 按 display_order、id 升序后分别写入 prepImageMap / pickupImageMap
|
||||||
|
* (订单ID → [{ id, url, display_order }]);无引用模型或查询失败时保持空映射
|
||||||
|
* (列表输出空数组),不影响列表主流程。
|
||||||
|
*
|
||||||
|
* @param {Object} targetMaps 输出映射容器。
|
||||||
|
* @param {Map<number, Array<Object>>} [targetMaps.prepImageMap] 备货照片输出映射。
|
||||||
|
* @param {Map<number, Array<Object>>} [targetMaps.pickupImageMap] 提货照片输出映射。
|
||||||
|
* @param {Array<number>} orderIds 订单ID列表。
|
||||||
|
* @param {number} warehouseId 仓库ID。
|
||||||
|
* @return {Promise<void>} 无返回值。
|
||||||
|
*/
|
||||||
|
async attachB2bImages(targetMaps = {}, orderIds = [], warehouseId = 0) {
|
||||||
|
const fileReferenceModel = this.ctx.model && this.ctx.model.FileReference;
|
||||||
|
const prepImageMap = targetMaps && targetMaps.prepImageMap;
|
||||||
|
const pickupImageMap = targetMaps && targetMaps.pickupImageMap;
|
||||||
|
if ((!prepImageMap && !pickupImageMap) || !fileReferenceModel
|
||||||
|
|| typeof fileReferenceModel.findAll !== 'function') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const imageRefs = await fileReferenceModel.findAll({
|
||||||
|
where: {
|
||||||
|
business_type: {
|
||||||
|
[this.app.Sequelize.Op.in]: [ FILE_BUSINESS_TYPE.B2B_ORDER, FILE_BUSINESS_TYPE.B2B_PICKUP ],
|
||||||
|
},
|
||||||
|
business_id: { [this.app.Sequelize.Op.in]: orderIds.map(String) },
|
||||||
|
warehouse_id: warehouseId,
|
||||||
|
},
|
||||||
|
include: [{
|
||||||
|
model: this.ctx.model.File,
|
||||||
|
as: 'file',
|
||||||
|
attributes: [ 'file_url' ],
|
||||||
|
required: false,
|
||||||
|
}],
|
||||||
|
order: [[ 'display_order', 'ASC' ], [ 'id', 'ASC' ]],
|
||||||
|
raw: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
for (const ref of (Array.isArray(imageRefs) ? imageRefs : [])) {
|
||||||
|
const businessType = String(ref && ref.business_type || '').trim();
|
||||||
|
const targetMap = businessType === FILE_BUSINESS_TYPE.B2B_PICKUP
|
||||||
|
? pickupImageMap
|
||||||
|
: businessType === FILE_BUSINESS_TYPE.B2B_ORDER
|
||||||
|
? prepImageMap
|
||||||
|
: null;
|
||||||
|
if (!targetMap) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const orderId = Number(ref && ref.business_id || 0);
|
||||||
|
const fileId = Number(ref && ref.file_id || 0);
|
||||||
|
if (!Number.isInteger(orderId) || orderId <= 0 || !Number.isInteger(fileId) || fileId <= 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!targetMap.has(orderId)) {
|
||||||
|
targetMap.set(orderId, []);
|
||||||
|
}
|
||||||
|
const url = String(ref['file.file_url'] || '').trim();
|
||||||
|
targetMap.get(orderId).push({
|
||||||
|
file_id: fileId,
|
||||||
|
url: url || null,
|
||||||
|
display_order: Number(ref.display_order || 0),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
if (this.ctx.logger && typeof this.ctx.logger.warn === 'function') {
|
||||||
|
this.ctx.logger.warn('[attachB2bImages] 查询订单图片失败,列表输出空图片列表', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构造"加急优先"排序项(B2B 域列表专用)。
|
||||||
|
*
|
||||||
|
* 观察表为 wms_order_b2b(按 warehouse_id + order_id 唯一索引关联),
|
||||||
|
* 该行 is_urgent='Y' 时排在最前;无作业明细行时子查询为 NULL,排序落到最后。
|
||||||
|
*
|
||||||
|
* @param {Object} model 订单分表模型(用于取物理表名作为限定前缀)。
|
||||||
|
* @param {number|string} warehouseId 仓库ID。
|
||||||
|
* @return {Array} Sequelize order 单项 [literal, 'DESC']。
|
||||||
|
*/
|
||||||
|
buildB2bUrgentFirstOrder(model, warehouseId) {
|
||||||
|
const { Sequelize } = this.app;
|
||||||
|
const tableName = String(
|
||||||
|
(model && (model.tableName || (typeof model.getTableName === 'function' ? model.getTableName() : ''))) || ''
|
||||||
|
).trim();
|
||||||
|
const normalizedWarehouseId = Number(warehouseId || 0);
|
||||||
|
|
||||||
|
if (!tableName || !Number.isInteger(normalizedWarehouseId) || normalizedWarehouseId <= 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const orderIdColumn = `\`${tableName}\`.\`id\``;
|
||||||
|
|
||||||
|
return [
|
||||||
|
Sequelize.literal(
|
||||||
|
`(SELECT b2b.is_urgent FROM wms_order_b2b b2b WHERE b2b.warehouse_id = ${normalizedWarehouseId} AND b2b.order_id = ${orderIdColumn} LIMIT 1) = 'Y'`
|
||||||
|
),
|
||||||
|
'DESC',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构造"排除 B2B 订单"条件(is_b2b 为 NULL 的存量行视为非 B2B)。
|
* 构造"排除 B2B 订单"条件(is_b2b 为 NULL 的存量行视为非 B2B)。
|
||||||
* @return {Object} Sequelize 条件。
|
* @return {Object} Sequelize 条件。
|
||||||
@ -2180,6 +2398,42 @@ class OrderBaseService extends MainService {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断订单行是否为 B2B 订单(is_b2b='Y';NULL 存量行视为非 B2B)。
|
||||||
|
*
|
||||||
|
* @param {Object} row 订单行。
|
||||||
|
* @return {boolean} 是否 B2B 订单。
|
||||||
|
*/
|
||||||
|
isB2bOrderRow(row = {}) {
|
||||||
|
return String(row && row.is_b2b || '').trim() === 'Y';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 校验订单集合中不含 B2B 订单,命中即整批驳回。
|
||||||
|
*
|
||||||
|
* B2B 订单走备货/提货独立作业链路,不参与反审回待审核、波次抓取、批量发货、克隆等常规流程,
|
||||||
|
* 命中任意 B2B 订单时直接抛出业务异常(不做部分处理),由调用方整批返回不生效提示。
|
||||||
|
*
|
||||||
|
* @param {Array<Object>} rows 订单行集合(需包含 id、is_b2b 字段)。
|
||||||
|
* @param {string} actionName 操作名称,用于提示文案,如「反审回待审核」。
|
||||||
|
* @return {void} 无返回值;命中 B2B 订单时抛错。
|
||||||
|
*/
|
||||||
|
assertOrdersNotB2b(rows = [], actionName = '该操作') {
|
||||||
|
const b2bOrderIds = [ ...new Set((Array.isArray(rows) ? rows : [])
|
||||||
|
.filter(row => this.isB2bOrderRow(row))
|
||||||
|
.map(row => Number(row && row.id || 0))
|
||||||
|
.filter(orderId => Number.isInteger(orderId) && orderId > 0)) ]
|
||||||
|
.sort((a, b) => a - b);
|
||||||
|
|
||||||
|
if (b2bOrderIds.length === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const displayOrderIds = b2bOrderIds.slice(0, 10).join(',');
|
||||||
|
const suffix = b2bOrderIds.length > 10 ? ` 等 ${b2bOrderIds.length} 单` : '';
|
||||||
|
throw new Error(`B2B 订单不支持${actionName}(订单[${displayOrderIds}]${suffix}),操作不生效`);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 从 where 中提取 B2B 作业明细筛选条件(仅 B2B 域列表使用)。
|
* 从 where 中提取 B2B 作业明细筛选条件(仅 B2B 域列表使用)。
|
||||||
*
|
*
|
||||||
@ -2335,12 +2589,18 @@ class OrderBaseService extends MainService {
|
|||||||
? [ ...new Set(expresses.map(expr => String(expr && expr.waybill_code || '').trim()).filter(Boolean)) ]
|
? [ ...new Set(expresses.map(expr => String(expr && expr.waybill_code || '').trim()).filter(Boolean)) ]
|
||||||
: [];
|
: [];
|
||||||
|
|
||||||
|
// B2B 订单附加副表作业明细(备货/提货/箱数/车牌)与备货/提货照片;非 B2B 订单 b2b=null、images=[]、pickup_images=[]
|
||||||
|
const { b2b, images, pickup_images: pickupImages } = await this.buildB2bDetailExtras(order, warehouseId);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
detail: order,
|
detail: order,
|
||||||
items: orderItemsWithStockInfo,
|
items: orderItemsWithStockInfo,
|
||||||
expresses,
|
expresses,
|
||||||
waybill_codes: waybillCodes,
|
waybill_codes: waybillCodes,
|
||||||
logs,
|
logs,
|
||||||
|
b2b,
|
||||||
|
images,
|
||||||
|
pickup_images: pickupImages,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -36,6 +36,7 @@ class DeliveryOrder2bService extends OrderBaseService {
|
|||||||
const result = await this.listByModule('deliveryOrder', data, {
|
const result = await this.listByModule('deliveryOrder', data, {
|
||||||
fixedWhere: B2B_FIXED_WHERE,
|
fixedWhere: B2B_FIXED_WHERE,
|
||||||
b2bDetailFilter: true,
|
b2bDetailFilter: true,
|
||||||
|
urgentFirst: true,
|
||||||
});
|
});
|
||||||
return {
|
return {
|
||||||
...result,
|
...result,
|
||||||
|
|||||||
@ -13,9 +13,9 @@ class OrderIndexService extends OrderBaseService {
|
|||||||
constructor(ctx) {
|
constructor(ctx) {
|
||||||
super(ctx);
|
super(ctx);
|
||||||
const _noNeedLogin = '';
|
const _noNeedLogin = '';
|
||||||
const _noNeedRight = 'list,badgeCount,manualOutboundOrder,queryOrderLogs,queryOrderLogList,detail,updateExpressWeighingWeight,export,exportTaskProgress,bindExpressPackageMaterialByWaybill,convertToB2b,cancelB2b';
|
const _noNeedRight = 'list,badgeCount,manualOutboundOrder,queryOrderLogs,queryOrderLogList,detail,updateExpressWeighingWeight,export,exportTaskProgress,bindExpressPackageMaterialByWaybill,convertToB2b,cancelB2b,setB2bUrgent,cancelB2bUrgent,startB2bPrep,cancelB2bPrep,finishB2bPrep,updateB2bPackingItems,getB2bPackingSnapshot,setB2bPickupPlate,pickupB2b,updateB2bOrderImages';
|
||||||
const _noNeedLog = 'list,badgeCount,manualOutboundOrder,queryOrderLogs,queryOrderLogList,detail,updateExpressWeighingWeight,export,exportTaskProgress,bindExpressPackageMaterialByWaybill,convertToB2b,cancelB2b';
|
const _noNeedLog = 'list,badgeCount,manualOutboundOrder,queryOrderLogs,queryOrderLogList,detail,updateExpressWeighingWeight,export,exportTaskProgress,bindExpressPackageMaterialByWaybill,convertToB2b,cancelB2b,setB2bUrgent,cancelB2bUrgent,startB2bPrep,cancelB2bPrep,finishB2bPrep,updateB2bPackingItems,getB2bPackingSnapshot,setB2bPickupPlate,pickupB2b,updateB2bOrderImages';
|
||||||
const _noNeedAuth = 'list,badgeCount,manualOutboundOrder,queryOrderLogs,queryOrderLogList,detail,updateExpressWeighingWeight,export,exportTaskProgress,bindExpressPackageMaterialByWaybill,convertToB2b,cancelB2b';
|
const _noNeedAuth = 'list,badgeCount,manualOutboundOrder,queryOrderLogs,queryOrderLogList,detail,updateExpressWeighingWeight,export,exportTaskProgress,bindExpressPackageMaterialByWaybill,convertToB2b,cancelB2b,setB2bUrgent,cancelB2bUrgent,startB2bPrep,cancelB2bPrep,finishB2bPrep,updateB2bPackingItems,getB2bPackingSnapshot,setB2bPickupPlate,pickupB2b,updateB2bOrderImages';
|
||||||
this.systemInit(_noNeedLogin, _noNeedRight, _noNeedLog, _noNeedAuth);
|
this.systemInit(_noNeedLogin, _noNeedRight, _noNeedLog, _noNeedAuth);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,6 +115,396 @@ class OrderIndexService extends OrderBaseService {
|
|||||||
return this.success('ok', result);
|
return this.success('ok', result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 取消 B2B 订单加急(仅对 B2B 订单生效)。
|
||||||
|
*
|
||||||
|
* 等价于 order.setB2bUrgent 传 is_urgent='N',入参 is_urgent 被强制覆盖为 N,
|
||||||
|
* 避免调用方误传导致加急未被取消。校验与跳过口径同 setB2bUrgent:
|
||||||
|
* 非 B2B 订单、已取消订单跳过并在 skipped_reasons 返回原因。
|
||||||
|
*
|
||||||
|
* @param {Object} data 请求体。
|
||||||
|
* @param {Array<number|string>|number|string} [data.ids] 订单ID集合(优先)。
|
||||||
|
* @param {Array<number|string>|number|string} [data.order_ids] 订单ID集合别名。
|
||||||
|
* @param {Array<number|string>|number|string} [data.orderIds] 订单ID集合别名。
|
||||||
|
* @param {number|string} [data.id] 订单ID单值别名。
|
||||||
|
* @return {Promise<Object>} 统一成功包装响应(data.is_urgent 恒为 'N')。
|
||||||
|
*/
|
||||||
|
async cancelB2bUrgent(data = {}) {
|
||||||
|
const requestData = this.isPlainObject(data) ? data : {};
|
||||||
|
|
||||||
|
return await this.setB2bUrgent({
|
||||||
|
...requestData,
|
||||||
|
is_urgent: 'N',
|
||||||
|
isUrgent: 'N',
|
||||||
|
urgent: 'N',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置 B2B 订单是否加急(仅对 B2B 订单生效)。
|
||||||
|
*
|
||||||
|
* 非 B2B 订单跳过并在 skipped_reasons 返回原因;已取消订单同样跳过。
|
||||||
|
* 订单在 current 分表查找,未命中兜底到 dispatch 分表;事务内更新
|
||||||
|
* wms_order_b2b.is_urgent,提交后写操作日志。
|
||||||
|
*
|
||||||
|
* @param {Object} data 请求体。
|
||||||
|
* @param {Array<number|string>|number|string} [data.ids] 订单ID集合(优先)。
|
||||||
|
* @param {Array<number|string>|number|string} [data.order_ids] 订单ID集合别名。
|
||||||
|
* @param {Array<number|string>|number|string} [data.orderIds] 订单ID集合别名。
|
||||||
|
* @param {number|string} [data.id] 订单ID单值别名。
|
||||||
|
* @param {string|boolean|number} [data.is_urgent='Y'] 是否加急(兼容 is_urgent/isUrgent/urgent,支持 Y/N、true/false、1/0)。
|
||||||
|
* @return {Promise<Object>} 统一成功包装响应(data 含 updated/skipped/not_found 分流结果)。
|
||||||
|
*/
|
||||||
|
async setB2bUrgent(data = {}) {
|
||||||
|
const requestData = this.isPlainObject(data) ? data : {};
|
||||||
|
const rawIds = requestData.ids !== undefined ? requestData.ids
|
||||||
|
: requestData.order_ids !== undefined ? requestData.order_ids
|
||||||
|
: requestData.orderIds !== undefined ? requestData.orderIds
|
||||||
|
: requestData.id !== undefined ? requestData.id
|
||||||
|
: requestData.order_id !== undefined ? requestData.order_id
|
||||||
|
: requestData.orderId;
|
||||||
|
const orderIds = [ ...new Set(
|
||||||
|
(Array.isArray(rawIds) ? rawIds : [ rawIds ])
|
||||||
|
.map(item => Number(item))
|
||||||
|
.filter(item => Number.isInteger(item) && item > 0)
|
||||||
|
) ];
|
||||||
|
if (orderIds.length === 0) {
|
||||||
|
return this.fail('订单ID不能为空', {}, 400);
|
||||||
|
}
|
||||||
|
if (orderIds.length > 200) {
|
||||||
|
return this.fail('单次最多设置 200 个订单', {}, 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
const isUrgent = requestData.is_urgent !== undefined ? requestData.is_urgent
|
||||||
|
: requestData.isUrgent !== undefined ? requestData.isUrgent
|
||||||
|
: requestData.urgent;
|
||||||
|
const warehouseId = this.getWarehouseId();
|
||||||
|
const operator = this.getOrderLogOperator();
|
||||||
|
|
||||||
|
let result;
|
||||||
|
try {
|
||||||
|
result = await this.service.systems.orderB2b.setOrdersB2bUrgent({
|
||||||
|
warehouseId,
|
||||||
|
orderIds,
|
||||||
|
isUrgent,
|
||||||
|
operator,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
if (error && /is_urgent 参数不合法/.test(error.message)) {
|
||||||
|
return this.fail(error.message, {}, 400);
|
||||||
|
}
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.success('ok', result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 备货开始(仅 B2B 订单,单订单作业):记录备货人工号与开始时间。
|
||||||
|
*
|
||||||
|
* 操作人为当前登录工号(ctx.user);同工号重复开始幂等成功,
|
||||||
|
* 订单已由其他工号开始或已完成时返回失败。ids 仅允许传 1 个订单ID。
|
||||||
|
* 作业前置条件:已打印(print_status=fin)、已分配储位(storage_status=fin)且未拦截
|
||||||
|
* (intercept_status=none),不满足返回 failure 400 且不写入任何备货数据;
|
||||||
|
* 领料(claim_status)不校验——领料只在波次整波领单流程产生,B2B 订单无波次。
|
||||||
|
*
|
||||||
|
* @param {Object} data 请求体。
|
||||||
|
* @param {Array<number|string>|number|string} [data.ids] 订单ID集合(优先)。
|
||||||
|
* @param {Array<number|string>|number|string} [data.order_ids] 订单ID集合别名。
|
||||||
|
* @return {Promise<Object>} 统一响应。
|
||||||
|
*/
|
||||||
|
async startB2bPrep(data = {}) {
|
||||||
|
return await this.runB2bSingleOrderAction(
|
||||||
|
data,
|
||||||
|
'startOrdersB2bPrep',
|
||||||
|
d => ({ warehouseId: this.getWarehouseId(), orderIds: this.normalizeB2bPrepOrderIds(d), operator: this.getOrderLogOperator() }),
|
||||||
|
'备货作业'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 取消备货(仅 B2B 订单,单订单作业):重置备货人、开始时间与备货状态。
|
||||||
|
*
|
||||||
|
* 仅备货中的订单可取消,且必须由记录在案的同一工号操作,否则返回失败。ids 仅允许传 1 个订单ID。
|
||||||
|
*
|
||||||
|
* @param {Object} data 请求体(入参同 startB2bPrep)。
|
||||||
|
* @return {Promise<Object>} 统一响应。
|
||||||
|
*/
|
||||||
|
async cancelB2bPrep(data = {}) {
|
||||||
|
return await this.runB2bSingleOrderAction(
|
||||||
|
data,
|
||||||
|
'cancelOrdersB2bPrep',
|
||||||
|
d => ({ warehouseId: this.getWarehouseId(), orderIds: this.normalizeB2bPrepOrderIds(d), operator: this.getOrderLogOperator() }),
|
||||||
|
'备货作业'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 备货结束(仅 B2B 订单,单订单作业):写入备货备注、总箱数、完成时间与备货用时。
|
||||||
|
*
|
||||||
|
* 结束时间取提交时刻;仅备货中的订单可结束,且必须由同一工号提交,否则返回失败。ids 仅允许传 1 个订单ID。
|
||||||
|
*
|
||||||
|
* @param {Object} data 请求体。
|
||||||
|
* @param {Array<number|string>|number|string} [data.ids] 订单ID集合(优先)。
|
||||||
|
* @param {string} data.prep_remark 备货备注(必填,兼容 prepRemark)。
|
||||||
|
* @param {number|string} data.total_box_count 总箱数(必填,兼容 totalBoxCount)。
|
||||||
|
* @return {Promise<Object>} 统一响应。
|
||||||
|
*/
|
||||||
|
async finishB2bPrep(data = {}) {
|
||||||
|
return await this.runB2bSingleOrderAction(
|
||||||
|
data,
|
||||||
|
'finishOrdersB2bPrep',
|
||||||
|
d => ({
|
||||||
|
warehouseId: this.getWarehouseId(),
|
||||||
|
orderIds: this.normalizeB2bPrepOrderIds(d),
|
||||||
|
operator: this.getOrderLogOperator(),
|
||||||
|
prepRemark: d.prep_remark !== undefined ? d.prep_remark : d.prepRemark,
|
||||||
|
totalBoxCount: d.total_box_count !== undefined ? d.total_box_count : d.totalBoxCount,
|
||||||
|
}),
|
||||||
|
'备货作业'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 全量更新单个 B2B 订单的商品分箱明细。
|
||||||
|
* @param {Object} data 请求体。
|
||||||
|
* @param {Array<Object>} data.items 分箱行:order_item_id、box_no、quantity。
|
||||||
|
* @return {Promise<Object>} 更新结果。
|
||||||
|
*/
|
||||||
|
async updateB2bPackingItems(data = {}) {
|
||||||
|
return await this.runB2bSingleOrderAction(
|
||||||
|
data,
|
||||||
|
'updateB2bPackingItems',
|
||||||
|
d => ({
|
||||||
|
warehouseId: this.getWarehouseId(),
|
||||||
|
orderIds: this.normalizeB2bPrepOrderIds(d),
|
||||||
|
operator: this.getOrderLogOperator(),
|
||||||
|
items: d.items,
|
||||||
|
}),
|
||||||
|
'更新分箱明细'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取单个 B2B 订单商品与分箱记录的完整快照。
|
||||||
|
* @param {Object} data 请求体。
|
||||||
|
* @return {Promise<Object>} 订单快照。
|
||||||
|
*/
|
||||||
|
async getB2bPackingSnapshot(data = {}) {
|
||||||
|
return await this.runB2bSingleOrderAction(
|
||||||
|
data,
|
||||||
|
'getB2bPackingSnapshot',
|
||||||
|
d => ({
|
||||||
|
warehouseId: this.getWarehouseId(),
|
||||||
|
orderIds: this.normalizeB2bPrepOrderIds(d),
|
||||||
|
}),
|
||||||
|
'查询分箱快照'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 录入/修改 B2B 提货车牌(单订单,提货前可改)。
|
||||||
|
*
|
||||||
|
* 仅 B2B 订单且未取消的订单可录入;订单已提货(is_picked_up='Y')后车牌锁定,
|
||||||
|
* 不允许再修改。作业明细行缺失时自动补建。传空字符串或 null 表示清空车牌;
|
||||||
|
* 车牌会去掉空格与分隔符并转大写后落库。ids 仅允许传 1 个订单ID。
|
||||||
|
*
|
||||||
|
* @param {Object} data 请求体。
|
||||||
|
* @param {number|string} [data.ids] 订单ID(单值或单元素数组)。
|
||||||
|
* @param {string|null} data.pickup_plate_number 提货车牌(必传键;兼容 pickupPlateNumber,空串/null 清空)。
|
||||||
|
* @return {Promise<Object>} 统一响应。
|
||||||
|
*/
|
||||||
|
async setB2bPickupPlate(data = {}) {
|
||||||
|
return await this.runB2bSingleOrderAction(
|
||||||
|
data,
|
||||||
|
'setOrdersB2bPickupPlate',
|
||||||
|
d => ({
|
||||||
|
warehouseId: this.getWarehouseId(),
|
||||||
|
orderIds: this.normalizeB2bPrepOrderIds(d),
|
||||||
|
operator: this.getOrderLogOperator(),
|
||||||
|
pickupPlateNumber: d.pickup_plate_number !== undefined ? d.pickup_plate_number : d.pickupPlateNumber,
|
||||||
|
}),
|
||||||
|
'录入提货车牌'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* B2B 提货(单订单作业):记录提货时间。仅 B2B 订单生效。
|
||||||
|
*
|
||||||
|
* 要求备货已完成(prep_status=fin);已提货订单幂等成功(保留首次提货时间)。
|
||||||
|
* 可选传 pickup_plate_number 在提货同时写入车牌(提货后不允许再改);
|
||||||
|
* 可选传 file_ids(标准字段,兼容 pickup_file_ids / pickupFileIds / pickup_images / pickupImages)
|
||||||
|
* 在提货同时写入提货照片,照片只做一轮存在性校验后追加到 business_type='b2b_pickup' 的关联下。
|
||||||
|
* ids 仅允许传 1 个订单ID。
|
||||||
|
*
|
||||||
|
* @param {Object} data 请求体。
|
||||||
|
* @param {number|string} [data.ids] 订单ID(单值或单元素数组)。
|
||||||
|
* @param {string|null} [data.pickup_plate_number] 提货车牌(可选,兼容 pickupPlateNumber)。
|
||||||
|
* @param {Array<Object|number|string>} [data.file_ids] 提货照片列表(标准字段,
|
||||||
|
* 元素为 file_id 或 { file_id, display_order })。
|
||||||
|
* @return {Promise<Object>} 统一响应。
|
||||||
|
*/
|
||||||
|
async pickupB2b(data = {}) {
|
||||||
|
return await this.runB2bSingleOrderAction(
|
||||||
|
data,
|
||||||
|
'pickupOrdersB2b',
|
||||||
|
d => ({
|
||||||
|
warehouseId: this.getWarehouseId(),
|
||||||
|
orderIds: this.normalizeB2bPrepOrderIds(d),
|
||||||
|
operator: this.getOrderLogOperator(),
|
||||||
|
pickupPlateNumber: d.pickup_plate_number !== undefined ? d.pickup_plate_number : d.pickupPlateNumber,
|
||||||
|
pickupImages: this.resolveB2bPickupImageInput(d),
|
||||||
|
}),
|
||||||
|
'提货'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解析 B2B 图片入参(统一标准字段 file_ids,兼容各别名)。
|
||||||
|
*
|
||||||
|
* 标准写法:file_ids,元素为 file_id(数字/数字字符串)或 { file_id, display_order }。
|
||||||
|
* 别名按传入顺序作为后备:同时传标准字段与别名时以 file_ids/fileIds 为准。
|
||||||
|
*
|
||||||
|
* @param {Object} data 请求体。
|
||||||
|
* @param {string[]} [aliasKeys=[]] 该场景额外接受的别名字段。
|
||||||
|
* @return {*} 原始图片入参(未传时返回 undefined)。
|
||||||
|
*/
|
||||||
|
resolveB2bFileIdsInput(data = {}, aliasKeys = []) {
|
||||||
|
const keys = [ 'file_ids', 'fileIds', ...aliasKeys ];
|
||||||
|
for (const key of keys) {
|
||||||
|
if (data[key] !== undefined) {
|
||||||
|
return data[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解析提货时随车提交的照片入参(标准 file_ids)。
|
||||||
|
*
|
||||||
|
* 兼容别名:pickup_file_ids / pickupFileIds / pickup_images / pickupImages。
|
||||||
|
*
|
||||||
|
* @param {Object} data 请求体。
|
||||||
|
* @return {Array|undefined} 图片列表;未传时返回 undefined(表示本次不附带提货照片)。
|
||||||
|
*/
|
||||||
|
resolveB2bPickupImageInput(data = {}) {
|
||||||
|
return this.resolveB2bFileIdsInput(data, [ 'pickup_file_ids', 'pickupFileIds', 'pickup_images', 'pickupImages' ]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解析备货照片入参(标准 file_ids)。
|
||||||
|
*
|
||||||
|
* 兼容别名:images(历史写法,语义等价于 file_ids)。
|
||||||
|
*
|
||||||
|
* @param {Object} data 请求体。
|
||||||
|
* @return {*} 原始图片入参(未传时返回 undefined,由业务层判定为非法)。
|
||||||
|
*/
|
||||||
|
resolveB2bImageListInput(data = {}) {
|
||||||
|
return this.resolveB2bFileIdsInput(data, [ 'images' ]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新 B2B 订单图片(单订单,全量覆盖)。
|
||||||
|
*
|
||||||
|
* 图片关系统一落在 wms_file_reference:business_type='b2b_order'、
|
||||||
|
* business_id=订单ID、warehouse_id=当前仓库、display_order 控制展示顺序。
|
||||||
|
* 标准入参为 file_ids(元素 file_id 或 { file_id, display_order }),
|
||||||
|
* 兼容别名 images / fileIds;全量覆盖语义:未包含的旧关联会被删除,
|
||||||
|
* 新关联按列表顺序写入;传空数组表示清空该订单图片。
|
||||||
|
* 仅 B2B 订单(is_b2b='Y')且未取消的订单可更新。
|
||||||
|
*
|
||||||
|
* @param {Object} data 请求体。
|
||||||
|
* @param {number|string} [data.id] 订单ID(单值或单元素数组)。
|
||||||
|
* @param {Array<Object|number|string>} data.file_ids 图片列表(标准字段),元素可为
|
||||||
|
* { file_id, display_order } 或直接传 file_id;兼容 images / fileIds 简写。
|
||||||
|
* @return {Promise<Object>} 统一响应。
|
||||||
|
*/
|
||||||
|
async updateB2bOrderImages(data = {}) {
|
||||||
|
const requestData = this.isPlainObject(data) ? data : {};
|
||||||
|
const orderIds = this.normalizeB2bPrepOrderIds(requestData);
|
||||||
|
|
||||||
|
if (orderIds.length === 0) {
|
||||||
|
return this.fail('订单ID不能为空', {}, 400);
|
||||||
|
}
|
||||||
|
if (orderIds.length > 1) {
|
||||||
|
return this.fail('更新订单图片仅支持单个订单,请单条提交', { order_ids: orderIds }, 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
const rawImages = this.resolveB2bImageListInput(requestData);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const result = await this.service.systems.orderB2b.updateOrderImages({
|
||||||
|
warehouseId: this.getWarehouseId(),
|
||||||
|
orderIds,
|
||||||
|
images: rawImages,
|
||||||
|
operator: this.getOrderLogOperator(),
|
||||||
|
});
|
||||||
|
return this.success('ok', result);
|
||||||
|
} catch (error) {
|
||||||
|
const code = String(error && error.code || '');
|
||||||
|
if (code.startsWith('B2B_IMAGE_')) {
|
||||||
|
return this.fail(error.message, error.data || {}, 400);
|
||||||
|
}
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 归一化备货/提货单订单入参(6 种别名,单值或单元素数组)。
|
||||||
|
* @param {Object} requestData 请求体。
|
||||||
|
* @return {number[]} 订单ID数组。
|
||||||
|
*/
|
||||||
|
normalizeB2bPrepOrderIds(requestData = {}) {
|
||||||
|
const rawIds = requestData.ids !== undefined ? requestData.ids
|
||||||
|
: requestData.order_ids !== undefined ? requestData.order_ids
|
||||||
|
: requestData.orderIds !== undefined ? requestData.orderIds
|
||||||
|
: requestData.id !== undefined ? requestData.id
|
||||||
|
: requestData.order_id !== undefined ? requestData.order_id
|
||||||
|
: requestData.orderId;
|
||||||
|
return [ ...new Set(
|
||||||
|
(Array.isArray(rawIds) ? rawIds : [ rawIds ])
|
||||||
|
.map(item => Number(item))
|
||||||
|
.filter(item => Number.isInteger(item) && item > 0)
|
||||||
|
) ];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* B2B 单订单作业统一执行壳:入参校验 → 调业务层 → 统一成功/失败包装。
|
||||||
|
*
|
||||||
|
* 业务层抛出的备货/提货/车牌/图片校验错误(带 code/data,
|
||||||
|
* 前缀 B2B_PREP_ / B2B_PICKUP_ / B2B_PLATE_ / B2B_IMAGE_)统一转 failure 400,
|
||||||
|
* 便于前端展示原因;其它异常继续抛出(由控制器转 500)。
|
||||||
|
*
|
||||||
|
* @param {Object} data 请求体。
|
||||||
|
* @param {string} serviceMethod 业务方法名。
|
||||||
|
* @param {Function} buildParams 参数构造器。
|
||||||
|
* @param {string} [actionText='备货作业'] 动作文案(用于批量拒绝提示)。
|
||||||
|
* @return {Promise<Object>} 统一响应。
|
||||||
|
*/
|
||||||
|
async runB2bSingleOrderAction(data = {}, serviceMethod, buildParams, actionText = '备货作业') {
|
||||||
|
const requestData = this.isPlainObject(data) ? data : {};
|
||||||
|
const params = buildParams(requestData);
|
||||||
|
|
||||||
|
if (params.orderIds.length === 0) {
|
||||||
|
return this.fail('订单ID不能为空', {}, 400);
|
||||||
|
}
|
||||||
|
if (params.orderIds.length > 1) {
|
||||||
|
return this.fail(`${actionText}仅支持单个订单,请单条提交`, { order_ids: params.orderIds }, 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const result = await this.service.systems.orderB2b[serviceMethod](params);
|
||||||
|
return this.success('ok', result);
|
||||||
|
} catch (error) {
|
||||||
|
const code = String(error && error.code || '');
|
||||||
|
if (code.startsWith('B2B_PREP_') || code.startsWith('B2B_PACKING_') || code.startsWith('B2B_PICKUP_')
|
||||||
|
|| code.startsWith('B2B_PLATE_') || code.startsWith('B2B_IMAGE_')) {
|
||||||
|
return this.fail(error.message, error.data || {}, 400);
|
||||||
|
}
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 提交订单导出任务。
|
* 提交订单导出任务。
|
||||||
*
|
*
|
||||||
|
|||||||
@ -1012,11 +1012,17 @@ class PendingOrderService extends OrderBaseService {
|
|||||||
|
|
||||||
const expresses = await this.getOrderExpressesByOrderId(orderId, order);
|
const expresses = await this.getOrderExpressesByOrderId(orderId, order);
|
||||||
|
|
||||||
|
// B2B 订单附加副表作业明细(备货/提货/箱数/车牌)与备货/提货照片;非 B2B 订单 b2b=null、images=[]、pickup_images=[]
|
||||||
|
const { b2b, images, pickup_images: pickupImages } = await this.buildB2bDetailExtras(order, warehouseId);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
detail: order,
|
detail: order,
|
||||||
items: orderItemsWithPicking,
|
items: orderItemsWithPicking,
|
||||||
expresses,
|
expresses,
|
||||||
storage_items: storageItems,
|
storage_items: storageItems,
|
||||||
|
b2b,
|
||||||
|
images,
|
||||||
|
pickup_images: pickupImages,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1044,7 +1050,7 @@ class PendingOrderService extends OrderBaseService {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const targetOrders = await model.findAll({
|
const targetOrders = await model.findAll({
|
||||||
attributes: [ 'id', 'wave_id', 'wave_no' ],
|
attributes: [ 'id', 'wave_id', 'wave_no', 'is_b2b' ],
|
||||||
where,
|
where,
|
||||||
raw: true,
|
raw: true,
|
||||||
...dbQueryOptions,
|
...dbQueryOptions,
|
||||||
@ -1054,6 +1060,9 @@ class PendingOrderService extends OrderBaseService {
|
|||||||
throw new Error('订单不存在或不属于当前仓库');
|
throw new Error('订单不存在或不属于当前仓库');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// B2B 订单走备货/提货作业链路,不支持反审回待审核:命中即整批驳回
|
||||||
|
this.assertOrdersNotB2b(targetOrders, '反审回待审核');
|
||||||
|
|
||||||
const targetOrderIds = targetOrders
|
const targetOrderIds = targetOrders
|
||||||
.map(order => Number(order && order.id || 0))
|
.map(order => Number(order && order.id || 0))
|
||||||
.filter(id => Number.isInteger(id) && id > 0);
|
.filter(id => Number.isInteger(id) && id > 0);
|
||||||
@ -3754,6 +3763,9 @@ class PendingOrderService extends OrderBaseService {
|
|||||||
}
|
}
|
||||||
const original = existingOrders[0];
|
const original = existingOrders[0];
|
||||||
|
|
||||||
|
// B2B 订单走备货/提货作业链路,不支持克隆(克隆会取消原单并重建普通订单)
|
||||||
|
this.assertOrdersNotB2b([ original ], '克隆订单');
|
||||||
|
|
||||||
if (!this.isCancelablePendingOrder(original)) {
|
if (!this.isCancelablePendingOrder(original)) {
|
||||||
throw new Error('订单当前状态不允许克隆');
|
throw new Error('订单当前状态不允许克隆');
|
||||||
}
|
}
|
||||||
|
|||||||
@ -36,6 +36,7 @@ class PendingOrder2bService extends OrderBaseService {
|
|||||||
const result = await this.listByModule('pendingOrder', data, {
|
const result = await this.listByModule('pendingOrder', data, {
|
||||||
fixedWhere: B2B_FIXED_WHERE,
|
fixedWhere: B2B_FIXED_WHERE,
|
||||||
b2bDetailFilter: true,
|
b2bDetailFilter: true,
|
||||||
|
urgentFirst: true,
|
||||||
});
|
});
|
||||||
return {
|
return {
|
||||||
...result,
|
...result,
|
||||||
|
|||||||
@ -4394,7 +4394,7 @@ class RecheckOrderService extends OrderBaseService {
|
|||||||
attributes: [
|
attributes: [
|
||||||
'id', 'delivery_order_code', 'pre_delivery_order_code',
|
'id', 'delivery_order_code', 'pre_delivery_order_code',
|
||||||
'storage_status', 'post_status', 'sync_status', 'status', 'intercept_status',
|
'storage_status', 'post_status', 'sync_status', 'status', 'intercept_status',
|
||||||
'pick_status', 'recheck_status', 'wave_id', 'wave_no', 'has_sn_item',
|
'pick_status', 'recheck_status', 'wave_id', 'wave_no', 'has_sn_item', 'is_b2b',
|
||||||
],
|
],
|
||||||
raw: true,
|
raw: true,
|
||||||
});
|
});
|
||||||
@ -4404,6 +4404,9 @@ class RecheckOrderService extends OrderBaseService {
|
|||||||
orderMap.set(Number(row.id), row);
|
orderMap.set(Number(row.id), row);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// B2B 订单走备货/提货作业链路,不参与批量发货(快捷复核):命中即整批驳回
|
||||||
|
this.assertOrdersNotB2b(orderRows, '批量发货');
|
||||||
|
|
||||||
// ── 2. 前置条件检查:将订单分为有效订单与跳过订单 ──
|
// ── 2. 前置条件检查:将订单分为有效订单与跳过订单 ──
|
||||||
const validOrders = [];
|
const validOrders = [];
|
||||||
const failedOrders = [];
|
const failedOrders = [];
|
||||||
@ -4572,11 +4575,14 @@ class RecheckOrderService extends OrderBaseService {
|
|||||||
attributes: [
|
attributes: [
|
||||||
'id', 'delivery_order_code', 'pre_delivery_order_code',
|
'id', 'delivery_order_code', 'pre_delivery_order_code',
|
||||||
'storage_status', 'post_status', 'sync_status', 'status', 'intercept_status',
|
'storage_status', 'post_status', 'sync_status', 'status', 'intercept_status',
|
||||||
'pick_status', 'recheck_status', 'wave_id', 'wave_no', 'has_sn_item',
|
'pick_status', 'recheck_status', 'wave_id', 'wave_no', 'has_sn_item', 'is_b2b',
|
||||||
],
|
],
|
||||||
raw: true,
|
raw: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 按波次批量发货同样对 B2B 订单无效:波次内命中 B2B 订单即整批驳回
|
||||||
|
this.assertOrdersNotB2b(orderRows, '批量发货');
|
||||||
|
|
||||||
// 按 wave_id 分组
|
// 按 wave_id 分组
|
||||||
const waveOrderMap = new Map();
|
const waveOrderMap = new Map();
|
||||||
for (const row of orderRows) {
|
for (const row of orderRows) {
|
||||||
|
|||||||
@ -8482,12 +8482,8 @@ class WaveService extends OrderBaseService {
|
|||||||
.map(row => Number(row && row.id || 0))
|
.map(row => Number(row && row.id || 0))
|
||||||
.filter(id => Number.isInteger(id) && id > 0)) ]
|
.filter(id => Number.isInteger(id) && id > 0)) ]
|
||||||
.sort((a, b) => a - b);
|
.sort((a, b) => a - b);
|
||||||
// B2B 订单不参与波次抓取(NULL 视为非 B2B,兼容存量行)
|
// B2B 订单走备货/提货作业链路,不参与波次抓取:命中即整批驳回(不做部分抓取)
|
||||||
const excludedB2bOrderIds = [ ...new Set(normalizedOrderRows
|
this.assertOrdersNotB2b(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);
|
|
||||||
// SN(序列号管理)订单允许按订单ID显式抓取散单:SN 策略只是「不自动出现在散单策略候选」,
|
// SN(序列号管理)订单允许按订单ID显式抓取散单:SN 策略只是「不自动出现在散单策略候选」,
|
||||||
// 手工按订单抓取时不受限(manual_ids 波次在拣货侧固定走先拣后分 pick_mode=3,与 SN 策略一致),
|
// 手工按订单抓取时不受限(manual_ids 波次在拣货侧固定走先拣后分 pick_mode=3,与 SN 策略一致),
|
||||||
// 因此这里不再排除 SN 订单,excluded_sn_order_ids 保留在响应中但恒为空数组。
|
// 因此这里不再排除 SN 订单,excluded_sn_order_ids 保留在响应中但恒为空数组。
|
||||||
@ -8515,11 +8511,6 @@ class WaveService extends OrderBaseService {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// B2B 订单不允许抓取波次
|
|
||||||
if (String(row && row.is_b2b || '').trim() === 'Y') {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -8541,7 +8532,6 @@ class WaveService extends OrderBaseService {
|
|||||||
excluded_existing_wave_order_ids: excludedExistingWaveOrderIds,
|
excluded_existing_wave_order_ids: excludedExistingWaveOrderIds,
|
||||||
excluded_intercepted_order_ids: excludedInterceptedOrderIds,
|
excluded_intercepted_order_ids: excludedInterceptedOrderIds,
|
||||||
excluded_locked_order_ids: excludedLockedOrderIds,
|
excluded_locked_order_ids: excludedLockedOrderIds,
|
||||||
excluded_b2b_order_ids: excludedB2bOrderIds,
|
|
||||||
excluded_sn_order_ids: excludedSnOrderIds,
|
excluded_sn_order_ids: excludedSnOrderIds,
|
||||||
skipped_order_ids: skippedOrderIds,
|
skipped_order_ids: skippedOrderIds,
|
||||||
not_found_order_ids: notFoundOrderIds,
|
not_found_order_ids: notFoundOrderIds,
|
||||||
@ -8662,7 +8652,6 @@ class WaveService extends OrderBaseService {
|
|||||||
excluded_existing_wave_order_ids: excludedExistingWaveOrderIds,
|
excluded_existing_wave_order_ids: excludedExistingWaveOrderIds,
|
||||||
excluded_intercepted_order_ids: excludedInterceptedOrderIds,
|
excluded_intercepted_order_ids: excludedInterceptedOrderIds,
|
||||||
excluded_locked_order_ids: excludedLockedOrderIds,
|
excluded_locked_order_ids: excludedLockedOrderIds,
|
||||||
excluded_b2b_order_ids: excludedB2bOrderIds,
|
|
||||||
excluded_sn_order_ids: excludedSnOrderIds,
|
excluded_sn_order_ids: excludedSnOrderIds,
|
||||||
skipped_order_ids: skippedOrderIds,
|
skipped_order_ids: skippedOrderIds,
|
||||||
not_found_order_ids: notFoundOrderIds,
|
not_found_order_ids: notFoundOrderIds,
|
||||||
|
|||||||
@ -278,6 +278,8 @@ class expressInterfaceService extends MainService {
|
|||||||
templateUrl: camelTemplateUrl,
|
templateUrl: camelTemplateUrl,
|
||||||
ext_data: extData,
|
ext_data: extData,
|
||||||
extData: camelExtData,
|
extData: camelExtData,
|
||||||
|
goods_description: goodsDescription,
|
||||||
|
goodsDescription: camelGoodsDescription,
|
||||||
template_id: templateId,
|
template_id: templateId,
|
||||||
templateId: camelTemplateId,
|
templateId: camelTemplateId,
|
||||||
paymode,
|
paymode,
|
||||||
@ -328,6 +330,9 @@ class expressInterfaceService extends MainService {
|
|||||||
if (extData !== undefined || camelExtData !== undefined) {
|
if (extData !== undefined || camelExtData !== undefined) {
|
||||||
payload.ext_data = extData !== undefined ? extData : camelExtData;
|
payload.ext_data = extData !== undefined ? extData : camelExtData;
|
||||||
}
|
}
|
||||||
|
if (goodsDescription !== undefined || camelGoodsDescription !== undefined) {
|
||||||
|
payload.goods_description = goodsDescription !== undefined ? goodsDescription : camelGoodsDescription;
|
||||||
|
}
|
||||||
if (templateId !== undefined || camelTemplateId !== undefined) {
|
if (templateId !== undefined || camelTemplateId !== undefined) {
|
||||||
payload.template_id = templateId !== undefined ? templateId : camelTemplateId;
|
payload.template_id = templateId !== undefined ? templateId : camelTemplateId;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2008,7 +2008,7 @@ class ExpressPlatformService extends MainService {
|
|||||||
name: item.item_name || '商品',
|
name: item.item_name || '商品',
|
||||||
count: item.plan_qty,
|
count: item.plan_qty,
|
||||||
})) || [],
|
})) || [],
|
||||||
goods_description: '化妆品',
|
goods_description: String(listByWarehousePlatformCode.goods_description || '').trim() || '化妆品',
|
||||||
id: `${orderDelivery.warehouse_id}_${orderDelivery.id}_${order_tmp.business_key}`,
|
id: `${orderDelivery.warehouse_id}_${orderDelivery.id}_${order_tmp.business_key}`,
|
||||||
length: Number(orderDelivery.length || 1),
|
length: Number(orderDelivery.length || 1),
|
||||||
width: Number(orderDelivery.width || 1),
|
width: Number(orderDelivery.width || 1),
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@ -762,6 +762,7 @@ class SettingExpressInterfaceService extends Service {
|
|||||||
town_name: this.normalizeOptionalText(row.town_name, 'town_name', 255),
|
town_name: this.normalizeOptionalText(row.town_name, 'town_name', 255),
|
||||||
site_code: this.normalizeOptionalText(row.site_code, 'site_code', 255),
|
site_code: this.normalizeOptionalText(row.site_code, 'site_code', 255),
|
||||||
product_type: this.normalizeOptionalText(row.product_type, 'product_type', 50),
|
product_type: this.normalizeOptionalText(row.product_type, 'product_type', 50),
|
||||||
|
goods_description: this.normalizeOptionalText(row.goods_description, 'goods_description', 255),
|
||||||
shop_name: this.normalizeOptionalText(
|
shop_name: this.normalizeOptionalText(
|
||||||
(row.shop && row.shop.shop_name) || row.shop_name,
|
(row.shop && row.shop.shop_name) || row.shop_name,
|
||||||
'shop_name',
|
'shop_name',
|
||||||
@ -1087,7 +1088,7 @@ class SettingExpressInterfaceService extends Service {
|
|||||||
'sys_express_code',
|
'sys_express_code',
|
||||||
'sender_name', 'sender_tel', 'weight', 'viewer', 'client_id', 'is_share',
|
'sender_name', 'sender_tel', 'weight', 'viewer', 'client_id', 'is_share',
|
||||||
'province_name', 'city_name', 'district_name', 'site_code',
|
'province_name', 'city_name', 'district_name', 'site_code',
|
||||||
'product_type', 'weight_type', 'shop_name', 'address', 'town_name', 'ispickup', 'shipperno', 'template_url', 'ext_data', 'is_enabled',
|
'product_type', 'goods_description', 'weight_type', 'shop_name', 'address', 'town_name', 'ispickup', 'shipperno', 'template_url', 'ext_data', 'is_enabled',
|
||||||
],
|
],
|
||||||
order: [[ 'weight', 'ASC' ], [ 'id', 'DESC' ]],
|
order: [[ 'weight', 'ASC' ], [ 'id', 'DESC' ]],
|
||||||
offset,
|
offset,
|
||||||
@ -1278,6 +1279,11 @@ class SettingExpressInterfaceService extends Service {
|
|||||||
town_name: this.normalizeOptionalText(data.town_name || data.townName, 'town_name', 255),
|
town_name: this.normalizeOptionalText(data.town_name || data.townName, 'town_name', 255),
|
||||||
site_code: this.normalizeOptionalText(data.site_code || data.siteCode, 'site_code', 255),
|
site_code: this.normalizeOptionalText(data.site_code || data.siteCode, 'site_code', 255),
|
||||||
product_type: this.normalizeOptionalText(data.product_type || data.productType, 'product_type', 50),
|
product_type: this.normalizeOptionalText(data.product_type || data.productType, 'product_type', 50),
|
||||||
|
goods_description: this.normalizeOptionalText(
|
||||||
|
data.goods_description !== undefined ? data.goods_description : data.goodsDescription,
|
||||||
|
'goods_description',
|
||||||
|
255
|
||||||
|
),
|
||||||
shop_name: this.normalizeOptionalText(data.shop_name || data.shopName, 'shop_name', 255),
|
shop_name: this.normalizeOptionalText(data.shop_name || data.shopName, 'shop_name', 255),
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1361,6 +1367,8 @@ class SettingExpressInterfaceService extends Service {
|
|||||||
|| Object.prototype.hasOwnProperty.call(data, 'siteCode');
|
|| Object.prototype.hasOwnProperty.call(data, 'siteCode');
|
||||||
const hasProductType = Object.prototype.hasOwnProperty.call(data, 'product_type')
|
const hasProductType = Object.prototype.hasOwnProperty.call(data, 'product_type')
|
||||||
|| Object.prototype.hasOwnProperty.call(data, 'productType');
|
|| Object.prototype.hasOwnProperty.call(data, 'productType');
|
||||||
|
const hasGoodsDescription = Object.prototype.hasOwnProperty.call(data, 'goods_description')
|
||||||
|
|| Object.prototype.hasOwnProperty.call(data, 'goodsDescription');
|
||||||
const hasShopName = Object.prototype.hasOwnProperty.call(data, 'shop_name')
|
const hasShopName = Object.prototype.hasOwnProperty.call(data, 'shop_name')
|
||||||
|| Object.prototype.hasOwnProperty.call(data, 'shopName');
|
|| Object.prototype.hasOwnProperty.call(data, 'shopName');
|
||||||
const hasExtData = Object.prototype.hasOwnProperty.call(data, 'ext_data')
|
const hasExtData = Object.prototype.hasOwnProperty.call(data, 'ext_data')
|
||||||
@ -1374,7 +1382,7 @@ class SettingExpressInterfaceService extends Service {
|
|||||||
&& !hasProviderType && !hasProviderId && !hasViewer && !hasClientId && !hasIsPickup
|
&& !hasProviderType && !hasProviderId && !hasViewer && !hasClientId && !hasIsPickup
|
||||||
&& !hasShipperNo && !hasTemplateUrl && !hasProvinceName && !hasCityName
|
&& !hasShipperNo && !hasTemplateUrl && !hasProvinceName && !hasCityName
|
||||||
&& !hasDistrictName && !hasAddress && !hasTownName && !hasSiteCode
|
&& !hasDistrictName && !hasAddress && !hasTownName && !hasSiteCode
|
||||||
&& !hasProductType && !hasShopName && !hasExtData && !hasIsEnabled) {
|
&& !hasProductType && !hasGoodsDescription && !hasShopName && !hasExtData && !hasIsEnabled) {
|
||||||
throw this.createError('至少需要提供一个可更新字段', 400);
|
throw this.createError('至少需要提供一个可更新字段', 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1559,6 +1567,14 @@ class SettingExpressInterfaceService extends Service {
|
|||||||
updates.product_type = this.normalizeOptionalText(data.product_type || data.productType, 'product_type', 50);
|
updates.product_type = this.normalizeOptionalText(data.product_type || data.productType, 'product_type', 50);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (hasGoodsDescription) {
|
||||||
|
updates.goods_description = this.normalizeOptionalText(
|
||||||
|
data.goods_description !== undefined ? data.goods_description : data.goodsDescription,
|
||||||
|
'goods_description',
|
||||||
|
255
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (hasShopName) {
|
if (hasShopName) {
|
||||||
updates.shop_name = this.normalizeOptionalText(data.shop_name || data.shopName, 'shop_name', 255);
|
updates.shop_name = this.normalizeOptionalText(data.shop_name || data.shopName, 'shop_name', 255);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -369,6 +369,14 @@ const WAREHOUSE_SETTING_FIELDS = Object.freeze([
|
|||||||
required: false,
|
required: false,
|
||||||
description: '开启后散单称重(订单波次范围 wave_scope 非 1 大团购 / 3 小团购)须处于打包中或已打包(pack_status=padding/fin);未打包或打包异常时拒绝称重并返回错误,默认 false(关闭)',
|
description: '开启后散单称重(订单波次范围 wave_scope 非 1 大团购 / 3 小团购)须处于打包中或已打包(pack_status=padding/fin);未打包或打包异常时拒绝称重并返回错误,默认 false(关闭)',
|
||||||
}),
|
}),
|
||||||
|
Object.freeze({
|
||||||
|
key: 'b2b_packing_quantity_check',
|
||||||
|
name: 'B2B备货完成校验分箱数量',
|
||||||
|
type: 'flag',
|
||||||
|
default: false,
|
||||||
|
required: false,
|
||||||
|
description: '开启后 B2B 备货完成前逐订单商品校验分箱数量合计等于应拣数量,并校验总箱数与分箱箱号数一致;默认 false(关闭)',
|
||||||
|
}),
|
||||||
Object.freeze({
|
Object.freeze({
|
||||||
key: 'stock_warning_enabled',
|
key: 'stock_warning_enabled',
|
||||||
name: '是否开启库存预警',
|
name: '是否开启库存预警',
|
||||||
|
|||||||
@ -0,0 +1,90 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* wms_order_b2b 增加 is_urgent 列(是否加急,默认 N)与 idx_is_urgent 索引。
|
||||||
|
*
|
||||||
|
* 背景:B2B 作业明细需要区分加急备货订单;列表(order.pendingOrder2b.list /
|
||||||
|
* order.deliveryOrder2b.list)输出该字段并支持 where.is_urgent 筛选,
|
||||||
|
* 转换时以订单表 is_urgency 作为初始值。
|
||||||
|
*
|
||||||
|
* 幂等:列/索引存在性判断后再执行,重复运行安全。
|
||||||
|
*/
|
||||||
|
|
||||||
|
const TABLE_NAME = 'wms_order_b2b';
|
||||||
|
const COLUMN_NAME = 'is_urgent';
|
||||||
|
const INDEX_NAME = 'idx_is_urgent';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断索引是否存在。
|
||||||
|
* @param {import('sequelize').QueryInterface} queryInterface 查询接口。
|
||||||
|
* @param {string} indexName 索引名。
|
||||||
|
* @return {Promise<boolean>} 是否存在。
|
||||||
|
*/
|
||||||
|
async function indexExists(queryInterface, indexName) {
|
||||||
|
const indexes = await queryInterface.showIndex(TABLE_NAME);
|
||||||
|
return (Array.isArray(indexes) ? indexes : []).some(index => {
|
||||||
|
const name = String(index && (index.name || index.Key_name || index.key_name) || '');
|
||||||
|
return name.toLowerCase() === String(indexName).toLowerCase();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
/**
|
||||||
|
* 执行迁移:新增 is_urgent 列与索引。
|
||||||
|
* @param {import('sequelize').QueryInterface} queryInterface 查询接口。
|
||||||
|
* @param {Object} Sequelize Sequelize 类型集合。
|
||||||
|
* @return {Promise<void>} 无返回值。
|
||||||
|
*/
|
||||||
|
async up(queryInterface, Sequelize) {
|
||||||
|
const { ENUM } = Sequelize;
|
||||||
|
const log = [];
|
||||||
|
|
||||||
|
const columns = await queryInterface.describeTable(TABLE_NAME);
|
||||||
|
if (!columns || Object.keys(columns).length === 0) {
|
||||||
|
throw new Error(`表 ${TABLE_NAME} 不存在,无法新增 ${COLUMN_NAME}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Object.prototype.hasOwnProperty.call(columns, COLUMN_NAME)) {
|
||||||
|
await queryInterface.addColumn(TABLE_NAME, COLUMN_NAME, {
|
||||||
|
type: ENUM('Y', 'N'),
|
||||||
|
allowNull: false,
|
||||||
|
defaultValue: 'N',
|
||||||
|
comment: '是否加急:Y=加急 N=普通',
|
||||||
|
});
|
||||||
|
log.push({ action: 'add-column', columnName: COLUMN_NAME });
|
||||||
|
} else {
|
||||||
|
log.push({ action: 'skip-add-column', columnName: COLUMN_NAME, reason: 'exists' });
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(await indexExists(queryInterface, INDEX_NAME))) {
|
||||||
|
await queryInterface.addIndex(TABLE_NAME, [ COLUMN_NAME ], { name: INDEX_NAME });
|
||||||
|
log.push({ action: 'add-index', indexName: INDEX_NAME });
|
||||||
|
} else {
|
||||||
|
log.push({ action: 'skip-add-index', indexName: INDEX_NAME, reason: 'exists' });
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('[20261117180000-add-is-urgent-to-wms-order-b2b] up results:', JSON.stringify(log));
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 回滚迁移:移除 is_urgent 索引与列。
|
||||||
|
* @param {import('sequelize').QueryInterface} queryInterface 查询接口。
|
||||||
|
* @return {Promise<void>} 无返回值。
|
||||||
|
*/
|
||||||
|
async down(queryInterface) {
|
||||||
|
const log = [];
|
||||||
|
|
||||||
|
if (await indexExists(queryInterface, INDEX_NAME)) {
|
||||||
|
await queryInterface.removeIndex(TABLE_NAME, INDEX_NAME);
|
||||||
|
log.push({ action: 'drop-index', indexName: INDEX_NAME });
|
||||||
|
}
|
||||||
|
|
||||||
|
const columns = await queryInterface.describeTable(TABLE_NAME);
|
||||||
|
if (Object.prototype.hasOwnProperty.call(columns, COLUMN_NAME)) {
|
||||||
|
await queryInterface.removeColumn(TABLE_NAME, COLUMN_NAME);
|
||||||
|
log.push({ action: 'drop-column', columnName: COLUMN_NAME });
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('[20261117180000-add-is-urgent-to-wms-order-b2b] down results:', JSON.stringify(log));
|
||||||
|
},
|
||||||
|
};
|
||||||
@ -0,0 +1,140 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* wms_order_b2b 增加备货作业字段(B2B 备货开始 / 取消备货 / 备货结束)。
|
||||||
|
*
|
||||||
|
* 新增:
|
||||||
|
* - prep_status ENUM('none','padding','fin') NOT NULL DEFAULT 'none' 备货状态
|
||||||
|
* - prep_operator_id BIGINT UNSIGNED NULL 备货人工号ID
|
||||||
|
* - prep_operator_name VARCHAR(50) NULL 备货人姓名
|
||||||
|
* - prep_start_at DATETIME NULL 备货开始时间
|
||||||
|
* - idx_prep_status_operator (prep_status, prep_operator_id) 我的备货任务筛选
|
||||||
|
*
|
||||||
|
* 已有字段复用:prep_remark(备货备注)、total_box_count(总箱数)、
|
||||||
|
* prep_at(备货完成时间)、prep_duration_seconds(备货用时)。
|
||||||
|
*
|
||||||
|
* 幂等:列/索引存在性判断后再执行,重复运行安全。
|
||||||
|
*/
|
||||||
|
|
||||||
|
const TABLE_NAME = 'wms_order_b2b';
|
||||||
|
const INDEX_NAME = 'idx_prep_status_operator';
|
||||||
|
|
||||||
|
const COLUMNS = [
|
||||||
|
{
|
||||||
|
name: 'prep_status',
|
||||||
|
definition: {
|
||||||
|
type: "ENUM('none', 'padding', 'fin')",
|
||||||
|
allowNull: false,
|
||||||
|
defaultValue: 'none',
|
||||||
|
comment: '备货状态:none=未开始 padding=备货中 fin=已完成',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'prep_operator_id',
|
||||||
|
definition: {
|
||||||
|
type: 'BIGINT UNSIGNED',
|
||||||
|
allowNull: true,
|
||||||
|
comment: '备货人工号ID(工号,用于同工号校验)',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'prep_operator_name',
|
||||||
|
definition: {
|
||||||
|
type: 'VARCHAR(50)',
|
||||||
|
allowNull: true,
|
||||||
|
comment: '备货人姓名',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'prep_start_at',
|
||||||
|
definition: {
|
||||||
|
type: 'DATETIME',
|
||||||
|
allowNull: true,
|
||||||
|
comment: '备货开始时间',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断索引是否存在。
|
||||||
|
* @param {import('sequelize').QueryInterface} queryInterface 查询接口。
|
||||||
|
* @param {string} indexName 索引名。
|
||||||
|
* @return {Promise<boolean>} 是否存在。
|
||||||
|
*/
|
||||||
|
async function indexExists(queryInterface, indexName) {
|
||||||
|
const indexes = await queryInterface.showIndex(TABLE_NAME);
|
||||||
|
return (Array.isArray(indexes) ? indexes : []).some(index => {
|
||||||
|
const name = String(index && (index.name || index.Key_name || index.key_name) || '');
|
||||||
|
return name.toLowerCase() === String(indexName).toLowerCase();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
/**
|
||||||
|
* 执行迁移:新增备货作业字段与索引。
|
||||||
|
* @param {import('sequelize').QueryInterface} queryInterface 查询接口。
|
||||||
|
* @param {Object} Sequelize Sequelize 类型集合。
|
||||||
|
* @return {Promise<void>} 无返回值。
|
||||||
|
*/
|
||||||
|
async up(queryInterface, Sequelize) {
|
||||||
|
const { DataTypes } = Sequelize;
|
||||||
|
const log = [];
|
||||||
|
|
||||||
|
const columns = await queryInterface.describeTable(TABLE_NAME);
|
||||||
|
if (!columns || Object.keys(columns).length === 0) {
|
||||||
|
throw new Error(`表 ${TABLE_NAME} 不存在,无法新增备货字段`);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const column of COLUMNS) {
|
||||||
|
if (Object.prototype.hasOwnProperty.call(columns, column.name)) {
|
||||||
|
log.push({ action: 'skip-add-column', columnName: column.name, reason: 'exists' });
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const definition = column.name === 'prep_status'
|
||||||
|
? { type: DataTypes.ENUM('none', 'padding', 'fin'), allowNull: false, defaultValue: 'none', comment: column.definition.comment }
|
||||||
|
: column.name === 'prep_operator_id'
|
||||||
|
? { type: DataTypes.BIGINT.UNSIGNED, allowNull: true, comment: column.definition.comment }
|
||||||
|
: column.name === 'prep_operator_name'
|
||||||
|
? { type: DataTypes.STRING(50), allowNull: true, comment: column.definition.comment }
|
||||||
|
: { type: DataTypes.DATE, allowNull: true, comment: column.definition.comment };
|
||||||
|
|
||||||
|
await queryInterface.addColumn(TABLE_NAME, column.name, definition);
|
||||||
|
log.push({ action: 'add-column', columnName: column.name });
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(await indexExists(queryInterface, INDEX_NAME))) {
|
||||||
|
await queryInterface.addIndex(TABLE_NAME, [ 'prep_status', 'prep_operator_id' ], { name: INDEX_NAME });
|
||||||
|
log.push({ action: 'add-index', indexName: INDEX_NAME });
|
||||||
|
} else {
|
||||||
|
log.push({ action: 'skip-add-index', indexName: INDEX_NAME, reason: 'exists' });
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('[20261117200000-add-prep-fields-to-wms-order-b2b] up results:', JSON.stringify(log));
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 回滚迁移:移除备货作业字段与索引。
|
||||||
|
* @param {import('sequelize').QueryInterface} queryInterface 查询接口。
|
||||||
|
* @return {Promise<void>} 无返回值。
|
||||||
|
*/
|
||||||
|
async down(queryInterface) {
|
||||||
|
const log = [];
|
||||||
|
|
||||||
|
if (await indexExists(queryInterface, INDEX_NAME)) {
|
||||||
|
await queryInterface.removeIndex(TABLE_NAME, INDEX_NAME);
|
||||||
|
log.push({ action: 'drop-index', indexName: INDEX_NAME });
|
||||||
|
}
|
||||||
|
|
||||||
|
const columns = await queryInterface.describeTable(TABLE_NAME);
|
||||||
|
for (const column of [ ...COLUMNS ].reverse()) {
|
||||||
|
if (!Object.prototype.hasOwnProperty.call(columns, column.name)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
await queryInterface.removeColumn(TABLE_NAME, column.name);
|
||||||
|
log.push({ action: 'drop-column', columnName: column.name });
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('[20261117200000-add-prep-fields-to-wms-order-b2b] down results:', JSON.stringify(log));
|
||||||
|
},
|
||||||
|
};
|
||||||
@ -0,0 +1,61 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* wms_express_interface 增加 goods_description 列(物品描述)。
|
||||||
|
*
|
||||||
|
* 背景:菜鸟等电子面单接口的 package_info.goods_description 需要按快递接口配置下发,
|
||||||
|
* 原先在代码内硬编码为「化妆品」。现改为读取接口配置,未配置时仍回退到「化妆品」。
|
||||||
|
*
|
||||||
|
* 幂等:列存在性判断后再执行,重复运行安全。
|
||||||
|
*/
|
||||||
|
|
||||||
|
const TABLE_NAME = 'wms_express_interface';
|
||||||
|
const COLUMN_NAME = 'goods_description';
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
/**
|
||||||
|
* 执行迁移:新增 goods_description 列。
|
||||||
|
* @param {import('sequelize').QueryInterface} queryInterface 查询接口。
|
||||||
|
* @param {Object} Sequelize Sequelize 类型集合。
|
||||||
|
* @return {Promise<void>} 无返回值。
|
||||||
|
*/
|
||||||
|
async up(queryInterface, Sequelize) {
|
||||||
|
const { STRING } = Sequelize;
|
||||||
|
const log = [];
|
||||||
|
|
||||||
|
const columns = await queryInterface.describeTable(TABLE_NAME);
|
||||||
|
if (!columns || Object.keys(columns).length === 0) {
|
||||||
|
throw new Error(`表 ${TABLE_NAME} 不存在,无法新增 ${COLUMN_NAME}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Object.prototype.hasOwnProperty.call(columns, COLUMN_NAME)) {
|
||||||
|
await queryInterface.addColumn(TABLE_NAME, COLUMN_NAME, {
|
||||||
|
type: STRING(255),
|
||||||
|
allowNull: true,
|
||||||
|
comment: '物品描述',
|
||||||
|
});
|
||||||
|
log.push({ action: 'add-column', columnName: COLUMN_NAME });
|
||||||
|
} else {
|
||||||
|
log.push({ action: 'skip-add-column', columnName: COLUMN_NAME, reason: 'exists' });
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('[20261118200000-add-goods-description-to-express-interface] up results:', JSON.stringify(log));
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 回滚迁移:移除 goods_description 列。
|
||||||
|
* @param {import('sequelize').QueryInterface} queryInterface 查询接口。
|
||||||
|
* @return {Promise<void>} 无返回值。
|
||||||
|
*/
|
||||||
|
async down(queryInterface) {
|
||||||
|
const log = [];
|
||||||
|
|
||||||
|
const columns = await queryInterface.describeTable(TABLE_NAME);
|
||||||
|
if (Object.prototype.hasOwnProperty.call(columns, COLUMN_NAME)) {
|
||||||
|
await queryInterface.removeColumn(TABLE_NAME, COLUMN_NAME);
|
||||||
|
log.push({ action: 'drop-column', columnName: COLUMN_NAME });
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('[20261118200000-add-goods-description-to-express-interface] down results:', JSON.stringify(log));
|
||||||
|
},
|
||||||
|
};
|
||||||
@ -0,0 +1,65 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const TABLE_NAME = 'wms_order_b2b_items';
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
async up(queryInterface, Sequelize) {
|
||||||
|
const { BIGINT, INTEGER, STRING, DATE } = Sequelize;
|
||||||
|
await queryInterface.createTable(TABLE_NAME, {
|
||||||
|
id: {
|
||||||
|
type: BIGINT(20).UNSIGNED,
|
||||||
|
primaryKey: true,
|
||||||
|
autoIncrement: true,
|
||||||
|
allowNull: false,
|
||||||
|
comment: '主键ID',
|
||||||
|
},
|
||||||
|
warehouse_id: {
|
||||||
|
type: BIGINT(20).UNSIGNED,
|
||||||
|
allowNull: false,
|
||||||
|
comment: '仓库ID',
|
||||||
|
},
|
||||||
|
order_id: {
|
||||||
|
type: BIGINT(20).UNSIGNED,
|
||||||
|
allowNull: false,
|
||||||
|
comment: '订单ID',
|
||||||
|
},
|
||||||
|
order_item_id: {
|
||||||
|
type: BIGINT(20).UNSIGNED,
|
||||||
|
allowNull: false,
|
||||||
|
comment: '订单商品明细ID',
|
||||||
|
},
|
||||||
|
box_no: {
|
||||||
|
type: STRING(50),
|
||||||
|
allowNull: false,
|
||||||
|
comment: '箱号',
|
||||||
|
},
|
||||||
|
quantity: {
|
||||||
|
type: INTEGER(11).UNSIGNED,
|
||||||
|
allowNull: false,
|
||||||
|
comment: '该商品在该箱中的数量',
|
||||||
|
},
|
||||||
|
created_at: {
|
||||||
|
type: DATE,
|
||||||
|
allowNull: false,
|
||||||
|
comment: '创建时间',
|
||||||
|
},
|
||||||
|
updated_at: {
|
||||||
|
type: DATE,
|
||||||
|
allowNull: false,
|
||||||
|
comment: '更新时间',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
await queryInterface.addIndex(TABLE_NAME,
|
||||||
|
[ 'warehouse_id', 'order_id', 'order_item_id', 'box_no' ],
|
||||||
|
{ unique: true, name: 'uk_warehouse_order_item_box' });
|
||||||
|
await queryInterface.addIndex(TABLE_NAME,
|
||||||
|
[ 'warehouse_id', 'order_id' ],
|
||||||
|
{ name: 'idx_warehouse_order' });
|
||||||
|
await queryInterface.addIndex(TABLE_NAME, [ 'order_item_id' ], { name: 'idx_order_item' });
|
||||||
|
},
|
||||||
|
|
||||||
|
async down(queryInterface) {
|
||||||
|
await queryInterface.dropTable(TABLE_NAME);
|
||||||
|
},
|
||||||
|
};
|
||||||
@ -0,0 +1,34 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const TABLE_NAME = 'wms_inbox_block';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 屏蔽表新增「是否机器人账号」标记。
|
||||||
|
*
|
||||||
|
* 背景:仓库群(internal group)会忽略「仅用户级(无群ID)」的屏蔽记录,避免外部群的
|
||||||
|
* 用户级屏蔽连带跳过内部群消息;但机器人自身回信被桥接回灌成入站消息时会形成自问自答
|
||||||
|
* 死循环(生产实测单群 500+ 条/小时),这类屏蔽必须不受仓库群例外影响。
|
||||||
|
*
|
||||||
|
* 故新增 is_robot:is_robot=1 的记录在任意群(含仓库群)都生效,
|
||||||
|
* 且仅带 user_id 时按仓库维度全局生效。
|
||||||
|
*/
|
||||||
|
module.exports = {
|
||||||
|
up: async (queryInterface, Sequelize) => {
|
||||||
|
const cols = await queryInterface.describeTable(TABLE_NAME);
|
||||||
|
if (cols.is_robot) return;
|
||||||
|
|
||||||
|
await queryInterface.addColumn(TABLE_NAME, 'is_robot', {
|
||||||
|
type: Sequelize.TINYINT(1),
|
||||||
|
allowNull: false,
|
||||||
|
defaultValue: 0,
|
||||||
|
comment: '是否机器人账号:机器人屏蔽在仓库群同样生效(仓库群默认忽略仅用户级屏蔽)',
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
down: async queryInterface => {
|
||||||
|
const cols = await queryInterface.describeTable(TABLE_NAME);
|
||||||
|
if (!cols.is_robot) return;
|
||||||
|
|
||||||
|
await queryInterface.removeColumn(TABLE_NAME, 'is_robot');
|
||||||
|
},
|
||||||
|
};
|
||||||
@ -1,5 +1,17 @@
|
|||||||
{
|
{
|
||||||
"include": [
|
"include": [
|
||||||
"**/*"
|
"**/*"
|
||||||
|
],
|
||||||
|
"exclude": [
|
||||||
|
"node_modules",
|
||||||
|
"logs",
|
||||||
|
"run",
|
||||||
|
"runtime",
|
||||||
|
"test_reports",
|
||||||
|
"temp",
|
||||||
|
"tmp",
|
||||||
|
"coverage",
|
||||||
|
".nyc_output",
|
||||||
|
"typings"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@ -1,4 +1,328 @@
|
|||||||
[
|
[
|
||||||
|
{
|
||||||
|
"version": "2026.11.19-b2b-snapshot-pick-locations",
|
||||||
|
"date": "2026-11-19",
|
||||||
|
"type": "updated",
|
||||||
|
"summary": "B2B 分箱快照新增取货储位:order.getB2bPackingSnapshot 输出 pick_locations / pick_location_count(取代 order.pendingOrder2b.list 的列表级储位汇总)",
|
||||||
|
"methods": [
|
||||||
|
"order.getB2bPackingSnapshot",
|
||||||
|
"order.pendingOrder2b.list"
|
||||||
|
],
|
||||||
|
"notes": [
|
||||||
|
"数据源 wms_picking(订单储位分配结果),按 warehouse_id + order_id + status != 'cancel' 一次查询,按 order_item_id 关联到商品明细行;同一商品在同一储位的多条记录合并数量,按库位名称升序。",
|
||||||
|
"响应新增 items[].pick_locations:[{ space_id, space_name, quantity }](该商品从哪些储位取多少货),以及订单级 pick_location_count(本单涉及的不同储位个数),未分配储位时为空数组与 0;返回只读,提交变更仍用 order.updateB2bPackingItems。",
|
||||||
|
"变更原因:取货储位属于单个订单的作业视图,应由分箱快照(order.getB2bPackingSnapshot)按商品行提供;order.pendingOrder2b.list 撤回 pick_locations / pick_location_count,避免列表分页响应携带储位明细。",
|
||||||
|
"实现:app/service/systems/order_b2b.js#loadB2bPickLocationsByItem(新增)由 getB2bPackingSnapshot 调用。",
|
||||||
|
"库表维护源说明:维护源为库表(wms_api_method_doc + wms_method_doc_meta),methods/system.json 是导出产物;本次按 docs/api-doc-update-workflow.md 走 npm run doc:api:update 写入 JSON 与变更记录后,再用 script/method-doc-import.cjs 回填开发库(127.0.0.1:3307/wms),import → export 往返校验与文件逐字节一致。"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"version": "2026.11.19-b2b-packing-items",
|
||||||
|
"date": "2026-11-19",
|
||||||
|
"type": "added",
|
||||||
|
"summary": "新增 B2B 按商品分箱明细、全量更新与订单分箱快照接口,并增加仓库级齐套校验开关",
|
||||||
|
"methods": [
|
||||||
|
"order.updateB2bPackingItems",
|
||||||
|
"order.getB2bPackingSnapshot",
|
||||||
|
"order.finishB2bPrep",
|
||||||
|
"setting.warehouse.getSettings",
|
||||||
|
"setting.warehouse.getFieldMeta",
|
||||||
|
"setting.warehouse.saveSettings"
|
||||||
|
],
|
||||||
|
"notes": [
|
||||||
|
"新增 wms_order_b2b_items,按 warehouse_id + order_id + order_item_id + box_no 保存箱号及箱内数量;不修改订单明细分表。",
|
||||||
|
"order.updateB2bPackingItems 对单个备货中 B2B 订单全量替换分箱快照,items 为空数组可清空;每条商品行 ID 必须属于该订单,并同步 wms_order_b2b.total_box_count 为不同箱号数。",
|
||||||
|
"order.getB2bPackingSnapshot 返回订单号/状态、应拣商品明细、每个商品已分箱数量与箱号分布,以及 total_box_count 和齐套校验开关。",
|
||||||
|
"仓库 subject_config 新增 b2b_packing_quantity_check(flag,默认 false)。开启后 order.finishB2bPrep 逐商品明细校验分箱数量合计等于 plan_qty,并校验总箱数与分箱箱号数一致;失败时事务回滚。",
|
||||||
|
"操作日志新增 ORDER_B2B_PACKING_ITEMS;更新与校验均不改变既有库存扣减流程。"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"version": "2026.11.19-b2b-pickup-images-merge",
|
||||||
|
"date": "2026-11-19",
|
||||||
|
"type": "updated",
|
||||||
|
"summary": "B2B 提货照片收敛到提货接口:取消独立维护接口 order.setB2bPickupImages,改为提货时随单提交 file_id",
|
||||||
|
"methods": [
|
||||||
|
"order.pickupB2b"
|
||||||
|
],
|
||||||
|
"notes": [
|
||||||
|
"删除 order.setB2bPickupImages:提货照片不再提供独立的全量维护接口,避免一个业务两个入口。",
|
||||||
|
"order.pickupB2b 入参 pickup_file_ids(兼容 pickupFileIds / file_ids / fileIds / pickup_images)保持有效:上传接口已返回文件ID,提货时一并提交即可。",
|
||||||
|
"校验口径:只做一轮存在性校验(wms_file 命中且 is_deleted=false,不校验仓库归属),缺失则整个提货事务回滚并返回 B2B_IMAGE_FILE_INVALID。",
|
||||||
|
"落库口径:写入 wms_file_reference(business_type=b2b_pickup,display_order 顺延已有最大序号),追加语义、重复提交同一批 file_id 幂等。",
|
||||||
|
"明细与列表的 pickup_images 字段保持不变(order.pendingOrder.detail / order.deliveryOrder.detail / order.pendingOrder2b.list / order.deliveryOrder2b.list)。"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"version": "2026.11.19-b2b-pickup-images",
|
||||||
|
"date": "2026-11-19",
|
||||||
|
"type": "added",
|
||||||
|
"summary": "新增 B2B 提货照片:order.setB2bPickupImages;order.pickupB2b 支持提货时追加照片;明细/列表新增 pickup_images 字段",
|
||||||
|
"methods": [
|
||||||
|
"order.setB2bPickupImages",
|
||||||
|
"order.pickupB2b",
|
||||||
|
"order.updateB2bOrderImages",
|
||||||
|
"order.pendingOrder.detail",
|
||||||
|
"order.deliveryOrder.detail",
|
||||||
|
"order.pendingOrder2b.list",
|
||||||
|
"order.deliveryOrder2b.list"
|
||||||
|
],
|
||||||
|
"notes": [
|
||||||
|
"新增 order.setB2bPickupImages:单订单全量覆盖提货照片,business_type=b2b_pickup;文件只做一轮存在性校验(不校验仓库归属);仅 B2B 且未取消订单可更新,提货前预传与提货后补传均允许。",
|
||||||
|
"order.pickupB2b 新增可选入参 pickup_file_ids / pickupFileIds / file_ids / fileIds / pickup_images(追加语义),响应新增 pickup_images 与 pickup_image_count。",
|
||||||
|
"业务类型区分:备货照片保持 b2b_order(order.updateB2bOrderImages 文案同步改为「备货留证照片」),提货照片使用 b2b_pickup,两者互不覆盖。",
|
||||||
|
"明细与列表输出:order.pendingOrder.detail / order.deliveryOrder.detail / order.pendingOrder2b.list / order.deliveryOrder2b.list 新增 pickup_images(与 images 一次查询后按业务类型分组,无 N+1)。",
|
||||||
|
"操作日志新增 ORDER_B2B_PICKUP_IMAGES(更新B2B提货照片);order.pickupB2b 的 ORDER_B2B_PICKUP 日志 extras 增加 pickup_file_ids。"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"version": "2026.11.18-b2b-pickup-plate",
|
||||||
|
"date": "2026-11-18",
|
||||||
|
"type": "added",
|
||||||
|
"summary": "新增 B2B 提货车牌录入/修改:order.setB2bPickupPlate;order.pickupB2b 支持提货时顺带写入车牌",
|
||||||
|
"methods": [
|
||||||
|
"order.setB2bPickupPlate",
|
||||||
|
"order.pickupB2b"
|
||||||
|
],
|
||||||
|
"notes": [
|
||||||
|
"order.setB2bPickupPlate:单订单作业,仅 B2B 订单且未取消可录入;提货后车牌锁定不允许修改;传空字符串或 null 清空;车牌去空格/分隔符并转大写后落库,值变化写 ORDER_B2B_PICKUP_PLATE 操作日志。",
|
||||||
|
"order.pickupB2b:新增可选入参 pickup_plate_number / pickupPlateNumber,同一事务内随提货写入车牌;响应新增 pickup_plate_number。已提货订单传入不同车牌返回 failure 400。",
|
||||||
|
"车牌基础校验:首字符为汉字或字母、整体 5~10 位的汉字/字母/数字组合,兼容军牌、使领馆牌、挂车等特殊牌照,仅拦截明显无效输入。",
|
||||||
|
"字段复用说明:wms_order_b2b.pickup_plate_number 此前只有模型/列表/筛选,没有写入入口,本次补齐写入链路。"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"version": "0.3.374-b2b-detail-fields",
|
||||||
|
"date": "2026-11-18",
|
||||||
|
"type": "updated",
|
||||||
|
"summary": "order.pendingOrder.detail / order.deliveryOrder.detail 为 B2B 订单附加副表作业明细 b2b 与订单图片 images",
|
||||||
|
"methods": [
|
||||||
|
"order.pendingOrder.detail",
|
||||||
|
"order.deliveryOrder.detail"
|
||||||
|
],
|
||||||
|
"notes": [
|
||||||
|
"变更:两个详情接口在响应顶层新增 b2b(wms_order_b2b 作业明细对象)与 images(B2B 订单图片数组);仅 is_b2b=Y 的订单查询副表与图片,非 B2B 订单 b2b=null、images=[],结构稳定、不额外查库。",
|
||||||
|
"b2b 字段:total_box_count / pickup_plate_number / prep_remark / prep_duration_seconds / prep_status / prep_operator_id / prep_operator_name / prep_start_at / is_urgent / is_picked_up / picked_up_at / created_at / prep_at;副表行缺失时输出空值占位(与 B2B 列表口径一致)。",
|
||||||
|
"images 字段:wms_file_reference business_type=b2b_order,按 display_order、id 升序,元素 { id: file_id, url, display_order };与 order.pendingOrder2b.list / order.deliveryOrder2b.list 的行内 images 同源。",
|
||||||
|
"实现:app/service/systemMethods/order/base.js 新增 formatB2bDetailFields(列表/详情共用字段映射)与 buildB2bDetailExtras(is_b2b=Y 时查副表 + 图片),由 base.js#detail 与 pendingOrder.js#detail 返回前调用;列表 attachB2bJobDetail 改为复用同一映射,避免两处字段漂移。"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"version": "0.3.373-b2b-pickup-outbound-status",
|
||||||
|
"date": "2026-11-18",
|
||||||
|
"type": "updated",
|
||||||
|
"summary": "order.pickupB2b 提货即出库完成:写主表 outbound_status=fin / step=4 / delivery_time,触发出库迁移到配送表",
|
||||||
|
"methods": [
|
||||||
|
"order.pickupB2b"
|
||||||
|
],
|
||||||
|
"notes": [
|
||||||
|
"变更:提货成功时在同一事务内把订单所在分表(current 优先、dispatch 兜底,按 modelMap 精确定位)的 outbound_status 置 fin、step 置 4、delivery_time 置提货时间、updated_at 置当前时间,与 order.markOutboundOrder 的出库口径一致。",
|
||||||
|
"迁移触发:定时任务 schedule/sync_outbound_orders_to_delivery 按 outbound_status IN (fin,padding) 且 step IN (4,9) 选源,因此提货后无需人工干预即会迁移到配送表(dispatch_lane=m4),order.deliveryOrder2b.list 可见;迁移脚本本身不做任何 B2B 特判。",
|
||||||
|
"统计联动:warehouse_panel#queryB2b(B2B 今日出库)按 outbound_status=fin + delivery_time 当日统计,此前 B2B 从不写这两个字段导致统计恒为 0,本次一并修复。",
|
||||||
|
"历史数据自愈:is_picked_up=Y 但主表未出库的订单重复调用提货时,按首次 picked_up_at 补写 delivery_time,不重复写 ORDER_B2B_PICKUP 日志;已出库则跳过(outbound_marked=false)。",
|
||||||
|
"响应新增 outbound_status / step / outbound_marked 三个字段。",
|
||||||
|
"实现:app/service/systems/order_b2b.js#pickupOrdersB2b、#loadPrepTargets(新增 modelMap 与 outbound_status/step/delivery_time 查询字段)。"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"version": "0.3.373-express-interface-goods-description",
|
||||||
|
"date": "2026-11-18",
|
||||||
|
"type": "updated",
|
||||||
|
"summary": "???????? goods_description????????????? package_info.goods_description ????????????????????",
|
||||||
|
"methods": [
|
||||||
|
"setting.expressInterface.create",
|
||||||
|
"setting.expressInterface.update",
|
||||||
|
"setting.expressInterface.list",
|
||||||
|
"setting.expressInterface.listByWarehousePlatformCode"
|
||||||
|
],
|
||||||
|
"notes": [
|
||||||
|
"????wms_express_interface ?? goods_description VARCHAR(255) NULL COMMENT '????'??? 20261118200000-add-goods-description-to-express-interface.js??????",
|
||||||
|
"???setting.expressInterface.create / update ?? goods_description??? goodsDescription???????? 255 ??????????????? 400?????????????",
|
||||||
|
"???setting.expressInterface.list / update / listByWarehousePlatformCode ?? goods_description ???",
|
||||||
|
"?????app/service/systems/express_platform.js ???? package_info.goods_description ?????????????????????????????"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"version": "0.3.372-b2b-order-images",
|
||||||
|
"date": "2026-11-18",
|
||||||
|
"type": "added",
|
||||||
|
"summary": "新增 order.updateB2bOrderImages:B2B 订单图片更新(wms_file_reference business_type=b2b_order),B2B 列表挂载 images",
|
||||||
|
"methods": [
|
||||||
|
"order.updateB2bOrderImages",
|
||||||
|
"order.pendingOrder2b.list",
|
||||||
|
"order.deliveryOrder2b.list"
|
||||||
|
],
|
||||||
|
"notes": [
|
||||||
|
"新接口:单订单全量覆盖更新 B2B 订单图片,入参 images 支持 { file_id, display_order } 或直接 file_id(兼容 file_ids/fileIds),传空数组清空;单订单最多 20 张,重复 file_id 去重,display_order 缺省按顺序补 0 起序号。",
|
||||||
|
"落库口径:wms_file_reference.business_type=b2b_order、business_id=订单ID字符串、warehouse_id=当前仓库、display_order 控制顺序、created_by=操作人姓名;文件本体复用 wms_file,不做物理删除。business_type 常量集中登记在 app/lib/file_business_types.js(stock / stock_check_record / receivingItem / b2b_order)。",
|
||||||
|
"校验:仅 B2B 订单(is_b2b=Y)且未取消;订单 current 优先、dispatch 兜底;文件必须属于当前仓库且未删除(B2B_IMAGE_FILE_INVALID);错误码前缀 B2B_IMAGE_ 由方法层统一转 failure 400。",
|
||||||
|
"事务:关联 diff(删除/新增/更新顺序)在同一事务内完成,失败整体回滚。",
|
||||||
|
"列表联动:order.pendingOrder2b.list / order.deliveryOrder2b.list 每行新增 images: [{ id, url, display_order }],按页一次性批量查询(FileReference include File),查询失败降级为空数组、不影响列表主流程。",
|
||||||
|
"操作日志:ORDER_B2B_IMAGES(「更新B2B订单图片」,已在 app/dict/businessDict.js 登记),extras 带 image_count / added_file_ids / removed_file_ids。"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"version": "0.3.371-b2b-prep-drop-claim-guard",
|
||||||
|
"date": "2026-11-18",
|
||||||
|
"type": "updated",
|
||||||
|
"summary": "order.startB2bPrep 新增作业前置条件:未打印、未分配储位、已拦截的订单不允许开始备货(领料不参与校验)",
|
||||||
|
"methods": [
|
||||||
|
"order.startB2bPrep"
|
||||||
|
],
|
||||||
|
"notes": [
|
||||||
|
"前置条件:intercept_status=none(未拦截)→ print_status=fin(已打印)→ storage_status=fin(已分配储位),任一不满足即 failure 400(错误码 B2B_PREP_NOT_READY)且不写入 wms_order_b2b、不写操作日志;data 回带 order_id / print_status / storage_status / intercept_status。",
|
||||||
|
"领料(claim_status)不作为前置条件:领料仅由 pick.waveClaimScan 整波领单写入(要求订单 wave_id>0 且波次 source=0),B2B 订单已被强制排除在波次抓取之外、没有波次,claim_status 恒为 none,若把已领料列为前置条件会让所有 B2B 订单永久无法开始备货。",
|
||||||
|
"已分配储位与已打印对 B2B 均可达:储位分配走 orderStorageAllocation.allocatePicking(订单级,不依赖波次、未排除 is_b2b),打印/手工运单号录入同样按订单维度、不依赖波次。",
|
||||||
|
"幂等口径不变:同工号重复开始仍幂等成功,但同样先执行前置条件校验(备货中订单若被取消分配储位或改为拦截,重复开始会失败)。",
|
||||||
|
"实现:app/service/systems/order/order_b2b.js 中 assertPrepStartReady 新增(实际路径 app/service/systems/order_b2b.js),loadPrepTargets 增加查询 print_status/storage_status/intercept_status,由 startOrdersB2bPrep 在「已完成/其他工号」校验之后、幂等分支之前调用;cancelB2bPrep / finishB2bPrep / pickupB2b 不受影响。"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"version": "0.3.369-b2b-op-guard",
|
||||||
|
"date": "2026-11-18",
|
||||||
|
"type": "updated",
|
||||||
|
"summary": "反审回待审核、抓取散单、批量发货、克隆订单对 B2B 订单不再生效:命中 B2B 订单整批驳回并返回不生效提示",
|
||||||
|
"methods": [
|
||||||
|
"order.pendingOrder.reverseReviewOrder",
|
||||||
|
"order.pendingOrder.cloneOrder",
|
||||||
|
"order.wave.singleFetchByIds",
|
||||||
|
"order.recheckOrder.batchQuickRecheck",
|
||||||
|
"order.recheckOrder.batchQuickRecheckByWave"
|
||||||
|
],
|
||||||
|
"notes": [
|
||||||
|
"口径:B2B 订单(wms_order_delivery.is_b2b=Y,NULL 存量行视为非 B2B)走备货/提货独立作业链路,不参与反审回待审核、抓取散单(按订单抓散单)、批量发货(快捷复核,含按波次)、克隆订单。",
|
||||||
|
"驳回方式:入参/波次内命中任意 B2B 订单即整批驳回(与既有「锁单/拦截」部分跳过口径不同,不做部分处理),错误文案「B2B 订单不支持{操作}(订单[ID...]),操作不生效」,最多展示前 10 个订单 ID。",
|
||||||
|
"order.pendingOrder.reverseReviewOrder:在运单号校验前先做 B2B 校验,命中时不改动 inspection_status/step/wave 关联。",
|
||||||
|
"order.pendingOrder.cloneOrder:在可取消状态校验前做 B2B 校验,命中时不取消原单、不释放库存、不创建新单。",
|
||||||
|
"order.wave.singleFetchByIds:原先的「排除 B2B 订单并返回 excluded_b2b_order_ids」改为整批驳回,响应移除 excluded_b2b_order_ids 字段(波次内不写入任何 B2B 订单)。",
|
||||||
|
"order.recheckOrder.batchQuickRecheck / batchQuickRecheckByWave:批次内命中 B2B 订单直接抛错,不产生 success/failed 明细(SN 订单的原先部分失败口径不变)。",
|
||||||
|
"实现:app/service/systemMethods/order/base.js#assertOrdersNotB2b 统一校验(isB2bOrderRow 判定 is_b2b=Y),由 pendingOrder.js#reverseReviewOrder / #cloneOrder、wave.js#singleFetchByIds、recheckOrder.js#batchQuickRecheck / #batchQuickRecheckByWave 调用。"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"version": "0.3.368",
|
||||||
|
"date": "2026-11-17",
|
||||||
|
"type": "updated",
|
||||||
|
"summary": "order.finishB2bPrep 备货完成同步扣减库存,口径与拣货完成一致",
|
||||||
|
"methods": [
|
||||||
|
"order.finishB2bPrep"
|
||||||
|
],
|
||||||
|
"notes": [
|
||||||
|
"变更:备货完成(order.finishB2bPrep)在同一事务内同步执行库存出库,处理逻辑与拣货完成(systems/pick.js#wavePickTaskComplete、systemMethods/order/recheckOrder.js#_completePickForOrder)保持一致。",
|
||||||
|
"扣减明细:按 wms_picking(order_id + warehouse_id + status=pending + deleted_at IS NULL,FOR UPDATE)汇总各 storage_id 数量 → 校验 wms_storage.locked_quantity 足够 → 同时扣减 locked_quantity 与 quantity → 写入 wms_storage_transaction(transaction_type=OUTBOUND、order_type=PICK_OUTBOUND、order_id=订单ID、remark=备货完成出库(B2B))→ wms_picking 置 fin。",
|
||||||
|
"失败语义:任一 storage 锁定数量不足时整单失败(failure 400,data 带 storage_id/locked_quantity/deduction_quantity),备货完成不落库、库存不变。",
|
||||||
|
"无 pending 拣货记录的订单(未走拣货流程或已扣减过)不做库存变更,备货仍正常完成,响应 stock_deducted_* 为空/0。",
|
||||||
|
"响应新增 stock_deducted_storage_ids、stock_deducted_quantity 两个字段。",
|
||||||
|
"实现位置:app/service/systems/order_b2b.js#completeB2bPrepStockOutbound(新抽取的库存扣减方法),由 #finishOrdersB2bPrep 在事务内调用。",
|
||||||
|
"未改动订单主表 pick_status:备货完成只影响副表与库存,避免干扰拣货/复核状态机。"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"version": "0.3.367",
|
||||||
|
"date": "2026-11-17",
|
||||||
|
"type": "added",
|
||||||
|
"summary": "新增 order.pickupB2b:B2B 订单提货并记录提货时间(单订单)",
|
||||||
|
"methods": [
|
||||||
|
"order.pickupB2b"
|
||||||
|
],
|
||||||
|
"notes": [
|
||||||
|
"新接口:传入单个订单ID,把 wms_order_b2b.is_picked_up 置 Y、picked_up_at 置提交时刻,记录提货时间。",
|
||||||
|
"校验:仅 B2B 订单(is_b2b=Y)、非已取消;要求备货已完成(prep_status=fin),否则 failure 400「订单未备货完成,不允许提货」;已提货幂等(already_picked_up=true,保留首次提货时间、不重复写日志)。",
|
||||||
|
"单订单口径:只接受 1 个订单ID,同备货三接口一致(方法层 app/service/systemMethods/order/index.js#runB2bSingleOrderAction 与业务层 normalizeB2bOrderIds 双层拦截)。",
|
||||||
|
"实现位置:app/service/systems/order_b2b.js#pickupOrdersB2b,出口 app/service/systemMethods/order/index.js#pickupB2b;操作码 ORDER_B2B_PICKUP 已在 app/dict/businessDict.js 登记为「B2B提货」。",
|
||||||
|
"列表联动:order.pendingOrder2b.list / order.deliveryOrder2b.list 已输出 is_picked_up、picked_up_at 并支持 where.is_picked_up 筛选,提货后立即反映。"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"version": "0.3.366",
|
||||||
|
"date": "2026-11-17",
|
||||||
|
"type": "updated",
|
||||||
|
"summary": "B2B 备货三接口改为单订单作业,禁止批量提交",
|
||||||
|
"methods": [
|
||||||
|
"order.startB2bPrep",
|
||||||
|
"order.cancelB2bPrep",
|
||||||
|
"order.finishB2bPrep"
|
||||||
|
],
|
||||||
|
"notes": [
|
||||||
|
"变更:order.startB2bPrep / order.cancelB2bPrep / order.finishB2bPrep 由批量口径收紧为单订单作业,method 层(runB2bSingleOrderAction)与业务层(normalizeB2bOrderIds)双层拦截,传多个订单ID直接 failure 400「备货作业仅支持单个订单,请单条提交」,data.order_ids 返回传入的多个订单ID。",
|
||||||
|
"入参别名:ids / order_ids / orderIds / id / order_id / orderId 均支持单值或单元素数组,取值优先级同上。",
|
||||||
|
"原因:备货为逐个订单的实际作业,批量提交会出现部分成功难以追溯;批量场景由前端按订单循环调用。"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"version": "0.3.365",
|
||||||
|
"date": "2026-11-17",
|
||||||
|
"type": "added",
|
||||||
|
"summary": "新增 order.cancelB2bUrgent:批量取消 B2B 订单加急(仅 B2B 订单生效)",
|
||||||
|
"methods": [
|
||||||
|
"order.cancelB2bUrgent"
|
||||||
|
],
|
||||||
|
"notes": [
|
||||||
|
"新接口:等价于 order.setB2bUrgent 传 is_urgent=N,内部强制把 is_urgent 覆盖为 N(调用方传 Y 也不会变成设置加急)。",
|
||||||
|
"跳过口径:非 B2B 与已取消订单跳过并在 skipped_reasons 返回原因,单次上限 200 单;current 未命中时兜底 dispatch 分表。",
|
||||||
|
"落库位置:wms_order_b2b.is_urgent 置 N,作业明细行缺失时补建;操作日志写 ORDER_B2B_SET_URGENT(说明「取消B2B订单加急」)。"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"version": "0.3.364",
|
||||||
|
"date": "2026-11-17",
|
||||||
|
"type": "added",
|
||||||
|
"summary": "新增 order.setB2bUrgent:批量设置 B2B 订单是否加急(仅 B2B 订单生效)",
|
||||||
|
"methods": [
|
||||||
|
"order.setB2bUrgent"
|
||||||
|
],
|
||||||
|
"notes": [
|
||||||
|
"新接口:批量设置/取消 B2B 订单加急标记,写入 wms_order_b2b.is_urgent(不修改订单主表 is_urgency),关联条件 warehouse_id + order_id,作业明细行缺失时补建。",
|
||||||
|
"取值兼容:is_urgent 支持 Y/N、true/false、1/0、是/否,缺省 Y;非法取值直接报错。",
|
||||||
|
"跳过口径:非 B2B(is_b2b != Y)与已取消(status=cancel)订单跳过并在 skipped_reasons 返回原因,单次上限 200 单;current 未命中时兜底查询 dispatch 分表,两表都查不到计入 not_found_order_ids。",
|
||||||
|
"操作日志:每次设置写一条 ORDER_B2B_SET_URGENT(操作名称「设置B2B加急」)。列表联动:order.pendingOrder2b.list / order.deliveryOrder2b.list 的加急优先排序与 where.is_urgent 筛选立即生效。"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"version": "0.3.363",
|
||||||
|
"date": "2026-11-17",
|
||||||
|
"type": "added",
|
||||||
|
"summary": "新增 order.finishB2bPrep:B2B 订单备货完成,写入备注/总箱数/完成时间与用时",
|
||||||
|
"methods": [
|
||||||
|
"order.finishB2bPrep"
|
||||||
|
],
|
||||||
|
"notes": [
|
||||||
|
"新接口:必传 prep_remark(备货备注)与 total_box_count(总箱数),写入 prep_remark、total_box_count、prep_at(提交时刻)与 prep_duration_seconds(提交时刻 - prep_start_at 秒数,缺失时按 0),prep_status 置 fin。",
|
||||||
|
"校验:仅 B2B 订单;prep_status 非 padding 返回「订单未处于备货中,不允许提交备货完成」;备货人工号与当前工号不一致返回「订单备货人为其他工号(xxx)」;备注为空或总箱数非正整数返回入参错误。",
|
||||||
|
"操作日志:每个订单写一条 ORDER_B2B_PREP_FINISH(操作名称「备货完成」)。",
|
||||||
|
"实现位置:app/service/systems/order_b2b.js#finishOrdersB2bPrep,出口 app/service/systemMethods/order/index.js#finishB2bPrep。"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"version": "0.3.362",
|
||||||
|
"date": "2026-11-17",
|
||||||
|
"type": "added",
|
||||||
|
"summary": "新增 order.cancelB2bPrep:取消 B2B 订单备货并重置备货人与时间",
|
||||||
|
"methods": [
|
||||||
|
"order.cancelB2bPrep"
|
||||||
|
],
|
||||||
|
"notes": [
|
||||||
|
"新接口:把 wms_order_b2b.prep_status 重置为 none,清空 prep_operator_id / prep_operator_name / prep_start_at / prep_at,prep_duration_seconds 置 0;不清空 prep_remark 与 total_box_count。",
|
||||||
|
"校验:仅 B2B 订单;prep_status 非 padding 返回「订单未处于备货中,不允许取消备货」;备货人工号与当前工号不一致返回「订单备货人为其他工号(xxx)」。",
|
||||||
|
"操作日志:每个订单写一条 ORDER_B2B_PREP_CANCEL(操作名称「取消备货」)。",
|
||||||
|
"实现位置:app/service/systems/order_b2b.js#cancelOrdersB2bPrep,出口 app/service/systemMethods/order/index.js#cancelB2bPrep。"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"version": "0.3.361",
|
||||||
|
"date": "2026-11-17",
|
||||||
|
"type": "added",
|
||||||
|
"summary": "新增 order.startB2bPrep:B2B 订单备货开始并记录备货人工号与开始时间",
|
||||||
|
"methods": [
|
||||||
|
"order.startB2bPrep"
|
||||||
|
],
|
||||||
|
"notes": [
|
||||||
|
"新接口:传入订单ID,把 wms_order_b2b.prep_status 置为 padding,写入 prep_operator_id(当前登录工号)、prep_operator_name 与 prep_start_at(服务端当前时间);作业明细行缺失时按默认值补建。",
|
||||||
|
"校验:仅 B2B 订单(is_b2b=Y,current 分表优先、dispatch 分表兜底),订单不存在或非 B2B 整单失败;prep_status=fin 返回「订单已备货完成,不允许重新开始备货」;已由其他工号开始返回「订单备货人为其他工号(xxx)」,同工号重复开始幂等成功(保留首次 prep_start_at)。",
|
||||||
|
"操作日志:每个订单写一条 ORDER_B2B_PREP_START(操作名称「备货开始」),事务提交后写入,失败仅告警。",
|
||||||
|
"实现位置:app/service/systems/order_b2b.js#startOrdersB2bPrep,出口 app/service/systemMethods/order/index.js#startB2bPrep。"
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"version": "0.3.360",
|
"version": "0.3.360",
|
||||||
"date": "2026-11-15",
|
"date": "2026-11-15",
|
||||||
|
|||||||
1280
methods/system.json
1280
methods/system.json
File diff suppressed because it is too large
Load Diff
@ -20,6 +20,11 @@ function resolveEnv(argv = process.argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function loadDbConfig(env) {
|
function loadDbConfig(env) {
|
||||||
|
// database/config.js 只按 WMS_DB_TARGET 选连接目标(development / production 导出同一个 baseConfig),
|
||||||
|
// 因此 --env production 必须先落到 WMS_DB_TARGET,否则会静默连开发库。
|
||||||
|
if (env === 'production' && !process.env.WMS_DB_TARGET) {
|
||||||
|
process.env.WMS_DB_TARGET = 'production';
|
||||||
|
}
|
||||||
const dbConfig = require(path.join(__dirname, '..', 'database', 'config'));
|
const dbConfig = require(path.join(__dirname, '..', 'database', 'config'));
|
||||||
return dbConfig[env];
|
return dbConfig[env];
|
||||||
}
|
}
|
||||||
|
|||||||
@ -378,6 +378,70 @@ describe('test/app/controller/system.order.pendingOrder.reverseReviewOrder.test.
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should reject reversing when any order is B2B and keep all orders unchanged', async () => {
|
||||||
|
const { service, capture } = createPendingOrderService(buildRows(3, index => ({
|
||||||
|
id: index + 1,
|
||||||
|
warehouse_id: 100000,
|
||||||
|
step: 1,
|
||||||
|
inspection_status: 'fin',
|
||||||
|
is_b2b: index === 1 ? 'Y' : 'N',
|
||||||
|
updated_at: '2026-04-12 00:00:00',
|
||||||
|
})));
|
||||||
|
|
||||||
|
await assert.rejects(
|
||||||
|
async () => await service.reverseReviewOrder({
|
||||||
|
ids: [ 1, 2, 3 ],
|
||||||
|
}),
|
||||||
|
/B2B 订单不支持反审回待审核(订单\[2\]),操作不生效/
|
||||||
|
);
|
||||||
|
|
||||||
|
// 整批驳回:不更新任何订单
|
||||||
|
assert.equal(capture.updateValues, undefined);
|
||||||
|
for (const row of capture.rows) {
|
||||||
|
assert.equal(row.inspection_status, 'fin');
|
||||||
|
assert.equal(row.step, 1);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should reverse orders when is_b2b is null or N', async () => {
|
||||||
|
const { service, capture } = createPendingOrderService(buildRows(2, index => ({
|
||||||
|
id: index + 1,
|
||||||
|
warehouse_id: 100000,
|
||||||
|
step: 1,
|
||||||
|
inspection_status: 'fin',
|
||||||
|
is_b2b: index === 0 ? null : 'N',
|
||||||
|
updated_at: '2026-04-12 00:00:00',
|
||||||
|
})));
|
||||||
|
|
||||||
|
const result = await service.reverseReviewOrder({ ids: [ 1, 2 ] });
|
||||||
|
|
||||||
|
assert.equal(capture.updateValues.inspection_status, 'none');
|
||||||
|
assert.equal(result.updated_count, 2);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should reject cloning a B2B order without cancelling it', async () => {
|
||||||
|
const { service, capture } = createPendingOrderService(buildRows(1, () => ({
|
||||||
|
id: 9,
|
||||||
|
warehouse_id: 100000,
|
||||||
|
step: 1,
|
||||||
|
status: 'created',
|
||||||
|
inspection_status: 'fin',
|
||||||
|
is_b2b: 'Y',
|
||||||
|
storage_status: 'none',
|
||||||
|
updated_at: '2026-04-12 00:00:00',
|
||||||
|
})));
|
||||||
|
|
||||||
|
await assert.rejects(
|
||||||
|
async () => await service.cloneOrder({ order_id: 9 }),
|
||||||
|
/B2B 订单不支持克隆订单(订单\[9\]),操作不生效/
|
||||||
|
);
|
||||||
|
|
||||||
|
// 原订单未被取消
|
||||||
|
assert.equal(capture.updateValues, undefined);
|
||||||
|
assert.equal(capture.rows[0].status, 'created');
|
||||||
|
assert.equal(capture.rows[0].step, 1);
|
||||||
|
});
|
||||||
|
|
||||||
it('should write back to pending review status', async () => {
|
it('should write back to pending review status', async () => {
|
||||||
const { service, capture } = createPendingOrderService(buildRows(1, index => ({
|
const { service, capture } = createPendingOrderService(buildRows(1, index => ({
|
||||||
id: index + 1,
|
id: index + 1,
|
||||||
|
|||||||
@ -309,20 +309,51 @@ describe('test/app/service/systemMethods/order/wave.singleFetchByIds.test.js', (
|
|||||||
assert.deepEqual(result.skipped_order_ids, []);
|
assert.deepEqual(result.skipped_order_ids, []);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should still exclude B2B and intercepted orders while allowing SN orders', async () => {
|
it('should still fetch SN orders while excluding intercepted orders', async () => {
|
||||||
const { service } = createHarness({
|
const { service } = createHarness({
|
||||||
orders: [
|
orders: [
|
||||||
{ id: 501, wave_id: 0, wave_no: '', step: 1, status: 'new', outbound_status: 'none', has_sn_item: 'Y' },
|
{ id: 501, wave_id: 0, wave_no: '', step: 1, status: 'new', outbound_status: 'none', has_sn_item: 'Y' },
|
||||||
{ id: 502, wave_id: 0, wave_no: '', step: 1, status: 'new', outbound_status: 'none', is_b2b: 'Y' },
|
|
||||||
{ id: 503, wave_id: 0, wave_no: '', step: 1, status: 'new', outbound_status: 'none', intercept_status: 'padding' },
|
{ id: 503, wave_id: 0, wave_no: '', step: 1, status: 'new', outbound_status: 'none', intercept_status: 'padding' },
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
const result = await service.singleFetchByIds({ ids: [ 501, 502, 503 ] });
|
const result = await service.singleFetchByIds({ ids: [ 501, 503 ] });
|
||||||
|
|
||||||
assert.deepEqual(result.fetched_order_ids, [ 501 ]);
|
assert.deepEqual(result.fetched_order_ids, [ 501 ]);
|
||||||
assert.deepEqual(result.excluded_b2b_order_ids, [ 502 ]);
|
|
||||||
assert.deepEqual(result.excluded_intercepted_order_ids, [ 503 ]);
|
assert.deepEqual(result.excluded_intercepted_order_ids, [ 503 ]);
|
||||||
assert.deepEqual(result.excluded_sn_order_ids, []);
|
assert.deepEqual(result.excluded_sn_order_ids, []);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should reject the whole request when any B2B order is included', async () => {
|
||||||
|
const { service, state } = createHarness({
|
||||||
|
orders: [
|
||||||
|
{ id: 601, wave_id: 0, wave_no: '', step: 1, status: 'new', outbound_status: 'none' },
|
||||||
|
{ id: 602, wave_id: 0, wave_no: '', step: 1, status: 'new', outbound_status: 'none', is_b2b: 'Y' },
|
||||||
|
{ id: 603, wave_id: 0, wave_no: '', step: 1, status: 'new', outbound_status: 'none', is_b2b: 'N' },
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
await assert.rejects(
|
||||||
|
async () => await service.singleFetchByIds({ ids: [ 601, 602, 603 ] }),
|
||||||
|
/B2B 订单不支持抓取散单(订单\[602\]),操作不生效/
|
||||||
|
);
|
||||||
|
|
||||||
|
// 整批驳回:不建波次、不写订单日志,事务回滚
|
||||||
|
assert.equal(state.createWaveCalls.length, 0);
|
||||||
|
assert.equal(state.orderLogItems.length, 0);
|
||||||
|
assert.equal(state.committed, false);
|
||||||
|
assert.equal(state.rolledBack, true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should treat null is_b2b as non B2B order', async () => {
|
||||||
|
const { service } = createHarness({
|
||||||
|
orders: [
|
||||||
|
{ id: 701, wave_id: 0, wave_no: '', step: 1, status: 'new', outbound_status: 'none', is_b2b: null },
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
const result = await service.singleFetchByIds({ ids: [ 701 ] });
|
||||||
|
|
||||||
|
assert.deepEqual(result.fetched_order_ids, [ 701 ]);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -355,6 +355,26 @@ describe('test/app/service/systems/express_platform.cainiao.test.js', () => {
|
|||||||
assert.equal(bizBody.trade_order_info_dtos[0].template_url, DEFAULT_CAINIAO_TEMPLATE_URL);
|
assert.equal(bizBody.trade_order_info_dtos[0].template_url, DEFAULT_CAINIAO_TEMPLATE_URL);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should use configured goods_description and fall back to default when empty', async () => {
|
||||||
|
const { service, calls } = createCainiaoHarness();
|
||||||
|
|
||||||
|
const payload = buildPayload();
|
||||||
|
payload.listByWarehousePlatformCode.goods_description = ' 化妆品套装 ';
|
||||||
|
await service.cainiao(payload);
|
||||||
|
|
||||||
|
let requestBody = calls.curlOptions.options.data;
|
||||||
|
let bizBody = JSON.parse(requestBody.param_waybill_cloud_print_apply_new_request);
|
||||||
|
assert.equal(bizBody.trade_order_info_dtos[0].package_info.goods_description, '化妆品套装');
|
||||||
|
|
||||||
|
const fallbackPayload = buildPayload();
|
||||||
|
fallbackPayload.listByWarehousePlatformCode.goods_description = '';
|
||||||
|
await service.cainiao(fallbackPayload);
|
||||||
|
|
||||||
|
requestBody = calls.curlOptions.options.data;
|
||||||
|
bizBody = JSON.parse(requestBody.param_waybill_cloud_print_apply_new_request);
|
||||||
|
assert.equal(bizBody.trade_order_info_dtos[0].package_info.goods_description, '化妆品');
|
||||||
|
});
|
||||||
|
|
||||||
it('should throw when taobao returns error_response', async () => {
|
it('should throw when taobao returns error_response', async () => {
|
||||||
const { service } = createCainiaoHarness({
|
const { service } = createCainiaoHarness({
|
||||||
responseData: {
|
responseData: {
|
||||||
|
|||||||
218
test/app/service/systems/order_b2b_packing.test.js
Normal file
218
test/app/service/systems/order_b2b_packing.test.js
Normal file
@ -0,0 +1,218 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const assert = require('assert');
|
||||||
|
const OrderB2bService = require('../../../../app/service/systems/order_b2b');
|
||||||
|
|
||||||
|
describe('OrderB2bService packing quantity validation', () => {
|
||||||
|
function createService({ orderItems, packedItems }) {
|
||||||
|
const service = Object.create(OrderB2bService.prototype);
|
||||||
|
service.ctx = {
|
||||||
|
model: {
|
||||||
|
OrderItemsFactory: {
|
||||||
|
getCurrentModel: async () => ({
|
||||||
|
findAll: async () => orderItems,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
OrderB2bItem: {
|
||||||
|
findAll: async () => packedItems,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
return service;
|
||||||
|
}
|
||||||
|
|
||||||
|
it('accepts exact per-line quantities and matching carton count', async () => {
|
||||||
|
const service = createService({
|
||||||
|
orderItems: [
|
||||||
|
{ id: 11, item_code: 'SKU-A', item_name: '商品A', plan_qty: 3 },
|
||||||
|
{ id: 12, item_code: 'SKU-B', item_name: '商品B', plan_qty: 1 },
|
||||||
|
],
|
||||||
|
packedItems: [
|
||||||
|
{ order_item_id: 11, box_no: 'A01', quantity: 2 },
|
||||||
|
{ order_item_id: 11, box_no: 'A02', quantity: 1 },
|
||||||
|
{ order_item_id: 12, box_no: 'A02', quantity: 1 },
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
const result = await service.assertB2bPackingQuantityComplete({
|
||||||
|
warehouseId: 7,
|
||||||
|
orderId: 99,
|
||||||
|
sourceType: 'current',
|
||||||
|
totalBoxCount: 2,
|
||||||
|
transaction: { LOCK: { UPDATE: 'UPDATE' } },
|
||||||
|
});
|
||||||
|
assert.deepStrictEqual(result, { boxCount: 2 });
|
||||||
|
});
|
||||||
|
|
||||||
|
it('rejects underpacked product lines with per-item mismatch details', async () => {
|
||||||
|
const service = createService({
|
||||||
|
orderItems: [
|
||||||
|
{ id: 11, item_code: 'SKU-A', item_name: '商品A', plan_qty: 3 },
|
||||||
|
],
|
||||||
|
packedItems: [
|
||||||
|
{ order_item_id: 11, box_no: 'A01', quantity: 2 },
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
await assert.rejects(
|
||||||
|
service.assertB2bPackingQuantityComplete({
|
||||||
|
warehouseId: 7,
|
||||||
|
orderId: 99,
|
||||||
|
sourceType: 'current',
|
||||||
|
totalBoxCount: 1,
|
||||||
|
transaction: { LOCK: { UPDATE: 'UPDATE' } },
|
||||||
|
}),
|
||||||
|
error => {
|
||||||
|
assert.strictEqual(error.code, 'B2B_PREP_PACKING_INCOMPLETE');
|
||||||
|
assert.deepStrictEqual(error.data.item_mismatches, [
|
||||||
|
{
|
||||||
|
order_item_id: 11,
|
||||||
|
item_code: 'SKU-A',
|
||||||
|
item_name: '商品A',
|
||||||
|
expected_quantity: 3,
|
||||||
|
packed_quantity: 2,
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('replaces all packing rows only with item lines from the target order', async () => {
|
||||||
|
const transaction = {
|
||||||
|
LOCK: { UPDATE: 'UPDATE' },
|
||||||
|
commit: async () => {},
|
||||||
|
rollback: async () => {},
|
||||||
|
};
|
||||||
|
const deleted = [];
|
||||||
|
const created = [];
|
||||||
|
const service = Object.create(OrderB2bService.prototype);
|
||||||
|
service.ctx = {
|
||||||
|
model: {
|
||||||
|
transaction: async () => transaction,
|
||||||
|
OrderItemsFactory: {
|
||||||
|
getCurrentModel: async () => ({
|
||||||
|
findAll: async () => [{ id: 11 }],
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
OrderB2bItem: {
|
||||||
|
destroy: async options => deleted.push(options),
|
||||||
|
bulkCreate: async (rows, options) => created.push({ rows, options }),
|
||||||
|
},
|
||||||
|
OrderB2b: {
|
||||||
|
update: async () => {},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
service.loadPrepTargets = async () => ({
|
||||||
|
rowMap: new Map([[ 99, { is_b2b: 'Y', status: 'pending' }]]),
|
||||||
|
b2bMap: new Map([[ 99, { prep_status: 'padding' }]]),
|
||||||
|
sourceTypeMap: new Map([[ 99, 'current' ]]),
|
||||||
|
});
|
||||||
|
service.assertPrepOrders = () => {};
|
||||||
|
service.writePrepOperationLogs = async () => {};
|
||||||
|
|
||||||
|
const result = await service.updateB2bPackingItems({
|
||||||
|
warehouseId: 7,
|
||||||
|
orderIds: [ 99 ],
|
||||||
|
items: [
|
||||||
|
{ order_item_id: 11, box_no: 'A01', quantity: 2 },
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.deepStrictEqual(result, { order_id: 99, item_count: 1, box_count: 1 });
|
||||||
|
assert.deepStrictEqual(deleted[0].where, { warehouse_id: 7, order_id: 99 });
|
||||||
|
assert.strictEqual(created[0].rows[0].order_item_id, 11);
|
||||||
|
assert.strictEqual(created[0].rows[0].quantity, 2);
|
||||||
|
assert.strictEqual(created[0].options.transaction, transaction);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns per-item pick locations from wms_picking merged by space', async () => {
|
||||||
|
const transaction = { commit: async () => {}, rollback: async () => {} };
|
||||||
|
const pickQueries = [];
|
||||||
|
const service = Object.create(OrderB2bService.prototype);
|
||||||
|
service.app = { Sequelize: { Op: { ne: Symbol('ne') } } };
|
||||||
|
service.ctx = {
|
||||||
|
model: {
|
||||||
|
transaction: async () => transaction,
|
||||||
|
OrderDeliveryFactory: {
|
||||||
|
getCurrentModel: async () => ({
|
||||||
|
findOne: async () => ({ id: 99, is_b2b: 'Y', status: 'pending', delivery_order_code: 'DO-99' }),
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
OrderItemsFactory: {
|
||||||
|
getCurrentModel: async () => ({
|
||||||
|
findAll: async () => [
|
||||||
|
{ id: 11, item_code: 'SKU-A', item_name: '商品A', plan_qty: 3 },
|
||||||
|
{ id: 12, item_code: 'SKU-B', item_name: '商品B', plan_qty: 1 },
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
OrderB2bItem: { findAll: async () => [{ order_item_id: 11, box_no: 'A01', quantity: 3 }] },
|
||||||
|
OrderB2b: { findOne: async () => ({ prep_status: 'padding', total_box_count: 1 }) },
|
||||||
|
Picking: {
|
||||||
|
findAll: async options => {
|
||||||
|
pickQueries.push(options);
|
||||||
|
return [
|
||||||
|
{ order_item_id: 11, space_id: 31, space_name: 'B-02-01', quantity: 2 },
|
||||||
|
{ order_item_id: 11, space_id: 30, space_name: 'A-01-01', quantity: 1 },
|
||||||
|
{ order_item_id: 11, space_id: 31, space_name: 'B-02-01', quantity: 1 },
|
||||||
|
{ order_item_id: 12, space_id: 30, space_name: 'A-01-01', quantity: 1 },
|
||||||
|
{ order_item_id: 12, space_id: null, space_name: '', quantity: 1 },
|
||||||
|
];
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
service.isB2bPackingQuantityCheckEnabled = async () => false;
|
||||||
|
|
||||||
|
const result = await service.getB2bPackingSnapshot({ warehouseId: 7, orderIds: [ 99 ] });
|
||||||
|
|
||||||
|
assert.strictEqual(pickQueries.length, 1);
|
||||||
|
assert.deepStrictEqual(pickQueries[0].where, {
|
||||||
|
warehouse_id: 7,
|
||||||
|
order_id: 99,
|
||||||
|
status: { [service.app.Sequelize.Op.ne]: 'cancel' },
|
||||||
|
});
|
||||||
|
assert.strictEqual(result.pick_location_count, 3);
|
||||||
|
assert.deepStrictEqual(result.items[0].pick_locations, [
|
||||||
|
{ space_id: 30, space_name: 'A-01-01', quantity: 1 },
|
||||||
|
{ space_id: 31, space_name: 'B-02-01', quantity: 3 },
|
||||||
|
]);
|
||||||
|
assert.deepStrictEqual(result.items[1].pick_locations, [
|
||||||
|
{ space_id: null, space_name: null, quantity: 1 },
|
||||||
|
{ space_id: 30, space_name: 'A-01-01', quantity: 1 },
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('outputs empty pick locations when the order has no allocation rows', async () => {
|
||||||
|
const transaction = { commit: async () => {}, rollback: async () => {} };
|
||||||
|
const service = Object.create(OrderB2bService.prototype);
|
||||||
|
service.app = { Sequelize: { Op: { ne: Symbol('ne') } } };
|
||||||
|
service.ctx = {
|
||||||
|
model: {
|
||||||
|
transaction: async () => transaction,
|
||||||
|
OrderDeliveryFactory: {
|
||||||
|
getCurrentModel: async () => ({
|
||||||
|
findOne: async () => ({ id: 99, is_b2b: 'Y', status: 'pending', delivery_order_code: 'DO-99' }),
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
OrderItemsFactory: {
|
||||||
|
getCurrentModel: async () => ({
|
||||||
|
findAll: async () => [{ id: 11, item_code: 'SKU-A', item_name: '商品A', plan_qty: 1 }],
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
OrderB2bItem: { findAll: async () => [] },
|
||||||
|
OrderB2b: { findOne: async () => null },
|
||||||
|
Picking: { findAll: async () => [] },
|
||||||
|
},
|
||||||
|
};
|
||||||
|
service.isB2bPackingQuantityCheckEnabled = async () => false;
|
||||||
|
|
||||||
|
const result = await service.getB2bPackingSnapshot({ warehouseId: 7, orderIds: [ 99 ] });
|
||||||
|
|
||||||
|
assert.strictEqual(result.pick_location_count, 0);
|
||||||
|
assert.deepStrictEqual(result.items[0].pick_locations, []);
|
||||||
|
assert.strictEqual(result.items[0].packed_quantity, 0);
|
||||||
|
});
|
||||||
|
});
|
||||||
@ -167,6 +167,7 @@ function createHarness(options = {}) {
|
|||||||
district_name: {},
|
district_name: {},
|
||||||
site_code: {},
|
site_code: {},
|
||||||
product_type: {},
|
product_type: {},
|
||||||
|
goods_description: {},
|
||||||
weight_type: {},
|
weight_type: {},
|
||||||
shop_name: {},
|
shop_name: {},
|
||||||
address: {},
|
address: {},
|
||||||
@ -608,6 +609,7 @@ describe('test/app/service/systems/setting/expressInterface.test.js', () => {
|
|||||||
template_id: 1202,
|
template_id: 1202,
|
||||||
brandno: 'BRAND-SF',
|
brandno: 'BRAND-SF',
|
||||||
providertype: 'CAINIAO',
|
providertype: 'CAINIAO',
|
||||||
|
goods_description: '化妆品',
|
||||||
name: '顺丰接口',
|
name: '顺丰接口',
|
||||||
express_code: 'SF',
|
express_code: 'SF',
|
||||||
platform_code: 'TB',
|
platform_code: 'TB',
|
||||||
@ -664,6 +666,8 @@ describe('test/app/service/systems/setting/expressInterface.test.js', () => {
|
|||||||
assert.equal(result.data[0].template_id, 1202);
|
assert.equal(result.data[0].template_id, 1202);
|
||||||
assert.equal(result.data[0].brandno, 'BRAND-SF');
|
assert.equal(result.data[0].brandno, 'BRAND-SF');
|
||||||
assert.equal(result.data[0].providertype, 'CAINIAO');
|
assert.equal(result.data[0].providertype, 'CAINIAO');
|
||||||
|
assert.equal(result.data[0].goods_description, '化妆品');
|
||||||
|
assert.equal(Object.prototype.hasOwnProperty.call(result.data[1], 'goods_description'), false);
|
||||||
assert.equal(result.data[1].express_code, 'ZTO');
|
assert.equal(result.data[1].express_code, 'ZTO');
|
||||||
assert.equal(result.data[1].brandno, 'BRAND-ZTO');
|
assert.equal(result.data[1].brandno, 'BRAND-ZTO');
|
||||||
assert.equal(result.data[2].express_code, 'YTO');
|
assert.equal(result.data[2].express_code, 'YTO');
|
||||||
@ -1021,6 +1025,47 @@ describe('test/app/service/systems/setting/expressInterface.test.js', () => {
|
|||||||
assert.equal(calls.cacheDeletes.includes('express_interface:warehouse:100000:platform:PDD'), true);
|
assert.equal(calls.cacheDeletes.includes('express_interface:warehouse:100000:platform:PDD'), true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should save trimmed goods_description on create', async () => {
|
||||||
|
const { ctx, calls } = createHarness();
|
||||||
|
const service = new SettingExpressInterfaceService(ctx);
|
||||||
|
|
||||||
|
const result = await service.create({
|
||||||
|
name: '物品描述接口',
|
||||||
|
express_code: 'SF',
|
||||||
|
platform_code: 'TB',
|
||||||
|
goodsDescription: ' 化妆品套装 ',
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.equal(calls.createPayload.goods_description, '化妆品套装');
|
||||||
|
assert.equal(result.data.goods_description, '化妆品套装');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should allow empty goods_description and reject value longer than 255', async () => {
|
||||||
|
const { ctx, calls } = createHarness();
|
||||||
|
const service = new SettingExpressInterfaceService(ctx);
|
||||||
|
|
||||||
|
const result = await service.update({
|
||||||
|
id: 11,
|
||||||
|
goods_description: '',
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.equal(calls.updatePayload.updates.goods_description, '');
|
||||||
|
assert.equal(result.data.goods_description, '');
|
||||||
|
|
||||||
|
let error = null;
|
||||||
|
try {
|
||||||
|
await service.update({
|
||||||
|
id: 11,
|
||||||
|
goods_description: 'a'.repeat(256),
|
||||||
|
});
|
||||||
|
} catch (err) {
|
||||||
|
error = err;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.equal(error && error.code, 400);
|
||||||
|
assert.equal(error && error.message, 'goods_description 长度不能超过 255');
|
||||||
|
});
|
||||||
|
|
||||||
it('should sync token from shop access_token when updating shop_id', async () => {
|
it('should sync token from shop access_token when updating shop_id', async () => {
|
||||||
const { ctx, calls } = createHarness();
|
const { ctx, calls } = createHarness();
|
||||||
const service = new SettingExpressInterfaceService(ctx);
|
const service = new SettingExpressInterfaceService(ctx);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user