oms/backend/app/model/productUnit.js
liufumingren 9c9a81f168 feat: 商品属性(分类/品牌/单位)关联货主
- product_categories / product_brands / product_units 新增 subsidiary_id(NULL 表示主体级、全集团共用)
- 列表与下拉按货主范围过滤:货主权限仅可见「主体级 + 自己所属公司」,并支持按货主筛选
- 新增/编辑支持选择货主,货主权限只能选主体或自己所属公司;同货主范围内名称唯一
- 详情/更新/删除对越权属性返回 403;导出新增货主列并收窄到可见范围

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-11-05 02:15:25 +08:00

36 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';
/**
* 商品单位模型,对应 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;
};