增加自动回复

pull/30/head
陶士涵 4 years ago
parent fac200d3f9
commit 6c0cef9c04

@ -2,9 +2,9 @@ package controller
import (
"encoding/json"
"fmt"
"github.com/gin-gonic/gin"
"github.com/gorilla/websocket"
"github.com/taoshihan1991/imaptool/config"
"github.com/taoshihan1991/imaptool/models"
"github.com/taoshihan1991/imaptool/tools"
"log"
@ -13,27 +13,23 @@ import (
)
func GetNotice(c *gin.Context) {
kefuId:=c.Query("kefu_id")
lang,_:=c.Get("lang")
language:=config.CreateLanguage(lang.(string))
welcome:=models.FindWelcomeByUserId(kefuId)
welcomes:=models.FindWelcomesByUserId(kefuId)
user:=models.FindUser(kefuId)
var content string
log.Println(welcome)
if welcome.Content!=""{
content=welcome.Content
}else {
content=language.Notice
result:=make([]gin.H,0)
for _,welcome:=range welcomes{
h:=gin.H{
"name":user.Nickname,
"avator":user.Avator,
"is_kefu":false,
"content":welcome.Content,
"time":time.Now().Format("2006-01-02 15:04:05"),
}
result=append(result,h)
}
c.JSON(200, gin.H{
"code": 200,
"msg": "ok",
"result":gin.H{
"nickname":user.Nickname,
"avator":user.Avator,
"name":user.Name,
"content":content,
"time":time.Now().Format("2006-01-02 15:04:05"),
},
"result":result,
})
}
func GetNotices(c *gin.Context) {
@ -45,6 +41,26 @@ func GetNotices(c *gin.Context) {
"result":welcomes,
})
}
func PostNotice(c *gin.Context) {
kefuId,_:=c.Get("kefu_name")
content:=c.PostForm("content")
models.CreateWelcome(fmt.Sprintf("%s",kefuId),content)
c.JSON(200, gin.H{
"code": 200,
"msg": "ok",
"result":"",
})
}
func DelNotice(c *gin.Context) {
kefuId,_:=c.Get("kefu_name")
id:=c.Query("id")
models.DeleteWelcome(kefuId,id)
c.JSON(200, gin.H{
"code": 200,
"msg": "ok",
"result":"",
})
}
var upgrader = websocket.Upgrader{}
var oldFolders map[string]int

@ -118,6 +118,8 @@ func main() {
engine.GET("/statistics",middleware.JwtApiMiddleware, controller.GetStatistics)
//前台接口
engine.GET("/notice",middleware.SetLanguage, controller.GetNotice)
engine.POST("/notice",middleware.JwtApiMiddleware, controller.PostNotice)
engine.DELETE("/notice",middleware.JwtApiMiddleware, controller.DelNotice)
engine.GET("/notices",middleware.JwtApiMiddleware, controller.GetNotices)
//前台引入js接口
engine.GET("/webjs", tmpl.PageWebJs)

@ -9,6 +9,18 @@ type Welcome struct {
IsDefault uint `json:"is_default"`
Ctime time.Time `json:"ctime"`
}
func CreateWelcome(userId string,content string)uint{
if userId==""||content==""{
return 0
}
w:=&Welcome{
UserId: userId,
Content: content,
Ctime: time.Now(),
}
DB.Create(w)
return w.ID
}
func FindWelcomeByUserId(userId interface{})Welcome{
var w Welcome
DB.Where("user_id = ? and is_default=?", userId,1).First(&w)
@ -18,4 +30,7 @@ func FindWelcomesByUserId(userId interface{})[]Welcome{
var w []Welcome
DB.Where("user_id = ?", userId).Find(&w)
return w
}
func DeleteWelcome(userId interface{},id string){
DB.Where("user_id = ? and id = ?", userId,id).Delete(Welcome{})
}

@ -366,20 +366,17 @@
getNotice : function (){
let _this=this;
$.get("/notice?kefu_id="+guest.to_id+"&lang={{.Lang}}",function(res) {
console.log(res);
//debugger;
if (res.result != null) {
let msg = res.result;
let content = {}
content.avator = msg.avator;
content.name = msg.nickname;
content.content = replaceContent(msg.content);
content.is_kefu = false;
content.time = msg.time;
setTimeout(function () {
_this.msgList.push(content);
_this.scrollBottom();
}, 4000);
;
for(let i=0;i<msg.length;i++){
let content = msg[i];
content.content = replaceContent(content.content);
setTimeout(function () {
_this.msgList.push(content);
_this.scrollBottom();
}, 5000*(i+1));
}
}
});
},

@ -246,6 +246,22 @@
}
});
},
//提交欢迎表单
submitWelcomeForm(formName){
let _this=this;
this.$refs[formName].validate((valid) => {
if (valid) {
this.sendAjax("/notice","POST",_this.welcomeForm,function(result){
_this.welcomeDialog=false;
_this.sendAjax("/notices","get",{},function(result){
_this.noticeList=result;
});
});
} else {
return false;
}
});
},
//编辑客服表单
editKefuForm(formName){
let _this=this;
@ -278,6 +294,16 @@
});
});
},
//删除欢迎
deleteWelcome(id){
let _this=this;
this.sendAjax("/notice?id="+id,"DELETE",{id:id},function(result){
_this.kefuDialog=false;
_this.sendAjax("/notices","get",{},function(result){
_this.noticeList=result;
});
});
},
//配置角色权限
showAuthDialog(id,name,method,path){
this.roleForm.id=id

@ -22,7 +22,6 @@
prop="id"
label="操作">
<template slot-scope="scope">
<el-button @click="getWelcome(scope.row.id)" type="primary" size="small" plain>编辑</el-button>
<el-button @click="deleteWelcome(scope.row.id)" type="danger" size="small" plain>删除</el-button>
</template>
</el-table-column>

@ -93,4 +93,8 @@ function filter (obj){
}
}
return false;
}
}
function sleep(time) {
var startTime = new Date().getTime() + parseInt(time, 10);
while(new Date().getTime() < startTime) {}
};
Loading…
Cancel
Save