order.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. const { DataTypes } = require('sequelize');
  2. const connect = require('./connect');
  3. const { dateFormat } = require('../../utils');
  4. /*
  5. type: DataTypes.STRING,
  6. allowNull: false,
  7. defaultValue:'',
  8. comment: '名',
  9. */
  10. function format(m) {
  11. m.payAt && (m.payAt = dateFormat(m.payAt));
  12. }
  13. const model = connect.define(
  14. __filename.slice(__dirname.length + 1).replace('.js', ''),
  15. {
  16. id: {
  17. type: DataTypes.STRING,
  18. primaryKey: true,
  19. comment: 'id',
  20. },
  21. title: {
  22. type: DataTypes.STRING,
  23. allowNull: false,
  24. comment: '课程',
  25. },
  26. detailimg: {
  27. type: DataTypes.STRING,
  28. allowNull: false,
  29. comment: '课程',
  30. },
  31. recordId: {
  32. type: DataTypes.INTEGER,
  33. comment: '录播讲师',
  34. },
  35. cid: {
  36. type: DataTypes.INTEGER,
  37. allowNull: false,
  38. comment: '课程id',
  39. },
  40. price: {
  41. type: DataTypes.DECIMAL(10, 2),
  42. allowNull: false,
  43. comment: '支付价格',
  44. },
  45. discount: {
  46. type: DataTypes.CHAR(5),
  47. defaultValue: '',
  48. comment: '折扣价格',
  49. },
  50. code: {
  51. type: DataTypes.CHAR(6),
  52. defaultValue: '',
  53. comment: '邀请码',
  54. },
  55. uid: {
  56. type: DataTypes.INTEGER,
  57. allowNull: false,
  58. comment: '用户id',
  59. },
  60. payAt: {
  61. type: DataTypes.DATE,
  62. comment: '支付时间',
  63. },
  64. status: {
  65. type: DataTypes.INTEGER,
  66. defaultValue: 0,
  67. comment: '0为支付1亿支付2渠道',
  68. },
  69. channel: {
  70. type: DataTypes.INTEGER,
  71. defaultValue: 0,
  72. comment: '0在线支付2渠道',
  73. },
  74. },
  75. {
  76. comment: '订单',
  77. hooks: {
  78. beforeFind(option) {
  79. if (!option.order) {
  80. option.order = [['id', 'desc']];
  81. }
  82. },
  83. afterFind(m) {
  84. m && (Array.isArray(m) ? m.forEach(item => format(item)) : format(m));
  85. },
  86. },
  87. }
  88. );
  89. module.exports = model;