'use strict'; module.exports = app => { const { BIGINT, STRING, DATE, INTEGER } = app.Sequelize; const Picking = app.model.define('picking', { id: { type: BIGINT(20).UNSIGNED, primaryKey: true, autoIncrement: true, allowNull: false, comment: '主键ID', }, order_id: { type: BIGINT(20).UNSIGNED, allowNull: false, comment: '订单ID', }, warehouse_id: { type: BIGINT(20).UNSIGNED, allowNull: false, comment: '仓库ID', }, order_item_id: { type: BIGINT(20).UNSIGNED, allowNull: false, comment: '订单明细ID', }, storage_id: { type: BIGINT(20).UNSIGNED, allowNull: true, comment: '库存记录ID', }, stock_id: { type: BIGINT(20), allowNull: true, comment: '商品SKU ID', }, quantity: { type: INTEGER(10).UNSIGNED, allowNull: false, defaultValue: 1, comment: '分配数量', }, space_id: { type: BIGINT(20).UNSIGNED, allowNull: true, comment: '库位ID', }, space_name: { type: STRING(100), allowNull: true, comment: '库位名称', }, status: { type: STRING(20), allowNull: false, defaultValue: 'pending', 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'), comment: '更新时间', }, }, { tableName: 'wms_picking', freezeTableName: true, underscored: true, timestamps: true, createdAt: 'created_at', updatedAt: 'updated_at', comment: '订单储位分配表', indexes: [ { name: 'idx_wms_picking_warehouse_id', fields: [ 'warehouse_id' ], }, { name: 'idx_wms_picking_order_id', fields: [ 'order_id' ], }, { name: 'idx_wms_picking_order_item_id', fields: [ 'order_item_id' ], }, { name: 'idx_wms_picking_storage_id', fields: [ 'storage_id' ], }, { name: 'idx_wms_picking_space_id', fields: [ 'space_id' ], }, { name: 'idx_wms_picking_status', fields: [ 'status' ], }, { name: 'idx_wms_picking_order_item_space', fields: [ 'order_item_id', 'space_id' ], }, { name: 'idx_wms_picking_warehouse_stock', fields: [ 'warehouse_id', 'stock_id' ], }, ], }); Picking.associate = function() { const { OrderItems, Storage, LocationSpace, StockWarehouse } = app.model; if (OrderItems) { Picking.belongsTo(OrderItems, { foreignKey: 'order_item_id', as: 'orderItem', constraints: false, }); } if (Storage) { Picking.belongsTo(Storage, { foreignKey: 'storage_id', as: 'storageRecord', constraints: false, }); } if (LocationSpace) { Picking.belongsTo(LocationSpace, { foreignKey: 'space_id', as: 'space', constraints: false, }); } if (StockWarehouse) { Picking.belongsTo(StockWarehouse, { foreignKey: 'stock_id', as: 'stock', constraints: false, }); } }; return Picking; };