oms/backend/app/model/product.js

35 lines
1.5 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';
/**
* 商品模型,对应 products 表
* @param {Egg.Application} app egg application
* @return {object} product model
*/
module.exports = app => {
const { BIGINT, STRING, TINYINT, DECIMAL, DATE } = app.Sequelize;
const Product = app.model.define('product', {
id: { type: BIGINT.UNSIGNED, primaryKey: true, autoIncrement: true, comment: '主键' },
principal_id: { type: BIGINT.UNSIGNED, allowNull: false, comment: '所属主体ID' },
code: { type: STRING(50), allowNull: false, comment: '商品编码' },
name: { type: STRING(100), allowNull: false, comment: '商品名称' },
type: { type: TINYINT, allowNull: false, defaultValue: 1, comment: '商品类型' },
category: { type: STRING(50), comment: '分类' },
spec: { type: STRING(100), comment: '规格' },
unit: { type: STRING(20), comment: '单位' },
price: { type: DECIMAL(12, 2), allowNull: false, defaultValue: 0, comment: '销售价' },
cost_price: { type: DECIMAL(12, 2), comment: '成本价' },
image: { type: STRING(255), 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: '更新时间' },
});
Product.associate = () => {
app.model.Product.belongsTo(app.model.Principal, { foreignKey: 'principal_id', as: 'principal' });
};
return Product;
};