'use strict'; module.exports = app => { const { INTEGER, BIGINT, ENUM, DATE } = app.Sequelize; const EntryReceivingBinding = app.model.define('wms_entry_receiving_binding', { id: { type: BIGINT(20).UNSIGNED, primaryKey: true, autoIncrement: true, comment: '主键ID', }, entry_item_id: { type: BIGINT(20).UNSIGNED, allowNull: false, comment: '入库明细ID', }, receiving_detail_id: { type: INTEGER, allowNull: false, comment: '收货明细ID', }, allocated_quantity: { type: INTEGER, allowNull: false, comment: '预分配数量', validate: { min: 1, }, }, status: { type: ENUM('pending', 'committed', 'released'), allowNull: false, defaultValue: 'pending', comment: '绑定状态:pending-待提交 committed-已提交 released-已释放', }, creator_id: { type: BIGINT(20).UNSIGNED, allowNull: true, comment: '创建人ID', }, created_at: { type: DATE, allowNull: false, comment: '创建时间', }, updated_at: { type: DATE, allowNull: false, comment: '更新时间', }, }, { tableName: 'wms_entry_receiving_binding', comment: '入库单明细-收货明细绑定关系表', timestamps: true, createdAt: 'created_at', updatedAt: 'updated_at', paranoid: true, deletedAt: 'deleted_at', indexes: [ { name: 'idx_entry_item_id', fields: [ 'entry_item_id' ], }, { name: 'idx_receiving_detail_id', fields: [ 'receiving_detail_id' ], }, { name: 'idx_status', fields: [ 'status' ], }, { name: 'uk_entry_receiving', unique: true, fields: [ 'entry_item_id', 'receiving_detail_id', 'status' ], }, ], }); // 关联关系 EntryReceivingBinding.associate = function() { const { EntryReceivingBinding, EntryItems, ReceivingDetail } = app.model; // 关联入库明细 EntryReceivingBinding.belongsTo(EntryItems, { foreignKey: 'entry_item_id', as: 'entryItem', }); // 关联收货明细 EntryReceivingBinding.belongsTo(ReceivingDetail, { foreignKey: 'receiving_detail_id', as: 'receivingDetail', }); }; return EntryReceivingBinding; };