contact.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. const { DataTypes } = require('sequelize');
  2. const sequelize = require('./index').sequelize;
  3. const Contact = sequelize.define('Contact', {
  4. id: {
  5. type: DataTypes.INTEGER,
  6. primaryKey: true,
  7. autoIncrement: true
  8. },
  9. name: {
  10. type: DataTypes.STRING(100),
  11. allowNull: false,
  12. comment: '联系人姓名'
  13. },
  14. email: {
  15. type: DataTypes.STRING(255),
  16. allowNull: false,
  17. validate: {
  18. isEmail: true
  19. },
  20. comment: '联系人邮箱'
  21. },
  22. phone: {
  23. type: DataTypes.STRING(20),
  24. allowNull: true,
  25. comment: '联系电话'
  26. },
  27. company: {
  28. type: DataTypes.STRING(200),
  29. allowNull: true,
  30. comment: '公司名称'
  31. },
  32. subject: {
  33. type: DataTypes.STRING(200),
  34. allowNull: false,
  35. comment: '留言主题'
  36. },
  37. message: {
  38. type: DataTypes.TEXT,
  39. allowNull: false,
  40. comment: '留言内容'
  41. },
  42. status: {
  43. type: DataTypes.INTEGER,
  44. defaultValue: 0,
  45. comment: '处理状态:0-未处理,1-已处理'
  46. },
  47. isEmailSent: {
  48. type: DataTypes.BOOLEAN,
  49. defaultValue: false,
  50. comment: '是否已发送邮件通知'
  51. }
  52. }, {
  53. tableName: 'contacts',
  54. timestamps: true,
  55. indexes: [
  56. {
  57. fields: ['email']
  58. },
  59. {
  60. fields: ['status']
  61. },
  62. {
  63. fields: ['createdAt']
  64. }
  65. ]
  66. });
  67. module.exports = Contact;