分页消息记录接口

master
taoshihan 2 years ago
parent dc573856d1
commit 4711e1812c

@ -150,7 +150,6 @@ CREATE TABLE `reply_item` (
KEY `user_id` (`user_id`),
KEY `group_id` (`group_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8|
INSERT INTO `reply_item` (`id`, `content`, `group_id`, `user_id`, `item_name`) VALUES (NULL, '在这里[官网]link[https://gofly.sopans.com]!','1','kefu2', '官方地址在哪?')|
DROP TABLE IF EXISTS `land_page`|
CREATE TABLE `land_page` (
`id` int(11) NOT NULL,

@ -110,7 +110,7 @@ func MainCheckAuth(c *gin.Context) {
}
func GetStatistics(c *gin.Context) {
visitors := models.CountVisitors()
message := models.CountMessage()
message := models.CountMessage(nil,nil)
session := len(ws.ClientList)
kefuNum := 0
c.JSON(200, gin.H{

@ -111,7 +111,7 @@ func SendMessageV2(c *gin.Context) {
ws.OneKefuMessage(kefuInfo.Name, str)
//ws.KefuMessage(vistorInfo.VisitorId, content, kefuInfo)
kefu, ok := ws.KefuList[kefuInfo.Name]
if !ok || kefu == nil{
if !ok || kefu == nil {
go SendNoticeEmail(content+"|"+vistorInfo.Name, content)
}
go ws.VisitorAutoReply(vistorInfo, kefuInfo, content)
@ -287,3 +287,23 @@ func GetMessagesV2(c *gin.Context) {
"result": chatMessages,
})
}
func GetMessagespages(c *gin.Context) {
visitorId := c.Query("visitor_id")
page, _ := strconv.Atoi(c.DefaultQuery("page", "1"))
pageSize, _ := strconv.Atoi(c.DefaultQuery("pagesize", "10"))
if pageSize > 20 {
pageSize = 20
}
count := models.CountMessage("visitor_id = ?", visitorId)
list := models.FindMessageByPage(uint(page), uint(pageSize), "message.visitor_id = ?", visitorId)
c.JSON(200, gin.H{
"code": 200,
"msg": "ok",
"result": gin.H{
"count": count,
"page": page,
"list": list,
"pagesize": pageSize,
},
})
}

@ -100,8 +100,21 @@ func FindMessageByWhere(query interface{}, args ...interface{}) []MessageKefu {
}
//查询条数
func CountMessage() uint {
func CountMessage(query interface{}, args ...interface{}) uint {
var count uint
DB.Model(&Message{}).Count(&count)
DB.Model(&Message{}).Where(query, args...).Count(&count)
return count
}
//分页查询
func FindMessageByPage(page uint, pagesize uint, query interface{}, args ...interface{}) []*MessageKefu {
offset := (page - 1) * pagesize
if offset < 0 {
offset = 0
}
var messages []*MessageKefu
DB.Table("message").Select("message.*,visitor.avator visitor_avator,visitor.name visitor_name,user.avator kefu_avator,user.nickname kefu_name").Offset(offset).Joins("left join user on message.kefu_id=user.name").Joins("left join visitor on visitor.visitor_id=message.visitor_id").Where(query, args...).Limit(pagesize).Order("message.id desc").Find(&messages)
for _, mes := range messages {
mes.CreateTime = mes.CreatedAt.Format("2006-01-02 15:04:05")
}
return messages
}

@ -19,6 +19,8 @@ func InitApiRouter(engine *gin.Engine) {
v2.GET("/message_close", controller.SendCloseMessageV2)
//绑定
v2.POST("/bindOfficial", controller.PostBindOfficial)
//分页查询消息
v2.GET("/messagesPages", controller.GetMessagespages)
}
engine.GET("/captcha", controller.GetCaptcha)
engine.POST("/check", controller.LoginCheckPass)

@ -217,14 +217,14 @@
font-size: 14px;
}
.chatContent2 {
border-radius: 0px 8px 8px 8px;
border-radius: 8px 8px 8px 0px;
padding: 10px 15px;
}
.chatBoxMe{
margin-top: 10px;
}
.chatBoxMe .chatContent2 {
border-radius: 8px 0px 8px 8px;
border-radius: 8px 8px 0px 8px;
background-color: #cde0ff;
color: #000;
}

@ -0,0 +1,62 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
</body>
<script>
// 设置重连时间间隔(单位:毫秒)
const RECONNECT_INTERVAL = 1000;
// 设置最大重连次数
const MAX_RECONNECT_TIMES = 3;
let reconnectTimes = 0;
let ws;
// 尝试连接 WebSocket
function connect() {
ws = new WebSocket('wss://gofly.v1kf.com/ws_visitor?visitor_id=5|a780d122-daa3-4315-a413-f93b29b026d0&to_id=taoshihan');
ws.onopen = function () {
console.log('WebSocket 连接已打开');
reconnectTimes = 0;
};
ws.onclose = function () {
console.log('WebSocket 连接已关闭');
// 尝试重连
reconnect();
};
ws.onmessage = function (event) {
console.log(`收到服务器的消息:${event.data}`);
// // 解析消息
// const message = JSON.parse(event.data);
// if (message.type === 'message') {
// console.log(`收到消息:${message.data}`);
// }
};
}
// 尝试重连
function reconnect() {
if (reconnectTimes >= MAX_RECONNECT_TIMES) {
console.log('重连失败');
return;
}
reconnectTimes++;
console.log(`正在尝试重连(第 ${reconnectTimes} 次)`);
setTimeout(function () {
connect();
}, RECONNECT_INTERVAL);
}
connect();
</script>
</html>

@ -24,6 +24,7 @@ new Vue({
showFaceIcon:false,
isIframe:false,
kefuInfo:{},
showLoadMore:false,
},
methods: {
//初始化websocket
@ -215,54 +216,8 @@ new Vue({
// }
},
//获取信息列表
getMesssagesByVisitorId:function(isAll){
let _this=this;
$.ajax({
type:"get",
url:"/messages?visitorId="+this.visitor.visitor_id,
success: function(data) {
if(data.code==200 && data.result!=null&&data.result.length!=0){
_this.msgListNum=data.result.length;
let msgList=data.result;
_this.msgList=[];
if(!isAll&&msgList.length>1){
var i=msgList.length-1
}else{
_this.msgListNum=0;
var i=0;
}
for(;i<msgList.length;i++){
let visitorMes=msgList[i];
let content = {}
if(visitorMes["mes_type"]=="kefu"){
content.is_kefu = false;
content.avator = visitorMes["kefu_avator"];
content.name = visitorMes["kefu_name"];
}else{
content.is_kefu = true;
content.avator = visitorMes["visitor_avator"];
content.name = visitorMes["visitor_name"];
}
content.content = replaceContent(visitorMes["content"]);
content.time = visitorMes["time"];
_this.msgList.push(content);
_this.scrollBottom();
}
}
if(data.code!=200){
_this.$message({
message: data.msg,
type: 'error'
});
}
if(data.code!=200){
_this.$message({
message: data.msg,
type: 'error'
});
}
}
});
loadMoreMessages:function(){
},
//滚动到底部
scrollBottom:function(){

@ -2,7 +2,7 @@
<head>
<meta charset="utf-8">
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0;" name="viewport" />
<meta name="keywords" content="开源客服系统,golang在线客服,免费客服系统,go语言在线聊天工具,gofly,GOFLY客服系统"/>
<meta name="keywords" content="开源客服系统"/>
<meta name="description" content="golang开发的开源免费客服系统,可独立部署客服系统,支持文字/表情/图片/文件发送,支持快捷回复,支持IP黑名单,展示访客信息,后台权限控制"/>
<title>开源智能在线客服系统</title>
<link rel="stylesheet" href="https://cdn.staticfile.org/element-ui/2.15.1/theme-chalk/index.min.css">
@ -32,6 +32,9 @@
<div class="chatEntBox">
<div class="chatContext chatVisitorPage">
<div class="chatBox">
<div class="chatNotice" v-on:click="loadMoreMessages" v-show="showLoadMore">
<a class="chatNoticeContent">点击加载更多记录</a>
</div>
<el-row :gutter="2" v-for="v in msgList" v-bind:class="{'chatBoxMe': v.is_kefu==true}">
<div class="chatTime" v-bind:class="{'chatTimeHide': v.show_time==false}"><span><{v.time}></span></div>
<div v-if="v.is_kefu!=true" style="display: flex;">
@ -78,7 +81,7 @@
</div>
</div>
<div class="chatArticle">
<h3 class="hotQuestionTitle"><img src="/static/images/fire.svg" class="fire">公告通知
<h3 class="hotQuestionTitle">公告通知
</h3>
<div class="allNotice" v-html><{kefuInfo.allNotice}></div>
</div>

Loading…
Cancel
Save