177 lines
4.4 KiB
JavaScript
177 lines
4.4 KiB
JavaScript
// app/model/receiving.js
|
||
module.exports = app => {
|
||
const { STRING, INTEGER, DATE, DECIMAL, TEXT, BOOLEAN, ENUM } = app.Sequelize;
|
||
|
||
const Receiving = app.model.define('wms_receiving', {
|
||
id: {
|
||
type: INTEGER,
|
||
primaryKey: true,
|
||
autoIncrement: true,
|
||
comment: '收货单ID',
|
||
},
|
||
receiving_number: {
|
||
type: STRING(50),
|
||
unique: true,
|
||
allowNull: false,
|
||
comment: '收货单号,如: RCV202312150001',
|
||
},
|
||
creator_id: {
|
||
type: INTEGER,
|
||
allowNull: false,
|
||
comment: '创建人工号ID',
|
||
},
|
||
creator_snapshot: {
|
||
type: TEXT,
|
||
allowNull: false,
|
||
comment: '创建人信息快照(JSON格式)',
|
||
},
|
||
status: {
|
||
type: ENUM('receiving', 'completed', 'cancelled'),
|
||
defaultValue: 'receiving',
|
||
allowNull: false,
|
||
comment: '收货状态:receiving-收货中, completed-收货完成, cancelled-作废',
|
||
},
|
||
detail_status: {
|
||
type: ENUM('all_matched', 'partial_matched', 'unmatched'),
|
||
defaultValue: 'unmatched',
|
||
allowNull: false,
|
||
comment: '明细匹配状态:all_matched-全部匹配, partial_matched-部分匹配, unmatched-未匹配',
|
||
},
|
||
storage_status: {
|
||
type: ENUM('none', 'partial', 'all'),
|
||
defaultValue: 'none',
|
||
allowNull: false,
|
||
comment: '入库状态:none-未入库, partial-部分入库, all-全部入库',
|
||
},
|
||
delivery_method: {
|
||
type: ENUM('truck', 'express', 'air_freight', 'sea_freight', 'other'),
|
||
allowNull: false,
|
||
comment: '来货方式:truck-货车, express-快递, air_freight-空运, sea_freight-海运, other-其他',
|
||
},
|
||
license_plate: {
|
||
type: STRING(20),
|
||
comment: '车牌号(货车运输时需要)',
|
||
},
|
||
tracking_number: {
|
||
type: STRING(100),
|
||
comment: '快递单号/物流单号',
|
||
},
|
||
loading_method: {
|
||
type: ENUM('with_pallet', 'without_pallet'),
|
||
allowNull: false,
|
||
comment: '装卸方式:with_pallet-带托盘, without_pallet-不带托盘',
|
||
},
|
||
video_device_id: {
|
||
type: STRING(50),
|
||
comment: '录像设备ID(可选)',
|
||
},
|
||
total_items: {
|
||
type: INTEGER,
|
||
defaultValue: 0,
|
||
comment: '总商品种类数',
|
||
},
|
||
total_quantity: {
|
||
type: INTEGER,
|
||
defaultValue: 0,
|
||
comment: '商品总数量',
|
||
},
|
||
total_boxes: {
|
||
type: INTEGER,
|
||
defaultValue: 0,
|
||
comment: '总箱数',
|
||
},
|
||
total_pallets: {
|
||
type: INTEGER,
|
||
defaultValue: 0,
|
||
comment: '总托盘数',
|
||
},
|
||
warehouse_id: {
|
||
type: INTEGER,
|
||
allowNull: false,
|
||
comment: '收货仓库ID',
|
||
},
|
||
remark: {
|
||
type: TEXT,
|
||
comment: '备注信息',
|
||
},
|
||
store_name: {
|
||
type: STRING(50),
|
||
},
|
||
store_id: {
|
||
type: INTEGER,
|
||
},
|
||
receiving_start_time: {
|
||
type: DATE,
|
||
comment: '收货开始时间',
|
||
},
|
||
receiving_end_time: {
|
||
type: DATE,
|
||
comment: '收货结束时间',
|
||
},
|
||
is_deleted: {
|
||
type: BOOLEAN,
|
||
defaultValue: false,
|
||
comment: '是否删除',
|
||
},
|
||
}, {
|
||
tableName: 'wms_receiving',
|
||
timestamps: true,
|
||
createdAt: 'created_at',
|
||
updatedAt: 'updated_at',
|
||
paranoid: false,
|
||
indexes: [
|
||
{
|
||
unique: true,
|
||
fields: [ 'receiving_number' ],
|
||
},
|
||
{
|
||
fields: [ 'creator_id' ],
|
||
},
|
||
{
|
||
fields: [ 'status' ],
|
||
},
|
||
{
|
||
fields: [ 'delivery_method' ],
|
||
},
|
||
{
|
||
fields: [ 'warehouse_id' ],
|
||
},
|
||
{
|
||
fields: [ 'created_at' ],
|
||
},
|
||
],
|
||
});
|
||
|
||
// 关联定义
|
||
Receiving.associate = function() {
|
||
const { ReceivingDetail, Store, AccountStoreEmployee, StoreWarehouse } = app.model;
|
||
// 关联收货明细
|
||
Receiving.hasMany(ReceivingDetail, {
|
||
foreignKey: 'receiving_id',
|
||
as: 'details',
|
||
});
|
||
|
||
// 关联仓库
|
||
Receiving.belongsTo(Store, {
|
||
foreignKey: 'warehouse_id',
|
||
as: 'warehouse',
|
||
});
|
||
|
||
// 关联创建人(用户表)
|
||
Receiving.belongsTo(AccountStoreEmployee, {
|
||
foreignKey: 'creator_id',
|
||
as: 'creator',
|
||
});
|
||
|
||
// wms_storage 无 receiving_id 字段,避免声明无效关联。
|
||
Receiving.belongsTo(StoreWarehouse, {
|
||
foreignKey: 'store_id', // 当前表的外键字段
|
||
targetKey: 'store_id', // 关联表的业务键字段(非主键)
|
||
as: 'store',
|
||
constraints: false,
|
||
});
|
||
};
|
||
|
||
return Receiving;
|
||
};
|