离线留言通知和导表结果展示

pull/23/head
陶士涵 3 years ago
parent de5cdcc0c0
commit cd89760b5c

@ -7,6 +7,7 @@ import (
"github.com/taoshihan1991/imaptool/models" "github.com/taoshihan1991/imaptool/models"
"github.com/taoshihan1991/imaptool/tools" "github.com/taoshihan1991/imaptool/tools"
"io/ioutil" "io/ioutil"
"log"
"os" "os"
"strings" "strings"
) )
@ -33,6 +34,11 @@ func install() {
if sql == "" { if sql == "" {
continue continue
} }
models.Execute(sql) err := models.Execute(sql)
if err == nil {
log.Println(sql, "\t success!")
} else {
log.Println(sql, err, "\t failed!")
}
} }
} }

@ -153,33 +153,14 @@ func SendMessageV2(c *gin.Context) {
}) })
return return
} }
kefus, ok := ws.KefuList[kefuInfo.Name]
if !ok || len(kefus) == 0 {
log.Println("客服不在线,发送邮件通知")
go SendNoticeEmail(content+vistorInfo.Name, content)
}
models.CreateMessage(kefuInfo.Name, vistorInfo.VisitorId, content, cType) models.CreateMessage(kefuInfo.Name, vistorInfo.VisitorId, content, cType)
var msg TypeMessage var msg TypeMessage
if cType == "kefu" { if cType == "kefu" {
guest, ok := ws.ClientList[vistorInfo.VisitorId] guest, ok := ws.ClientList[vistorInfo.VisitorId]
if guest != nil && ok { if guest != nil && ok {
conn := guest.Conn ws.VisitorMessage(vistorInfo.VisitorId, content, kefuInfo)
msg = TypeMessage{
Type: "message",
Data: ws.ClientMessage{
Name: kefuInfo.Nickname,
Avator: kefuInfo.Avator,
Id: kefuInfo.Name,
Time: time.Now().Format("2006-01-02 15:04:05"),
ToId: vistorInfo.VisitorId,
Content: content,
IsKefu: "no",
},
}
str, _ := json.Marshal(msg)
conn.WriteMessage(websocket.TextMessage, str)
} }
msg = TypeMessage{ msg = TypeMessage{
@ -228,6 +209,17 @@ func SendMessageV2(c *gin.Context) {
"msg": "ok", "msg": "ok",
"result": msg, "result": msg,
}) })
kefus, ok := ws.KefuList[kefuInfo.Name]
if !ok || len(kefus) == 0 {
log.Println("客服不在线,发送邮件通知")
go SendNoticeEmail(content+"|"+vistorInfo.Name, content)
go func() {
time.Sleep(1 * time.Second)
content = "我暂时离线,留言已转发到我的邮箱,稍后回复~"
ws.VisitorMessage(vistorInfo.VisitorId, content, kefuInfo)
models.CreateMessage(kefuInfo.Name, vistorInfo.VisitorId, content, "kefu")
}()
}
} }
func SendVisitorNotice(c *gin.Context) { func SendVisitorNotice(c *gin.Context) {
notice := c.Query("msg") notice := c.Query("msg")

@ -33,8 +33,9 @@ func init() {
InitConfig() InitConfig()
} }
func Execute(sql string) { func Execute(sql string) error {
DB.Exec(sql) DB.Exec(sql)
return DB.Error
} }
func CloseDB() { func CloseDB() {
defer DB.Close() defer DB.Close()

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.9 KiB

After

Width:  |  Height:  |  Size: 6.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.1 KiB

After

Width:  |  Height:  |  Size: 6.9 KiB

@ -6,6 +6,7 @@ import (
"github.com/gorilla/websocket" "github.com/gorilla/websocket"
"github.com/taoshihan1991/imaptool/models" "github.com/taoshihan1991/imaptool/models"
"log" "log"
"time"
) )
func NewVisitorServer(c *gin.Context) { func NewVisitorServer(c *gin.Context) {
@ -121,3 +122,20 @@ func VisitorNotice(visitorId string, notice string) {
visitor := ClientList[visitorId] visitor := ClientList[visitorId]
visitor.Conn.WriteMessage(websocket.TextMessage, str) visitor.Conn.WriteMessage(websocket.TextMessage, str)
} }
func VisitorMessage(visitorId, content string, kefuInfo models.User) {
msg := TypeMessage{
Type: "message",
Data: ClientMessage{
Name: kefuInfo.Nickname,
Avator: kefuInfo.Avator,
Id: kefuInfo.Name,
Time: time.Now().Format("2006-01-02 15:04:05"),
ToId: visitorId,
Content: content,
IsKefu: "no",
},
}
str, _ := json.Marshal(msg)
visitor := ClientList[visitorId]
visitor.Conn.WriteMessage(websocket.TextMessage, str)
}

Loading…
Cancel
Save