47 lines
1.2 KiB
Go
47 lines
1.2 KiB
Go
package v2
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
"kefu/models"
|
|
"kefu/tools"
|
|
"time"
|
|
)
|
|
|
|
func GetChartStatistic(c *gin.Context) {
|
|
kefuName, _ := c.Get("kefu_name")
|
|
|
|
//今天0点日期字符串
|
|
//todayTimeStr := time.Now().Format("2006-01-02")
|
|
////日期字符串转时间
|
|
//todayTime, _ := time.Parse("2006-01-02", todayTimeStr)
|
|
////时间转时间戳
|
|
//todayTimenum := todayTime.Unix()
|
|
////15天前开始的时间
|
|
//startTimenum := todayTimenum - 15*24*3600
|
|
////时间戳转时间转日期字符串
|
|
//startTime := time.Unix(startTimenum, 0).Format("2006-01-02")
|
|
dayNumMap := make(map[string]string)
|
|
result := models.CountVisitorsEveryDay(kefuName.(string))
|
|
for _, item := range result {
|
|
dayNumMap[item.Day] = tools.Int2Str(item.Num)
|
|
}
|
|
|
|
nowTime := time.Now()
|
|
list := make([]map[string]string, 0)
|
|
for i := 0; i > -46; i-- {
|
|
getTime := nowTime.AddDate(0, 0, i) //年,月,日 获取一天前的时间
|
|
resTime := getTime.Format("06-01-02") //获取的时间的格式
|
|
tmp := make(map[string]string)
|
|
tmp["day"] = resTime
|
|
tmp["num"] = dayNumMap[resTime]
|
|
list = append(list, tmp)
|
|
}
|
|
|
|
c.JSON(200, gin.H{
|
|
"code": 200,
|
|
"msg": "ok",
|
|
"result": list,
|
|
})
|
|
|
|
}
|