129 lines
2.8 KiB
JavaScript
129 lines
2.8 KiB
JavaScript
'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',
|
|
},
|
|
order_item_id: {
|
|
type: BIGINT(20).UNSIGNED,
|
|
allowNull: false,
|
|
comment: '订单明细ID',
|
|
},
|
|
storage_id: {
|
|
type: BIGINT(20).UNSIGNED,
|
|
allowNull: true,
|
|
comment: '库存记录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_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' ],
|
|
},
|
|
],
|
|
});
|
|
|
|
Picking.associate = function() {
|
|
const { OrderItems, Storage, LocationSpace } = 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,
|
|
});
|
|
}
|
|
};
|
|
|
|
return Picking;
|
|
};
|