oms/backend/app/model/orderIndex.js
liufumingren 6c03a20364 feat(backend): 订单状态分表、WMS 推送与归档
- 新增 order_index 索引表 + 6 张同构状态表(待审核/异常/委外中/配送/已作废/已取消)与历史表,
  订单 ID 全局唯一,状态由业务事务推动:审核、驳回、取消、作废、恢复、归档
- 明细表 order_status_items、收件人文本智能解析、批量切换仓库/店铺并刷新快照
- WMS deliveryorder.create 推送(单条/批量)、推送失败定时重试、订单归档定时任务
- 迁移:建表、旧发货单数据迁入新表、菜单合并与迁移记录清理
- routes / swagger contract 补充订单状态接口

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-10-30 23:06:18 +08:00

33 lines
1.7 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';
const { ORDER_INDEX_TABLE } = require('../lib/orderStatus');
/**
* 订单索引表(order_index)
*
* 订单的**全局唯一 ID 以本表为准**:各状态表与历史表的主键都取自本表 id,
* 另通过 current_table 记录订单当前所在状态表、current_status 记录当前状态,
* 便于「不依赖具体状态表」地定位任一订单(批量流转时按索引表分组处理)。
* @param {Egg.Application} app egg application
* @return {object} orderIndex model
*/
module.exports = app => {
const { BIGINT, STRING, DATE } = app.Sequelize;
const OrderIndex = app.model.define(ORDER_INDEX_TABLE, {
id: { type: BIGINT.UNSIGNED, primaryKey: true, autoIncrement: true, comment: '主键(订单全局唯一 ID)' },
order_no: { type: STRING(50), allowNull: false, comment: '订单号' },
parent_order_no: { type: STRING(50), comment: '来源订单号(上游/平台订单号)' },
principal_id: { type: BIGINT.UNSIGNED, allowNull: false, comment: '所属主体ID(主体隔离)' },
current_table: { type: STRING(16), allowNull: false, defaultValue: 'pending', comment: '当前所在表:pending/exception/outsourcing/delivery/history' },
current_status: { type: STRING(16), allowNull: false, defaultValue: 'pending', comment: '当前状态:pending 待审核 / exception 异常 / outsourcing 委外中 / delivery 配送 / history 历史' },
created_at: { type: DATE, comment: '创建时间(用于超 3 个月自动归档判断)' },
updated_at: { type: DATE, comment: '更新时间' },
}, {
tableName: ORDER_INDEX_TABLE,
comment: '订单索引表(订单 ID 以此为准)',
});
return OrderIndex;
};