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

92 lines
2.3 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 } = app.Sequelize;
const AccountPlatformActive = app.model.define('account_platform_active', {
account_id: {
type: BIGINT.UNSIGNED,
allowNull: false,
comment: '账号ID',
},
employee_id: {
type: BIGINT.UNSIGNED,
allowNull: false,
comment: '账号仓库角色关联ID',
},
platform_code: {
type: STRING(50),
allowNull: false,
validate: {
notEmpty: true,
len: [ 1, 50 ],
},
comment: '平台编码(web、pda、mini、app等)',
},
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_account_platform_active',
freezeTableName: true,
underscored: true,
timestamps: true,
createdAt: 'created_at',
updatedAt: 'updated_at',
paranoid: false, // 明确禁用软删除
comment: '账号平台激活状态表',
// 无主键ID,使用组合主键
id: false,
// 指定组合主键
primaryKey: [ 'account_id', 'platform_code' ],
indexes: [
{
name: 'uk_account_platform',
fields: [ 'account_id', 'platform_code' ],
unique: true,
},
{
name: 'uk_account_store_role_platform',
fields: [ 'employee_id', 'platform_code' ],
unique: true,
},
{
name: 'idx_account_id',
fields: [ 'account_id' ],
},
{
name: 'idx_platform_code',
fields: [ 'platform_code' ],
},
{
name: 'idx_employee_id',
fields: [ 'employee_id' ],
},
],
});
// 关联关系 - 注释掉或删除,统一在 app.js 中处理
AccountPlatformActive.associate = function() {
const { Account, AccountStoreEmployee } = app.model;
AccountPlatformActive.belongsTo(Account, {
foreignKey: 'account_id',
as: 'account',
});
AccountPlatformActive.belongsTo(AccountStoreEmployee, {
foreignKey: 'employee_id',
as: 'accountStoreEmployee',
});
};
return AccountPlatformActive;
};