123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- /* 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_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;
- };
|