feat(order): B2B 加急优先、分箱明细与取货储位,作业链路收口
- 列表:B2B 待处理/配送列表固定加急优先排序(wms_order_b2b.is_urgent='Y' 置顶), 作业明细筛选口径不变 - 备货/提货:新增 setB2bUrgent/cancelB2bUrgent、startB2bPrep/cancelB2bPrep/finishB2bPrep、 setB2bPickupPlate、pickupB2b、updateB2bOrderImages;提货即出库完成 (写 outbound_status=fin / step=4 / delivery_time 并迁移到配送表),车牌与提货照片 随单落库 - 分箱:新增 wms_order_b2b_items 与 order.updateB2bPackingItems、order.getB2bPackingSnapshot; 快照按商品行返回 wms_picking 取货储位(items[].pick_locations / pick_location_count), 列表不再携带储位明细 - 齐套校验:仓库 subject_config 新增 b2b_packing_quantity_check,备货完成时逐商品校验 分箱数量合计等于 plan_qty 且总箱数与箱号数一致 - 拦截:B2B 订单不参与波次抓取、快捷复核批量发货、反审回待审核与克隆,命中即整批驳回 - 明细:order.pendingOrder.detail / order.deliveryOrder.detail 为 B2B 订单附加副表作业明细 b2b、备货照片 images 与提货照片 pickup_images - 迁移:wms_order_b2b 新增 is_urgent 与备货作业字段,新建 wms_order_b2b_items - 文档:methods/system.json 与 methods/changes/system.json 同步至 0.3.375 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
parent
06d0bc8ef8
commit
59bc65b443
@ -77,6 +77,15 @@ module.exports = {
|
||||
ORDER_WAVE_AUTO_GROUP: '自动加团',
|
||||
ORDER_WAVE_STRATEGY_FETCH: '策略抓取波次',
|
||||
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_AUTO_EXPRESS_SKIP: '跳过自动分配快递',
|
||||
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,
|
||||
};
|
||||
@ -5,7 +5,7 @@
|
||||
*
|
||||
* 对应数据库表 `wms_order_b2b`,与发货单(订单)分表 wms_order_delivery_% 一对一,
|
||||
* 记录 B2B 订单的备货/提货作业信息:总箱数、提货车牌、备货备注、备货用时、
|
||||
* 备货完成时间、是否提货等。
|
||||
* 备货完成时间、备货状态与备货人、是否加急、是否提货等。
|
||||
*
|
||||
* 不分表(不按仓库分表),关联读统一使用 warehouse_id + order_id(分表 id 按仓库
|
||||
* 各自发号,跨仓可能重叠,故不单独依赖 order_id)。取消 B2B 时物理删除行,不做软删除。
|
||||
@ -59,12 +59,39 @@ module.exports = app => {
|
||||
allowNull: true,
|
||||
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: {
|
||||
type: ENUM('Y', 'N'),
|
||||
allowNull: false,
|
||||
defaultValue: 'N',
|
||||
comment: '是否提货:Y=已提货 N=未提货',
|
||||
},
|
||||
is_urgent: {
|
||||
type: ENUM('Y', 'N'),
|
||||
allowNull: false,
|
||||
defaultValue: 'N',
|
||||
comment: '是否加急:Y=加急 N=普通',
|
||||
},
|
||||
picked_up_at: {
|
||||
type: DATE,
|
||||
allowNull: true,
|
||||
@ -93,6 +120,14 @@ module.exports = app => {
|
||||
name: 'idx_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,
|
||||
big_group_pack_coefficient: 3,
|
||||
single_weigh_require_pack: false,
|
||||
b2b_packing_quantity_check: false,
|
||||
stock_warning_enabled: false,
|
||||
stock_warning_quantity: 0,
|
||||
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')) {
|
||||
normalized.stock_warning_enabled = normalizeBooleanFlag(
|
||||
|
||||
@ -4,6 +4,7 @@ const MainService = require('../../main');
|
||||
const { parseWhereConditions } = require('../../../lib/query_condition_parser');
|
||||
const { isInterceptedOrderStatus } = require('../../../lib/intercept_guard');
|
||||
const { isLockedOrderStatus } = require('../../../lib/lock_guard');
|
||||
const { FILE_BUSINESS_TYPE } = require('../../../lib/file_business_types');
|
||||
|
||||
const DEFAULT_PAGE_SIZE = 20;
|
||||
const MAX_PAGE_SIZE = 500;
|
||||
@ -58,6 +59,11 @@ const ORDER_B2B_DETAIL_ATTRIBUTES = Object.freeze([
|
||||
'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',
|
||||
@ -70,6 +76,11 @@ const ORDER_B2B_DETAIL_EMPTY = Object.freeze({
|
||||
pickup_plate_number: null,
|
||||
prep_remark: null,
|
||||
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',
|
||||
picked_up_at: null,
|
||||
created_at: null,
|
||||
@ -82,6 +93,10 @@ const ORDER_B2B_DETAIL_FILTER_FIELDS = Object.freeze([
|
||||
'pickup_plate_number',
|
||||
'prep_remark',
|
||||
'prep_duration_seconds',
|
||||
'prep_status',
|
||||
'prep_operator_id',
|
||||
'prep_start_at',
|
||||
'is_urgent',
|
||||
'is_picked_up',
|
||||
'picked_up_at',
|
||||
'created_at',
|
||||
@ -1934,7 +1949,8 @@ class OrderBaseService extends MainService {
|
||||
* 不可被请求中的同名字段覆盖(用于 B2B 等固定域列表)。
|
||||
* @param {boolean} [options.b2bDetailFilter=false] 是否支持用 wms_order_b2b 作业明细字段
|
||||
* (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>} 列表与分页信息。
|
||||
*/
|
||||
async listByModule(moduleName = 'order', data = {}, options = {}) {
|
||||
@ -2023,7 +2039,11 @@ class OrderBaseService extends MainService {
|
||||
}
|
||||
|
||||
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 moduleConfig = this.getModuleConfig(moduleName);
|
||||
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 关联);
|
||||
* 无副表行时输出空值占位,保证响应字段结构稳定。附加字段:
|
||||
* 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 {number|string|null} [warehouseId=null] 仓库ID,缺省取当前上下文。
|
||||
* @return {Promise<Array<Object>>} 附加 B2B 作业明细后的列表。
|
||||
* @return {Promise<Array<Object>>} 附加 B2B 作业明细与图片后的列表。
|
||||
*/
|
||||
async attachB2bJobDetail(list = [], warehouseId = null) {
|
||||
const rows = Array.isArray(list) ? list : [];
|
||||
@ -2118,6 +2225,8 @@ class OrderBaseService extends MainService {
|
||||
const normalizedWarehouseId = Number(warehouseId ?? this.getWarehouseId() ?? 0);
|
||||
const b2bModel = this.ctx.model && this.ctx.model.OrderB2b;
|
||||
const detailMap = new Map();
|
||||
const imageMap = new Map();
|
||||
const pickupImageMap = new Map();
|
||||
|
||||
if (Number.isInteger(normalizedWarehouseId) && normalizedWarehouseId > 0
|
||||
&& b2bModel && typeof b2bModel.findAll === 'function') {
|
||||
@ -2141,29 +2250,138 @@ class OrderBaseService extends MainService {
|
||||
detailMap.set(orderId, detail);
|
||||
}
|
||||
}
|
||||
|
||||
await this.attachB2bImages({
|
||||
prepImageMap: imageMap,
|
||||
pickupImageMap,
|
||||
}, orderIds, normalizedWarehouseId);
|
||||
}
|
||||
}
|
||||
|
||||
return rows.map(row => {
|
||||
const detail = detailMap.get(Number(row && row.id || 0));
|
||||
if (!detail) {
|
||||
return { ...row, ...ORDER_B2B_DETAIL_EMPTY };
|
||||
}
|
||||
const orderId = Number(row && row.id || 0);
|
||||
const detail = detailMap.get(orderId);
|
||||
const images = imageMap.get(orderId) || [];
|
||||
const pickupImages = pickupImageMap.get(orderId) || [];
|
||||
|
||||
return {
|
||||
...row,
|
||||
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),
|
||||
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,
|
||||
...this.formatB2bDetailFields(detail),
|
||||
images,
|
||||
pickup_images: pickupImages,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量读取 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)。
|
||||
* @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 域列表使用)。
|
||||
*
|
||||
@ -2335,12 +2589,18 @@ class OrderBaseService extends MainService {
|
||||
? [ ...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 {
|
||||
detail: order,
|
||||
items: orderItemsWithStockInfo,
|
||||
expresses,
|
||||
waybill_codes: waybillCodes,
|
||||
logs,
|
||||
b2b,
|
||||
images,
|
||||
pickup_images: pickupImages,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@ -36,6 +36,7 @@ class DeliveryOrder2bService extends OrderBaseService {
|
||||
const result = await this.listByModule('deliveryOrder', data, {
|
||||
fixedWhere: B2B_FIXED_WHERE,
|
||||
b2bDetailFilter: true,
|
||||
urgentFirst: true,
|
||||
});
|
||||
return {
|
||||
...result,
|
||||
|
||||
@ -13,9 +13,9 @@ class OrderIndexService extends OrderBaseService {
|
||||
constructor(ctx) {
|
||||
super(ctx);
|
||||
const _noNeedLogin = '';
|
||||
const _noNeedRight = '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';
|
||||
const _noNeedAuth = '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,setB2bUrgent,cancelB2bUrgent,startB2bPrep,cancelB2bPrep,finishB2bPrep,updateB2bPackingItems,getB2bPackingSnapshot,setB2bPickupPlate,pickupB2b,updateB2bOrderImages';
|
||||
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);
|
||||
}
|
||||
|
||||
@ -115,6 +115,396 @@ class OrderIndexService extends OrderBaseService {
|
||||
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);
|
||||
|
||||
// B2B 订单附加副表作业明细(备货/提货/箱数/车牌)与备货/提货照片;非 B2B 订单 b2b=null、images=[]、pickup_images=[]
|
||||
const { b2b, images, pickup_images: pickupImages } = await this.buildB2bDetailExtras(order, warehouseId);
|
||||
|
||||
return {
|
||||
detail: order,
|
||||
items: orderItemsWithPicking,
|
||||
expresses,
|
||||
storage_items: storageItems,
|
||||
b2b,
|
||||
images,
|
||||
pickup_images: pickupImages,
|
||||
};
|
||||
}
|
||||
|
||||
@ -1044,7 +1050,7 @@ class PendingOrderService extends OrderBaseService {
|
||||
|
||||
try {
|
||||
const targetOrders = await model.findAll({
|
||||
attributes: [ 'id', 'wave_id', 'wave_no' ],
|
||||
attributes: [ 'id', 'wave_id', 'wave_no', 'is_b2b' ],
|
||||
where,
|
||||
raw: true,
|
||||
...dbQueryOptions,
|
||||
@ -1054,6 +1060,9 @@ class PendingOrderService extends OrderBaseService {
|
||||
throw new Error('订单不存在或不属于当前仓库');
|
||||
}
|
||||
|
||||
// B2B 订单走备货/提货作业链路,不支持反审回待审核:命中即整批驳回
|
||||
this.assertOrdersNotB2b(targetOrders, '反审回待审核');
|
||||
|
||||
const targetOrderIds = targetOrders
|
||||
.map(order => Number(order && order.id || 0))
|
||||
.filter(id => Number.isInteger(id) && id > 0);
|
||||
@ -3754,6 +3763,9 @@ class PendingOrderService extends OrderBaseService {
|
||||
}
|
||||
const original = existingOrders[0];
|
||||
|
||||
// B2B 订单走备货/提货作业链路,不支持克隆(克隆会取消原单并重建普通订单)
|
||||
this.assertOrdersNotB2b([ original ], '克隆订单');
|
||||
|
||||
if (!this.isCancelablePendingOrder(original)) {
|
||||
throw new Error('订单当前状态不允许克隆');
|
||||
}
|
||||
|
||||
@ -36,6 +36,7 @@ class PendingOrder2bService extends OrderBaseService {
|
||||
const result = await this.listByModule('pendingOrder', data, {
|
||||
fixedWhere: B2B_FIXED_WHERE,
|
||||
b2bDetailFilter: true,
|
||||
urgentFirst: true,
|
||||
});
|
||||
return {
|
||||
...result,
|
||||
|
||||
@ -4394,7 +4394,7 @@ class RecheckOrderService extends OrderBaseService {
|
||||
attributes: [
|
||||
'id', 'delivery_order_code', 'pre_delivery_order_code',
|
||||
'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,
|
||||
});
|
||||
@ -4404,6 +4404,9 @@ class RecheckOrderService extends OrderBaseService {
|
||||
orderMap.set(Number(row.id), row);
|
||||
}
|
||||
|
||||
// B2B 订单走备货/提货作业链路,不参与批量发货(快捷复核):命中即整批驳回
|
||||
this.assertOrdersNotB2b(orderRows, '批量发货');
|
||||
|
||||
// ── 2. 前置条件检查:将订单分为有效订单与跳过订单 ──
|
||||
const validOrders = [];
|
||||
const failedOrders = [];
|
||||
@ -4572,11 +4575,14 @@ class RecheckOrderService extends OrderBaseService {
|
||||
attributes: [
|
||||
'id', 'delivery_order_code', 'pre_delivery_order_code',
|
||||
'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,
|
||||
});
|
||||
|
||||
// 按波次批量发货同样对 B2B 订单无效:波次内命中 B2B 订单即整批驳回
|
||||
this.assertOrdersNotB2b(orderRows, '批量发货');
|
||||
|
||||
// 按 wave_id 分组
|
||||
const waveOrderMap = new Map();
|
||||
for (const row of orderRows) {
|
||||
|
||||
@ -8482,12 +8482,8 @@ class WaveService extends OrderBaseService {
|
||||
.map(row => Number(row && row.id || 0))
|
||||
.filter(id => Number.isInteger(id) && id > 0)) ]
|
||||
.sort((a, b) => a - b);
|
||||
// B2B 订单不参与波次抓取(NULL 视为非 B2B,兼容存量行)
|
||||
const excludedB2bOrderIds = [ ...new Set(normalizedOrderRows
|
||||
.filter(row => String(row && row.is_b2b || '').trim() === 'Y')
|
||||
.map(row => Number(row && row.id || 0))
|
||||
.filter(id => Number.isInteger(id) && id > 0)) ]
|
||||
.sort((a, b) => a - b);
|
||||
// B2B 订单走备货/提货作业链路,不参与波次抓取:命中即整批驳回(不做部分抓取)
|
||||
this.assertOrdersNotB2b(normalizedOrderRows, '抓取散单');
|
||||
// SN(序列号管理)订单允许按订单ID显式抓取散单:SN 策略只是「不自动出现在散单策略候选」,
|
||||
// 手工按订单抓取时不受限(manual_ids 波次在拣货侧固定走先拣后分 pick_mode=3,与 SN 策略一致),
|
||||
// 因此这里不再排除 SN 订单,excluded_sn_order_ids 保留在响应中但恒为空数组。
|
||||
@ -8515,11 +8511,6 @@ class WaveService extends OrderBaseService {
|
||||
return false;
|
||||
}
|
||||
|
||||
// B2B 订单不允许抓取波次
|
||||
if (String(row && row.is_b2b || '').trim() === 'Y') {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
@ -8541,7 +8532,6 @@ class WaveService extends OrderBaseService {
|
||||
excluded_existing_wave_order_ids: excludedExistingWaveOrderIds,
|
||||
excluded_intercepted_order_ids: excludedInterceptedOrderIds,
|
||||
excluded_locked_order_ids: excludedLockedOrderIds,
|
||||
excluded_b2b_order_ids: excludedB2bOrderIds,
|
||||
excluded_sn_order_ids: excludedSnOrderIds,
|
||||
skipped_order_ids: skippedOrderIds,
|
||||
not_found_order_ids: notFoundOrderIds,
|
||||
@ -8662,7 +8652,6 @@ class WaveService extends OrderBaseService {
|
||||
excluded_existing_wave_order_ids: excludedExistingWaveOrderIds,
|
||||
excluded_intercepted_order_ids: excludedInterceptedOrderIds,
|
||||
excluded_locked_order_ids: excludedLockedOrderIds,
|
||||
excluded_b2b_order_ids: excludedB2bOrderIds,
|
||||
excluded_sn_order_ids: excludedSnOrderIds,
|
||||
skipped_order_ids: skippedOrderIds,
|
||||
not_found_order_ids: notFoundOrderIds,
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -369,6 +369,14 @@ const WAREHOUSE_SETTING_FIELDS = Object.freeze([
|
||||
required: 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({
|
||||
key: 'stock_warning_enabled',
|
||||
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,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);
|
||||
},
|
||||
};
|
||||
@ -1,4 +1,129 @@
|
||||
[
|
||||
{
|
||||
"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",
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
{
|
||||
"module": "system",
|
||||
"description": "系统接口标准入口,method 对应系统内置方法,全部使用 POST 请求,参数统一放在 body 内",
|
||||
"version": "0.3.372",
|
||||
"updatedAt": "2026-11-18",
|
||||
"version": "0.3.375",
|
||||
"updatedAt": "2026-11-19",
|
||||
"headers": [
|
||||
{
|
||||
"name": "platform",
|
||||
@ -4242,12 +4242,157 @@
|
||||
"时间口径:prep_at 取服务端提交时刻;prep_duration_seconds = max(0, round((prep_at - prep_start_at)/1000)),prep_start_at 缺失时沿用原值(通常为 0)。",
|
||||
"操作日志:每个订单写一条 ORDER_B2B_PREP_FINISH(操作名称「备货完成」),提交后写入,失败仅告警。",
|
||||
"配套接口:order.startB2bPrep / order.cancelB2bPrep;列表侧 order.pendingOrder2b.list、order.deliveryOrder2b.list 输出 prep_status / prep_operator_id / prep_operator_name / prep_start_at 等字段并支持筛选。",
|
||||
"库存扣减口径(与拣货完成一致):备货完成在同一事务内按 wms_picking(order_id + warehouse_id + status=pending + 未删除,FOR UPDATE)汇总各 storage_id 数量 → 校验 wms_storage.locked_quantity 足够(不足直接失败回滚)→ 同时扣减 locked_quantity 与 quantity → 写入 wms_storage_transaction(transaction_type=OUTBOUND、order_type=PICK_OUTBOUND、order_id=订单ID、operator 为当前工号、remark=备货完成出库(B2B))→ 把 wms_picking 置 fin。订单无 pending 拣货记录时(未走拣货流程或已扣减过)不做任何库存变更,备货仍正常完成。"
|
||||
"库存扣减口径(与拣货完成一致):备货完成在同一事务内按 wms_picking(order_id + warehouse_id + status=pending + 未删除,FOR UPDATE)汇总各 storage_id 数量 → 校验 wms_storage.locked_quantity 足够(不足直接失败回滚)→ 同时扣减 locked_quantity 与 quantity → 写入 wms_storage_transaction(transaction_type=OUTBOUND、order_type=PICK_OUTBOUND、order_id=订单ID、operator 为当前工号、remark=备货完成出库(B2B))→ 把 wms_picking 置 fin。订单无 pending 拣货记录时(未走拣货流程或已扣减过)不做任何库存变更,备货仍正常完成。",
|
||||
"分箱齐套校验:读取当前仓库 subject_config.b2b_packing_quantity_check(默认 false);开启后,备货完成时逐个 wms_order_items 明细行校验 wms_order_b2b_items.quantity 合计等于 plan_qty,并校验 total_box_count 等于分箱箱号数,任一不符返回 failure 400(data.item_mismatches 带商品行、应拣与已分箱数量),事务回滚,不完成备货。"
|
||||
]
|
||||
},
|
||||
{
|
||||
"method": "order.updateB2bPackingItems",
|
||||
"description": "全量更新单个 B2B 订单的分箱商品明细。每条记录关联订单商品明细 order_item_id,并保存箱号 box_no 与该箱数量 quantity;本接口按整单全量替换,items 传空数组可清空,同时按不同箱号数同步 wms_order_b2b.total_box_count。仅当前仓库的 B2B 且备货中的订单可更新。",
|
||||
"isNeedAuth": false,
|
||||
"isNeedLogin": true,
|
||||
"headers": [
|
||||
{
|
||||
"name": "Authorization",
|
||||
"type": "string",
|
||||
"required": true,
|
||||
"description": "Bearer token"
|
||||
}
|
||||
],
|
||||
"params": [
|
||||
{
|
||||
"name": "ids / order_ids / orderIds / id / order_id / orderId",
|
||||
"type": "number",
|
||||
"required": true,
|
||||
"source": "body",
|
||||
"description": "订单ID(仅允许传 1 个;支持单值或单元素数组)"
|
||||
},
|
||||
{
|
||||
"name": "items",
|
||||
"type": "array<object>",
|
||||
"required": true,
|
||||
"source": "body",
|
||||
"description": "完整分箱明细数组,最多 10000 条;每项包含 order_item_id(订单商品明细ID)、box_no(箱号,最长 50 字符)、quantity(该商品在该箱的正整数数量);同一商品行与箱号不能重复。支持驼峰别名 orderItemId / boxNo。"
|
||||
}
|
||||
],
|
||||
"response": [
|
||||
{
|
||||
"name": "order_id",
|
||||
"type": "number",
|
||||
"required": true,
|
||||
"description": "订单ID"
|
||||
},
|
||||
{
|
||||
"name": "item_count",
|
||||
"type": "number",
|
||||
"required": true,
|
||||
"description": "本次保存的分箱明细行数"
|
||||
},
|
||||
{
|
||||
"name": "box_count",
|
||||
"type": "number",
|
||||
"required": true,
|
||||
"description": "不同箱号的数量"
|
||||
}
|
||||
],
|
||||
"errors": [
|
||||
{
|
||||
"code": "400",
|
||||
"message": "订单ID、items 或分箱明细格式不合法;订单非 B2B、已取消、未备货中或商品行不属于该订单"
|
||||
}
|
||||
],
|
||||
"notes": [
|
||||
"数据表 wms_order_b2b_items 按 warehouse_id + order_id 隔离,关联订单明细 ID;更新在事务内先删除该订单旧分箱行,再写入新快照,并同步总箱数。",
|
||||
"分箱数量和应拣数量是否必须相等由仓库配置 subject_config.b2b_packing_quantity_check 控制;本接口只校验数据格式与商品行归属。"
|
||||
]
|
||||
},
|
||||
{
|
||||
"method": "order.getB2bPackingSnapshot",
|
||||
"description": "查询单个 B2B 订单的商品明细与分箱快照。商品明细返回应拣数量、已分箱数量、对应箱号/箱内数量,以及该商品需要从哪些储位取货(取货储位来自订单储位分配表 wms_picking);同时返回订单号、订单状态、备货状态、总箱数、取货储位数量与当前仓库是否开启齐套校验。",
|
||||
"isNeedAuth": false,
|
||||
"isNeedLogin": true,
|
||||
"headers": [
|
||||
{
|
||||
"name": "Authorization",
|
||||
"type": "string",
|
||||
"required": true,
|
||||
"description": "Bearer token"
|
||||
}
|
||||
],
|
||||
"params": [
|
||||
{
|
||||
"name": "ids / order_ids / orderIds / id / order_id / orderId",
|
||||
"type": "number",
|
||||
"required": true,
|
||||
"source": "body",
|
||||
"description": "订单ID(仅允许传 1 个;支持单值或单元素数组)"
|
||||
}
|
||||
],
|
||||
"response": [
|
||||
{
|
||||
"name": "order_id",
|
||||
"type": "number",
|
||||
"required": true,
|
||||
"description": "订单ID"
|
||||
},
|
||||
{
|
||||
"name": "delivery_order_code",
|
||||
"type": "string",
|
||||
"required": true,
|
||||
"description": "发货单号"
|
||||
},
|
||||
{
|
||||
"name": "status",
|
||||
"type": "string",
|
||||
"required": false,
|
||||
"description": "订单状态"
|
||||
},
|
||||
{
|
||||
"name": "prep_status",
|
||||
"type": "string",
|
||||
"required": true,
|
||||
"description": "备货状态,无作业明细时为 none"
|
||||
},
|
||||
{
|
||||
"name": "total_box_count",
|
||||
"type": "number",
|
||||
"required": true,
|
||||
"description": "订单总箱数"
|
||||
},
|
||||
{
|
||||
"name": "pick_location_count",
|
||||
"type": "number",
|
||||
"required": true,
|
||||
"description": "取货储位数量(本单 wms_picking 涉及的不同储位个数),未分配储位时为 0"
|
||||
},
|
||||
{
|
||||
"name": "require_packing_quantity_match",
|
||||
"type": "boolean",
|
||||
"required": true,
|
||||
"description": "当前仓库是否启用分箱数量齐套校验"
|
||||
},
|
||||
{
|
||||
"name": "items",
|
||||
"type": "array<object>",
|
||||
"required": true,
|
||||
"description": "订单商品明细数组;每项含 order_item_id、item_id、stock_id、item_code、item_name、item_snapshot、plan_qty、packed_quantity、boxes({box_no, quantity} 数组)、pick_locations(取货储位数组)"
|
||||
}
|
||||
],
|
||||
"errors": [
|
||||
{
|
||||
"code": "400",
|
||||
"message": "订单ID不合法、订单不存在或订单不是 B2B"
|
||||
}
|
||||
],
|
||||
"notes": [
|
||||
"先查当前订单分表,未命中时查配送分表;商品明细从对应分表读取,分箱数据按 warehouse_id + order_id 读取。",
|
||||
"该接口返回只读完整快照;提交变更请使用 order.updateB2bPackingItems。",
|
||||
"取货储位口径:按 warehouse_id + order_id 查询 wms_picking(订单储位分配结果,排除 status=cancel),按 order_item_id 分到每个商品明细行,同一商品在同一储位(space_id,缺失时退回 space_name)的多条分配记录合并为一条并累加数量,按库位名称升序输出 pick_locations:[{ space_id, space_name, quantity }];pick_location_count 为本单涉及的不同储位个数,未分配储位时 items[].pick_locations 输出空数组、pick_location_count 为 0。"
|
||||
]
|
||||
},
|
||||
{
|
||||
"method": "order.pickupB2b",
|
||||
"description": "B2B 提货(仅 B2B 订单,单订单作业)。传入单个订单ID,记录提货时间:把 wms_order_b2b.is_picked_up 置为 'Y'、picked_up_at 置为提交时刻(即提货时间)。要求订单为 B2B(is_b2b=Y)、未取消,且备货已完成(prep_status=fin);已提货订单重复调用幂等成功并返回首次提货时间。订单先在 current 分表查找,未命中兜底 dispatch 分表。提货时间写入后,order.pendingOrder2b.list / order.deliveryOrder2b.list 的 is_picked_up、picked_up_at 字段立即反映。",
|
||||
"description": "B2B 提货(仅 B2B 订单,单订单作业)。传入单个订单ID,记录提货时间:把 wms_order_b2b.is_picked_up 置为 'Y'、picked_up_at 置为提交时刻(即提货时间)。要求订单为 B2B(is_b2b=Y)、未取消,且备货已完成(prep_status=fin);已提货订单重复调用幂等成功并返回首次提货时间。订单先在 current 分表查找,未命中兜底 dispatch 分表。提货时间写入后,order.pendingOrder2b.list / order.deliveryOrder2b.list 的 is_picked_up、picked_up_at 字段立即反映。提货即出库完成:同一事务内把订单所在分表(current 优先、dispatch 兜底)的 outbound_status 置 fin、step 置 4、delivery_time 置提货时间,由既有出库迁移调度(schedule/sync_outbound_orders_to_delivery:outbound_status IN (fin,padding) 且 step IN (4,9))把订单搬到配送表(dispatch_lane=m4),随后可从 order.deliveryOrder2b.list 查询;大屏 B2B 今日出库统计(outbound_status=fin + delivery_time 当日)同步生效。已提货但主表未完成出库的历史订单,重复调用会按首次提货时间补写(自愈),不重复写操作日志。可选传 pickup_plate_number 与 pickup_file_ids:车牌在同一事务内写入提货车牌(归一化后落库),提货照片只做存在性校验后追加到 business_type=b2b_pickup 的关联下;提货完成后车牌随提货锁定,不允许再改。",
|
||||
"isNeedAuth": false,
|
||||
"isNeedLogin": true,
|
||||
"headers": [
|
||||
@ -4265,6 +4410,20 @@
|
||||
"required": true,
|
||||
"source": "body",
|
||||
"description": "订单ID(单订单作业,仅允许传 1 个;支持单值或单元素数组)。取值优先级:ids > order_ids > orderIds > id > order_id > orderId;传多个订单ID返回 failure 400「提货仅支持单个订单,请单条提交」。"
|
||||
},
|
||||
{
|
||||
"name": "pickup_plate_number / pickupPlateNumber",
|
||||
"type": "string",
|
||||
"required": false,
|
||||
"source": "body",
|
||||
"description": "提货车牌(可选)。传空字符串或 null 表示清空;归一化规则:去掉空格与 ·/•/-/-/_ 分隔符并转大写,首字符须为汉字或字母、整体 5~10 位(兼容军牌、使领馆牌、挂车等特殊牌照)。订单已提货时传与原车牌不同的值返回 failure 400。"
|
||||
},
|
||||
{
|
||||
"name": "pickup_file_ids / pickupFileIds / file_ids / fileIds / pickup_images",
|
||||
"type": "array<object>|array<number>",
|
||||
"required": false,
|
||||
"source": "body",
|
||||
"description": "提货照片 file_id 列表(可选)。上传接口(index/ajax/upload 等)返回 file_id 后,提货时随单一次性提交即可,无需再调其它接口维护。元素支持 file_id 或 { file_id, display_order };只做一轮存在性校验(wms_file 未删除、不校验仓库归属),通过后追加写入 business_type=b2b_pickup 的关联,不覆盖已有提货照片;不传则不写任何照片。"
|
||||
}
|
||||
],
|
||||
"response": [
|
||||
@ -4280,6 +4439,24 @@
|
||||
"required": true,
|
||||
"description": "提货时间:本次写入时为提交时刻;已提货幂等命中时为首次提货时间"
|
||||
},
|
||||
{
|
||||
"name": "pickup_plate_number",
|
||||
"type": "string",
|
||||
"required": false,
|
||||
"description": "订单当前提货车牌:本次传入时为新值,未传时为库中已有值,均无车牌时为 null"
|
||||
},
|
||||
{
|
||||
"name": "pickup_images",
|
||||
"type": "array<object>",
|
||||
"required": true,
|
||||
"description": "订单当前提货照片列表(business_type=b2b_pickup),元素 { file_id, url, display_order };无照片输出空数组"
|
||||
},
|
||||
{
|
||||
"name": "pickup_image_count",
|
||||
"type": "number",
|
||||
"required": true,
|
||||
"description": "订单当前提货照片数量"
|
||||
},
|
||||
{
|
||||
"name": "picked_up_order_ids",
|
||||
"type": "number[]",
|
||||
@ -4297,6 +4474,24 @@
|
||||
"type": "boolean",
|
||||
"required": true,
|
||||
"description": "是否为重复提货(true=已提货幂等命中,未改写提货时间与操作日志;false=本次首次提货)"
|
||||
},
|
||||
{
|
||||
"name": "outbound_status",
|
||||
"type": "string",
|
||||
"required": true,
|
||||
"description": "提货后订单主表出库状态,固定为 fin"
|
||||
},
|
||||
{
|
||||
"name": "step",
|
||||
"type": "number",
|
||||
"required": true,
|
||||
"description": "提货后订单主表步骤,固定为 4(已出库,等待迁移到配送表)"
|
||||
},
|
||||
{
|
||||
"name": "outbound_marked",
|
||||
"type": "boolean",
|
||||
"required": true,
|
||||
"description": "本次调用是否写入了主表出库状态(已提货且主表已完成出库时为 false)"
|
||||
}
|
||||
],
|
||||
"errors": [
|
||||
@ -4319,6 +4514,18 @@
|
||||
{
|
||||
"code": "500",
|
||||
"message": "未识别到当前仓库上下文,HTTP 500,message 为「接口错误: 未识别到当前仓库上下文」"
|
||||
},
|
||||
{
|
||||
"code": "400",
|
||||
"message": "订单已提货,不允许修改提货车牌(响应体 flag=failure、code=400,data 带 order_id 与现有 pickup_plate_number)"
|
||||
},
|
||||
{
|
||||
"code": "400",
|
||||
"message": "车牌格式不正确 / 车牌超过 20 个字符(响应体 flag=failure、code=400,data 带 pickup_plate_number)"
|
||||
},
|
||||
{
|
||||
"code": "400",
|
||||
"message": "提货照片文件不存在或已删除:{file_ids}(响应体 flag=failure、code=400,data.file_ids 返回缺失文件ID;整个提货事务回滚)"
|
||||
}
|
||||
],
|
||||
"notes": [
|
||||
@ -4328,12 +4535,20 @@
|
||||
"落库位置:wms_order_b2b 按 warehouse_id + order_id 更新 is_picked_up、picked_up_at;不改订单主表状态。",
|
||||
"操作日志:首次提货写一条 ORDER_B2B_PICKUP(操作名称「B2B提货」,说明「B2B订单提货」),提交后写入,失败仅告警。",
|
||||
"单订单口径:只接受 1 个订单ID,传多个直接 failure 400,不做部分处理;批量提货请由前端按订单循环调用。",
|
||||
"配套接口:order.startB2bPrep / order.cancelB2bPrep / order.finishB2bPrep(备货作业),order.setB2bUrgent / order.cancelB2bUrgent(加急)。"
|
||||
"配套接口:order.startB2bPrep / order.cancelB2bPrep / order.finishB2bPrep(备货作业),order.setB2bUrgent / order.cancelB2bUrgent(加急)。",
|
||||
"出库联动(提货即出库完成):提货成功时在同一事务内更新订单所在分表 outbound_status=fin、step=4、delivery_time=提货时间、updated_at=当前时间,与 order.markOutboundOrder(手动出库)口径一致;此后由定时任务 sync_outbound_orders_to_delivery 按 outbound_status IN (fin,padding) 且 step IN (4,9) 把订单迁移到配送表(写入 dispatch_lane=m4、dispath_time),迁移脚本无需为 B2B 增加任何特判条件。",
|
||||
"历史数据自愈:is_picked_up=Y 但主表 outbound_status 非 fin 或 step 非 4 的订单,再次调用提货会以首次 picked_up_at 作为 delivery_time 补写出库状态;已提货且主表已出库时不做任何更新(outbound_marked=false)。",
|
||||
"为什么不把 B2B 条件加进迁移脚本:迁移是通用表搬运,按订单状态驱动(不 join 业务副表);若以 wms_order_b2b.is_picked_up 作为迁移条件,会重复业务判定、无法同时修正主表状态与 delivery_time 统计口径,且迁移后源行被删除、current 表状态与配送域语义不一致。",
|
||||
"提货车牌(可选):传 pickup_plate_number / pickupPlateNumber 时,在同一事务内随提货写入 wms_order_b2b.pickup_plate_number;不传则保持库中原值不变。",
|
||||
"车牌锁定口径:提货即出库,已提货订单的车牌不允许再修改——重复提货时传入与原车牌不同的值返回 failure 400「订单已提货,不允许修改提货车牌」,传入相同值时幂等成功。",
|
||||
"车牌归一化与校验同 order.setB2bPickupPlate:去空格与分隔符后转大写;首字符为汉字或字母、整体 5~10 位,仅拦截明显无效输入。",
|
||||
"提货前单独录入/修改车牌请使用 order.setB2bPickupPlate。",
|
||||
"提货照片(可选):传 pickup_file_ids(兼容 pickupFileIds / file_ids / fileIds / pickup_images)时,在同一事务内先做一轮存在性校验,再追加写入 wms_file_reference(business_type=b2b_pickup,display_order 顺延已有最大序号);重复提货传同一批照片幂等,不会重复插入。"
|
||||
]
|
||||
},
|
||||
{
|
||||
"method": "order.updateB2bOrderImages",
|
||||
"description": "更新 B2B 订单图片(单订单,全量覆盖)。图片关系统一落在 wms_file_reference:business_type 固定为 b2b_order、business_id 为订单ID(字符串)、warehouse_id 为当前登录仓库、display_order 控制展示顺序,文件本体复用 wms_file(不做物理删除)。传入 images 为全量覆盖语义:未包含的旧关联会被删除、新关联按列表顺序写入,传空数组表示清空该订单图片;仅 B2B 订单(is_b2b=Y)且未取消的订单可更新,订单在 current 分表优先、dispatch 分表兜底查找,文件必须属于当前仓库且未删除。",
|
||||
"description": "更新 B2B 订单备货留证照片(单订单,全量覆盖)。图片关系统一落在 wms_file_reference:business_type 固定为 b2b_order(备货留证照片,与提货照片 b2b_pickup 分开存放)、business_id 为订单ID(字符串)、warehouse_id 为当前登录仓库、display_order 控制展示顺序,文件本体复用 wms_file(不做物理删除)。传入 images 为全量覆盖语义:未包含的旧关联会被删除、新关联按列表顺序写入,传空数组表示清空该订单图片;仅 B2B 订单(is_b2b=Y)且未取消的订单可更新,订单在 current 分表优先、dispatch 分表兜底查找,文件必须属于当前仓库且未删除。",
|
||||
"isNeedAuth": false,
|
||||
"isNeedLogin": true,
|
||||
"headers": [
|
||||
@ -4383,7 +4598,7 @@
|
||||
"name": "images",
|
||||
"type": "array",
|
||||
"required": true,
|
||||
"description": "更新后的图片列表(按 display_order、id 升序)",
|
||||
"description": "更新后的备货照片列表(按 display_order、id 升序)",
|
||||
"children": [
|
||||
{
|
||||
"name": "file_id",
|
||||
@ -4456,7 +4671,116 @@
|
||||
"订单校验:仅 is_b2b=Y 的订单可更新;status=cancel 的订单不允许更新;订单查找 current 分表优先、dispatch 分表兜底(配送域 B2B 订单)。",
|
||||
"操作日志:成功后写一条 ORDER_B2B_IMAGES(操作名称「更新B2B订单图片」),extras 带 image_count / added_file_ids / removed_file_ids;失败仅告警不影响主流程。",
|
||||
"列表联动:order.pendingOrder2b.list / order.deliveryOrder2b.list 已按页批量挂载 images: [{ id: file_id, url, display_order }](按 display_order 升序),无图片输出空数组。",
|
||||
"实现:app/service/systems/order_b2b.js#updateOrderImages(含 normalizeOrderImages 归一化),出口 app/service/systemMethods/order/index.js#updateB2bOrderImages;列表挂载见 app/service/systemMethods/order/base.js#attachB2bJobDetail / #attachB2bOrderImages。"
|
||||
"实现:app/service/systems/order_b2b.js#updateOrderImages(含 normalizeOrderImages 归一化),出口 app/service/systemMethods/order/index.js#updateB2bOrderImages;列表挂载见 app/service/systemMethods/order/base.js#attachB2bJobDetail / #attachB2bOrderImages。",
|
||||
"业务类型区分:备货照片固定 business_type=b2b_order,提货照片固定 business_type=b2b_pickup(提货时随 order.pickupB2b 传入 pickup_file_ids 写入),两者在 order.pendingOrder.detail / order.deliveryOrder.detail 中分别输出 images 与 pickup_images,互不覆盖。"
|
||||
]
|
||||
},
|
||||
{
|
||||
"method": "order.setB2bPickupPlate",
|
||||
"description": "录入/修改 B2B 提货车牌(仅 B2B 订单,单订单作业,提货前可改)。传单个订单ID与车牌,车牌归一化(去空格与 ·/•/-/-/_ 分隔符后转大写)并写入 wms_order_b2b.pickup_plate_number;传空字符串或 null 表示清空车牌。仅 is_b2b=Y 且未取消的订单可录入,作业明细行缺失时按默认值补建。订单已提货(is_picked_up=Y)后车牌随提货锁定,不允许再修改。车牌也可在 order.pickupB2b 提货时通过 pickup_plate_number 一并写入。",
|
||||
"isNeedAuth": false,
|
||||
"isNeedLogin": true,
|
||||
"headers": [
|
||||
{
|
||||
"name": "Authorization",
|
||||
"type": "string",
|
||||
"required": true,
|
||||
"description": "Bearer token"
|
||||
}
|
||||
],
|
||||
"params": [
|
||||
{
|
||||
"name": "ids / order_ids / orderIds / id / order_id / orderId",
|
||||
"type": "number",
|
||||
"required": true,
|
||||
"source": "body",
|
||||
"description": "订单ID(单订单作业,仅允许传 1 个;支持单值或单元素数组)。取值优先级:ids > order_ids > orderIds > id > order_id > orderId;传多个订单ID返回 failure 400「录入提货车牌仅支持单个订单,请单条提交」。"
|
||||
},
|
||||
{
|
||||
"name": "pickup_plate_number / pickupPlateNumber",
|
||||
"type": "string",
|
||||
"required": true,
|
||||
"source": "body",
|
||||
"description": "提货车牌(键必须传;传空字符串或 null 表示清空)。归一化:去掉空格与 ·/•/-/-/_ 分隔符并转大写;基础格式校验为首字符为汉字或字母、整体 5~10 位汉字/字母/数字组合(兼容军牌、使领馆牌、挂车等特殊牌照),超长(>20 字符)或明显无效返回 failure 400。"
|
||||
}
|
||||
],
|
||||
"response": [
|
||||
{
|
||||
"name": "order_id",
|
||||
"type": "number",
|
||||
"required": true,
|
||||
"description": "订单ID"
|
||||
},
|
||||
{
|
||||
"name": "delivery_order_code",
|
||||
"type": "string",
|
||||
"required": true,
|
||||
"description": "发货单号"
|
||||
},
|
||||
{
|
||||
"name": "pickup_plate_number",
|
||||
"type": "string",
|
||||
"required": false,
|
||||
"description": "本次落库的提货车牌(归一化后);清空时为 null"
|
||||
},
|
||||
{
|
||||
"name": "previous_pickup_plate_number",
|
||||
"type": "string",
|
||||
"required": false,
|
||||
"description": "修改前的提货车牌;原本无车牌时为 null"
|
||||
},
|
||||
{
|
||||
"name": "changed",
|
||||
"type": "boolean",
|
||||
"required": true,
|
||||
"description": "车牌是否发生变化(false 表示与原值一致,未重复写操作日志)"
|
||||
},
|
||||
{
|
||||
"name": "detail_created",
|
||||
"type": "boolean",
|
||||
"required": true,
|
||||
"description": "作业明细行是否本次补建(true=原无 wms_order_b2b 行)"
|
||||
}
|
||||
],
|
||||
"errors": [
|
||||
{
|
||||
"code": "400",
|
||||
"message": "订单ID不能为空(HTTP 仍为 200,响应体 flag=failure、code=400)"
|
||||
},
|
||||
{
|
||||
"code": "400",
|
||||
"message": "pickup_plate_number 参数不能为空(未传该键;清空请传空字符串或 null)"
|
||||
},
|
||||
{
|
||||
"code": "400",
|
||||
"message": "车牌格式不正确 / 车牌超过 20 个字符(响应体 flag=failure、code=400,data 带 pickup_plate_number)"
|
||||
},
|
||||
{
|
||||
"code": "400",
|
||||
"message": "仅 B2B 订单支持录入提货车牌 / 订单不存在(响应体 flag=failure、code=400,data 带 not_b2b_order_ids 或 not_found_order_ids)"
|
||||
},
|
||||
{
|
||||
"code": "400",
|
||||
"message": "订单已取消 / 订单已提货不允许修改提货车牌(响应体 flag=failure、code=400,data 带 order_id 与 pickup_plate_number)"
|
||||
},
|
||||
{
|
||||
"code": "400",
|
||||
"message": "录入提货车牌仅支持单个订单,请单条提交(响应体 flag=failure、code=400,data.order_ids 返回传入的多个订单ID)"
|
||||
},
|
||||
{
|
||||
"code": "500",
|
||||
"message": "未识别到当前仓库上下文,HTTP 500,message 为「接口错误: 未识别到当前仓库上下文」"
|
||||
}
|
||||
],
|
||||
"notes": [
|
||||
"单订单口径:只接受 1 个订单ID,传多个直接 failure 400,不做部分处理;批量录入请由前端按订单循环调用。",
|
||||
"生效范围(仅 B2B 订单):订单必须存在于当前仓库(current 分表优先、dispatch 分表兜底)且 is_b2b=Y,否则返回 failure 400。",
|
||||
"可改时机:提货前(is_picked_up=N)可反复录入/修改/清空;提货后车牌锁定,返回 failure 400「订单已提货,不允许修改提货车牌」,避免出库后留证与实物/车辆对不上。",
|
||||
"落库位置:wms_order_b2b 按 warehouse_id + order_id 更新 pickup_plate_number;作业明细行缺失时按默认值补建(total_box_count=0、prep_duration_seconds=0、is_picked_up=N 等)。",
|
||||
"车牌归一化:去掉空格与 ·/•/-/-/_ 分隔符并转大写,例如「 粤b·12345 」→「粤B12345」;基础格式校验为首字符为汉字或字母、整体 5~10 位(兼容军牌、使领馆牌、挂车等特殊牌照)。",
|
||||
"操作日志:车牌实际发生变化时写一条 ORDER_B2B_PICKUP_PLATE(操作名称「录入B2B提货车牌」,extras 带新旧车牌),提交后写入,失败仅告警不影响主流程;值未变化不写日志。",
|
||||
"列表联动:order.pendingOrder2b.list / order.deliveryOrder2b.list 的 pickup_plate_number 字段与 where.pickup_plate_number 筛选立即生效,可用于提货台按车牌找单。",
|
||||
"配套接口:order.pickupB2b(提货时可用 pickup_plate_number 一并写入)、order.finishB2bPrep(备货完成)、order.updateB2bOrderImages(订单留证图片)。"
|
||||
]
|
||||
}
|
||||
]
|
||||
@ -4831,7 +5155,7 @@
|
||||
},
|
||||
{
|
||||
"method": "order.pendingOrder.detail",
|
||||
"description": "查询单个订单详情,返回订单头、商品明细和运单信息;忽略传入的表位参数,固定先查配送表(dispatch),查不到再兜底查询待处理表(current);运单信息强制同仓校验:wms_order_express 按「订单ID + 订单所属仓库ID」隔离读取,禁止仅凭订单ID跨仓串读运单号",
|
||||
"description": "查询单个订单详情,返回订单头、商品明细和运单信息;忽略传入的表位参数,固定先查配送表(dispatch),查不到再兜底查询待处理表(current);运单信息强制同仓校验:wms_order_express 按「订单ID + 订单所属仓库ID」隔离读取,禁止仅凭订单ID跨仓串读运单号B2B 订单额外返回副表 b2b 作业明细与 images 订单图片。",
|
||||
"isNeedAuth": false,
|
||||
"isNeedLogin": true,
|
||||
"headers": [
|
||||
@ -4882,6 +5206,24 @@
|
||||
"type": "array",
|
||||
"description": "按库位平铺的储位分配明细(附商品编码、名称、规格、单位等库存信息)",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"name": "b2b",
|
||||
"type": "object|null",
|
||||
"required": true,
|
||||
"description": "B2B 作业明细对象(仅 is_b2b=Y 输出,非 B2B 为 null;副表无行时输出空值占位)。子字段: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。"
|
||||
},
|
||||
{
|
||||
"name": "images",
|
||||
"type": "array",
|
||||
"required": true,
|
||||
"description": "B2B 订单备货留证照片(business_type=b2b_order),元素 { id: file_id, url, display_order };无图片输出空数组。"
|
||||
},
|
||||
{
|
||||
"name": "pickup_images",
|
||||
"type": "array<object>",
|
||||
"required": true,
|
||||
"description": "B2B 订单提货留证照片(business_type=b2b_pickup),元素 { id: file_id, url, display_order };无图片输出空数组;与 images(备货照片)分开输出。"
|
||||
}
|
||||
],
|
||||
"errors": [
|
||||
@ -4897,6 +5239,10 @@
|
||||
"code": "500",
|
||||
"message": "内部错误"
|
||||
}
|
||||
],
|
||||
"notes": [
|
||||
"B2B 订单附加字段(仅 is_b2b=Y 的订单):b2b 为副表 wms_order_b2b 作业明细对象(total_box_count 总箱数 / pickup_plate_number 提货车牌 / prep_remark 备货备注 / prep_duration_seconds 备货用时 / prep_status 备货状态 none|padding|fin / prep_operator_id 备货人工号 / prep_operator_name 备货人姓名 / prep_start_at 备货开始时间 / is_urgent 是否加急 / is_picked_up 是否提货 / picked_up_at 提货时间 / created_at 副表创建时间 / prep_at 备货完成时间);副表行缺失时输出空值占位(total_box_count=0、prep_status=none、is_urgent=N、is_picked_up=N 等),字段结构稳定。非 B2B 订单 b2b 固定为 null。",
|
||||
"images 为 B2B 订单图片数组:[{ id: file_id, url: 文件地址, display_order: 展示顺序 }],数据源 wms_file_reference(business_type=b2b_order,按 display_order、id 升序);非 B2B 或无图片时输出空数组。图片维护接口见 order.updateB2bOrderImages。"
|
||||
]
|
||||
},
|
||||
{
|
||||
@ -7550,6 +7896,18 @@
|
||||
"type": "string",
|
||||
"required": false,
|
||||
"description": "B2B 作业明细创建时间(wms_order_b2b.created_at),与订单自身的 create_at 不同;无作业明细行时为 null"
|
||||
},
|
||||
{
|
||||
"name": "images",
|
||||
"type": "array<object>",
|
||||
"required": true,
|
||||
"description": "B2B 订单备货留证照片(wms_file_reference business_type=b2b_order),元素 { id: file_id, url, display_order };无图片输出空数组"
|
||||
},
|
||||
{
|
||||
"name": "pickup_images",
|
||||
"type": "array<object>",
|
||||
"required": true,
|
||||
"description": "B2B 订单提货留证照片(wms_file_reference business_type=b2b_pickup),元素 { id: file_id, url, display_order };与 images(备货照片)一次查询后分组输出,无图片输出空数组"
|
||||
}
|
||||
],
|
||||
"errors": [
|
||||
@ -13733,7 +14091,7 @@
|
||||
},
|
||||
{
|
||||
"method": "order.deliveryOrder.detail",
|
||||
"description": "查询单个订单详情,返回订单头、商品明细和运单信息",
|
||||
"description": "查询单个订单详情,返回订单头、商品明细和运单信息B2B 订单额外返回副表 b2b 作业明细与 images 订单图片。",
|
||||
"isNeedAuth": false,
|
||||
"isNeedLogin": true,
|
||||
"headers": [
|
||||
@ -13790,6 +14148,24 @@
|
||||
"type": "array",
|
||||
"required": true,
|
||||
"description": "去重后的运单号字符串数组"
|
||||
},
|
||||
{
|
||||
"name": "b2b",
|
||||
"type": "object|null",
|
||||
"required": true,
|
||||
"description": "B2B 作业明细对象(仅 is_b2b=Y 输出,非 B2B 为 null;副表无行时输出空值占位)。子字段: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。"
|
||||
},
|
||||
{
|
||||
"name": "images",
|
||||
"type": "array",
|
||||
"required": true,
|
||||
"description": "B2B 订单备货留证照片(business_type=b2b_order),元素 { id: file_id, url, display_order };无图片输出空数组。"
|
||||
},
|
||||
{
|
||||
"name": "pickup_images",
|
||||
"type": "array<object>",
|
||||
"required": true,
|
||||
"description": "B2B 订单提货留证照片(business_type=b2b_pickup),元素 { id: file_id, url, display_order };无图片输出空数组;与 images(备货照片)分开输出。"
|
||||
}
|
||||
],
|
||||
"errors": [
|
||||
@ -13805,6 +14181,10 @@
|
||||
"code": "500",
|
||||
"message": "内部错误"
|
||||
}
|
||||
],
|
||||
"notes": [
|
||||
"B2B 订单附加字段(仅 is_b2b=Y 的订单):b2b 为副表 wms_order_b2b 作业明细对象(total_box_count 总箱数 / pickup_plate_number 提货车牌 / prep_remark 备货备注 / prep_duration_seconds 备货用时 / prep_status 备货状态 none|padding|fin / prep_operator_id 备货人工号 / prep_operator_name 备货人姓名 / prep_start_at 备货开始时间 / is_urgent 是否加急 / is_picked_up 是否提货 / picked_up_at 提货时间 / created_at 副表创建时间 / prep_at 备货完成时间);副表行缺失时输出空值占位(total_box_count=0、prep_status=none、is_urgent=N、is_picked_up=N 等),字段结构稳定。非 B2B 订单 b2b 固定为 null。",
|
||||
"images 为 B2B 订单图片数组:[{ id: file_id, url: 文件地址, display_order: 展示顺序 }],数据源 wms_file_reference(business_type=b2b_order,按 display_order、id 升序);非 B2B 或无图片时输出空数组。图片维护接口见 order.updateB2bOrderImages。"
|
||||
]
|
||||
},
|
||||
{
|
||||
@ -14367,6 +14747,18 @@
|
||||
"type": "string",
|
||||
"required": false,
|
||||
"description": "B2B 作业明细创建时间(wms_order_b2b.created_at),与订单自身的 create_at 不同;无作业明细行时为 null"
|
||||
},
|
||||
{
|
||||
"name": "images",
|
||||
"type": "array<object>",
|
||||
"required": true,
|
||||
"description": "B2B 订单备货留证照片(wms_file_reference business_type=b2b_order),元素 { id: file_id, url, display_order };无图片输出空数组"
|
||||
},
|
||||
{
|
||||
"name": "pickup_images",
|
||||
"type": "array<object>",
|
||||
"required": true,
|
||||
"description": "B2B 订单提货留证照片(wms_file_reference business_type=b2b_pickup),元素 { id: file_id, url, display_order };与 images(备货照片)一次查询后分组输出,无图片输出空数组"
|
||||
}
|
||||
],
|
||||
"errors": [
|
||||
@ -17068,6 +17460,12 @@
|
||||
"required": false,
|
||||
"description": "散单称重是否需要打包(flag,默认 false 关闭):开启后散单称重(订单波次范围 wave_scope 非 1 大团购/3 小团购)须处于打包中或已打包(pack_status=padding/fin);未打包或打包异常时拒绝称重并返回错误"
|
||||
},
|
||||
{
|
||||
"name": "subject_config.b2b_packing_quantity_check",
|
||||
"type": "boolean",
|
||||
"required": false,
|
||||
"description": "B2B备货完成是否校验逐商品分箱齐套,默认 false;开启后分箱数量合计须等于订单商品 plan_qty,且总箱数须等于箱号数"
|
||||
},
|
||||
{
|
||||
"name": "subject_config.return_unpack_max_record_minutes",
|
||||
"type": "number",
|
||||
@ -17447,6 +17845,13 @@
|
||||
"source": "body.subject_config",
|
||||
"description": "散单称重是否需要打包(flag,默认 false 关闭):开启后散单称重(wave_scope 非 1 大团购/3 小团购)须处于打包中或已打包(pack_status=padding/fin)。仅接受布尔/like-flag(true/1/'1'/'true' → true;false/0/'0'/'false' → false),非法值报 400:subject_config.single_weigh_require_pack 必须是布尔值"
|
||||
},
|
||||
{
|
||||
"name": "subject_config.b2b_packing_quantity_check",
|
||||
"type": "boolean",
|
||||
"required": false,
|
||||
"source": "body.subject_config",
|
||||
"description": "B2B备货完成是否校验逐商品分箱齐套,默认 false。仅接受布尔/like-flag(true/1/'1'/'true' → true;false/0/'0'/'false' → false),非法值报 400"
|
||||
},
|
||||
{
|
||||
"name": "subject_config.return_unpack_max_record_minutes",
|
||||
"type": "number",
|
||||
|
||||
@ -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 () => {
|
||||
const { service, capture } = createPendingOrderService(buildRows(1, index => ({
|
||||
id: index + 1,
|
||||
|
||||
@ -309,20 +309,51 @@ describe('test/app/service/systemMethods/order/wave.singleFetchByIds.test.js', (
|
||||
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({
|
||||
orders: [
|
||||
{ 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' },
|
||||
],
|
||||
});
|
||||
|
||||
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.excluded_b2b_order_ids, [ 502 ]);
|
||||
assert.deepEqual(result.excluded_intercepted_order_ids, [ 503 ]);
|
||||
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 ]);
|
||||
});
|
||||
});
|
||||
|
||||
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);
|
||||
});
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user