From f0ea379b16f41c90e9a598407299c113cdb735cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=B6=E5=A3=AB=E6=B6=B5?= <630892807@qq.com> Date: Fri, 25 Sep 2020 20:49:33 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BC=96=E8=BE=91=E4=BF=AE=E6=94=B9=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E5=9B=9E=E5=A4=8D=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controller/notice.go | 11 +++++++++++ models/welcomes.go | 10 ++++++++++ router/api.go | 1 + static/html/setting_bottom.html | 9 +++++++++ static/html/setting_welcome.html | 3 +++ 5 files changed, 34 insertions(+) diff --git a/controller/notice.go b/controller/notice.go index 9d00046..22ad845 100644 --- a/controller/notice.go +++ b/controller/notice.go @@ -52,6 +52,17 @@ func PostNotice(c *gin.Context) { "result": "", }) } +func PostNoticeSave(c *gin.Context) { + kefuId, _ := c.Get("kefu_name") + content := c.PostForm("content") + id := c.PostForm("id") + models.UpdateWelcome(fmt.Sprintf("%s", kefuId),id, 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") diff --git a/models/welcomes.go b/models/welcomes.go index f1c7eb6..698651b 100644 --- a/models/welcomes.go +++ b/models/welcomes.go @@ -22,6 +22,16 @@ func CreateWelcome(userId string, content string) uint { DB.Create(w) return w.ID } +func UpdateWelcome(userId string,id string, content string) uint { + if userId == "" || content == "" { + return 0 + } + w := &Welcome{ + Content: content, + } + DB.Model(w).Where("user_id = ? and id = ?", userId,id).Update(w) + return w.ID +} func FindWelcomeByUserId(userId interface{}) Welcome { var w Welcome DB.Where("user_id = ? and is_default=?", userId, 1).First(&w) diff --git a/router/api.go b/router/api.go index f96168b..6f34777 100644 --- a/router/api.go +++ b/router/api.go @@ -50,6 +50,7 @@ func InitApiRouter(engine *gin.Engine) { engine.GET("/notice", middleware.SetLanguage, controller.GetNotice) engine.POST("/notice", middleware.JwtApiMiddleware, controller.PostNotice) engine.DELETE("/notice", middleware.JwtApiMiddleware, controller.DelNotice) + engine.POST("/notice_save", middleware.JwtApiMiddleware, controller.PostNoticeSave) engine.GET("/notices", middleware.JwtApiMiddleware, controller.GetNotices) engine.POST("/ipblack", middleware.JwtApiMiddleware, controller.PostIpblack) engine.DELETE("/ipblack", middleware.JwtApiMiddleware, controller.DelIpblack) diff --git a/static/html/setting_bottom.html b/static/html/setting_bottom.html index ee5a860..08d8878 100644 --- a/static/html/setting_bottom.html +++ b/static/html/setting_bottom.html @@ -342,6 +342,15 @@ }); }); }, + //设置配置项 + setWelcomeItem(id,content){ + let _this=this; + this.sendAjax("/notice_save","POST",{id:id,content:content},function(result){ + _this.sendAjax("/notices","get",{},function(result){ + _this.noticeList=result; + }); + }); + }, //提交角色表单 submitRoleForm(formName){ let _this=this; diff --git a/static/html/setting_welcome.html b/static/html/setting_welcome.html index 0187b02..56714ef 100644 --- a/static/html/setting_welcome.html +++ b/static/html/setting_welcome.html @@ -13,6 +13,9 @@ +