message.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package models
  2. import "github.com/jinzhu/gorm"
  3. type Message struct {
  4. ProjectName string
  5. ConsumeName string
  6. SourceId int64
  7. UserId string
  8. }
  9. type MessageInfo struct {
  10. ID int64 `gorm:"column:id;primary_key;auto_increment;"`
  11. Title string `gorm:"column:title"`
  12. Content string `gorm:"column:content"`
  13. SourceId int64 `gorm:"column:source_id"`
  14. Type int `gorm:"column:type"`
  15. Subtype int `gorm:"column:subtype"`
  16. }
  17. func (MessageInfo) TableName() string {
  18. return "btk_message_info"
  19. }
  20. func (m Message) GetMessageTitle() string {
  21. return "【励华科技】提醒您, “" + m.ProjectName + "”" + m.ConsumeName + "建议更换, 请及时处理。"
  22. }
  23. func (m Message) GetMessageContent() string {
  24. return "“" + m.ProjectName + "”" + m.ConsumeName + "建议更换, 您可以进入 服务-服务管理 模块进行预约更换, " +
  25. "我们在收到你的预约后将与您联系确认上门时间, 请保证联系方式正确并保持通讯正常。\n感谢您的支持!"
  26. }
  27. func (m Message) Save(db *gorm.DB) error {
  28. var err error
  29. var msgInfo = MessageInfo{
  30. Title: m.GetMessageTitle(),
  31. Content: m.GetMessageContent(),
  32. SourceId: m.SourceId,
  33. Type: 1,
  34. Subtype: 2,
  35. }
  36. if err = db.Save(&msgInfo).Error; err != nil {
  37. return err
  38. }
  39. sql := "INSERT INTO btk_message_user_relation(message_id, message_type, receiver_id) VALUES(?,?,?)"
  40. if err = db.Exec(sql, msgInfo.ID, 1, m.UserId).Error; err != nil {
  41. return err
  42. }
  43. return nil
  44. }