// app/model/order_item_sn.js 'use strict'; module.exports = app => { const { BIGINT, STRING, INTEGER, DATE } = app.Sequelize; const OrderItemSn = app.model.define('wms_order_item_sn', { id: { type: BIGINT(20).UNSIGNED, primaryKey: true, autoIncrement: true, allowNull: false, comment: '主键ID', }, warehouse_id: { type: BIGINT(20).UNSIGNED, allowNull: false, comment: '仓库ID', }, store_id: { type: BIGINT(20).UNSIGNED, allowNull: true, comment: '货主ID(复核落库时从订单冗余,便于按货主隔离查询)', }, order_id: { type: BIGINT(20).UNSIGNED, allowNull: false, comment: '订单ID,逻辑关联分仓订单主表,不做物理外键', }, order_item_id: { type: BIGINT(20).UNSIGNED, allowNull: false, comment: '订单明细ID,逻辑关联分仓订单明细表,不做物理外键', }, sn_code: { type: STRING(512), allowNull: false, comment: 'SN编码(支持链接/二维码内容,最长512字符)', }, sn_status: { type: STRING(32), allowNull: false, defaultValue: 'BOUND', comment: 'SN状态:BOUND/VERIFIED/RETURNED/REISSUED/INVALID', }, verify_status: { type: STRING(32), allowNull: false, defaultValue: 'UNVERIFIED', comment: '核验状态:UNVERIFIED/PASS/FAIL', }, bound_at: { type: DATE, allowNull: true, comment: '绑定时间', }, verified_at: { type: DATE, allowNull: true, comment: '核验时间', }, returned_at: { type: DATE, allowNull: true, comment: '退回时间', }, reissued_at: { type: DATE, allowNull: true, comment: '重发时间', }, version: { type: INTEGER.UNSIGNED, allowNull: false, defaultValue: 1, comment: '版本号', }, created_at: { type: DATE, allowNull: false, defaultValue: app.Sequelize.literal('CURRENT_TIMESTAMP'), comment: '创建时间', }, updated_at: { type: DATE, allowNull: false, defaultValue: app.Sequelize.literal('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'), comment: '更新时间', }, }, { tableName: 'wms_order_item_sn', timestamps: false, comment: '订单明细SN当前关系与状态表', indexes: [ { name: 'uk_wms_order_item_sn_warehouse_sn_code', unique: true, fields: [ 'warehouse_id', 'sn_code' ], }, { name: 'idx_wms_order_item_sn_order_id', fields: [ 'order_id' ], }, { name: 'idx_wms_order_item_sn_order_item_id', fields: [ 'order_item_id' ], }, { name: 'idx_wms_order_item_sn_sn_code', fields: [ 'sn_code' ], }, { name: 'idx_wms_order_item_sn_store_id', fields: [ 'store_id' ], }, ], }); return OrderItemSn; };