/* indent size: 2 */ 'use strict'; module.exports = app => { const DataTypes = app.Sequelize; const Model = app.model.define('Products', { product_id: { type: DataTypes.INTEGER(10).UNSIGNED, primaryKey: true, autoIncrement: true, }, product_name: { type: DataTypes.STRING(255), allowNull: true, }, product_desction: { type: DataTypes.STRING(255), allowNull: true, }, product_stock: { type: DataTypes.INTEGER(10).UNSIGNED, allowNull: true, }, product_image: { type: DataTypes.STRING(255), allowNull: true, }, market_price: { type: DataTypes.FLOAT, allowNull: true, }, cost_price: { type: DataTypes.FLOAT, allowNull: true, }, shop_price: { type: DataTypes.FLOAT, allowNull: true, }, activity_id: { type: DataTypes.INTEGER(10).UNSIGNED, allowNull: true, }, carousel_id: { type: DataTypes.INTEGER(10).UNSIGNED, allowNull: true, }, category_id: { type: DataTypes.INTEGER(10).UNSIGNED, allowNull: true, }, product_sn: { type: DataTypes.CHAR(20), allowNull: true, }, supplier_id: { type: DataTypes.INTEGER(10).UNSIGNED, allowNull: true, }, is_sale: { type: DataTypes.INTEGER(1).UNSIGNED, allowNull: true, }, alert_stock: { type: DataTypes.INTEGER(10).UNSIGNED, allowNull: true, }, goods_type: { type: DataTypes.INTEGER(1).UNSIGNED, allowNull: true, }, sale_count: { type: DataTypes.INTEGER(10).UNSIGNED, allowNull: true, }, is_new: { type: DataTypes.INTEGER(1).UNSIGNED, allowNull: true, }, is_top: { type: DataTypes.INTEGER(1).UNSIGNED, allowNull: true, }, is_home: { type: DataTypes.INTEGER(1).UNSIGNED, allowNull: true, }, is_hot: { type: DataTypes.INTEGER(1).UNSIGNED, allowNull: true, }, content_id: { type: DataTypes.INTEGER(10).UNSIGNED, allowNull: true, }, admin_id: { type: DataTypes.INTEGER(10).UNSIGNED, allowNull: true, }, dinning_coin_amount: { type: DataTypes.INTEGER(10).UNSIGNED, allowNull: true, }, dining_partner_id: { type: DataTypes.INTEGER(8), allowNull: true, }, update_time: { type: DataTypes.TIME, }, create_time: { type: DataTypes.DATE, allowNull: true, }, }, { tableName: 'szj_products', }); Model.associate = function() { // 关联管理员表 Model.belongsTo(app.model.AdminUser, { foreignKey: 'admin_id', targetKey: 'admin_id', as: 'admin_user' }); // 关联产品内容表 Model.belongsTo(app.model.ProductContents, { foreignKey: 'content_id', targetKey: 'content_id', as: 'contents' }); // 关联产品供货商表 Model.belongsTo(app.model.ProductSuppliers, { foreignKey: 'supplier_id', targetKey: 'supplier_id', as: 'suppliers', }); // 关联产品分类表 Model.belongsTo(app.model.ProductCategory, { foreignKey: 'category_id', targetKey: 'category_id', as: 'categorys', }); // 关联产品相册表 Model.belongsTo(app.model.ProductCarousels, { foreignKey: 'carousel_id', targetKey: 'carousel_id', as: 'carousels', }); // 关联商品评论表 Model.belongsTo(app.model.ProductComment, { foreignKey: 'product_id', targetKey: 'product_id', as: 'product_comment', }); // 关联商品sku Model.hasMany(app.model.ProductSku, { foreignKey: 'product_id', targetKey: 'product_id', as: 'productSkus', }); }; // 同步:没有就新建,有就不变 Model.sync(); return Model; };