feat(widget): 优化访客在线轨迹、GeoIP与多站点渠道
CI / Frontend (typecheck + lint + build) (push) Successful in 2m5s
CI / Backend (go vet + test) (push) Failing after 5m20s

This commit is contained in:
yml2213
2026-11-06 18:21:30 +08:00
parent 24fac1bcf1
commit 38d6fc1684
37 changed files with 1071 additions and 123 deletions
+16 -11
View File
@@ -392,18 +392,27 @@ func (h *StatisticsHandler) ChannelDistribution(c *gin.Context) {
c.JSON(http.StatusInternalServerError, gin.H{"code": 500, "message": "查询渠道分布失败"})
return
}
channelTypes := make(map[uint]string)
channelByID := make(map[uint]model.Channel)
for _, channel := range channels {
channelTypes[channel.ID] = channel.Type
channelByID[channel.ID] = channel
}
labels := map[string]string{"web": "网页", "wechat": "微信", "app": "APP", "phone": "电话工单", "email": "邮件"}
counts := make(map[string]int)
for _, session := range sessions {
channelType := channelTypes[session.ChannelID]
if channelType == "" {
channelType = "unknown"
label := "未知渠道"
if channel, ok := channelByID[session.ChannelID]; ok {
label = strings.TrimSpace(channel.Name)
if label == "" {
label = labels[channel.Type]
}
if label == "" {
label = channel.Type
}
}
counts[channelType]++
if siteHost := strings.TrimSpace(session.SiteHost); siteHost != "" {
label += " · " + siteHost
}
counts[label]++
}
keys := make([]string, 0, len(counts))
for key := range counts {
@@ -412,11 +421,7 @@ func (h *StatisticsHandler) ChannelDistribution(c *gin.Context) {
sort.Strings(keys)
data := make([]gin.H, 0, len(keys))
for _, key := range keys {
label := labels[key]
if label == "" {
label = key
}
data = append(data, gin.H{"type": label, "value": counts[key]})
data = append(data, gin.H{"type": key, "value": counts[key]})
}
middleware.JSON(c, data)
}