diff --git a/config/go-fly.sql b/config/go-fly.sql index 760f2c9..7280eac 100644 --- a/config/go-fly.sql +++ b/config/go-fly.sql @@ -27,4 +27,18 @@ CREATE TABLE `visitor` ( `client_ip` varchar(100) NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `visitor_id` (`visitor_id`) -) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8 \ No newline at end of file +) 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 \ No newline at end of file diff --git a/controller/kefu.go b/controller/kefu.go index f03df5d..61790bc 100644 --- a/controller/kefu.go +++ b/controller/kefu.go @@ -3,6 +3,8 @@ package controller import ( "github.com/gin-gonic/gin" "github.com/taoshihan1991/imaptool/models" + "github.com/taoshihan1991/imaptool/tools" + "log" ) func GetKefuInfo(c *gin.Context){ @@ -19,10 +21,14 @@ func GetKefuInfo(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{ "code": 200, "msg": "ok", - "result":"aaa", + "result":"", }) } func GetKefuList(c *gin.Context){ @@ -33,3 +39,13 @@ func GetKefuList(c *gin.Context){ "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":"", + }) +} diff --git a/models/users.go b/models/users.go index 72fa747..be41050 100644 --- a/models/users.go +++ b/models/users.go @@ -10,10 +10,11 @@ type User struct { Nickname string `json:"nickname"` Avator string `json:"avator"` } -func CreateUser(name string,password string){ +func CreateUser(name string,password string,avator string){ user:=&User{ Name:name, Password: password, + Avator:avator, } DB.Create(user) } @@ -27,6 +28,9 @@ func FindUserById(id interface{})User{ DB.Where("id = ?", id).First(&user) return user } +func DeleteUserById(id string){ + DB.Where("id = ?",id).Delete(User{}) +} func FindUsers()[]User{ var users []User DB.Order("id desc").Find(&users) diff --git a/server.go b/server.go index 911294b..1481bcf 100644 --- a/server.go +++ b/server.go @@ -42,6 +42,7 @@ func main() { //获取客服信息 engine.GET("/kefuinfo",middleware.JwtApiMiddleware, controller.GetKefuInfo) engine.POST("/kefuinfo",middleware.JwtApiMiddleware, controller.PostKefuInfo) + engine.DELETE("/kefuinfo",middleware.JwtApiMiddleware, controller.DeleteKefuInfo) engine.GET("/kefulist",middleware.JwtApiMiddleware, controller.GetKefuList) //设置页 engine.GET("/setting", tmpl.PageSetting) diff --git a/static/html/setting_bottom.html b/static/html/setting_bottom.html index 4d3909f..9a11db2 100644 --- a/static/html/setting_bottom.html +++ b/static/html/setting_bottom.html @@ -46,7 +46,9 @@ kefuList:[], kefuDialog:false, kefuForm:{ - + name:"", + password:"", + avator:"", }, }, methods: { @@ -147,6 +149,7 @@ $.ajax({ type: method, url: url, + data:params, headers: { "token": localStorage.getItem("token") }, @@ -173,17 +176,25 @@ let _this=this; this.$refs[formName].validate((valid) => { if (valid) { - this.sendAjax("/kefuinfo","post",_this.kefuForm,function(result){ - _this.$message({ - message: data.msg, - type: 'success' - }); + this.sendAjax("/kefuinfo","POST",_this.kefuForm,function(result){ _this.kefuDialog=false; + _this.sendAjax("/kefulist","get",{},function(result){ + _this.kefuList=result; + }); }); } else { 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 () { diff --git a/static/html/setting_kefu_list.html b/static/html/setting_kefu_list.html index 64b2142..a432912 100644 --- a/static/html/setting_kefu_list.html +++ b/static/html/setting_kefu_list.html @@ -31,8 +31,8 @@ prop="id" label="操作">