添加自动欢迎

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

@ -2,12 +2,29 @@ package controller
import ( import (
"encoding/json" "encoding/json"
"github.com/gin-gonic/gin"
"github.com/gorilla/websocket" "github.com/gorilla/websocket"
"github.com/taoshihan1991/imaptool/models"
"github.com/taoshihan1991/imaptool/tools" "github.com/taoshihan1991/imaptool/tools"
"log" "log"
"net/http" "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 upgrader = websocket.Upgrader{}
var oldFolders map[string]int var oldFolders map[string]int

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

@ -118,7 +118,7 @@
guest.name = typeof(returnCitySN)!="undefined" ?returnCitySN["cip"]+"-"+returnCitySN["cname"]:"小米"; guest.name = typeof(returnCitySN)!="undefined" ?returnCitySN["cip"]+"-"+returnCitySN["cname"]:"小米";
guest.avator = "/static/images/"+Math.floor(Math.random()*(14-0+1)+0)+".jpg"; guest.avator = "/static/images/"+Math.floor(Math.random()*(14-0+1)+0)+".jpg";
guest.group = "1"; guest.group = "1";
guest.to_id=""; guest.to_id="kefu2";
new Vue({ new Vue({
el: '#app', el: '#app',
@ -176,7 +176,6 @@
}, },
//发送给客户 //发送给客户
chatToUser() { chatToUser() {
if(guest.to_id==""){ if(guest.to_id==""){
this.$message({ this.$message({
message: '暂时没有客服接手', message: '暂时没有客服接手',
@ -270,6 +269,27 @@
}); });
return uuid; 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 () { created: function () {
this.initConn(); this.initConn();
@ -277,6 +297,8 @@
this.msgList=this.getHistory(); this.msgList=this.getHistory();
//滚动底部 //滚动底部
this.scrollBottom(); this.scrollBottom();
//获取欢迎
this.getNotice();
} }
}) })

Loading…
Cancel
Save