From ee7f08b192c7aed2514a29215567cfb21d015a8b Mon Sep 17 00:00:00 2001 From: liufumingren Date: Thu, 8 Oct 2026 21:58:02 +0800 Subject: [PATCH] =?UTF-8?q?feat(order):=20wms=5Forder=5Fb2b=20=E8=A1=A8?= =?UTF-8?q?=E6=A8=A1=E5=9E=8B=E4=B8=8E=E8=BF=81=E7=A7=BB=E5=86=85=E5=AE=B9?= =?UTF-8?q?=EF=BC=88order=5Fdelivery=20=E9=99=84=E5=B1=9E=E8=A1=A8?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - app/model/order_b2b.js:ctx.model.OrderB2b,order_id 关联 wms_order_delivery 分表 id,uk_order_id 唯一,warehouse_id/store_id 维度隔离,软删除 - order_stockout.js 回滚 hasOne(OrderStockoutB2b) 关联 - 迁移内容改为 wms_order_b2b + delivery_order_code 快照 - 开发库已执行核验 14 列;生产库待随发布执行 --- app/model/order_b2b.js | 131 ++++++++++++++++++ app/model/order_stockout.js | 8 +- .../20261008193000-create-wms-order-b2b.js | 20 +-- 3 files changed, 142 insertions(+), 17 deletions(-) create mode 100644 app/model/order_b2b.js diff --git a/app/model/order_b2b.js b/app/model/order_b2b.js new file mode 100644 index 0000000..ede1d12 --- /dev/null +++ b/app/model/order_b2b.js @@ -0,0 +1,131 @@ +'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=未提货', + }, + 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_deleted_at', + fields: [ 'deleted_at' ], + }, + ], + }); + + return OrderB2b; +}; diff --git a/app/model/order_stockout.js b/app/model/order_stockout.js index 3a34de5..66f6c17 100644 --- a/app/model/order_stockout.js +++ b/app/model/order_stockout.js @@ -284,7 +284,7 @@ module.exports = app => { * - 关联出库明细表 */ OrderStockout.associate = function() { - const { OrderStockout, Store, OrderStockoutItems, OrderStockoutB2b } = app.model; + const { OrderStockout, Store, OrderStockoutItems } = app.model; // 关联仓库 OrderStockout.belongsTo(Store, { @@ -303,12 +303,6 @@ module.exports = app => { foreignKey: 'order_id', as: 'items', }); - - // 关联 B2B 出库作业明细(一对一) - OrderStockout.hasOne(OrderStockoutB2b, { - foreignKey: 'order_id', - as: 'b2bWork', - }); }; // ---------- 状态机辅助方法 ---------- diff --git a/database/migrations/20261008193000-create-wms-order-b2b.js b/database/migrations/20261008193000-create-wms-order-b2b.js index ee52b25..f771b0c 100644 --- a/database/migrations/20261008193000-create-wms-order-b2b.js +++ b/database/migrations/20261008193000-create-wms-order-b2b.js @@ -1,16 +1,16 @@ 'use strict'; /** - * 创建 B2B 出库作业明细表 wms_order_stockout_b2b。 + * 创建 B2B 订单作业明细表 wms_order_b2b。 * - * 与出库单主表 wms_order_stockout 一对一(order_id 关联主表 id,uk_order_id 唯一), + * 与发货单(订单)主表 wms_order_delivery 分表一对一(order_id 关联分表 id,uk_order_id 唯一), * 不分表(单表全量),通过 warehouse_id/store_id 做数据隔离与检索维度, * 类似 wms_order_express(运单号表)的落表方式。 * * 字段: - * order_id 出库单ID(关联 wms_order_stockout.id,唯一) + * order_id 订单ID(关联 wms_order_delivery 分表 id,唯一) * warehouse_id / store_id 仓库/货主维度 - * stockout_order_code 出库单号快照(便于按单号检索) + * delivery_order_code 发货单号快照(便于按单号检索) * total_box_count 总箱数 * pickup_plate_number 提货车牌 * prep_remark 备货备注 @@ -21,11 +21,11 @@ * * 索引: * uk_order_id(order_id 唯一) - * idx_warehouse_id / idx_store_id / idx_stockout_order_code + * idx_warehouse_id / idx_store_id / idx_delivery_order_code * idx_pickup_plate_number / idx_is_picked_up / idx_deleted_at */ -const TABLE_NAME = 'wms_order_stockout_b2b'; +const TABLE_NAME = 'wms_order_b2b'; module.exports = { // eslint-disable-next-line no-unused-vars @@ -42,7 +42,7 @@ module.exports = { order_id: { type: BIGINT(20).UNSIGNED, allowNull: false, - comment: '出库单ID,关联 wms_order_stockout.id', + comment: '订单ID,关联 wms_order_delivery 分表 id', }, warehouse_id: { type: BIGINT(20).UNSIGNED, @@ -54,10 +54,10 @@ module.exports = { allowNull: true, comment: '货主ID', }, - stockout_order_code: { + delivery_order_code: { type: STRING(50), allowNull: true, - comment: '出库单号快照', + comment: '发货单号快照', }, total_box_count: { type: INTEGER(11), @@ -100,7 +100,7 @@ module.exports = { await queryInterface.addIndex(TABLE_NAME, [ 'order_id' ], { unique: true, name: 'uk_order_id' }); await queryInterface.addIndex(TABLE_NAME, [ 'warehouse_id' ], { name: 'idx_warehouse_id' }); await queryInterface.addIndex(TABLE_NAME, [ 'store_id' ], { name: 'idx_store_id' }); - await queryInterface.addIndex(TABLE_NAME, [ 'stockout_order_code' ], { name: 'idx_stockout_order_code' }); + await queryInterface.addIndex(TABLE_NAME, [ 'delivery_order_code' ], { name: 'idx_delivery_order_code' }); await queryInterface.addIndex(TABLE_NAME, [ 'pickup_plate_number' ], { name: 'idx_pickup_plate_number' }); await queryInterface.addIndex(TABLE_NAME, [ 'is_picked_up' ], { name: 'idx_is_picked_up' }); await queryInterface.addIndex(TABLE_NAME, [ 'deleted_at' ], { name: 'idx_deleted_at' });