From 8c766d2c2d5969ff69af8bdd61a0f75e88895a93 Mon Sep 17 00:00:00 2001 From: taoshihan1991 <630892807@qq.com> Date: Fri, 21 Aug 2020 11:42:40 +0800 Subject: [PATCH 1/7] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=85=A8=E9=83=A8?= =?UTF-8?q?=E6=B8=85=E7=90=86tcp=E5=AE=A2=E6=88=B7=E7=AB=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controller/tcp.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/controller/tcp.go b/controller/tcp.go index 9d53129..6b03cab 100644 --- a/controller/tcp.go +++ b/controller/tcp.go @@ -27,7 +27,8 @@ func NewTcpServer(tcpBaseServer string){ } func PushServerTcp(str []byte){ for ip,conn:=range clientTcpList{ - _,err:=conn.Write(str) + line:=append(str,[]byte("\r\n")...) + _,err:=conn.Write(line) log.Println(ip,err) if err!=nil{ conn.Close() @@ -43,6 +44,10 @@ func DeleteOnlineTcp(c *gin.Context) { conn.Close() delete(clientTcpList,ip) } + if ip=="all"{ + conn.Close() + delete(clientTcpList,ipkey) + } } c.JSON(200, gin.H{ "code": 200, 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 2/7] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=AC=A2=E8=BF=8E?= =?UTF-8?q?=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); ; } }); From c041df0b2a8366eef9975a56bb254259318cddbb Mon Sep 17 00:00:00 2001 From: taoshihan1991 <630892807@qq.com> Date: Mon, 24 Aug 2020 15:27:27 +0800 Subject: [PATCH 3/7] =?UTF-8?q?=E7=AE=80=E5=8C=96=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- static/html/login.html | 162 ++++++++++++----------------------------- 1 file changed, 46 insertions(+), 116 deletions(-) diff --git a/static/html/login.html b/static/html/login.html index c685689..c8d4256 100644 --- a/static/html/login.html +++ b/static/html/login.html @@ -4,94 +4,73 @@ - GO-FLY登录页 + GO-FLY客服系统登录页 - - - +
+

账户登录

+

请联系开发者获取登录账号

+ + + + + + + + + 登录 + + + +
+ - +