kefu/controller/xlsx.go

40 lines
1002 B
Go
Raw Permalink Normal View History

2024-12-10 02:50:12 +00:00
package controller
import (
"github.com/gin-gonic/gin"
"kefu/models"
"kefu/tools"
)
//导出访客聊天记录
func GetExportVisitorMessage(c *gin.Context) {
entId, _ := c.Get("ent_id")
visitorId := c.Query("visitor_id")
list := models.FindMessageByPage(1, 100000, "message.ent_id= ? and message.visitor_id=?", entId, visitorId)
if len(list) == 0 {
c.JSON(200, gin.H{
"code": 400,
"msg": "no data",
})
return
}
titleList := []string{
"from_name", "to_name", "content", "time",
}
data := make([]map[string]interface{}, 0)
for _, item := range list {
row := make(map[string]interface{})
if item.MesType == "kefu" {
row["from_name"] = item.KefuName
row["to_name"] = item.VisitorName
} else {
row["from_name"] = item.VisitorName
row["to_name"] = item.KefuName
}
row["content"] = item.Content
row["time"] = item.CreateTime
data = append(data, row)
}
tools.ExportExcelByMap(c, titleList, data, list[0].VisitorName+"聊天记录", "visitor_message")
}