'use strict'; /** * 运单物流轨迹模型。 * 一个运单(express_id)对应多条轨迹,由外部快递/轨迹接口回传。 * @param {import('egg').Application} app Egg 应用实例。 * @return {import('sequelize').ModelCtor} Sequelize 模型。 */ module.exports = app => { const { BIGINT, STRING, INTEGER, DATE, JSON: JSON_TYPE } = app.Sequelize; const OrderExpressTrace = app.model.define('order_express_trace', { id: { type: BIGINT(20).UNSIGNED, primaryKey: true, autoIncrement: true, allowNull: false, comment: '主键ID', }, express_id: { type: BIGINT(20).UNSIGNED, allowNull: false, comment: '运单ID(wms_order_express.id)', }, waybill_code: { type: STRING(50), allowNull: false, comment: '运单号(冗余,便于按运单号直查)', }, order_id: { type: BIGINT(20).UNSIGNED, allowNull: true, comment: '订单ID(冗余,便于按订单查轨迹)', }, warehouse_id: { type: BIGINT(20).UNSIGNED, allowNull: false, comment: '仓库ID(数据隔离维度)', }, op_time: { type: DATE, allowNull: true, comment: '操作时间(opTime)', }, out_biz_code: { type: STRING(191), allowNull: true, comment: '外部业务码(outBizCode)', }, memo: { type: STRING(500), allowNull: true, comment: '轨迹描述(memo)', }, op_org_city_name: { type: STRING(100), allowNull: true, comment: '操作机构所在城市(opOrgCityName)', }, weight: { type: INTEGER(11), allowNull: true, defaultValue: 0, comment: '重量(weight,来源原值)', }, scan_type: { type: STRING(50), allowNull: true, comment: '扫描类型(scanType),如 发件/到件/派件/签收', }, raw_data: { type: JSON_TYPE, allowNull: true, comment: '原始轨迹报文(未落库字段的兜底存储)', }, }, { tableName: 'wms_order_express_trace', freezeTableName: true, underscored: true, timestamps: true, createdAt: 'created_at', updatedAt: 'updated_at', deletedAt: 'deleted_at', paranoid: true, comment: '运单物流轨迹表(1 运单 : N 轨迹)', indexes: [ { name: 'uk_express_op_scan', unique: true, fields: [ 'express_id', 'op_time', 'scan_type' ] }, { name: 'idx_waybill_code', fields: [ 'waybill_code', 'op_time' ] }, { name: 'idx_order_id', fields: [ 'order_id' ] }, { name: 'idx_warehouse_op_time', fields: [ 'warehouse_id', 'op_time' ] }, ], }); return OrderExpressTrace; };