orders_products.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /* eslint-disable strict */
  2. /* indent size: 2 */
  3. module.exports = app => {
  4. const DataTypes = app.Sequelize;
  5. const Model = app.model.define('OrdersProducts', {
  6. rec_id: {
  7. type: DataTypes.INTEGER(10).UNSIGNED,
  8. allowNull: false,
  9. primaryKey: true,
  10. autoIncrement: true,
  11. },
  12. order_id: {
  13. type: DataTypes.INTEGER(10).UNSIGNED,
  14. allowNull: true,
  15. },
  16. product_id: {
  17. type: DataTypes.INTEGER(10).UNSIGNED,
  18. allowNull: true,
  19. },
  20. category_id: {
  21. type: DataTypes.INTEGER(10).UNSIGNED,
  22. allowNull: true,
  23. },
  24. product_name: {
  25. type: DataTypes.STRING(255),
  26. allowNull: true,
  27. },
  28. product_image: {
  29. type: DataTypes.STRING(255),
  30. allowNull: true,
  31. },
  32. product_count: {
  33. type: DataTypes.INTEGER(10).UNSIGNED,
  34. allowNull: true,
  35. },
  36. shop_price: {
  37. type: DataTypes.FLOAT,
  38. allowNull: true,
  39. },
  40. goods_type: {
  41. type: DataTypes.INTEGER(1).UNSIGNED,
  42. allowNull: true,
  43. },
  44. activity_id: {
  45. type: DataTypes.INTEGER(10).UNSIGNED,
  46. allowNull: true,
  47. },
  48. activity_name: {
  49. type: DataTypes.STRING(255),
  50. allowNull: true,
  51. },
  52. activity_desc: {
  53. type: DataTypes.STRING(255),
  54. allowNull: true,
  55. },
  56. is_deliver: {
  57. type: DataTypes.INTEGER(1).UNSIGNED,
  58. allowNull: true,
  59. },
  60. deliver_count: {
  61. type: DataTypes.INTEGER(10).UNSIGNED,
  62. allowNull: true,
  63. },
  64. total_price: {
  65. type: DataTypes.FLOAT,
  66. allowNull: true,
  67. },
  68. create_time: {
  69. type: DataTypes.DATE,
  70. allowNull: true,
  71. },
  72. volume: {
  73. type: DataTypes.INTEGER(10).UNSIGNED,
  74. allowNull: false,
  75. },
  76. price: {
  77. type: DataTypes.FLOAT,
  78. allowNull: true,
  79. },
  80. dinning_coin_amount: {
  81. type: DataTypes.INTEGER(10).UNSIGNED,
  82. allowNull: true,
  83. },
  84. dining_partner_id: {
  85. type: DataTypes.INTEGER(8),
  86. allowNull: true,
  87. },
  88. }, {
  89. tableName: 'szj_orders_products',
  90. });
  91. Model.associate = function() {
  92. // 关联订单表
  93. Model.belongsTo(app.model.Orders, { foreignKey: 'order_id', targetKey: 'order_id', as: 'orders' });
  94. // 关联商品表
  95. Model.belongsTo(app.model.Products, { foreignKey: 'product_id', targetKey: 'product_id', as: 'products' });
  96. // 关联评价表
  97. Model.belongsTo(app.model.ProductComment, {
  98. foreignKey: 'product_id',
  99. targetKey: 'product_id',
  100. as: 'product_comment',
  101. });
  102. };
  103. // 同步:没有就新建,有就不变
  104. Model.sync();
  105. return Model;
  106. };