124 lines
3.2 KiB
Go
124 lines
3.2 KiB
Go
package controller
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"github.com/gin-gonic/gin"
|
|
"kefu/models"
|
|
"kefu/tools"
|
|
"kefu/types"
|
|
"kefu/ws"
|
|
"math"
|
|
)
|
|
|
|
func GetSendComment(c *gin.Context) {
|
|
entId, _ := c.Get("ent_id")
|
|
kefuName, _ := c.Get("kefu_name")
|
|
visitorId := c.Query("visitor_id")
|
|
msg := ws.TypeMessage{
|
|
Type: "comment",
|
|
}
|
|
ws.VisitorCustomMessage(visitorId, msg)
|
|
|
|
logContent := fmt.Sprintf("'%s'向'%s'发送评价请求", kefuName.(string), visitorId)
|
|
go models.CreateFlyLog(entId.(string), c.ClientIP(), logContent, "comment")
|
|
|
|
c.JSON(200, gin.H{
|
|
"code": 200,
|
|
"msg": "ok",
|
|
})
|
|
}
|
|
func GetCommentStatistics(c *gin.Context) {
|
|
entId, _ := c.Get("ent_id")
|
|
kefuName, _ := c.Get("kefu_name")
|
|
|
|
args := []interface{}{entId, kefuName}
|
|
UserAttr := models.FindUserAttrRow("ent_id = ? and kefu_name = ?", args...)
|
|
var (
|
|
goodPre, normalPre, badPre float64
|
|
)
|
|
if UserAttr.ID != 0 {
|
|
sumNum := float64(UserAttr.GoodNum + UserAttr.BadNum + UserAttr.NormalNum)
|
|
if sumNum != 0 {
|
|
goodPre = math.Floor((float64(UserAttr.GoodNum) / sumNum) * 100)
|
|
normalPre = math.Floor((float64(UserAttr.NormalNum) / sumNum) * 100)
|
|
badPre = math.Floor((float64(UserAttr.BadNum) / sumNum) * 100)
|
|
}
|
|
}
|
|
|
|
c.JSON(200, gin.H{
|
|
"code": 200,
|
|
"msg": "ok",
|
|
"result": gin.H{
|
|
"good_num": tools.Int2Str(UserAttr.GoodNum),
|
|
"good_pre": tools.Int2Str(goodPre),
|
|
"bad_num": tools.Int2Str(UserAttr.GoodNum),
|
|
"bad_pre": tools.Int2Str(badPre),
|
|
"normal_num": tools.Int2Str(UserAttr.GoodNum),
|
|
"normal_pre": tools.Int2Str(normalPre),
|
|
"money": UserAttr.Money,
|
|
},
|
|
})
|
|
}
|
|
func PostVisitorComment(c *gin.Context) {
|
|
entId := c.PostForm("ent_id")
|
|
kefuName := c.PostForm("kefu_name")
|
|
visitorId := c.PostForm("visitor_id")
|
|
//tagName := c.PostForm("tag_name")
|
|
score := c.PostForm("comment_score")
|
|
content := c.PostForm("comment_content")
|
|
kefuInfo := models.FindUser(kefuName)
|
|
//var (
|
|
// goodNum uint
|
|
// normalNum uint
|
|
// badNum uint
|
|
//)
|
|
//if tagName == "good" {
|
|
// goodNum = 1
|
|
//}
|
|
//if tagName == "normal" {
|
|
// normalNum = 1
|
|
//}
|
|
//if tagName == "bad" {
|
|
// badNum = 1
|
|
//}
|
|
msg := ws.TypeMessage{
|
|
Type: "comment",
|
|
Data: "访客发送评价“" + score + "”",
|
|
}
|
|
str, _ := json.Marshal(msg)
|
|
|
|
go ws.OneKefuMessage(kefuName, str)
|
|
//go VisitorTagFunc(tagName, kefuName, entId, visitorId)
|
|
|
|
//args := []interface{}{}
|
|
//args = append(args, entId)
|
|
//args = append(args, kefuName)
|
|
//UserAttr := models.FindUserAttrRow("ent_id = ? and kefu_name = ?", args...)
|
|
//if UserAttr.ID == 0 {
|
|
// models.CreateUserAttr(entId, kefuName, goodNum, normalNum, badNum)
|
|
//} else {
|
|
// UserAttr.GoodNum = UserAttr.GoodNum + goodNum
|
|
// UserAttr.NormalNum = UserAttr.NormalNum + normalNum
|
|
// UserAttr.BadNum = UserAttr.BadNum + badNum
|
|
// UserAttr.SaveUserAttr("ent_id = ? and kefu_name = ?", args...)
|
|
//}
|
|
rate := &models.Rate{
|
|
EntId: entId,
|
|
KefuName: kefuName,
|
|
Score: uint(tools.Str2Int(score)),
|
|
CreatedAt: types.Time{},
|
|
VisitorId: visitorId,
|
|
Content: content,
|
|
KefuNickname: kefuInfo.Nickname,
|
|
}
|
|
rate.AddRate()
|
|
logContent := fmt.Sprintf("'%s'向'%s'发送评价'%s'结果", visitorId, kefuName, score)
|
|
go models.CreateFlyLog(entId, c.ClientIP(), logContent, "comment")
|
|
|
|
c.JSON(200, gin.H{
|
|
"code": 200,
|
|
"msg": "ok",
|
|
})
|
|
}
|