- 按主体隔离的分类/品牌/单位 CRUD 与 /select 下拉接口 - 商品模型增加 brand_id / unit_id,属性被商品引用时禁止删除(attributeUsage) - 迁移:建三张字典表、商品表加字段、种子属性菜单、is_system 保护内置项 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
34 lines
1.5 KiB
JavaScript
34 lines
1.5 KiB
JavaScript
'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' },
|
||
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' });
|
||
};
|
||
|
||
return ProductUnit;
|
||
};
|