oms/backend/app/model/principal.js

39 lines
1.7 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';
/**
* 主体模型,对应 principals 表
* @param {Egg.Application} app egg application
* @return {object} principal model
*/
module.exports = app => {
const { BIGINT, STRING, TINYINT, DATE } = app.Sequelize;
const Principal = app.model.define('principal', {
id: { type: BIGINT.UNSIGNED, primaryKey: true, autoIncrement: true, comment: '主键' },
code: { type: STRING(50), allowNull: false, comment: '主体编码' },
name: { type: STRING(100), allowNull: false, comment: '主体名称' },
type: { type: TINYINT, allowNull: false, defaultValue: 1, comment: '主体类型:1自营 2加盟 3外部' },
contact_name: { type: STRING(50), comment: '联系人' },
contact_phone: { type: STRING(20), comment: '联系电话' },
status: { type: TINYINT, allowNull: false, defaultValue: 1, comment: '状态:1启用 0禁用' },
remark: { type: STRING(255), comment: '备注' },
created_at: { type: DATE, comment: '创建时间' },
updated_at: { type: DATE, comment: '更新时间' },
});
Principal.associate = () => {
app.model.Principal.belongsToMany(app.model.User, {
through: app.model.PrincipalUser,
foreignKey: 'principal_id',
otherKey: 'user_id',
as: 'users',
});
app.model.Principal.hasMany(app.model.Product, { foreignKey: 'principal_id', as: 'products' });
app.model.Principal.hasMany(app.model.ComboProduct, { foreignKey: 'principal_id', as: 'comboProducts' });
app.model.Principal.hasMany(app.model.Order, { foreignKey: 'principal_id', as: 'orders' });
app.model.Principal.hasMany(app.model.PrincipalExternalApi, { foreignKey: 'principal_id', as: 'externalApis' });
};
return Principal;
};