WMS_MAIN/app/model/order_b2b.js
liufumingren 183e542d74 feat(order): 新增 order.convertToB2b 接口,订单转 B2B
- systems/order_b2b.js convertOrdersToB2b:
  1) 仅限待处理表(current 分表)订单,事务内 SELECT ... FOR UPDATE 后逐行校验:
     待处理(step!=0)/未打印(print_status!=fin)/未锁定(lock_status=none)/
     未拦截(intercept_status=none)/未转 B2B(is_b2b!=Y),不符合条件跳过
     (skipped_reasons 返回原因),不存在的订单计入 not_found_order_ids
  2) 事务内:订单 is_b2b 置 Y + wms_order_b2b 写入(findOrCreate by uk_order_id,
     已存在不覆盖);提交后写操作日志 ORDER_B2B_CONVERT(失败不影响主流程)
  3) 单次上限 200,仓库隔离(warehouse_id 过滤)
- systemMethods/order/index.js convertToB2b:ids/order_ids/orderIds 数组
  与 id/order_id/orderId 单值兼容,空/超限 400;白名单三处加 convertToB2b
- wms_order_b2b 新增 is_print 字段(ENUM('Y','N') 默认 N 未打印)+ idx_is_print
  (迁移 20261009100000 已执行开发库并核验 15 列)
- 验证:临时集成测试 3/3 PASS(转换落库+日志+还原、跳过分流、400 边界);
  ESLint 0 error;生产迁移待随发布执行
2026-10-09 00:22:25 +08:00

142 lines
3.3 KiB
JavaScript
Raw 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_% 一对一
* (order_id 关联分表 id),记录 B2B 订单的提货作业信息:
* 总箱数、提货车牌、备货备注、备货用时、是否提货等。
*
* 不分表(不按仓库分表),通过 warehouse_id/store_id 维度隔离,
* 落表方式类似 wms_order_express(运单号表)。
* @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',
},
store_id: {
type: BIGINT(20).UNSIGNED,
allowNull: true,
comment: '货主ID',
},
delivery_order_code: {
type: STRING(50),
allowNull: true,
comment: '发货单号快照',
},
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: '备货用时(秒)',
},
is_picked_up: {
type: ENUM('Y', 'N'),
allowNull: false,
defaultValue: 'N',
comment: '是否提货:Y=已提货 N=未提货',
},
is_print: {
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: '创建时间',
},
updated_at: {
type: DATE,
allowNull: false,
comment: '更新时间',
},
deleted_at: {
type: DATE,
allowNull: true,
comment: '软删除时间',
},
}, {
tableName: 'wms_order_b2b',
comment: 'B2B订单作业明细表',
timestamps: false,
indexes: [
{
name: 'uk_order_id',
unique: true,
fields: [ 'order_id' ],
},
{
name: 'idx_warehouse_id',
fields: [ 'warehouse_id' ],
},
{
name: 'idx_store_id',
fields: [ 'store_id' ],
},
{
name: 'idx_delivery_order_code',
fields: [ 'delivery_order_code' ],
},
{
name: 'idx_pickup_plate_number',
fields: [ 'pickup_plate_number' ],
},
{
name: 'idx_is_picked_up',
fields: [ 'is_picked_up' ],
},
{
name: 'idx_is_print',
fields: [ 'is_print' ],
},
{
name: 'idx_deleted_at',
fields: [ 'deleted_at' ],
},
],
});
return OrderB2b;
};