WMS_MAIN/app/model/order_b2b.js
liufumingren 0a6e82e00a feat(order): B2B 订单作业链路(列表/转换/取消/波次排除/作业明细表重构)
- 新增 order.pendingOrder2b.list / order.deliveryOrder2b.list:复用待处理与配送列表条件,
  强制 is_b2b='Y'(fixedWhere 以 AND 追加,请求 where 无法覆盖),并带出 wms_order_b2b
  作业明细字段(total_box_count/pickup_plate_number/prep_remark/prep_duration_seconds/
  prep_at/is_picked_up/picked_up_at/created_at),无明细行时输出空值占位
- B2B 列表 where 支持按作业明细字段筛选:先按 warehouse_id + order_id 查副表取 order_id,
  再以 id IN (...) 回填;该筛选仅这两个接口开放,不影响普通订单列表
- 其余订单列表(order/reviewOrder/pendingOrder/outboundOrder/expectionOrder/entrustOrder/
  deliveryOrder/deliveryExpectionOrder/archiveOrder 及 waveStrategyFallbackOrderList)
  统一追加 (is_b2b IS NULL OR is_b2b = 'N'),B2B 订单不再混入普通列表
- order.convertToB2b 收紧准入:status!=cancel、step in [1,2,3]、未拣货、未复核、未锁定、
  未拦截、未 B2B(打印状态不限制);已在波次中的订单转换后在同一事务内从波次摘除
  (含库内抓取订单),波次存在进行中拣货任务则跳过
- order.cancelB2b 放开打印限制,作业明细由软删除改为物理删除
- 波次抓取全链路排除 B2B:补上自动加团 appendOrderToWave / countCandidateGroupOrders
  两处遗漏;抽出 detachOrdersFromWavesInTransaction 供 batchRemoveOrders 与转 B2B 复用
- wms_order_delivery 分表新增 is_b2b 列表索引(current/dispatch,等值列前置 + 排序列),
  由订单工厂结构漂移同步自动补建
- 迁移 20261115180000-refactor-wms-order-b2b:新增 prep_at;移除 is_print/updated_at/
  deleted_at/delivery_order_code/store_id;唯一键改 uk_warehouse_order(warehouse_id, order_id);
  迁移前清理历史软删除行与重复行(开发库与生产库均已执行)
- operation_log 兜底用 changeSummary 写入 message,修复转/取消 B2B 日志操作说明为空
- 同步 methods/system.json 与变更记录 0.3.351~0.3.360

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-11-17 01:30:08 +08:00

101 lines
2.5 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'use strict';
/**
* B2B 订单作业明细表 Model。
*
* 对应数据库表 `wms_order_b2b`,与发货单(订单)分表 wms_order_delivery_% 一对一,
* 记录 B2B 订单的备货/提货作业信息:总箱数、提货车牌、备货备注、备货用时、
* 备货完成时间、是否提货等。
*
* 不分表(不按仓库分表),关联读统一使用 warehouse_id + order_id(分表 id 按仓库
* 各自发号,跨仓可能重叠,故不单独依赖 order_id)。取消 B2B 时物理删除行,不做软删除。
* @param {import('egg').Application} app - Egg 应用实例
*/
module.exports = app => {
const { STRING, INTEGER, BIGINT, ENUM, DATE } = app.Sequelize;
const OrderB2b = app.model.define('wms_order_b2b', {
id: {
type: BIGINT(20).UNSIGNED,
primaryKey: true,
autoIncrement: true,
allowNull: false,
comment: '主键ID',
},
order_id: {
type: BIGINT(20).UNSIGNED,
allowNull: false,
comment: '订单ID,关联 wms_order_delivery 分表 id',
},
warehouse_id: {
type: BIGINT(20).UNSIGNED,
allowNull: false,
comment: '仓库ID',
},
total_box_count: {
type: INTEGER(11),
allowNull: false,
defaultValue: 0,
comment: '总箱数',
},
pickup_plate_number: {
type: STRING(20),
allowNull: true,
comment: '提货车牌',
},
prep_remark: {
type: STRING(500),
allowNull: true,
comment: '备货备注',
},
prep_duration_seconds: {
type: INTEGER(11),
allowNull: false,
defaultValue: 0,
comment: '备货用时(秒)',
},
prep_at: {
type: DATE,
allowNull: true,
comment: '备货完成时间',
},
is_picked_up: {
type: ENUM('Y', 'N'),
allowNull: false,
defaultValue: 'N',
comment: '是否提货:Y=已提货 N=未提货',
},
picked_up_at: {
type: DATE,
allowNull: true,
comment: '提货时间',
},
created_at: {
type: DATE,
allowNull: false,
comment: '创建时间',
},
}, {
tableName: 'wms_order_b2b',
comment: 'B2B订单作业明细表',
timestamps: false,
indexes: [
{
name: 'uk_warehouse_order',
unique: true,
fields: [ 'warehouse_id', 'order_id' ],
},
{
name: 'idx_pickup_plate_number',
fields: [ 'pickup_plate_number' ],
},
{
name: 'idx_is_picked_up',
fields: [ 'is_picked_up' ],
},
],
});
return OrderB2b;
};