products.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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_top: {
  80. type: DataTypes.INTEGER(1).UNSIGNED,
  81. allowNull: true,
  82. },
  83. is_home: {
  84. type: DataTypes.INTEGER(1).UNSIGNED,
  85. allowNull: true,
  86. },
  87. is_hot: {
  88. type: DataTypes.INTEGER(1).UNSIGNED,
  89. allowNull: true,
  90. },
  91. content_id: {
  92. type: DataTypes.INTEGER(10).UNSIGNED,
  93. allowNull: true,
  94. },
  95. admin_id: {
  96. type: DataTypes.INTEGER(10).UNSIGNED,
  97. allowNull: true,
  98. },
  99. dinning_coin_amount: {
  100. type: DataTypes.INTEGER(10).UNSIGNED,
  101. allowNull: true,
  102. },
  103. dining_partner_id: {
  104. type: DataTypes.INTEGER(8),
  105. allowNull: true,
  106. },
  107. update_time: {
  108. type: DataTypes.TIME,
  109. },
  110. create_time: {
  111. type: DataTypes.DATE,
  112. allowNull: true,
  113. },
  114. }, {
  115. tableName: 'szj_products',
  116. });
  117. Model.associate = function() {
  118. // 关联管理员表
  119. Model.belongsTo(app.model.AdminUser, { foreignKey: 'admin_id', targetKey: 'admin_id', as: 'admin_user' });
  120. // 关联产品内容表
  121. Model.belongsTo(app.model.ProductContents, { foreignKey: 'content_id', targetKey: 'content_id', as: 'contents' });
  122. // 关联产品供货商表
  123. Model.belongsTo(app.model.ProductSuppliers, {
  124. foreignKey: 'supplier_id',
  125. targetKey: 'supplier_id',
  126. as: 'suppliers',
  127. });
  128. // 关联产品分类表
  129. Model.belongsTo(app.model.ProductCategory, {
  130. foreignKey: 'category_id',
  131. targetKey: 'category_id',
  132. as: 'categorys',
  133. });
  134. // 关联产品相册表
  135. Model.belongsTo(app.model.ProductCarousels, {
  136. foreignKey: 'carousel_id',
  137. targetKey: 'carousel_id',
  138. as: 'carousels',
  139. });
  140. // 关联商品评论表
  141. Model.belongsTo(app.model.ProductComment, {
  142. foreignKey: 'product_id',
  143. targetKey: 'product_id',
  144. as: 'product_comment',
  145. });
  146. // 关联商品sku
  147. Model.hasMany(app.model.ProductSku, {
  148. foreignKey: 'product_id',
  149. targetKey: 'product_id',
  150. as: 'productSkus',
  151. });
  152. };
  153. // 同步:没有就新建,有就不变
  154. Model.sync();
  155. return Model;
  156. };