diff --git a/controller/message.go b/controller/message.go index ecc4d07..df0e467 100644 --- a/controller/message.go +++ b/controller/message.go @@ -115,6 +115,7 @@ func SendMessageV2(c *gin.Context) { go SendNoticeEmail(content+"|"+vistorInfo.Name, content) } go ws.VisitorAutoReply(vistorInfo, kefuInfo, content) + go models.UpdateVisitorLastMessage(vistorInfo.VisitorId, content) c.JSON(200, gin.H{ "code": 200, "msg": "ok", @@ -165,6 +166,7 @@ func SendKefuMessage(c *gin.Context) { ws.VisitorMessage(vistorInfo.VisitorId, content, kefuInfo) } ws.KefuMessage(vistorInfo.VisitorId, content, kefuInfo) + go models.UpdateVisitorLastMessage(vistorInfo.VisitorId, content) c.JSON(200, gin.H{ "code": 200, "msg": "ok", diff --git a/import.sql b/import.sql index 128f1a7..6d4cb54 100644 --- a/import.sql +++ b/import.sql @@ -28,6 +28,7 @@ CREATE TABLE `visitor` ( `visitor_id` varchar(100) NOT NULL DEFAULT '', `status` tinyint(4) NOT NULL DEFAULT '0', `refer` varchar(500) NOT NULL DEFAULT '', + `last_message` varchar(500) NOT NULL DEFAULT '', `city` varchar(100) NOT NULL DEFAULT '', `client_ip` varchar(100) NOT NULL DEFAULT '', `extra` varchar(2048) NOT NULL DEFAULT '', diff --git a/models/visitors.go b/models/visitors.go index 896a452..146e37f 100644 --- a/models/visitors.go +++ b/models/visitors.go @@ -6,16 +6,17 @@ import ( type Visitor struct { Model - Name string `json:"name"` - Avator string `json:"avator"` - SourceIp string `json:"source_ip"` - ToId string `json:"to_id"` - VisitorId string `json:"visitor_id"` - Status uint `json:"status"` - Refer string `json:"refer"` - City string `json:"city"` - ClientIp string `json:"client_ip"` - Extra string `json:"extra"` + Name string `json:"name"` + Avator string `json:"avator"` + SourceIp string `json:"source_ip"` + ToId string `json:"to_id"` + VisitorId string `json:"visitor_id"` + Status uint `json:"status"` + Refer string `json:"refer"` + City string `json:"city"` + ClientIp string `json:"client_ip"` + LastMessage string `json:"last_message"` + Extra string `json:"extra"` } func CreateVisitor(name, avator, sourceIp, toId, visitorId, refer, city, clientIp, extra string) { @@ -64,6 +65,10 @@ func FindVisitorsOnline() []Visitor { DB.Where("status = ?", 1).Find(&visitors) return visitors } +func UpdateVisitorLastMessage(visitorId, lastMessage string) { + visitor := Visitor{} + DB.Model(&visitor).Where("visitor_id = ?", visitorId).Update("last_message", lastMessage) +} func UpdateVisitorStatus(visitorId string, status uint) { visitor := Visitor{} DB.Model(&visitor).Where("visitor_id = ?", visitorId).Update("status", status) @@ -86,21 +91,21 @@ func UpdateVisitorKefu(visitorId string, kefuId string) { DB.Model(&visitor).Where("visitor_id = ?", visitorId).Update("to_id", kefuId) } -//查询条数 +// 查询条数 func CountVisitors() uint { var count uint DB.Model(&Visitor{}).Count(&count) return count } -//查询条数 +// 查询条数 func CountVisitorsByKefuId(kefuId string) uint { var count uint DB.Model(&Visitor{}).Where("to_id=?", kefuId).Count(&count) return count } -//查询每天条数 +// 查询每天条数 type EveryDayNum struct { Day string `json:"day"` Num int64 `json:"num"` diff --git a/static/templates/chat_main.html b/static/templates/chat_main.html index 2ad75b8..4c50042 100644 --- a/static/templates/chat_main.html +++ b/static/templates/chat_main.html @@ -57,10 +57,11 @@
- + - - <{item.name}> + +
<{item.name}>
+
<{item.last_message}>
diff --git a/static/templates/pannel.html b/static/templates/pannel.html index d28a2e6..14a2295 100644 --- a/static/templates/pannel.html +++ b/static/templates/pannel.html @@ -7,7 +7,7 @@ box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1); } .deployment-section { - + padding: 20px; background: #f8fafc; border-radius: 8px;