inviter.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. const { DataTypes } = require('sequelize');
  2. const connect = require('./connect');
  3. /*
  4. type: DataTypes.STRING,
  5. allowNull: false,
  6. defaultValue:'',
  7. comment: '名',
  8. */
  9. const model = connect.define(
  10. __filename.slice(__dirname.length + 1).replace('.js', ''),
  11. {
  12. id: {
  13. type: DataTypes.INTEGER,
  14. autoIncrement: true,
  15. primaryKey: true,
  16. comment: 'id',
  17. },
  18. uid: {
  19. type: DataTypes.INTEGER,
  20. allowNull: false,
  21. comment: '用户id',
  22. },
  23. name: {
  24. type: DataTypes.STRING,
  25. comment: '名',
  26. },
  27. phone: {
  28. type: DataTypes.STRING,
  29. comment: '手机号',
  30. },
  31. code: {
  32. type: DataTypes.CHAR(6),
  33. allowNull: false,
  34. comment: '邀请码',
  35. },
  36. discount: {
  37. type: DataTypes.DECIMAL(3, 2),
  38. defaultValue: 1,
  39. comment: '折扣',
  40. },
  41. remark: {
  42. type: DataTypes.STRING,
  43. defaultValue: '',
  44. comment: '备注',
  45. },
  46. },
  47. {
  48. comment: '推荐人',
  49. hooks: {
  50. beforeFind(option) {
  51. if (!option.order) {
  52. option.order = [['id', 'desc']];
  53. }
  54. },
  55. },
  56. }
  57. );
  58. module.exports = model;