123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- package models
- import "github.com/jinzhu/gorm"
- type Message struct {
- ProjectName string
- ConsumeName string
- SourceId int64
- UserId string
- }
- type MessageInfo struct {
- ID int64 `gorm:"column:id;primary_key;auto_increment;"`
- Title string `gorm:"column:title"`
- Content string `gorm:"column:content"`
- SourceId int64 `gorm:"column:source_id"`
- Type int `gorm:"column:type"`
- Subtype int `gorm:"column:subtype"`
- }
- func (MessageInfo) TableName() string {
- return "btk_message_info"
- }
- func (m Message) GetMessageTitle() string {
- return "【励华科技】提醒您, “" + m.ProjectName + "”" + m.ConsumeName + "建议更换, 请及时处理。"
- }
- func (m Message) GetMessageContent() string {
- return "“" + m.ProjectName + "”" + m.ConsumeName + "建议更换, 您可以进入 服务-服务管理 模块进行预约更换, " +
- "我们在收到你的预约后将与您联系确认上门时间, 请保证联系方式正确并保持通讯正常。\n感谢您的支持!"
- }
- func (m Message) Save(db *gorm.DB) error {
- var err error
- var msgInfo = MessageInfo{
- Title: m.GetMessageTitle(),
- Content: m.GetMessageContent(),
- SourceId: m.SourceId,
- Type: 1,
- Subtype: 2,
- }
- if err = db.Save(&msgInfo).Error; err != nil {
- return err
- }
- sql := "INSERT INTO btk_message_user_relation(message_id, message_type, receiver_id) VALUES(?,?,?)"
- if err = db.Exec(sql, msgInfo.ID, 1, m.UserId).Error; err != nil {
- return err
- }
- return nil
- }
|