oms/backend/app/model/comboProduct.js
liufumingren e8e83c714b feat(combo): 组合商品关联货主与同货主明细约束
- combo_products 新增 subsidiary_id(由组合明细的商品货主推导),列表展示货主
- 组合明细只允许来自同一货主的系统商品,混货主直接拒绝(接口 + 页面提示)
- 组合商品按货主范围隔离:货主权限仅可见/可维护自己所属公司的组合,创建也不能越界
- 组合编码可留空,由系统生成 ZH + 时间戳 + 随机数(主体内唯一);更新不可清空
- 组合导出新增货主列并按范围收窄;商品选择列表带出货主,选定货主后候选商品自动收窄

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

36 lines
2.0 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';
/**
* 组合商品模型,对应 combo_products 表
* @param {Egg.Application} app egg application
* @return {object} comboProduct model
*/
module.exports = app => {
const { BIGINT, STRING, TINYINT, DECIMAL, DATE } = app.Sequelize;
const ComboProduct = app.model.define('combo_product', {
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);由组合明细的商品货主推导' },
code: { type: STRING(50), allowNull: false, comment: '组合商品编码' },
name: { type: STRING(100), allowNull: false, comment: '组合商品名称' },
price: { type: DECIMAL(12, 2), allowNull: false, defaultValue: 0, 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: '更新时间' },
});
ComboProduct.associate = () => {
app.model.ComboProduct.belongsTo(app.model.Principal, { foreignKey: 'principal_id', as: 'principal' });
app.model.ComboProduct.belongsTo(app.model.PrincipalSubsidiary, { foreignKey: 'subsidiary_id', as: 'subsidiary' });
// 组合明细:一个组合商品包含多条「系统商品 + 数量」关系
app.model.ComboProduct.hasMany(app.model.ComboProductItem, { foreignKey: 'combo_product_id', as: 'items' });
// 反向关联:店铺商品单向绑定到该组合商品、订单明细解析到该组合商品
app.model.ComboProduct.hasMany(app.model.ShopProduct, { foreignKey: 'combo_product_id', as: 'shopProducts' });
app.model.ComboProduct.hasMany(app.model.OrderItem, { foreignKey: 'combo_product_id', as: 'orderItems' });
};
return ComboProduct;
};