WMS_MAIN/app/model/platform_setting.js
liufumingren d743e67b9d 1
2026-06-17 01:18:55 +08:00

84 lines
1.8 KiB
JavaScript
Raw Permalink 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';
/**
* 平台设置模型定义。
*
* @param {Egg.Application} app 应用实例
* @return {Object} 平台设置模型
*/
module.exports = app => {
const { STRING, BIGINT, INTEGER } = app.Sequelize;
const PlatformSetting = app.model.define('platform_setting', {
id: {
type: INTEGER(11),
primaryKey: true,
autoIncrement: true,
allowNull: false,
comment: '主键ID',
},
platform_code: {
type: STRING(50),
allowNull: false,
comment: '平台代码',
},
code: {
type: STRING(50),
allowNull: false,
comment: '设置代码',
},
name: {
type: STRING(100),
allowNull: false,
comment: '别名',
},
warehouse_id: {
type: BIGINT(20),
allowNull: true,
comment: '仓库ID,NULL表示系统级设置',
},
}, {
tableName: 'wms_platfrom_setting',
freezeTableName: true,
timestamps: false,
comment: '平台设置表',
indexes: [
{
name: 'uk_platform_setting_warehouse_platform_code',
unique: true,
fields: [ 'platform_code', 'warehouse_id' ],
},
{
name: 'uk_platform_setting_warehouse_code',
unique: true,
fields: [ 'code', 'warehouse_id' ],
},
{
name: 'idx_platform_setting_warehouse_id',
fields: [ 'warehouse_id' ],
},
],
});
/**
* 定义平台设置关联关系。
*/
PlatformSetting.associate = function() {
const { Store, Platform } = app.model;
PlatformSetting.belongsTo(Platform, {
foreignKey: 'platform_code',
targetKey: 'code',
as: 'platform',
});
PlatformSetting.belongsTo(Store, {
foreignKey: 'warehouse_id',
targetKey: 'id',
as: 'warehouse',
});
};
return PlatformSetting;
};