You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
843 B
34 lines
843 B
package service
|
|
|
|
import (
|
|
"pure-admin/global"
|
|
"pure-admin/model"
|
|
"pure-admin/model/request"
|
|
)
|
|
|
|
func createOrUpdateNotify(info request.CreateNotify) error {
|
|
var (
|
|
err error
|
|
notify model.Notify
|
|
)
|
|
err = global.MG_DB.Model(&model.Notify{}).Where("user_id = ? AND relation_type = ? AND relation_id = ?", info.UserId, info.RelationType, info.RelationId).Find(¬ify).Error
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if notify.ID != 0 {
|
|
err = global.MG_DB.Model(&model.Notify{}).Where("id = ?", notify.ID).Update("title", info.Title).Error
|
|
if err != nil {
|
|
return err
|
|
}
|
|
} else {
|
|
notify.UserId = info.UserId
|
|
notify.RelationType = info.RelationType
|
|
notify.RelationId = info.RelationId
|
|
notify.Title = info.Title
|
|
err = global.MG_DB.Model(&model.Notify{}).Create(¬ify).Error
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return err
|
|
}
|
|
|