166 lines
4.1 KiB
JavaScript
166 lines
4.1 KiB
JavaScript
'use strict';
|
||
|
||
module.exports = app => {
|
||
const { STRING, BIGINT, INTEGER, DATE, TINYINT, TEXT, JSON: JSON_TYPE } = app.Sequelize;
|
||
|
||
const PackTask = app.model.define('pack_task', {
|
||
id: {
|
||
type: BIGINT(20).UNSIGNED,
|
||
primaryKey: true,
|
||
autoIncrement: true,
|
||
comment: '主键ID',
|
||
},
|
||
order_id: {
|
||
type: BIGINT(20).UNSIGNED,
|
||
allowNull: false,
|
||
comment: '订单ID',
|
||
},
|
||
warehouse_id: {
|
||
type: BIGINT(20).UNSIGNED,
|
||
allowNull: false,
|
||
defaultValue: 0,
|
||
comment: '仓库ID',
|
||
},
|
||
workbench_id: {
|
||
type: BIGINT(20).UNSIGNED,
|
||
allowNull: true,
|
||
comment: '工作台ID,关联 wms_workbench.id',
|
||
},
|
||
wave_id: {
|
||
type: BIGINT(20).UNSIGNED,
|
||
allowNull: true,
|
||
defaultValue: 0,
|
||
comment: '波次ID',
|
||
},
|
||
wave_no: {
|
||
type: STRING(50),
|
||
allowNull: true,
|
||
comment: '波次号',
|
||
},
|
||
waybill_code: {
|
||
type: STRING(50),
|
||
allowNull: true,
|
||
comment: '运单号',
|
||
},
|
||
pack_quantity: {
|
||
type: INTEGER.UNSIGNED,
|
||
allowNull: true,
|
||
defaultValue: 0,
|
||
comment: '打包数量(件数)',
|
||
},
|
||
item_quantity: {
|
||
type: INTEGER.UNSIGNED,
|
||
allowNull: true,
|
||
defaultValue: 0,
|
||
comment: '商品总数量',
|
||
},
|
||
sku_count: {
|
||
type: INTEGER.UNSIGNED,
|
||
allowNull: true,
|
||
defaultValue: 0,
|
||
comment: '商品种类数(SKU数)',
|
||
},
|
||
pack_mode: {
|
||
type: TINYINT.UNSIGNED,
|
||
allowNull: false,
|
||
defaultValue: 1,
|
||
comment: '打包模式:1=散单 2=团购',
|
||
},
|
||
status: {
|
||
type: TINYINT.UNSIGNED,
|
||
allowNull: false,
|
||
defaultValue: 0,
|
||
comment: '任务状态:0=待处理 1=打包中 2=已完成 3=异常',
|
||
},
|
||
start_time: {
|
||
type: DATE,
|
||
allowNull: true,
|
||
comment: '开始打包时间',
|
||
},
|
||
end_time: {
|
||
type: DATE,
|
||
allowNull: true,
|
||
comment: '结束打包时间',
|
||
},
|
||
operator_text: {
|
||
type: TEXT,
|
||
allowNull: true,
|
||
comment: '作业人员(自由文本,如多人逗号分隔)',
|
||
},
|
||
device_ids: {
|
||
type: JSON_TYPE,
|
||
allowNull: true,
|
||
comment: '设备ID列表,如 [1,2,3]',
|
||
},
|
||
remark: {
|
||
type: STRING(500),
|
||
allowNull: true,
|
||
comment: '备注',
|
||
},
|
||
meta: {
|
||
type: JSON_TYPE,
|
||
allowNull: true,
|
||
comment: '扩展信息JSON',
|
||
},
|
||
create_time: {
|
||
type: DATE,
|
||
allowNull: false,
|
||
comment: '创建时间',
|
||
},
|
||
update_time: {
|
||
type: DATE,
|
||
allowNull: false,
|
||
comment: '更新时间',
|
||
},
|
||
deleted_at: {
|
||
type: DATE,
|
||
allowNull: true,
|
||
comment: '删除时间',
|
||
},
|
||
}, {
|
||
tableName: 'wms_pack_task',
|
||
timestamps: true,
|
||
createdAt: 'create_time',
|
||
updatedAt: 'update_time',
|
||
paranoid: true,
|
||
deletedAt: 'deleted_at',
|
||
comment: '打包任务表(含作业记录)',
|
||
indexes: [
|
||
{ name: 'idx_order_id', fields: [ 'order_id' ] },
|
||
{ name: 'idx_warehouse_id', fields: [ 'warehouse_id' ] },
|
||
{ name: 'idx_warehouse_create_time', fields: [ 'warehouse_id', 'create_time' ] },
|
||
{ name: 'idx_workbench_id', fields: [ 'workbench_id' ] },
|
||
{ name: 'idx_wave_id', fields: [ 'wave_id' ] },
|
||
{ name: 'idx_waybill_code', fields: [ 'waybill_code' ] },
|
||
{ name: 'idx_pack_mode_status', fields: [ 'pack_mode', 'status' ] },
|
||
{ name: 'idx_start_time', fields: [ 'start_time' ] },
|
||
{ name: 'idx_status', fields: [ 'status' ] },
|
||
],
|
||
});
|
||
|
||
PackTask.associate = () => {
|
||
app.model.PackTask.belongsTo(app.model.Workbench, {
|
||
foreignKey: 'workbench_id',
|
||
targetKey: 'id',
|
||
as: 'workbench',
|
||
});
|
||
app.model.PackTask.hasMany(app.model.PackTaskVideo, {
|
||
foreignKey: 'pack_task_id',
|
||
sourceKey: 'id',
|
||
as: 'videos',
|
||
});
|
||
app.model.PackTask.hasMany(app.model.PackTaskPacker, {
|
||
foreignKey: 'pack_task_id',
|
||
sourceKey: 'id',
|
||
as: 'packers',
|
||
});
|
||
app.model.PackTask.hasMany(app.model.OrderExpress, {
|
||
foreignKey: 'order_id',
|
||
sourceKey: 'order_id',
|
||
as: 'expresses',
|
||
});
|
||
};
|
||
|
||
return PackTask;
|
||
};
|