'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: '来源订单号(外部平台唯一单号;店管家为系统编号 LogicOrderId)' }, principal_id: { type: BIGINT.UNSIGNED, allowNull: false, comment: '所属主体ID(主体隔离)' }, subsidiary_id: { type: BIGINT.UNSIGNED, 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; };