orders.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /* indent size: 2 */
  2. // eslint-disable-next-line strict
  3. module.exports = app => {
  4. const DataTypes = app.Sequelize;
  5. const Model = app.model.define('Orders', {
  6. order_id: {
  7. type: DataTypes.INTEGER(10).UNSIGNED,
  8. allowNull: false,
  9. primaryKey: true,
  10. autoIncrement: true,
  11. },
  12. order_sn: {
  13. type: DataTypes.CHAR(22),
  14. allowNull: true,
  15. },
  16. order_status: {
  17. type: DataTypes.INTEGER(3).UNSIGNED,
  18. allowNull: true,
  19. },
  20. pay_sn: {
  21. type: DataTypes.STRING(255),
  22. allowNull: true,
  23. },
  24. user_id: {
  25. type: DataTypes.INTEGER(10).UNSIGNED,
  26. allowNull: true,
  27. },
  28. inviter_id: {
  29. type: DataTypes.INTEGER(10).UNSIGNED,
  30. allowNull: true,
  31. },
  32. commission_log_id: {
  33. type: DataTypes.INTEGER(10).UNSIGNED,
  34. allowNull: true,
  35. },
  36. order_amount: {
  37. type: DataTypes.FLOAT,
  38. allowNull: true,
  39. },
  40. user_remarks: {
  41. type: DataTypes.STRING(255),
  42. allowNull: true,
  43. },
  44. seller_remarks: {
  45. type: DataTypes.STRING(255),
  46. allowNull: true,
  47. },
  48. consignee: {
  49. type: DataTypes.STRING(255),
  50. allowNull: true,
  51. },
  52. province_id: {
  53. type: DataTypes.INTEGER(10).UNSIGNED,
  54. allowNull: true,
  55. },
  56. city_id: {
  57. type: DataTypes.INTEGER(10).UNSIGNED,
  58. allowNull: true,
  59. },
  60. county_id: {
  61. type: DataTypes.INTEGER(10).UNSIGNED,
  62. allowNull: true,
  63. },
  64. address: {
  65. type: DataTypes.STRING(255),
  66. allowNull: true,
  67. },
  68. mobile: {
  69. type: DataTypes.STRING(255),
  70. allowNull: true,
  71. },
  72. shipping_id: {
  73. type: DataTypes.INTEGER(10).UNSIGNED,
  74. allowNull: true,
  75. },
  76. pay_id: {
  77. type: DataTypes.INTEGER(10).UNSIGNED,
  78. allowNull: true,
  79. },
  80. shipping_fee: {
  81. type: DataTypes.FLOAT,
  82. allowNull: true,
  83. },
  84. surplus_amout: {
  85. type: DataTypes.FLOAT,
  86. allowNull: true,
  87. },
  88. activity_id: {
  89. type: DataTypes.INTEGER(11),
  90. allowNull: true,
  91. },
  92. activity_name: {
  93. type: DataTypes.STRING(255),
  94. allowNull: true,
  95. },
  96. activity_desc: {
  97. type: DataTypes.STRING(255),
  98. allowNull: true,
  99. },
  100. is_urge: {
  101. type: DataTypes.INTEGER(3).UNSIGNED,
  102. allowNull: true,
  103. },
  104. is_express: {
  105. type: DataTypes.INTEGER(1).UNSIGNED,
  106. allowNull: true,
  107. },
  108. dining_coin_send: {
  109. type: DataTypes.INTEGER(1).UNSIGNED,
  110. allowNull: true,
  111. },
  112. express_sn: {
  113. type: DataTypes.STRING(255),
  114. allowNull: true,
  115. },
  116. deliver_desc: {
  117. type: DataTypes.STRING(255),
  118. allowNull: true,
  119. },
  120. express_id: {
  121. type: DataTypes.INTEGER(10).UNSIGNED,
  122. allowNull: true,
  123. },
  124. deliver_time: {
  125. type: DataTypes.DATE,
  126. },
  127. query_time: {
  128. type: DataTypes.DATE,
  129. },
  130. success_time: {
  131. type: DataTypes.DATE,
  132. },
  133. create_time: {
  134. type: DataTypes.DATE,
  135. },
  136. }, {
  137. tableName: 'szj_orders',
  138. });
  139. Model.associate = function() {
  140. // 关联用户表
  141. Model.belongsTo(app.model.Users, { foreignKey: 'user_id', targetKey: 'user_id', as: 'users' });
  142. Model.belongsTo(app.model.Users, { foreignKey: 'inviter_id', targetKey: 'user_id', as: 'inviter' });
  143. // 关联订单商品表
  144. Model.hasMany(app.model.OrdersProducts, { foreignKey: 'order_id', targetKey: 'order_id', as: 'orders_products' });
  145. // 关闭支付类型表
  146. Model.belongsTo(app.model.PaysConfig, { foreignKey: 'pay_id', targetKey: 'pay_id', as: 'pays_config' });
  147. // 关联订单支付表
  148. Model.belongsTo(app.model.Payments, { foreignKey: 'pay_sn', targetKey: 'out_trade_no', as: 'payments' });
  149. };
  150. // 同步:没有就新建,有就不变
  151. Model.sync();
  152. return Model;
  153. };