144 lines
3.2 KiB
Go
144 lines
3.2 KiB
Go
|
package controller
|
||
|
|
||
|
import (
|
||
|
"github.com/gin-gonic/gin"
|
||
|
"kefu/models"
|
||
|
"log"
|
||
|
)
|
||
|
|
||
|
type ReplyForm struct {
|
||
|
GroupName string `form:"group_name" binding:"required"`
|
||
|
IsTeam string `form:"is_team" binding:"required"`
|
||
|
}
|
||
|
type ReplyContentForm struct {
|
||
|
GroupId string `form:"group_id" binding:"required"`
|
||
|
Content string `form:"content" binding:"required"`
|
||
|
ItemName string `form:"item_name" binding:"required"`
|
||
|
}
|
||
|
|
||
|
//企业公用快捷回复列表
|
||
|
func GetEntReplys(c *gin.Context) {
|
||
|
entId, _ := c.Get("ent_id")
|
||
|
res := models.FindReplyByEntId(entId)
|
||
|
c.JSON(200, gin.H{
|
||
|
"code": 200,
|
||
|
"msg": "ok",
|
||
|
"result": res,
|
||
|
})
|
||
|
}
|
||
|
func GetReplys(c *gin.Context) {
|
||
|
kefuId, _ := c.Get("kefu_name")
|
||
|
log.Println(kefuId)
|
||
|
res := models.FindReplyByUserId(kefuId)
|
||
|
c.JSON(200, gin.H{
|
||
|
"code": 200,
|
||
|
"msg": "ok",
|
||
|
"result": res,
|
||
|
})
|
||
|
}
|
||
|
func GetAutoReplys(c *gin.Context) {
|
||
|
entId := c.Query("ent_id")
|
||
|
kefu := models.FindUserByUid(entId)
|
||
|
var res []*models.ReplyGroup
|
||
|
res = models.FindReplyTitleByUserId(kefu.Name)
|
||
|
var single interface{}
|
||
|
if len(res) >= 1 {
|
||
|
single = res[0]
|
||
|
}
|
||
|
c.JSON(200, gin.H{
|
||
|
"code": 200,
|
||
|
"msg": "ok",
|
||
|
"result": single,
|
||
|
})
|
||
|
}
|
||
|
func PostReply(c *gin.Context) {
|
||
|
var replyForm ReplyForm
|
||
|
kefuId, _ := c.Get("kefu_name")
|
||
|
entId, _ := c.Get("ent_id")
|
||
|
err := c.Bind(&replyForm)
|
||
|
if err != nil {
|
||
|
c.JSON(200, gin.H{
|
||
|
"code": 400,
|
||
|
"msg": "error:" + err.Error(),
|
||
|
})
|
||
|
return
|
||
|
}
|
||
|
models.CreateReplyGroup(replyForm.GroupName, kefuId.(string), entId.(string), replyForm.IsTeam)
|
||
|
c.JSON(200, gin.H{
|
||
|
"code": 200,
|
||
|
"msg": "ok",
|
||
|
})
|
||
|
}
|
||
|
func PostReplyContent(c *gin.Context) {
|
||
|
var replyContentForm ReplyContentForm
|
||
|
kefuId, _ := c.Get("kefu_name")
|
||
|
entId, _ := c.Get("ent_id")
|
||
|
err := c.Bind(&replyContentForm)
|
||
|
if err != nil {
|
||
|
c.JSON(400, gin.H{
|
||
|
"code": 200,
|
||
|
"msg": "error:" + err.Error(),
|
||
|
})
|
||
|
return
|
||
|
}
|
||
|
models.CreateReplyContent(replyContentForm.GroupId, kefuId.(string), replyContentForm.Content, replyContentForm.ItemName, entId.(string))
|
||
|
c.JSON(200, gin.H{
|
||
|
"code": 200,
|
||
|
"msg": "ok",
|
||
|
})
|
||
|
}
|
||
|
func PostReplyContentSave(c *gin.Context) {
|
||
|
kefuId, _ := c.Get("kefu_name")
|
||
|
replyId := c.PostForm("reply_id")
|
||
|
replyTitle := c.PostForm("reply_title")
|
||
|
replyContent := c.PostForm("reply_content")
|
||
|
if replyId == "" || replyTitle == "" || replyContent == "" {
|
||
|
c.JSON(400, gin.H{
|
||
|
"code": 200,
|
||
|
"msg": "参数错误!",
|
||
|
})
|
||
|
return
|
||
|
}
|
||
|
models.UpdateReplyContent(replyId, kefuId.(string), replyTitle, replyContent)
|
||
|
c.JSON(200, gin.H{
|
||
|
"code": 200,
|
||
|
"msg": "ok",
|
||
|
})
|
||
|
}
|
||
|
func DelReplyContent(c *gin.Context) {
|
||
|
kefuId, _ := c.Get("kefu_name")
|
||
|
id := c.Query("id")
|
||
|
models.DeleteReplyContent(id, kefuId.(string))
|
||
|
c.JSON(200, gin.H{
|
||
|
"code": 200,
|
||
|
"msg": "ok",
|
||
|
})
|
||
|
}
|
||
|
func DelReplyGroup(c *gin.Context) {
|
||
|
kefuId, _ := c.Get("kefu_name")
|
||
|
id := c.Query("id")
|
||
|
models.DeleteReplyGroup(id, kefuId.(string))
|
||
|
c.JSON(200, gin.H{
|
||
|
"code": 200,
|
||
|
"msg": "ok",
|
||
|
})
|
||
|
}
|
||
|
func PostReplySearch(c *gin.Context) {
|
||
|
kefuId, _ := c.Get("kefu_name")
|
||
|
entId, _ := c.Get("ent_id")
|
||
|
search := c.PostForm("search")
|
||
|
if search == "" {
|
||
|
c.JSON(200, gin.H{
|
||
|
"code": 400,
|
||
|
"msg": "参数错误",
|
||
|
})
|
||
|
return
|
||
|
}
|
||
|
res := models.FindReplyBySearcch(entId, kefuId, search)
|
||
|
c.JSON(200, gin.H{
|
||
|
"code": 200,
|
||
|
"msg": "ok",
|
||
|
"result": res,
|
||
|
})
|
||
|
}
|