176 lines
4.4 KiB
JavaScript
176 lines
4.4 KiB
JavaScript
'use strict';
|
||
|
||
module.exports = app => {
|
||
const { BIGINT, STRING, TEXT, DATE, INTEGER } = app.Sequelize;
|
||
|
||
const StoreWarehousePrintQuantityLog = app.model.define('store_warehouse_print_quantity_log', {
|
||
id: {
|
||
type: BIGINT(20).UNSIGNED,
|
||
primaryKey: true,
|
||
autoIncrement: true,
|
||
allowNull: false,
|
||
comment: '主键ID',
|
||
},
|
||
contract_id: {
|
||
type: BIGINT(20).UNSIGNED,
|
||
allowNull: false,
|
||
comment: '签约关系ID,对应 wms_store_warehouse.id',
|
||
references: {
|
||
model: 'store_warehouse',
|
||
key: 'id',
|
||
},
|
||
},
|
||
store_id: {
|
||
type: BIGINT(20).UNSIGNED,
|
||
allowNull: false,
|
||
comment: '货主ID,对应 wms_store.id',
|
||
references: {
|
||
model: 'store',
|
||
key: 'id',
|
||
},
|
||
},
|
||
warehouse_id: {
|
||
type: BIGINT(20).UNSIGNED,
|
||
allowNull: false,
|
||
comment: '仓库ID,对应 wms_store.id',
|
||
references: {
|
||
model: 'store',
|
||
key: 'id',
|
||
},
|
||
},
|
||
change_type: {
|
||
type: STRING(50),
|
||
allowNull: false,
|
||
comment: '变更类型,如 manual_adjust / order_deduct',
|
||
},
|
||
business_type: {
|
||
type: STRING(50),
|
||
allowNull: true,
|
||
comment: '业务来源类型,如 order_express',
|
||
},
|
||
business_id: {
|
||
type: BIGINT(20).UNSIGNED,
|
||
allowNull: true,
|
||
comment: '业务关联ID,预留关联 wms_order_express.id',
|
||
},
|
||
change_quantity: {
|
||
type: BIGINT(20),
|
||
allowNull: false,
|
||
comment: '本次变更数量,整数,可正可负',
|
||
},
|
||
balance_before: {
|
||
type: INTEGER(11),
|
||
allowNull: false,
|
||
comment: '本次变更数量,整数,可正可负',
|
||
},
|
||
balance_after: {
|
||
type: INTEGER(11),
|
||
allowNull: false,
|
||
comment: '变更后余额',
|
||
},
|
||
reason: {
|
||
type: TEXT,
|
||
allowNull: true,
|
||
comment: '变更缘由;人工调整时必填',
|
||
},
|
||
operator_id: {
|
||
type: BIGINT(20).UNSIGNED,
|
||
allowNull: true,
|
||
comment: '操作人账号ID',
|
||
},
|
||
created_by: {
|
||
type: BIGINT(20).UNSIGNED,
|
||
allowNull: true,
|
||
comment: '创建人账号ID',
|
||
},
|
||
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_store_warehouse_print_quantity_log',
|
||
freezeTableName: true,
|
||
underscored: true,
|
||
timestamps: true,
|
||
paranoid: false,
|
||
createdAt: 'created_at',
|
||
updatedAt: 'updated_at',
|
||
comment: '货主-仓库签约面单余额变更记录表',
|
||
indexes: [
|
||
{
|
||
name: 'idx_sw_print_qty_log_contract_id',
|
||
fields: [ 'contract_id', 'id' ],
|
||
},
|
||
{
|
||
name: 'idx_sw_print_qty_log_store_warehouse',
|
||
fields: [ 'store_id', 'warehouse_id' ],
|
||
},
|
||
{
|
||
name: 'idx_sw_print_qty_log_business',
|
||
fields: [ 'business_type', 'business_id' ],
|
||
},
|
||
{
|
||
name: 'idx_sw_print_qty_log_change_type',
|
||
fields: [ 'change_type' ],
|
||
},
|
||
{
|
||
name: 'idx_sw_print_qty_log_created_at',
|
||
fields: [ 'created_at' ],
|
||
},
|
||
],
|
||
});
|
||
|
||
StoreWarehousePrintQuantityLog.associate = function() {
|
||
const { StoreWarehouse, Store, Account, OrderExpress } = app.model;
|
||
|
||
StoreWarehousePrintQuantityLog.belongsTo(StoreWarehouse, {
|
||
foreignKey: 'contract_id',
|
||
targetKey: 'id',
|
||
as: 'contract',
|
||
});
|
||
|
||
StoreWarehousePrintQuantityLog.belongsTo(Store, {
|
||
foreignKey: 'store_id',
|
||
targetKey: 'id',
|
||
as: 'store',
|
||
});
|
||
|
||
StoreWarehousePrintQuantityLog.belongsTo(Store, {
|
||
foreignKey: 'warehouse_id',
|
||
targetKey: 'id',
|
||
as: 'warehouse',
|
||
});
|
||
|
||
StoreWarehousePrintQuantityLog.belongsTo(Account, {
|
||
foreignKey: 'operator_id',
|
||
targetKey: 'id',
|
||
as: 'operator',
|
||
constraints: false,
|
||
});
|
||
|
||
StoreWarehousePrintQuantityLog.belongsTo(Account, {
|
||
foreignKey: 'created_by',
|
||
targetKey: 'id',
|
||
as: 'creator',
|
||
constraints: false,
|
||
});
|
||
|
||
StoreWarehousePrintQuantityLog.belongsTo(OrderExpress, {
|
||
foreignKey: 'business_id',
|
||
targetKey: 'id',
|
||
as: 'order_express',
|
||
constraints: false,
|
||
});
|
||
};
|
||
|
||
return StoreWarehousePrintQuantityLog;
|
||
};
|