增加客服之间的用户隔离

pull/30/head
taoshihan1991 5 years ago
parent 849caa8514
commit 194b6f3418

@ -14,6 +14,7 @@ type vistor struct{
name string name string
id string id string
avator string avator string
to_id string
} }
type Message struct{ type Message struct{
conn *websocket.Conn conn *websocket.Conn
@ -130,26 +131,29 @@ func sendPingUpdateStatus() {
//定时推送当前在线用户 //定时推送当前在线用户
func sendPingOnlineUsers() { func sendPingOnlineUsers() {
for { for {
result := make([]map[string]string, 0)
var visitorIds []string var visitorIds []string
for visitorId, _ := range clientList { for visitorId, _ := range clientList {
visitorIds=append(visitorIds,visitorId) visitorIds=append(visitorIds,visitorId)
} }
sort.Strings(visitorIds) sort.Strings(visitorIds)
for _,visitorId:=range visitorIds{
user:=clientList[visitorId]
userInfo := make(map[string]string)
userInfo["uid"] = user.id
userInfo["username"] = user.name
userInfo["avator"] = user.avator
result = append(result, userInfo)
}
msg := TypeMessage{
Type: "getOnlineUsers",
Data: result,
}
str, _ := json.Marshal(msg)
for kefuId, kfConn := range kefuList { for kefuId, kfConn := range kefuList {
result := make([]map[string]string, 0)
for _,visitorId:=range visitorIds{
user:=clientList[visitorId]
userInfo := make(map[string]string)
userInfo["uid"] = user.id
userInfo["username"] = user.name
userInfo["avator"] = user.avator
if user.to_id==kefuId{
result = append(result, userInfo)
}
}
msg := TypeMessage{
Type: "getOnlineUsers",
Data: result,
}
str, _ := json.Marshal(msg)
err:=kfConn.WriteMessage(websocket.TextMessage,str) err:=kfConn.WriteMessage(websocket.TextMessage,str)
if err != nil { if err != nil {
delete(kefuList, kefuId) delete(kefuList, kefuId)
@ -185,6 +189,7 @@ func singleBroadcaster(){
name: clientMsg.Name, name: clientMsg.Name,
avator: clientMsg.Avator, avator: clientMsg.Avator,
id:clientMsg.Id, id:clientMsg.Id,
to_id:clientMsg.ToId,
} }
clientList[clientMsg.Id] = user clientList[clientMsg.Id] = user
//插入数据表 //插入数据表

@ -18,7 +18,8 @@ func GetVisitor(c *gin.Context) {
} }
func GetVisitors(c *gin.Context) { func GetVisitors(c *gin.Context) {
page,_:=strconv.Atoi(c.Query("page")) page,_:=strconv.Atoi(c.Query("page"))
vistors:=models.FindVisitors(uint(page),config.VisitorPageSize) kefuId,_:=c.Get("kefu_name")
vistors:=models.FindVisitorsByKefuId(uint(page),config.VisitorPageSize,kefuId.(string))
count:=models.CountVisitors() count:=models.CountVisitors()
c.JSON(200, gin.H{ c.JSON(200, gin.H{
"code": 200, "code": 200,

@ -39,5 +39,6 @@ func JwtApiMiddleware(c *gin.Context){
c.Set("user",userinfo["name"]) c.Set("user",userinfo["name"])
if userinfo["type"]=="kefu"{ if userinfo["type"]=="kefu"{
c.Set("kefu_id",userinfo["kefu_id"]) c.Set("kefu_id",userinfo["kefu_id"])
c.Set("kefu_name",userinfo["name"])
} }
} }

@ -46,6 +46,15 @@ func FindVisitors(page uint,pagesize uint)[]Visitor{
DB.Offset(offset).Limit(pagesize).Order("status desc, updated_at desc").Find(&visitors) DB.Offset(offset).Limit(pagesize).Order("status desc, updated_at desc").Find(&visitors)
return visitors return visitors
} }
func FindVisitorsByKefuId(page uint,pagesize uint,kefuId string)[]Visitor{
offset:=(page-1)*pagesize
if offset<0{
offset=0
}
var visitors []Visitor
DB.Where("to_id=?",kefuId).Offset(offset).Limit(pagesize).Order("status desc, updated_at desc").Find(&visitors)
return visitors
}
func FindVisitorsOnline()[]Visitor{ func FindVisitorsOnline()[]Visitor{
var visitors []Visitor var visitors []Visitor
DB.Where("status = ?",1).Find(&visitors) DB.Where("status = ?",1).Find(&visitors)

@ -1,7 +1,6 @@
var loadJs=function(url,callback){ var loadJs=function(url,callback){
var script = document.createElement('script'), fn = callback || function(){}; var script = document.createElement('script'), fn = callback || function(){};
script.type = 'text/javascript'; script.type = 'text/javascript';
//IE
if(script.readyState){ if(script.readyState){
script.onreadystatechange = function(){ script.onreadystatechange = function(){
if( script.readyState == 'loaded' || script.readyState == 'complete' ){ if( script.readyState == 'loaded' || script.readyState == 'complete' ){
@ -10,7 +9,6 @@ var loadJs=function(url,callback){
} }
}; };
}else{ }else{
//其他浏览器
script.onload = function(){ script.onload = function(){
fn(); fn();
}; };
@ -21,7 +19,11 @@ var loadJs=function(url,callback){
loadJs("https://cdn.jsdelivr.net/npm/jquery/dist/jquery.min.js",function(){ loadJs("https://cdn.jsdelivr.net/npm/jquery/dist/jquery.min.js",function(){
loadJs("https://cdn.bootcdn.net/ajax/libs/layer/3.1.1/layer.min.js" ,function () { loadJs("https://cdn.bootcdn.net/ajax/libs/layer/3.1.1/layer.min.js" ,function () {
$(function () { $(function () {
//==================================================================== var goflyKefuId="";
if(typedef(GOFLY_KEFU_ID)!="undefined"){
var goflyKefuId=GOFLY_KEFU_ID;
}
var div =document.createElement('div'); var div =document.createElement('div');
div.id ='goflyKefu'; div.id ='goflyKefu';
div.className +='goflyKefu'; div.className +='goflyKefu';
@ -36,15 +38,15 @@ loadJs("https://cdn.jsdelivr.net/npm/jquery/dist/jquery.min.js",function(){
title: '在线咨询', title: '在线咨询',
shadeClose: true, shadeClose: true,
shade: false, shade: false,
maxmin: true, //开启最大化最小化按钮 maxmin: true,
area: ['660px', '600px'], area: ['660px', '600px'],
content: ['http://gofly.sopans.com/chat_page?kefu_id='+KEFU_ID,'no'], content: ['http://gofly.sopans.com/chat_page?kefu_id='+goflyKefuId,'no'],
end: function(){ end: function(){
$("#goflyKefu").show(); $("#goflyKefu").show();
} }
}); });
}); });
//--------------------------------------------------------------- //END
}) })
}); });
}); });

@ -2,7 +2,7 @@
<el-menu <el-menu
default-active="3" default-active="3"
mode="horizontal"> mode="horizontal">
<el-menu-item class="mainLogo" v-on:click="openUrl('/login')">GO-FLY<span class="version">V0.0.3</span></el-menu-item> <el-menu-item class="mainLogo" v-on:click="openUrl('/login')">GO-FLY<span class="version">V0.0.5</span></el-menu-item>
<el-menu-item style="display:none" index="2" v-on:click="openIframeUrl('/list')">邮箱<el-badge class="mark" :value="mailTotal" style="margin-bottom: 20px;"/> <el-menu-item style="display:none" index="2" v-on:click="openIframeUrl('/list')">邮箱<el-badge class="mark" :value="mailTotal" style="margin-bottom: 20px;"/>
</el-menu-item> </el-menu-item>
<el-menu-item index="3" v-on:click="openIframeUrl('/chat_main')">聊天</el-menu-item> <el-menu-item index="3" v-on:click="openIframeUrl('/chat_main')">聊天</el-menu-item>

Loading…
Cancel
Save