products.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /* indent size: 2 */
  2. 'use strict';
  3. module.exports = app => {
  4. const DataTypes = app.Sequelize;
  5. const Model = app.model.define('Products', {
  6. product_id: {
  7. type: DataTypes.INTEGER(10).UNSIGNED,
  8. primaryKey: true,
  9. autoIncrement: true,
  10. },
  11. product_name: {
  12. type: DataTypes.STRING(255),
  13. allowNull: true,
  14. },
  15. product_desction: {
  16. type: DataTypes.STRING(255),
  17. allowNull: true,
  18. },
  19. product_stock: {
  20. type: DataTypes.INTEGER(10).UNSIGNED,
  21. allowNull: true,
  22. },
  23. product_image: {
  24. type: DataTypes.STRING(255),
  25. allowNull: true,
  26. },
  27. market_price: {
  28. type: DataTypes.FLOAT,
  29. allowNull: true,
  30. },
  31. cost_price: {
  32. type: DataTypes.FLOAT,
  33. allowNull: true,
  34. },
  35. shop_price: {
  36. type: DataTypes.FLOAT,
  37. allowNull: true,
  38. },
  39. activity_id: {
  40. type: DataTypes.INTEGER(10).UNSIGNED,
  41. allowNull: true,
  42. },
  43. carousel_id: {
  44. type: DataTypes.INTEGER(10).UNSIGNED,
  45. allowNull: true,
  46. },
  47. category_id: {
  48. type: DataTypes.INTEGER(10).UNSIGNED,
  49. allowNull: true,
  50. },
  51. product_sn: {
  52. type: DataTypes.CHAR(20),
  53. allowNull: true,
  54. },
  55. supplier_id: {
  56. type: DataTypes.INTEGER(10).UNSIGNED,
  57. allowNull: true,
  58. },
  59. is_sale: {
  60. type: DataTypes.INTEGER(1).UNSIGNED,
  61. allowNull: true,
  62. },
  63. alert_stock: {
  64. type: DataTypes.INTEGER(10).UNSIGNED,
  65. allowNull: true,
  66. },
  67. goods_type: {
  68. type: DataTypes.INTEGER(1).UNSIGNED,
  69. allowNull: true,
  70. },
  71. sale_count: {
  72. type: DataTypes.INTEGER(10).UNSIGNED,
  73. allowNull: true,
  74. },
  75. is_new: {
  76. type: DataTypes.INTEGER(1).UNSIGNED,
  77. allowNull: true,
  78. },
  79. is_home: {
  80. type: DataTypes.INTEGER(1).UNSIGNED,
  81. allowNull: true,
  82. },
  83. is_hot: {
  84. type: DataTypes.INTEGER(1).UNSIGNED,
  85. allowNull: true,
  86. },
  87. content_id: {
  88. type: DataTypes.INTEGER(10).UNSIGNED,
  89. allowNull: true,
  90. },
  91. admin_id: {
  92. type: DataTypes.INTEGER(10).UNSIGNED,
  93. allowNull: true,
  94. },
  95. dinning_coin_amount: {
  96. type: DataTypes.INTEGER(10).UNSIGNED,
  97. allowNull: true,
  98. },
  99. dining_partner_id: {
  100. type: DataTypes.INTEGER(8),
  101. allowNull: true,
  102. },
  103. update_time: {
  104. type: DataTypes.TIME,
  105. },
  106. create_time: {
  107. type: DataTypes.DATE,
  108. allowNull: true,
  109. },
  110. }, {
  111. tableName: 'szj_products',
  112. });
  113. Model.associate = function() {
  114. // 关联管理员表
  115. Model.belongsTo(app.model.AdminUser, { foreignKey: 'admin_id', targetKey: 'admin_id', as: 'admin_user' });
  116. // 关联产品内容表
  117. Model.belongsTo(app.model.ProductContents, { foreignKey: 'content_id', targetKey: 'content_id', as: 'contents' });
  118. // 关联产品供货商表
  119. Model.belongsTo(app.model.ProductSuppliers, {
  120. foreignKey: 'supplier_id',
  121. targetKey: 'supplier_id',
  122. as: 'suppliers',
  123. });
  124. // 关联产品分类表
  125. Model.belongsTo(app.model.ProductCategory, {
  126. foreignKey: 'category_id',
  127. targetKey: 'category_id',
  128. as: 'categorys',
  129. });
  130. // 关联产品相册表
  131. Model.belongsTo(app.model.ProductCarousels, {
  132. foreignKey: 'carousel_id',
  133. targetKey: 'carousel_id',
  134. as: 'carousels',
  135. });
  136. // 关联商品评论表
  137. Model.belongsTo(app.model.ProductComment, {
  138. foreignKey: 'product_id',
  139. targetKey: 'product_id',
  140. as: 'product_comment',
  141. });
  142. // 关联商品sku
  143. Model.hasMany(app.model.ProductSku, {
  144. foreignKey: 'product_id',
  145. targetKey: 'product_id',
  146. as: 'productSkus',
  147. });
  148. };
  149. // 同步:没有就新建,有就不变
  150. Model.sync();
  151. return Model;
  152. };