diff --git a/cmd/install.go b/cmd/install.go index ff20d45..3f7629e 100644 --- a/cmd/install.go +++ b/cmd/install.go @@ -7,6 +7,7 @@ import ( "github.com/taoshihan1991/imaptool/models" "github.com/taoshihan1991/imaptool/tools" "io/ioutil" + "log" "os" "strings" ) @@ -33,6 +34,11 @@ func install() { if sql == "" { continue } - models.Execute(sql) + err := models.Execute(sql) + if err == nil { + log.Println(sql, "\t success!") + } else { + log.Println(sql, err, "\t failed!") + } } } diff --git a/controller/message.go b/controller/message.go index 82710d6..dd48210 100644 --- a/controller/message.go +++ b/controller/message.go @@ -153,33 +153,14 @@ func SendMessageV2(c *gin.Context) { }) 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) var msg TypeMessage if cType == "kefu" { guest, ok := ws.ClientList[vistorInfo.VisitorId] if guest != nil && ok { - conn := guest.Conn - - 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) + ws.VisitorMessage(vistorInfo.VisitorId, content, kefuInfo) } msg = TypeMessage{ @@ -228,6 +209,17 @@ func SendMessageV2(c *gin.Context) { "msg": "ok", "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) { notice := c.Query("msg") diff --git a/models/models.go b/models/models.go index eb92f23..13c9339 100644 --- a/models/models.go +++ b/models/models.go @@ -33,8 +33,9 @@ func init() { InitConfig() } -func Execute(sql string) { +func Execute(sql string) error { DB.Exec(sql) + return DB.Error } func CloseDB() { defer DB.Close() diff --git a/static/images/12.jpg b/static/images/12.jpg index 504cb25..58dbdb0 100644 Binary files a/static/images/12.jpg and b/static/images/12.jpg differ diff --git a/static/images/4.jpg b/static/images/4.jpg index 58dbdb0..504cb25 100644 Binary files a/static/images/4.jpg and b/static/images/4.jpg differ diff --git a/ws/visitor.go b/ws/visitor.go index 4a700d7..4a2a1aa 100644 --- a/ws/visitor.go +++ b/ws/visitor.go @@ -6,6 +6,7 @@ import ( "github.com/gorilla/websocket" "github.com/taoshihan1991/imaptool/models" "log" + "time" ) func NewVisitorServer(c *gin.Context) { @@ -121,3 +122,20 @@ func VisitorNotice(visitorId string, notice string) { visitor := ClientList[visitorId] 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) +}