更新状态字段

pull/23/head
陶士涵 4 years ago
parent f79186716e
commit 5306f81ea6

@ -239,103 +239,103 @@ func sendPingOnlineUsers() {
} }
//后端广播发送消息 //后端广播发送消息
func singleBroadcaster() { //func singleBroadcaster() {
for { // for {
message := <-message // message := <-message
//log.Println("debug:",message) // //log.Println("debug:",message)
//
var typeMsg TypeMessage // var typeMsg TypeMessage
var clientMsg ClientMessage // var clientMsg ClientMessage
json.Unmarshal(message.content, &typeMsg) // json.Unmarshal(message.content, &typeMsg)
conn := message.conn // conn := message.conn
if typeMsg.Type == nil || typeMsg.Data == nil { // if typeMsg.Type == nil || typeMsg.Data == nil {
continue // continue
} // }
msgType := typeMsg.Type.(string) // msgType := typeMsg.Type.(string)
msgData, _ := json.Marshal(typeMsg.Data) // msgData, _ := json.Marshal(typeMsg.Data)
switch msgType { // switch msgType {
//用户上线 // //用户上线
case "userInit": // case "userInit":
json.Unmarshal(msgData, &clientMsg) // json.Unmarshal(msgData, &clientMsg)
vistorInfo := models.FindVisitorByVistorId(clientMsg.VisitorId) // vistorInfo := models.FindVisitorByVistorId(clientMsg.VisitorId)
if vistorInfo.VisitorId == "" { // if vistorInfo.VisitorId == "" {
SendNotice("访客数据不存在", conn) // SendNotice("访客数据不存在", conn)
continue // continue
} // }
//用户id对应的连接 // //用户id对应的连接
user := &vistor{ // user := &vistor{
conn: conn, // conn: conn,
name: clientMsg.Name, // name: clientMsg.Name,
avator: clientMsg.Avator, // avator: clientMsg.Avator,
id: clientMsg.VisitorId, // id: clientMsg.VisitorId,
to_id: clientMsg.ToId, // to_id: clientMsg.ToId,
} // }
clientList[clientMsg.VisitorId] = user // clientList[clientMsg.VisitorId] = user
//插入数据表 // //插入数据表
models.UpdateVisitor(clientMsg.VisitorId, 1, clientMsg.ClientIp, message.c.ClientIP(), clientMsg.Refer) // models.UpdateVisitor(clientMsg.VisitorId, 1, clientMsg.ClientIp, message.c.ClientIP(), clientMsg.Refer, "")
//models.CreateVisitor(clientMsg.Name,clientMsg.Avator,message.c.ClientIP(),clientMsg.ToId,clientMsg.VisitorId,clientMsg.Refer,clientMsg.City,clientMsg.ClientIp) // //models.CreateVisitor(clientMsg.Name,clientMsg.Avator,message.c.ClientIP(),clientMsg.ToId,clientMsg.VisitorId,clientMsg.Refer,clientMsg.City,clientMsg.ClientIp)
userInfo := make(map[string]string) // userInfo := make(map[string]string)
userInfo["uid"] = user.id // userInfo["uid"] = user.id
userInfo["username"] = user.name // userInfo["username"] = user.name
userInfo["avator"] = user.avator // userInfo["avator"] = user.avator
msg := TypeMessage{ // msg := TypeMessage{
Type: "userOnline", // Type: "userOnline",
Data: userInfo, // Data: userInfo,
} // }
str, _ := json.Marshal(msg) // str, _ := json.Marshal(msg)
//
//新版 // //新版
mKefuConns := ws.KefuList[user.to_id] // mKefuConns := ws.KefuList[user.to_id]
if mKefuConns != nil { // if mKefuConns != nil {
for _, kefu := range mKefuConns { // for _, kefu := range mKefuConns {
kefu.Conn.WriteMessage(websocket.TextMessage, str) // kefu.Conn.WriteMessage(websocket.TextMessage, str)
} // }
} // }
//
//兼容旧版 // //兼容旧版
kefuConns := kefuList[user.to_id] // kefuConns := kefuList[user.to_id]
if kefuConns != nil { // if kefuConns != nil {
for k, kefuConn := range kefuConns { // for k, kefuConn := range kefuConns {
log.Println(k, "xxxxxxxx") // log.Println(k, "xxxxxxxx")
kefuConn.WriteMessage(websocket.TextMessage, str) // kefuConn.WriteMessage(websocket.TextMessage, str)
} // }
} // }
//
//客户上线发微信通知 // //客户上线发微信通知
go SendServerJiang(userInfo["username"]) // go SendServerJiang(userInfo["username"])
sendPingOnlineUsers() // sendPingOnlineUsers()
//客服上线 // //客服上线
case "kfOnline": // case "kfOnline":
json.Unmarshal(msgData, &clientMsg) // json.Unmarshal(msgData, &clientMsg)
//客服id对应的连接 // //客服id对应的连接
var newKefuConns = []*websocket.Conn{conn} // var newKefuConns = []*websocket.Conn{conn}
kefuConns := kefuList[clientMsg.Id] // kefuConns := kefuList[clientMsg.Id]
if kefuConns != nil { // if kefuConns != nil {
newKefuConns = append(newKefuConns, kefuConns...) // newKefuConns = append(newKefuConns, kefuConns...)
} // }
log.Println(newKefuConns) // log.Println(newKefuConns)
kefuList[clientMsg.Id] = newKefuConns // kefuList[clientMsg.Id] = newKefuConns
//发送给客户 // //发送给客户
if len(clientList) == 0 { // if len(clientList) == 0 {
continue // continue
} // }
sendPingOnlineUsers() // sendPingOnlineUsers()
//客服接手 // //客服接手
case "kfConnect": // case "kfConnect":
json.Unmarshal(msgData, &clientMsg) // json.Unmarshal(msgData, &clientMsg)
visitor, ok := clientList[clientMsg.ToId] // visitor, ok := clientList[clientMsg.ToId]
if visitor == nil || !ok { // if visitor == nil || !ok {
continue // continue
} // }
SendKefuOnline(clientMsg, visitor.conn) // SendKefuOnline(clientMsg, visitor.conn)
//心跳 // //心跳
case "ping": // case "ping":
msg := TypeMessage{ // msg := TypeMessage{
Type: "pong", // Type: "pong",
} // }
str, _ := json.Marshal(msg) // str, _ := json.Marshal(msg)
conn.WriteMessage(websocket.TextMessage, str) // conn.WriteMessage(websocket.TextMessage, str)
} // }
//
} // }
} //}

Loading…
Cancel
Save