contact.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. 'use strict';
  2. const {
  3. Model
  4. } = require('sequelize');
  5. module.exports = (sequelize, DataTypes) => {
  6. class Contact extends Model {
  7. /**
  8. * Helper method for defining associations.
  9. * This method is not a part of Sequelize lifecycle.
  10. * The `models/index` file will call this method automatically.
  11. */
  12. static associate(models) {
  13. // define association here
  14. }
  15. }
  16. Contact.init({
  17. id: {
  18. type: DataTypes.INTEGER,
  19. primaryKey: true,
  20. autoIncrement: true
  21. },
  22. name: {
  23. type: DataTypes.STRING(100),
  24. allowNull: false,
  25. comment: '联系人姓名'
  26. },
  27. email: {
  28. type: DataTypes.STRING(255),
  29. allowNull: false,
  30. validate: {
  31. isEmail: true
  32. },
  33. comment: '联系人邮箱'
  34. },
  35. phone: {
  36. type: DataTypes.STRING(20),
  37. allowNull: true,
  38. comment: '联系电话'
  39. },
  40. company: {
  41. type: DataTypes.STRING(200),
  42. allowNull: true,
  43. comment: '公司名称'
  44. },
  45. subject: {
  46. type: DataTypes.STRING(200),
  47. allowNull: false,
  48. comment: '留言主题'
  49. },
  50. message: {
  51. type: DataTypes.TEXT,
  52. allowNull: false,
  53. comment: '留言内容'
  54. },
  55. status: {
  56. type: DataTypes.INTEGER,
  57. defaultValue: 0,
  58. comment: '处理状态:0-未处理,1-已处理'
  59. },
  60. isEmailSent: {
  61. type: DataTypes.BOOLEAN,
  62. defaultValue: false,
  63. comment: '是否已发送邮件通知'
  64. }
  65. }, {
  66. sequelize,
  67. modelName: 'Contact',
  68. tableName: 'contacts',
  69. timestamps: true,
  70. indexes: [
  71. {
  72. fields: ['email']
  73. },
  74. {
  75. fields: ['status']
  76. },
  77. {
  78. fields: ['createdAt']
  79. }
  80. ]
  81. });
  82. return Contact;
  83. };