'use strict'; /** * 商品单位模型,对应 product_units 表(按主体隔离) * 供商品选择单位:落 unit_id(本表主键)+ stock_unit(单位名称文本,冗余存储)。 * @param {Egg.Application} app egg application * @return {object} productUnit model */ module.exports = app => { const { BIGINT, STRING, TINYINT, INTEGER, DATE } = app.Sequelize; const ProductUnit = app.model.define('product_unit', { id: { type: BIGINT.UNSIGNED, primaryKey: true, autoIncrement: true, comment: '主键' }, principal_id: { type: BIGINT.UNSIGNED, allowNull: false, comment: '所属主体ID' }, subsidiary_id: { type: BIGINT.UNSIGNED, allowNull: true, comment: '所属货主(下属公司ID);NULL 表示主体级(全集团共用)' }, name: { type: STRING(100), allowNull: false, comment: '单位名称' }, code: { type: STRING(50), comment: '单位编码' }, status: { type: TINYINT, allowNull: false, defaultValue: 1, comment: '状态:1启用 0禁用' }, sort: { type: INTEGER, allowNull: false, defaultValue: 0, comment: '排序(下拉展示顺序,越小越靠前)' }, remark: { type: STRING(255), comment: '备注' }, is_system: { type: TINYINT, allowNull: false, defaultValue: 0, comment: '是否系统默认:1系统数据(不可改/删,全部主体可见) 0自定义(按主体隔离)' }, created_at: { type: DATE, comment: '创建时间' }, updated_at: { type: DATE, comment: '更新时间' }, }, { tableName: 'product_units', comment: '商品单位', }); ProductUnit.associate = () => { app.model.ProductUnit.belongsTo(app.model.Principal, { foreignKey: 'principal_id', as: 'principal' }); app.model.ProductUnit.belongsTo(app.model.PrincipalSubsidiary, { foreignKey: 'subsidiary_id', as: 'subsidiary' }); }; return ProductUnit; };