'use strict'; module.exports = app => { const { BIGINT, DATE, JSON: JSON_TYPE } = app.Sequelize; const EntryOrderReceiving = app.model.define('wms_entry_order_receiving', { id: { type: BIGINT(20).UNSIGNED, primaryKey: true, autoIncrement: true, comment: '主键ID', }, entry_order_id: { type: BIGINT(20).UNSIGNED, allowNull: false, comment: '入库单ID,关联 wms_entry_order.id', }, receiving_id: { type: BIGINT(20).UNSIGNED, allowNull: false, comment: '收货单ID,关联 wms_receiving.id', }, allocated_quantity: { type: JSON_TYPE, allowNull: true, defaultValue: null, comment: '数量台账:收货明细ID→已分配数量(JSON对象,如 {"123":8});null 表示旧数据未初始化', }, created_at: { type: DATE, allowNull: false, comment: '创建时间', }, updated_at: { type: DATE, allowNull: false, comment: '更新时间', }, }, { tableName: 'wms_entry_order_receiving', comment: '入库单-收货单主表级绑定关系表', timestamps: true, createdAt: 'created_at', updatedAt: 'updated_at', paranoid: true, deletedAt: 'deleted_at', indexes: [ { name: 'idx_entry_order_id', fields: [ 'entry_order_id' ], }, { name: 'idx_receiving_id', fields: [ 'receiving_id' ], }, { name: 'uk_entry_order_receiving', unique: true, fields: [ 'entry_order_id', 'receiving_id' ], }, ], }); // 关联关系 EntryOrderReceiving.associate = function() { const { EntryOrderReceiving, EntryOrder, Receiving } = app.model; // 关联入库单 EntryOrderReceiving.belongsTo(EntryOrder, { foreignKey: 'entry_order_id', as: 'entryOrder', }); // 关联收货单 EntryOrderReceiving.belongsTo(Receiving, { foreignKey: 'receiving_id', as: 'receiving', }); }; return EntryOrderReceiving; };