给超管发消息

pull/23/head
taoshihan1991 4 years ago
parent 6af8350add
commit fad3b1f75b

@ -5,6 +5,7 @@ import (
"github.com/taoshihan1991/imaptool/models"
"github.com/taoshihan1991/imaptool/tmpl"
"github.com/taoshihan1991/imaptool/tools"
"github.com/taoshihan1991/imaptool/ws"
"net/http"
)
@ -34,7 +35,7 @@ func MainCheckAuth(c *gin.Context) {
func GetStatistics(c *gin.Context) {
visitors := models.CountVisitors()
message := models.CountMessage()
session := len(clientList)
session := len(ws.ClientList)
c.JSON(200, gin.H{
"code": 200,
"msg": "ok",

@ -170,17 +170,30 @@ func SendMessageV2(c *gin.Context) {
}
str, _ := json.Marshal(msg)
conn.WriteMessage(websocket.TextMessage, str)
msg = TypeMessage{
Type: "message",
Data: ClientMessage{
Name: kefuInfo.Nickname,
Avator: kefuInfo.Avator,
Id: vistorInfo.VisitorId,
Time: time.Now().Format("2006-01-02 15:04:05"),
ToId: vistorInfo.VisitorId,
Content: content,
},
}
str2, _ := json.Marshal(msg)
ws.SuperAdminMessage(str2)
}
if cType == "visitor" {
kefuConns, ok := ws.KefuList[kefuInfo.Name]
if kefuConns == nil || !ok {
c.JSON(200, gin.H{
"code": 200,
"msg": "ok",
})
return
}
//kefuConns, ok := ws.KefuList[kefuInfo.Name]
//if kefuConns == nil || !ok {
// c.JSON(200, gin.H{
// "code": 200,
// "msg": "ok",
// })
// return
//}
msg = TypeMessage{
Type: "message",
Data: ClientMessage{
@ -193,9 +206,7 @@ func SendMessageV2(c *gin.Context) {
},
}
str, _ := json.Marshal(msg)
for _, kefuConn := range kefuConns {
kefuConn.Conn.WriteMessage(websocket.TextMessage, str)
}
ws.OneKefuMessage(kefuInfo.Name, str)
}
c.JSON(200, gin.H{
"code": 200,

@ -9,8 +9,8 @@ import (
)
func NewKefuServer(c *gin.Context) {
kefuId, _ := c.Get("kefu_name")
kefuInfo := models.FindUser(kefuId.(string))
kefuId, _ := c.Get("kefu_id")
kefuInfo := models.FindUserById(kefuId)
if kefuInfo.ID == 0 {
c.JSON(200, gin.H{
"code": 400,
@ -30,6 +30,7 @@ func NewKefuServer(c *gin.Context) {
kefu.Id = kefuInfo.Name
kefu.Name = kefuInfo.Nickname
kefu.Avator = kefuInfo.Avator
kefu.Role_id = kefuInfo.RoleId
kefu.Conn = conn
AddKefuToList(&kefu)
@ -96,3 +97,27 @@ func kefuServerBackend() {
}
}
//给超管发消息
func SuperAdminMessage(str []byte) {
//给超管发
for _, kefuUsers := range KefuList {
for _, kefuUser := range kefuUsers {
if kefuUser.Role_id == "2" {
kefuUser.Conn.WriteMessage(websocket.TextMessage, str)
}
}
}
}
//给指定客服发消息
func OneKefuMessage(toId string, str []byte) {
//新版
mKefuConns := KefuList[toId]
if mKefuConns != nil {
for _, kefu := range mKefuConns {
kefu.Conn.WriteMessage(websocket.TextMessage, str)
}
}
SuperAdminMessage(str)
}

@ -3,7 +3,6 @@ package ws
import (
"encoding/json"
"github.com/gin-gonic/gin"
"github.com/gorilla/websocket"
"github.com/taoshihan1991/imaptool/models"
"log"
)
@ -54,12 +53,8 @@ func NewVisitorServer(c *gin.Context) {
Data: userInfo,
}
str, _ := json.Marshal(msg)
kefuConns := KefuList[visitor.To_id]
if kefuConns != nil {
for _, kefuConn := range kefuConns {
kefuConn.Conn.WriteMessage(websocket.TextMessage, str)
}
}
//新版
OneKefuMessage(user.To_id, str)
}
}
log.Println(err)
@ -93,10 +88,5 @@ func AddVisitorToList(user *User) {
str, _ := json.Marshal(msg)
//新版
mKefuConns := KefuList[user.To_id]
if mKefuConns != nil {
for _, kefu := range mKefuConns {
kefu.Conn.WriteMessage(websocket.TextMessage, str)
}
}
OneKefuMessage(user.To_id, str)
}

@ -13,11 +13,12 @@ import (
)
type User struct {
Conn *websocket.Conn
Name string
Id string
Avator string
To_id string
Conn *websocket.Conn
Name string
Id string
Avator string
To_id string
Role_id string
}
type Message struct {
conn *websocket.Conn

Loading…
Cancel
Save