增加点击展示访客信息

pull/30/head
陶士涵 4 years ago
parent 6cac6cdd93
commit ab6b9d6bc7

@ -10,6 +10,7 @@ CREATE TABLE `user` (
PRIMARY KEY (`id`) PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8; ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;
CREATE TABLE `visitor` ( CREATE TABLE `visitor` (
`id` int(11) NOT NULL AUTO_INCREMENT, `id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(50) NOT NULL DEFAULT '', `name` varchar(50) NOT NULL DEFAULT '',
@ -20,6 +21,10 @@ CREATE TABLE `visitor` (
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`deleted_at` timestamp NULL DEFAULT NULL, `deleted_at` timestamp NULL DEFAULT NULL,
`visitor_id` varchar(100) NOT NULL DEFAULT '', `visitor_id` varchar(100) NOT NULL DEFAULT '',
`status` tinyint(4) NOT NULL DEFAULT '0',
`refer` varchar(500) NOT NULL DEFAULT '',
`city` varchar(100) NOT NULL DEFAULT '',
`client_ip` varchar(100) NOT NULL,
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
UNIQUE KEY `visitor_id` (`visitor_id`) UNIQUE KEY `visitor_id` (`visitor_id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8; ) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8

@ -16,7 +16,7 @@ type vistor struct{
} }
type Message struct{ type Message struct{
conn *websocket.Conn conn *websocket.Conn
ip string c *gin.Context
content []byte content []byte
} }
var clientList = make(map[string]*vistor) var clientList = make(map[string]*vistor)
@ -35,6 +35,8 @@ type ClientMessage struct {
Time string `json:"time"` Time string `json:"time"`
ToId string `json:"to_id"` ToId string `json:"to_id"`
Content string `json:"content"` Content string `json:"content"`
City string `json:"city"`
ClientIp string `json:"client_ip"`
} }
//定时检测客户端是否在线 //定时检测客户端是否在线
func init() { func init() {
@ -66,7 +68,7 @@ func NewChatServer(c *gin.Context){
message<-&Message{ message<-&Message{
conn:conn, conn:conn,
content: receive, content: receive,
ip:c.ClientIP(), c:c,
} }
} }
} }
@ -168,7 +170,7 @@ func singleBroadcaster(){
} }
clientList[clientMsg.Id] = user clientList[clientMsg.Id] = user
//插入数据表 //插入数据表
models.CreateVisitor(clientMsg.Name,clientMsg.Avator,message.ip,clientMsg.ToId,clientMsg.Id) models.CreateVisitor(clientMsg.Name,clientMsg.Avator,message.c.ClientIP(),clientMsg.ToId,clientMsg.Id,message.c.Request.Referer(),clientMsg.City,clientMsg.ClientIp)
SendNoticeToAllKefu() SendNoticeToAllKefu()
//客服上线 //客服上线
case "kfOnline": case "kfOnline":

@ -0,0 +1,18 @@
package controller
import (
"github.com/gin-gonic/gin"
"github.com/taoshihan1991/imaptool/models"
"log"
)
func GetVisitor(c *gin.Context) {
visitorId:=c.Query("visitorId")
vistor:=models.FindVisitorByVistorId(visitorId)
log.Println(visitorId)
c.JSON(200, gin.H{
"code": 200,
"msg": "ok",
"result":vistor,
})
}

@ -4,13 +4,17 @@ import "github.com/jinzhu/gorm"
type Visitor struct { type Visitor struct {
gorm.Model gorm.Model
Name string Name string `json:"name"`
Avator string Avator string `json:"avator"`
SourceIp string SourceIp string `json:"source_ip"`
ToId string ToId string `json:"to_id"`
VisitorId string VisitorId string `json:"visitor_id"`
Status uint `json:"status"`
Refer string `json:"refer"`
City string `json:"city"`
ClientIp string `json:"client_ip"`
} }
func CreateVisitor(name string,avator string,sourceIp string,toId string,visitorId string){ func CreateVisitor(name string,avator string,sourceIp string,toId string,visitorId string,refer string,city string,clientIp string){
old:=FindVisitorByVistorId(visitorId) old:=FindVisitorByVistorId(visitorId)
if old.Name!=""{ if old.Name!=""{
return return
@ -21,6 +25,10 @@ func CreateVisitor(name string,avator string,sourceIp string,toId string,visitor
SourceIp:sourceIp, SourceIp:sourceIp,
ToId:toId, ToId:toId,
VisitorId: visitorId, VisitorId: visitorId,
Status:1,
Refer:refer,
City:city,
ClientIp:clientIp,
} }
DB.Create(v) DB.Create(v)
} }

@ -39,6 +39,7 @@ func main() {
engine.GET("/setting_mysql", tmpl.PageSettingMysql) engine.GET("/setting_mysql", tmpl.PageSettingMysql)
engine.GET("/mysql",middleware.JwtApiMiddleware,middleware.CasbinACL, controller.MysqlGetConf) engine.GET("/mysql",middleware.JwtApiMiddleware,middleware.CasbinACL, controller.MysqlGetConf)
engine.POST("/mysql",middleware.JwtApiMiddleware,middleware.CasbinACL, controller.MysqlSetConf) engine.POST("/mysql",middleware.JwtApiMiddleware,middleware.CasbinACL, controller.MysqlSetConf)
engine.GET("/visitor",middleware.JwtApiMiddleware, controller.GetVisitor)
//------------------old code----------------------------- //------------------old code-----------------------------
mux := &http.ServeMux{} mux := &http.ServeMux{}
//根路径 //根路径

@ -102,13 +102,28 @@
<el-button type="primary" v-on:click="chatToUser">发送</el-button> <el-button type="primary" v-on:click="chatToUser">发送</el-button>
</div> </div>
</el-col> </el-col>
<el-col :span="6"> <el-col :span="6" class="chatLeft">
<el-menu class="chatLeft"> <el-menu>
<el-menu-item> <el-menu-item>
<i class="el-icon-s-tools"></i> <i class="el-icon-user"></i>
<span slot="title">访客信息</span> <span slot="title">访客信息</span>
</el-menu-item> </el-menu-item>
<el-menu-item>
<i class="el-icon-s-tools"></i>
<span slot="title">来源:<{visitor.refer}></span>
</el-menu-item>
<el-menu-item>
<i class="el-icon-s-tools"></i>
<span slot="title">IP<{visitor.client_ip}></span>
</el-menu-item>
<el-menu-item>
<i class="el-icon-s-tools"></i>
<span slot="title">城市:<{visitor.city}></span>
</el-menu-item>
<el-menu-item>
<i class="el-icon-s-tools"></i>
<span slot="title">状态:<{visitor.status}></span>
</el-menu-item>
</el-menu> </el-menu>
</el-col> </el-col>
</el-row> </el-row>
@ -138,6 +153,12 @@
name : "客服丽丽", name : "客服丽丽",
avator : "", avator : "",
to_id : "", to_id : "",
},
visitor:{
refer:"",
client_ip:"",
city:"",
status:"",
} }
}, },
methods: { methods: {
@ -240,6 +261,9 @@
this.kfConfig.to_id=guestId; this.kfConfig.to_id=guestId;
mes.data = this.kfConfig; mes.data = this.kfConfig;
this.socket.send(JSON.stringify(mes)); this.socket.send(JSON.stringify(mes));
//获取当前访客信息
this.getVistorInfo(guestId);
}, },
//发送给客户 //发送给客户
chatToUser() { chatToUser() {
@ -307,6 +331,33 @@
_this.initConn(); _this.initConn();
}); });
}, },
//获取客服信息
getVistorInfo(vid){
let _this=this;
$.ajax({
type:"get",
url:"/visitor",
data:{visitorId:vid},
headers:{
"token":localStorage.getItem("token")
},
success: function(data) {
if(data.result!=null){
let r=data.result;
_this.visitor.refer=r.refer;
_this.visitor.city=r.city;
_this.visitor.client_ip=r.client_ip;
_this.visitor.status=r.status;
}
if(data.code!=200){
_this.$message({
message: data.msg,
type: 'error'
});
}
}
});
},
}, },
created: function () { created: function () {
this.getKefuInfo(); this.getKefuInfo();

@ -133,6 +133,8 @@
let userinfo=this.getUserInfo(); let userinfo=this.getUserInfo();
let mes = {} let mes = {}
mes.type = "userInit"; mes.type = "userInit";
userinfo.client_ip=returnCitySN["cip"];
userinfo.city=returnCitySN["cname"];
mes.data = userinfo; mes.data = userinfo;
this.socket.send(JSON.stringify(mes)); this.socket.send(JSON.stringify(mes));
}, },

Loading…
Cancel
Save