增加点击展示访客信息

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

@ -10,6 +10,7 @@ CREATE TABLE `user` (
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;
CREATE TABLE `visitor` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(50) NOT NULL DEFAULT '',
@ -20,6 +21,10 @@ CREATE TABLE `visitor` (
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`deleted_at` timestamp NULL DEFAULT NULL,
`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`),
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{
conn *websocket.Conn
ip string
c *gin.Context
content []byte
}
var clientList = make(map[string]*vistor)
@ -35,6 +35,8 @@ type ClientMessage struct {
Time string `json:"time"`
ToId string `json:"to_id"`
Content string `json:"content"`
City string `json:"city"`
ClientIp string `json:"client_ip"`
}
//定时检测客户端是否在线
func init() {
@ -66,7 +68,7 @@ func NewChatServer(c *gin.Context){
message<-&Message{
conn:conn,
content: receive,
ip:c.ClientIP(),
c:c,
}
}
}
@ -168,7 +170,7 @@ func singleBroadcaster(){
}
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()
//客服上线
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 {
gorm.Model
Name string
Avator string
SourceIp string
ToId string
VisitorId string
Name string `json:"name"`
Avator string `json:"avator"`
SourceIp string `json:"source_ip"`
ToId string `json:"to_id"`
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)
if old.Name!=""{
return
@ -21,6 +25,10 @@ func CreateVisitor(name string,avator string,sourceIp string,toId string,visitor
SourceIp:sourceIp,
ToId:toId,
VisitorId: visitorId,
Status:1,
Refer:refer,
City:city,
ClientIp:clientIp,
}
DB.Create(v)
}

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

@ -102,13 +102,28 @@
<el-button type="primary" v-on:click="chatToUser">发送</el-button>
</div>
</el-col>
<el-col :span="6">
<el-menu class="chatLeft">
<el-col :span="6" class="chatLeft">
<el-menu>
<el-menu-item>
<i class="el-icon-s-tools"></i>
<i class="el-icon-user"></i>
<span slot="title">访客信息</span>
</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-col>
</el-row>
@ -138,6 +153,12 @@
name : "客服丽丽",
avator : "",
to_id : "",
},
visitor:{
refer:"",
client_ip:"",
city:"",
status:"",
}
},
methods: {
@ -240,6 +261,9 @@
this.kfConfig.to_id=guestId;
mes.data = this.kfConfig;
this.socket.send(JSON.stringify(mes));
//获取当前访客信息
this.getVistorInfo(guestId);
},
//发送给客户
chatToUser() {
@ -307,6 +331,33 @@
_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 () {
this.getKefuInfo();

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

Loading…
Cancel
Save