WMS_MAIN/app/model/account_store_employee.js
2026-04-09 01:36:49 +08:00

112 lines
2.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'use strict';
module.exports = app => {
const { BIGINT, STRING, DATE, TINYINT } = app.Sequelize;
const AccountStoreEmployee = app.model.define('wms_account_store_employee', {
id: {
type: BIGINT.UNSIGNED,
primaryKey: true,
autoIncrement: true,
allowNull: false,
comment: '关联ID',
},
account_id: {
type: BIGINT.UNSIGNED,
allowNull: false,
comment: '账号ID',
},
store_id: {
type: BIGINT.UNSIGNED,
allowNull: false,
comment: '仓库ID',
},
status: {
type: TINYINT(4),
allowNull: false,
defaultValue: 1,
validate: {
isIn: {
args: [[ 0, 1 ]],
msg: '状态值不合法,0-已解除,1-有效',
},
},
comment: '状态:0-已解除,1-有效',
},
created_at: {
type: DATE,
allowNull: false,
comment: '创建时间',
},
updated_at: {
type: DATE,
allowNull: false,
comment: '更新时间',
},
real_name: {
type: STRING(50),
allowNull: true,
comment: '工号的真实姓名',
},
}, {
tableName: 'wms_account_store_employee',
freezeTableName: true,
underscored: true,
timestamps: true,
createdAt: 'created_at',
updatedAt: 'updated_at',
comment: '账号仓库角色关联表',
indexes: [
{
name: 'uk_account_store_role',
fields: [ 'account_id', 'store_id' ],
unique: true,
},
{
name: 'idx_account_id',
fields: [ 'account_id' ],
},
{
name: 'idx_store_id',
fields: [ 'store_id' ],
},
{
name: 'idx_status',
fields: [ 'status' ],
},
],
});
// 关联关系
AccountStoreEmployee.associate = function() {
const { Account, Store, AccountPlatformActive, EmployeeRole, Receiving } = app.model;
AccountStoreEmployee.belongsTo(Account, {
foreignKey: 'account_id',
as: 'account',
});
AccountStoreEmployee.belongsTo(Store, {
foreignKey: 'store_id',
as: 'store',
});
AccountStoreEmployee.hasMany(AccountPlatformActive, {
foreignKey: 'employee_id',
as: 'platformActives',
});
AccountStoreEmployee.hasMany(EmployeeRole, {
foreignKey: 'employee_id',
as: 'employeeRoles',
});
AccountStoreEmployee.hasMany(Receiving, {
foreignKey: 'creator_id',
as: 'Receiving',
});
};
// 实例方法:检查是否有效
AccountStoreEmployee.prototype.isValid = function() {
return this.status === 1;
};
return AccountStoreEmployee;
};