添加自动欢迎

pull/30/head
陶士涵 4 years ago
parent c676514f8f
commit d2ae5c2476

@ -2,12 +2,29 @@ package controller
import (
"encoding/json"
"github.com/gin-gonic/gin"
"github.com/gorilla/websocket"
"github.com/taoshihan1991/imaptool/models"
"github.com/taoshihan1991/imaptool/tools"
"log"
"net/http"
"time"
)
func GetNotice(c *gin.Context) {
kefuId:=c.Query("kefu_id")
user:=models.FindUser(kefuId)
info:=make(map[string]interface{})
info["nickname"]=user.Nickname
info["avator"]=user.Avator
info["name"]=user.Name
info["content"]="欢迎您!有什么我能帮助您的?"
info["time"]=time.Now().String()
c.JSON(200, gin.H{
"code": 200,
"msg": "ok",
"result":info,
})
}
var upgrader = websocket.Upgrader{}
var oldFolders map[string]int

@ -54,5 +54,8 @@ func main() {
engine.GET("/visitor",middleware.JwtApiMiddleware, controller.GetVisitor)
engine.GET("/visitors",middleware.JwtApiMiddleware, controller.GetVisitors)
engine.GET("/setting_kefu_list",tmpl.PageKefuList)
//前台接口
engine.GET("/notice", controller.GetNotice)
engine.Run(baseServer)
}

@ -118,7 +118,7 @@
guest.name = typeof(returnCitySN)!="undefined" ?returnCitySN["cip"]+"-"+returnCitySN["cname"]:"小米";
guest.avator = "/static/images/"+Math.floor(Math.random()*(14-0+1)+0)+".jpg";
guest.group = "1";
guest.to_id="";
guest.to_id="kefu2";
new Vue({
el: '#app',
@ -176,7 +176,6 @@
},
//发送给客户
chatToUser() {
if(guest.to_id==""){
this.$message({
message: '暂时没有客服接手',
@ -270,6 +269,27 @@
});
return uuid;
},
//获取自动欢迎语句
getNotice : function (){
let _this=this;
$.get("/notice?kefu_id="+guest.to_id,function(res) {
console.log(res);
if (res.result != null) {
let msg = res.result;
let content = {}
content.avator = msg.avator;
content.name = msg.nickname;
content.content = msg.content;
content.is_kefu = false;
content.time = msg.time;
setTimeout(function () {
_this.msgList.push(content);
}, 2000);
;
}
});
},
},
created: function () {
this.initConn();
@ -277,6 +297,8 @@
this.msgList=this.getHistory();
//滚动底部
this.scrollBottom();
//获取欢迎
this.getNotice();
}
})

Loading…
Cancel
Save