From 688cff136b3e78a24ec3878f2bded1a404e71504 Mon Sep 17 00:00:00 2001 From: taoshihan1991 <630892807@qq.com> Date: Mon, 24 Aug 2020 11:00:11 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=AC=A2=E8=BF=8E=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/go-fly.sql | 10 ++++++++++ controller/notice.go | 23 +++++++++++++++-------- main.go | 1 + models/welcomes.go | 16 ++++++++++++++++ static/html/chat_page.html | 4 ++-- 5 files changed, 44 insertions(+), 10 deletions(-) create mode 100644 models/welcomes.go diff --git a/config/go-fly.sql b/config/go-fly.sql index f5be5b4..308134a 100644 --- a/config/go-fly.sql +++ b/config/go-fly.sql @@ -64,3 +64,13 @@ CREATE TABLE `role` ( `name` varchar(100) NOT NULL DEFAULT '', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 +DROP TABLE IF EXISTS `welcome`; +CREATE TABLE `welcome` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `user_id` varchar(100) NOT NULL DEFAULT '', + `content` varchar(500) NOT NULL DEFAULT '', + `is_default` tinyint(3) unsigned NOT NULL DEFAULT '0', + `ctime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + PRIMARY KEY (`id`), + KEY `user_id` (`user_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 diff --git a/controller/notice.go b/controller/notice.go index e0010d1..2600cda 100644 --- a/controller/notice.go +++ b/controller/notice.go @@ -15,18 +15,25 @@ func GetNotice(c *gin.Context) { kefuId:=c.Query("kefu_id") lang,_:=c.Get("lang") language:=config.CreateLanguage(lang.(string)) - + welcome:=models.FindWelcomeByUserId(kefuId) user:=models.FindUser(kefuId) - info:=make(map[string]interface{}) - info["nickname"]=user.Nickname - info["avator"]=user.Avator - info["name"]=user.Name - info["content"]=language.Notice - info["time"]=time.Now().Format("2006-01-02 15:04:05") + var content string + log.Println(welcome) + if welcome.Content!=""{ + content=welcome.Content + }else { + content=language.Notice + } c.JSON(200, gin.H{ "code": 200, "msg": "ok", - "result":info, + "result":gin.H{ + "nickname":user.Nickname, + "avator":user.Avator, + "name":user.Name, + "content":content, + "time":time.Now().Format("2006-01-02 15:04:05"), + }, }) } var upgrader = websocket.Upgrader{} diff --git a/main.go b/main.go index 900ac89..e8ab988 100644 --- a/main.go +++ b/main.go @@ -60,6 +60,7 @@ func main() { engine.GET("/login", tmpl.PageLogin) //咨询界面 engine.GET("/chat_page",middleware.SetLanguage, tmpl.PageChat) + engine.GET("/chatIndex",middleware.SetLanguage, tmpl.PageChat) //登陆验证 engine.POST("/check", controller.LoginCheckPass) //框架界面 diff --git a/models/welcomes.go b/models/welcomes.go new file mode 100644 index 0000000..ea3979f --- /dev/null +++ b/models/welcomes.go @@ -0,0 +1,16 @@ +package models + +import "time" + +type Welcome struct { + ID uint `gorm:"primary_key" json:"id"` + UserId string `json:"user_id"` + Content string `json:"content"` + IsDefault uint `json:"is_default"` + Ctime time.Time `json:"ctime"` +} +func FindWelcomeByUserId(userId interface{})Welcome{ + var w Welcome + DB.Where("user_id = ? and is_default=?", userId,1).First(&w) + return w +} \ No newline at end of file diff --git a/static/html/chat_page.html b/static/html/chat_page.html index 8c9fc55..b1047ab 100644 --- a/static/html/chat_page.html +++ b/static/html/chat_page.html @@ -186,7 +186,7 @@ if (redata.type == "kfOnline") { let msg = redata.data guest.to_id=msg.id; - this.chatTitle=msg.name+",为您服务!" + this.chatTitle=msg.name+",正在与您沟通!" $(".chatBox").append("
"+this.chatTitle+"
"); this.scrollBottom(); } @@ -374,7 +374,7 @@ setTimeout(function () { _this.msgList.push(content); _this.scrollBottom(); - }, 2000); + }, 4000); ; } });