orders_products.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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_sn: {
  29. type: DataTypes.STRING(255),
  30. allowNull: true,
  31. },
  32. product_image: {
  33. type: DataTypes.STRING(255),
  34. allowNull: true,
  35. },
  36. product_count: {
  37. type: DataTypes.INTEGER(10).UNSIGNED,
  38. allowNull: true,
  39. },
  40. shop_price: {
  41. type: DataTypes.FLOAT,
  42. allowNull: true,
  43. },
  44. goods_type: {
  45. type: DataTypes.INTEGER(1).UNSIGNED,
  46. allowNull: true,
  47. },
  48. activity_id: {
  49. type: DataTypes.INTEGER(10).UNSIGNED,
  50. allowNull: true,
  51. },
  52. activity_name: {
  53. type: DataTypes.STRING(255),
  54. allowNull: true,
  55. },
  56. activity_desc: {
  57. type: DataTypes.STRING(255),
  58. allowNull: true,
  59. },
  60. is_deliver: {
  61. type: DataTypes.INTEGER(1).UNSIGNED,
  62. allowNull: true,
  63. },
  64. deliver_count: {
  65. type: DataTypes.INTEGER(10).UNSIGNED,
  66. allowNull: true,
  67. },
  68. total_price: {
  69. type: DataTypes.FLOAT,
  70. allowNull: true,
  71. },
  72. create_time: {
  73. type: DataTypes.DATE,
  74. allowNull: true,
  75. },
  76. volume: {
  77. type: DataTypes.INTEGER(10).UNSIGNED,
  78. allowNull: false,
  79. },
  80. price: {
  81. type: DataTypes.FLOAT,
  82. allowNull: true,
  83. },
  84. dinning_coin_amount: {
  85. type: DataTypes.INTEGER(10).UNSIGNED,
  86. allowNull: true,
  87. },
  88. dining_partner_id: {
  89. type: DataTypes.INTEGER(8),
  90. allowNull: true,
  91. },
  92. }, {
  93. tableName: 'szj_orders_products',
  94. });
  95. Model.associate = function() {
  96. // 关联订单表
  97. Model.belongsTo(app.model.Orders, { foreignKey: 'order_id', targetKey: 'order_id', as: 'orders' });
  98. // 关联商品表
  99. Model.belongsTo(app.model.Products, { foreignKey: 'product_id', targetKey: 'product_id', as: 'products' });
  100. // 关联评价表
  101. Model.belongsTo(app.model.ProductComment, {
  102. foreignKey: 'product_id',
  103. targetKey: 'product_id',
  104. as: 'product_comment',
  105. });
  106. };
  107. // 同步:没有就新建,有就不变
  108. Model.sync();
  109. return Model;
  110. };