feat: 弃用腾讯tts,该用火山引擎tts
This commit is contained in:
@@ -3,37 +3,16 @@ package radio
|
||||
import (
|
||||
"sundynix-go/global"
|
||||
"sundynix-go/model/radio/response"
|
||||
"sundynix-go/utils/timer"
|
||||
"time"
|
||||
)
|
||||
|
||||
type AnalyticsService struct{}
|
||||
|
||||
// parseDateRange 解析日期范围,未传则默认最近30天
|
||||
func parseDateRange(startDate, endDate string) (time.Time, time.Time) {
|
||||
now := time.Now()
|
||||
layout := "2006-01-02"
|
||||
|
||||
end, err := time.ParseInLocation(layout, endDate, now.Location())
|
||||
if err != nil {
|
||||
end = now
|
||||
}
|
||||
// 结束日期取当天 23:59:59
|
||||
end = time.Date(end.Year(), end.Month(), end.Day(), 23, 59, 59, 0, end.Location())
|
||||
|
||||
start, err := time.ParseInLocation(layout, startDate, now.Location())
|
||||
if err != nil {
|
||||
start = end.AddDate(0, 0, -29) // 默认30天
|
||||
}
|
||||
// 开始日期取当天 00:00:00
|
||||
start = time.Date(start.Year(), start.Month(), start.Day(), 0, 0, 0, 0, start.Location())
|
||||
|
||||
return start, end
|
||||
}
|
||||
|
||||
// GetListeningTrend 获取收听趋势 (使用持久化的 ListenLog)
|
||||
func (s *AnalyticsService) GetListeningTrend(startDate, endDate, channelId string) (response.ListeningTrendResponse, error) {
|
||||
var resp response.ListeningTrendResponse
|
||||
start, end := parseDateRange(startDate, endDate)
|
||||
start, end := timer.ParseDateRange(startDate, endDate)
|
||||
|
||||
db := global.DB.Table("sundynix_radio_listen_log")
|
||||
if channelId != "" {
|
||||
@@ -60,7 +39,7 @@ func (s *AnalyticsService) GetListeningTrend(startDate, endDate, channelId strin
|
||||
// GetSubscriptionTrend 获取新增订阅趋势 (使用永久 Order 记录)
|
||||
func (s *AnalyticsService) GetSubscriptionTrend(startDate, endDate, channelId string) (response.SubscriptionTrendResponse, error) {
|
||||
var resp response.SubscriptionTrendResponse
|
||||
start, end := parseDateRange(startDate, endDate)
|
||||
start, end := timer.ParseDateRange(startDate, endDate)
|
||||
|
||||
// 订阅趋势 = 首次购买该频道成功的订单
|
||||
// 通过子查询找到每个 (user_id, channel_id) 的最小成功订单日期
|
||||
@@ -89,7 +68,7 @@ func (s *AnalyticsService) GetSubscriptionTrend(startDate, endDate, channelId st
|
||||
// GetRenewalTrend 获取续费趋势 (使用永久 Order 记录)
|
||||
func (s *AnalyticsService) GetRenewalTrend(startDate, endDate, channelId string) (response.RenewalTrendResponse, error) {
|
||||
var resp response.RenewalTrendResponse
|
||||
start, end := parseDateRange(startDate, endDate)
|
||||
start, end := timer.ParseDateRange(startDate, endDate)
|
||||
|
||||
// 续费 = 成功支付的订阅订单,且不是该用户对该频道的首笔订单
|
||||
db := global.DB.Table("sundynix_order AS o").
|
||||
@@ -118,7 +97,7 @@ func (s *AnalyticsService) GetRenewalTrend(startDate, endDate, channelId string)
|
||||
// GetSubscriberStats 获取订阅用户统计 (混合实时 Subscription 与历史 Order)
|
||||
func (s *AnalyticsService) GetSubscriberStats(startDate, endDate, channelId string) (response.SubscriberStatsResponse, error) {
|
||||
var resp response.SubscriberStatsResponse
|
||||
start, end := parseDateRange(startDate, endDate)
|
||||
start, end := timer.ParseDateRange(startDate, endDate)
|
||||
now := time.Now()
|
||||
|
||||
// 1. 当前有效订阅用户数 (实时表)
|
||||
@@ -190,7 +169,7 @@ func (s *AnalyticsService) GetContentQuality(channelId string) ([]response.Compl
|
||||
// GetUserStickiness 用户黏性分析:留存分析 (Cohort Analysis)
|
||||
func (s *AnalyticsService) GetUserStickiness(startDate, endDate string) ([]response.RetentionResponse, error) {
|
||||
var list []response.RetentionResponse
|
||||
start, end := parseDateRange(startDate, endDate)
|
||||
start, end := timer.ParseDateRange(startDate, endDate)
|
||||
|
||||
// 获取时间范围内的每日新增活跃用户
|
||||
var dailyNewUsers []struct {
|
||||
@@ -239,7 +218,7 @@ func (s *AnalyticsService) GetUserStickiness(startDate, endDate string) ([]respo
|
||||
// GetBusinessConversion 商业转化分析:漏斗与 LTV
|
||||
func (s *AnalyticsService) GetBusinessConversion(startDate, endDate string) (response.FunnelResponse, error) {
|
||||
var resp response.FunnelResponse
|
||||
start, end := parseDateRange(startDate, endDate)
|
||||
start, end := timer.ParseDateRange(startDate, endDate)
|
||||
|
||||
// 1. 活跃收听用户数 (Top of Funnel)
|
||||
global.DB.Table("sundynix_radio_listen_log").
|
||||
@@ -297,3 +276,30 @@ func (s *AnalyticsService) GetPreferenceAnalysis() (response.PreferenceAnalysisR
|
||||
|
||||
return resp, err
|
||||
}
|
||||
|
||||
// GetVipStats 获取VIP用户和营收统计
|
||||
func (s *AnalyticsService) GetVipStats(startDate, endDate string) (response.VipStatsResponse, error) {
|
||||
var resp response.VipStatsResponse
|
||||
start, end := timer.ParseDateRange(startDate, endDate)
|
||||
now := time.Now()
|
||||
|
||||
// 1. 获取当前有效VIP用户数
|
||||
global.DB.Table("sundynix_user").
|
||||
Where("is_vip = 1 AND vip_expire_at >= ?", now).
|
||||
Count(&resp.ActiveVipUsers)
|
||||
|
||||
// 2. 获取期间内VIP总营收 (Type = 2 为 VIP 支付)
|
||||
global.DB.Table("sundynix_order").
|
||||
Where("type = 2 AND status = 1 AND deleted_at IS NULL").
|
||||
Where("updated_at BETWEEN ? AND ?", start, end).
|
||||
Select("COALESCE(SUM(amount), 0)").
|
||||
Scan(&resp.VipRevenue)
|
||||
|
||||
// 3. 获取期间内新增VIP订单数
|
||||
global.DB.Table("sundynix_order").
|
||||
Where("type = 2 AND status = 1 AND deleted_at IS NULL").
|
||||
Where("updated_at BETWEEN ? AND ?", start, end).
|
||||
Count(&resp.NewVipOrders)
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user