增加客服接口

pull/30/head
taoshihan1991 4 years ago
parent 8cf2a617eb
commit 4c5e4a1139

@ -27,4 +27,18 @@ CREATE TABLE `visitor` (
`client_ip` varchar(100) NOT NULL, `client_ip` varchar(100) NOT NULL,
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
UNIQUE KEY `visitor_id` (`visitor_id`) UNIQUE KEY `visitor_id` (`visitor_id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8 ) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8
CREATE TABLE `message` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`from_id` varchar(100) NOT NULL DEFAULT '',
`to_id` varchar(100) NOT NULL DEFAULT '',
`content` varchar(2048) NOT NULL DEFAULT '',
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`deleted_at` timestamp NULL DEFAULT NULL,
`status` enum('read','unread') NOT NULL DEFAULT 'unread',
PRIMARY KEY (`id`),
KEY `from_id` (`from_id`),
KEY `to_id` (`to_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8

@ -3,6 +3,8 @@ package controller
import ( import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/taoshihan1991/imaptool/models" "github.com/taoshihan1991/imaptool/models"
"github.com/taoshihan1991/imaptool/tools"
"log"
) )
func GetKefuInfo(c *gin.Context){ func GetKefuInfo(c *gin.Context){
@ -19,10 +21,14 @@ func GetKefuInfo(c *gin.Context){
}) })
} }
func PostKefuInfo(c *gin.Context){ func PostKefuInfo(c *gin.Context){
name:=c.PostForm("name")
password:=c.PostForm("password")
avator:=c.PostForm("avator")
models.CreateUser(name,tools.Md5(password),avator)
c.JSON(200, gin.H{ c.JSON(200, gin.H{
"code": 200, "code": 200,
"msg": "ok", "msg": "ok",
"result":"aaa", "result":"",
}) })
} }
func GetKefuList(c *gin.Context){ func GetKefuList(c *gin.Context){
@ -33,3 +39,13 @@ func GetKefuList(c *gin.Context){
"result":users, "result":users,
}) })
} }
func DeleteKefuInfo(c *gin.Context){
kefuId := c.Query("id")
log.Println(kefuId)
models.DeleteUserById(kefuId)
c.JSON(200, gin.H{
"code": 200,
"msg": "删除成功",
"result":"",
})
}

@ -10,10 +10,11 @@ type User struct {
Nickname string `json:"nickname"` Nickname string `json:"nickname"`
Avator string `json:"avator"` Avator string `json:"avator"`
} }
func CreateUser(name string,password string){ func CreateUser(name string,password string,avator string){
user:=&User{ user:=&User{
Name:name, Name:name,
Password: password, Password: password,
Avator:avator,
} }
DB.Create(user) DB.Create(user)
} }
@ -27,6 +28,9 @@ func FindUserById(id interface{})User{
DB.Where("id = ?", id).First(&user) DB.Where("id = ?", id).First(&user)
return user return user
} }
func DeleteUserById(id string){
DB.Where("id = ?",id).Delete(User{})
}
func FindUsers()[]User{ func FindUsers()[]User{
var users []User var users []User
DB.Order("id desc").Find(&users) DB.Order("id desc").Find(&users)

@ -42,6 +42,7 @@ func main() {
//获取客服信息 //获取客服信息
engine.GET("/kefuinfo",middleware.JwtApiMiddleware, controller.GetKefuInfo) engine.GET("/kefuinfo",middleware.JwtApiMiddleware, controller.GetKefuInfo)
engine.POST("/kefuinfo",middleware.JwtApiMiddleware, controller.PostKefuInfo) engine.POST("/kefuinfo",middleware.JwtApiMiddleware, controller.PostKefuInfo)
engine.DELETE("/kefuinfo",middleware.JwtApiMiddleware, controller.DeleteKefuInfo)
engine.GET("/kefulist",middleware.JwtApiMiddleware, controller.GetKefuList) engine.GET("/kefulist",middleware.JwtApiMiddleware, controller.GetKefuList)
//设置页 //设置页
engine.GET("/setting", tmpl.PageSetting) engine.GET("/setting", tmpl.PageSetting)

@ -46,7 +46,9 @@
kefuList:[], kefuList:[],
kefuDialog:false, kefuDialog:false,
kefuForm:{ kefuForm:{
name:"",
password:"",
avator:"",
}, },
}, },
methods: { methods: {
@ -147,6 +149,7 @@
$.ajax({ $.ajax({
type: method, type: method,
url: url, url: url,
data:params,
headers: { headers: {
"token": localStorage.getItem("token") "token": localStorage.getItem("token")
}, },
@ -173,17 +176,25 @@
let _this=this; let _this=this;
this.$refs[formName].validate((valid) => { this.$refs[formName].validate((valid) => {
if (valid) { if (valid) {
this.sendAjax("/kefuinfo","post",_this.kefuForm,function(result){ this.sendAjax("/kefuinfo","POST",_this.kefuForm,function(result){
_this.$message({
message: data.msg,
type: 'success'
});
_this.kefuDialog=false; _this.kefuDialog=false;
_this.sendAjax("/kefulist","get",{},function(result){
_this.kefuList=result;
});
}); });
} else { } else {
return false; return false;
} }
}); });
},
//删除客服
deleteKefu(kefuId){
this.sendAjax("/kefuinfo","DELETE",{id:kefuId},function(result){
_this.kefuDialog=false;
_this.sendAjax("/kefulist","get",{},function(result){
_this.kefuList=result;
});
});
} }
}, },
created: function () { created: function () {

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

Loading…
Cancel
Save