|
@@ -9,12 +9,16 @@ import (
|
|
|
)
|
|
|
|
|
|
type MessageType string
|
|
|
+type UserType string
|
|
|
|
|
|
const (
|
|
|
UnReadStatus message.StatusType = "UNREAD"
|
|
|
ReadStatus message.StatusType = "READ"
|
|
|
MaxBatchNum = 1000
|
|
|
MyMessageColumns = "id,source_id,type,message"
|
|
|
+
|
|
|
+ Customer UserType = "user"
|
|
|
+ Admin UserType = "admin"
|
|
|
)
|
|
|
|
|
|
var (
|
|
@@ -30,6 +34,7 @@ type UserMessage struct {
|
|
|
Id int `gorm:"primaryKey;autoIncrement;column:id"`
|
|
|
AnalystId int `gorm:"column:analyst_id"`
|
|
|
UserId int `gorm:"column:user_id"`
|
|
|
+ UserType UserType `gorm:"column:user_type;type:enum('user','admin')"`
|
|
|
SourceId int `gorm:"column:source_id"`
|
|
|
Message string `gorm:"column:message"`
|
|
|
Type message.SourceType `gorm:"column:type;type:enum('REPORT','VIDEO','AUDIO')"`
|
|
@@ -65,7 +70,7 @@ func BatchInsertMessage(messages []UserMessage) bool {
|
|
|
func NeedNotice(userId int, analystId int) bool {
|
|
|
db := models.Main()
|
|
|
var count int
|
|
|
- err := db.Model(&UserMessage{}).Select("count(*)").Where("user_id =? and analyst_id =? and status=?", userId, analystId, UnReadStatus).Scan(&count).Error
|
|
|
+ err := db.Model(&UserMessage{}).Select("count(*)").Where("user_id =? and user_type=? and analyst_id =? and status=?", userId, Customer, analystId, UnReadStatus).Scan(&count).Error
|
|
|
if err != nil {
|
|
|
logger.Error("统计未读消息失败:%v", err)
|
|
|
return false
|
|
@@ -75,13 +80,13 @@ func NeedNotice(userId int, analystId int) bool {
|
|
|
|
|
|
func GetUnReadMessageList(userId int) (messages []UserMessage, err error) {
|
|
|
db := models.Main()
|
|
|
- err = db.Select(MyMessageColumns).Where("user_id=? and status=?", userId, UnReadStatus).Order("created_time desc").Find(&messages).Error
|
|
|
+ err = db.Select(MyMessageColumns).Where("user_id=? and user_type=? and status=?", userId, Customer, UnReadStatus).Order("created_time desc").Find(&messages).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func ReadMessage(userId int, messageId int) bool {
|
|
|
db := models.Main()
|
|
|
- err := db.Model(&UserMessage{}).Where("id=? and user_id=? and type in ?", messageId, userId, messageTypeMap).Update("status", ReadStatus).Error
|
|
|
+ err := db.Model(&UserMessage{}).Where("id=? and user_id=? and user_type=?", messageId, userId, Customer).Update("status", ReadStatus).Error
|
|
|
if err != nil {
|
|
|
return false
|
|
|
}
|
|
@@ -90,7 +95,7 @@ func ReadMessage(userId int, messageId int) bool {
|
|
|
|
|
|
func ReadMessages(userId int, analystId int) bool {
|
|
|
db := models.Main()
|
|
|
- err := db.Model(&UserMessage{}).Where("user_id=? and analyst_id =? and type in ?", userId, analystId, messageTypeMap).Update("status", ReadStatus).Error
|
|
|
+ err := db.Model(&UserMessage{}).Where("user_id=? and user_type=? and analyst_id =? ", userId, Customer, analystId).Update("status", ReadStatus).Error
|
|
|
if err != nil {
|
|
|
return false
|
|
|
}
|