|
|
@ -1,12 +1,60 @@
|
|
|
|
package controller
|
|
|
|
package controller
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
|
|
|
|
"encoding/json"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
|
|
|
|
"github.com/gorilla/websocket"
|
|
|
|
"github.com/taoshihan1991/imaptool/config"
|
|
|
|
"github.com/taoshihan1991/imaptool/config"
|
|
|
|
"github.com/taoshihan1991/imaptool/models"
|
|
|
|
"github.com/taoshihan1991/imaptool/models"
|
|
|
|
|
|
|
|
"log"
|
|
|
|
"strconv"
|
|
|
|
"strconv"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
func PostVisitor(c *gin.Context) {
|
|
|
|
|
|
|
|
name := c.PostForm("name")
|
|
|
|
|
|
|
|
avator := c.PostForm("avator")
|
|
|
|
|
|
|
|
toId := c.PostForm("to_id")
|
|
|
|
|
|
|
|
id := c.PostForm("id")
|
|
|
|
|
|
|
|
refer := c.PostForm("refer")
|
|
|
|
|
|
|
|
city := c.PostForm("city")
|
|
|
|
|
|
|
|
client_ip := c.PostForm("client_ip")
|
|
|
|
|
|
|
|
if name==""||avator==""||toId==""||id==""||refer==""||city==""||client_ip==""{
|
|
|
|
|
|
|
|
c.JSON(200, gin.H{
|
|
|
|
|
|
|
|
"code": 400,
|
|
|
|
|
|
|
|
"msg": "error",
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
kefuInfo:=models.FindUser(toId)
|
|
|
|
|
|
|
|
if kefuInfo.ID==0{
|
|
|
|
|
|
|
|
c.JSON(200, gin.H{
|
|
|
|
|
|
|
|
"code": 400,
|
|
|
|
|
|
|
|
"msg": "用户不存在",
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
models.CreateVisitor(name,avator,c.ClientIP(),toId,id,refer,city,client_ip)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
userInfo := make(map[string]string)
|
|
|
|
|
|
|
|
userInfo["uid"] = id
|
|
|
|
|
|
|
|
userInfo["username"] = name
|
|
|
|
|
|
|
|
userInfo["avator"] = avator
|
|
|
|
|
|
|
|
msg := TypeMessage{
|
|
|
|
|
|
|
|
Type: "userOnline",
|
|
|
|
|
|
|
|
Data: userInfo,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
str, _ := json.Marshal(msg)
|
|
|
|
|
|
|
|
kefuConns:=kefuList[toId]
|
|
|
|
|
|
|
|
if kefuConns!=nil{
|
|
|
|
|
|
|
|
for k,kefuConn:=range kefuConns{
|
|
|
|
|
|
|
|
log.Println(k,"xxxxxxxx")
|
|
|
|
|
|
|
|
kefuConn.WriteMessage(websocket.TextMessage,str)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
c.JSON(200, gin.H{
|
|
|
|
|
|
|
|
"code": 200,
|
|
|
|
|
|
|
|
"msg": "ok",
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
func GetVisitor(c *gin.Context) {
|
|
|
|
func GetVisitor(c *gin.Context) {
|
|
|
|
visitorId:=c.Query("visitorId")
|
|
|
|
visitorId:=c.Query("visitorId")
|
|
|
|
vistor:=models.FindVisitorByVistorId(visitorId)
|
|
|
|
vistor:=models.FindVisitorByVistorId(visitorId)
|
|
|
|