'use strict'; /** * 组合商品明细模型,对应 combo_product_items 表。 * 存储组合商品与系统商品的组合关系(product_id + quantity), * 一个组合内同一系统商品仅有一条记录。 * @param {Egg.Application} app egg application * @return {object} comboProductItem model */ module.exports = app => { const { BIGINT, INTEGER, DATE } = app.Sequelize; const ComboProductItem = app.model.define('combo_product_item', { id: { type: BIGINT.UNSIGNED, primaryKey: true, autoIncrement: true, comment: '主键' }, principal_id: { type: BIGINT.UNSIGNED, allowNull: false, comment: '所属主体ID' }, combo_product_id: { type: BIGINT.UNSIGNED, allowNull: false, comment: '所属组合商品ID' }, product_id: { type: BIGINT.UNSIGNED, allowNull: false, comment: '系统商品ID' }, quantity: { type: INTEGER.UNSIGNED, allowNull: false, defaultValue: 1, comment: '该商品在组合中的数量' }, created_at: { type: DATE, comment: '创建时间' }, updated_at: { type: DATE, comment: '更新时间' }, }); ComboProductItem.associate = () => { app.model.ComboProductItem.belongsTo(app.model.Principal, { foreignKey: 'principal_id', as: 'principal' }); app.model.ComboProductItem.belongsTo(app.model.ComboProduct, { foreignKey: 'combo_product_id', as: 'comboProduct' }); app.model.ComboProductItem.belongsTo(app.model.Product, { foreignKey: 'product_id', as: 'product' }); }; return ComboProductItem; };