准备设置消息状态

pull/30/head
taoshihan1991 4 years ago
parent 1cef6310d2
commit b6919e7e47

@ -69,6 +69,7 @@ func GetVisitorMessage(c *gin.Context) {
result=append(result,item) result=append(result,item)
} }
models.ReadMessageByVisitorId(visitorId)
c.JSON(200, gin.H{ c.JSON(200, gin.H{
"code": 200, "code": 200,
"msg": "ok", "msg": "ok",

@ -46,6 +46,13 @@ func main() {
engine.GET("/chat_server", controller.NewChatServer) engine.GET("/chat_server", controller.NewChatServer)
//获取消息 //获取消息
engine.GET("/messages",middleware.JwtApiMiddleware, controller.GetVisitorMessage) engine.GET("/messages",middleware.JwtApiMiddleware, controller.GetVisitorMessage)
//发送单条消息
engine.POST("/message",controller.GetVisitorMessage)
//获取未读消息数
engine.GET("/message_status",controller.GetVisitorMessage)
//设置消息已读
engine.POST("/message_status",controller.GetVisitorMessage)
//获取客服信息 //获取客服信息
engine.GET("/kefuinfo",middleware.JwtApiMiddleware, controller.GetKefuInfo) engine.GET("/kefuinfo",middleware.JwtApiMiddleware, controller.GetKefuInfo)
engine.GET("/kefuinfo_setting",middleware.JwtApiMiddleware, controller.GetKefuInfoSetting) engine.GET("/kefuinfo_setting",middleware.JwtApiMiddleware, controller.GetKefuInfoSetting)

@ -22,3 +22,16 @@ func FindMessageByVisitorId(visitor_id string)[]Message{
DB.Where("visitor_id=?",visitor_id).Order("id asc").Find(&messages) DB.Where("visitor_id=?",visitor_id).Order("id asc").Find(&messages)
return messages return messages
} }
//修改消息状态
func ReadMessageByVisitorId(visitor_id string){
message:=&Message{
Status:"read",
}
DB.Model(&message).Where("visitor_id=?",visitor_id).Update(message)
}
//获取未读数
func FindUnreadMessageNumByVisitorId(visitor_id string)uint{
var count uint
DB.Where("visitor_id=? and status=?",visitor_id,"unread").Count(&count)
return count
}
Loading…
Cancel
Save