This commit is contained in:
@@ -1301,8 +1301,10 @@ func (s *StatisticsApplicationServiceImpl) getUserApiCallsStats(ctx context.Cont
|
||||
}
|
||||
|
||||
// 获取今日调用次数
|
||||
today := time.Now().Truncate(24 * time.Hour)
|
||||
tomorrow := today.Add(24 * time.Hour)
|
||||
loc, _ := time.LoadLocation("Asia/Shanghai") // 东八时区
|
||||
now := time.Now().In(loc)
|
||||
today := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, loc) // 当天0点
|
||||
tomorrow := today.AddDate(0, 0, 1) // 次日0点
|
||||
todayCalls, err := s.getApiCallsCountByDateRange(ctx, userID, today, tomorrow)
|
||||
if err != nil {
|
||||
s.logger.Error("获取今日API调用次数失败", zap.String("user_id", userID), zap.Error(err))
|
||||
@@ -1356,8 +1358,10 @@ func (s *StatisticsApplicationServiceImpl) getUserConsumptionStats(ctx context.C
|
||||
}
|
||||
|
||||
// 获取今日消费金额
|
||||
today := time.Now().Truncate(24 * time.Hour)
|
||||
tomorrow := today.Add(24 * time.Hour)
|
||||
loc, _ := time.LoadLocation("Asia/Shanghai") // 东八时区
|
||||
now := time.Now().In(loc)
|
||||
today := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, loc) // 当天0点
|
||||
tomorrow := today.AddDate(0, 0, 1) // 次日0点
|
||||
todayAmount, err := s.getWalletTransactionsByDateRange(ctx, userID, today, tomorrow)
|
||||
if err != nil {
|
||||
s.logger.Error("获取今日消费金额失败", zap.String("user_id", userID), zap.Error(err))
|
||||
@@ -1411,8 +1415,10 @@ func (s *StatisticsApplicationServiceImpl) getUserRechargeStats(ctx context.Cont
|
||||
}
|
||||
|
||||
// 获取今日充值金额
|
||||
today := time.Now().Truncate(24 * time.Hour)
|
||||
tomorrow := today.Add(24 * time.Hour)
|
||||
loc, _ := time.LoadLocation("Asia/Shanghai") // 东八时区
|
||||
now := time.Now().In(loc)
|
||||
today := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, loc) // 当天0点
|
||||
tomorrow := today.AddDate(0, 0, 1) // 次日0点
|
||||
todayAmount, err := s.getRechargeRecordsByDateRange(ctx, userID, today, tomorrow)
|
||||
if err != nil {
|
||||
s.logger.Error("获取今日充值金额失败", zap.String("user_id", userID), zap.Error(err))
|
||||
@@ -1682,13 +1688,13 @@ func (s *StatisticsApplicationServiceImpl) getCertificationStats(ctx context.Con
|
||||
successRate = float64(userStats.CertifiedUsers) / float64(userStats.TotalUsers)
|
||||
}
|
||||
|
||||
// 根据时间范围获取趋势数据
|
||||
// 根据时间范围获取认证趋势数据(基于is_certified字段)
|
||||
var trendData []map[string]interface{}
|
||||
if !startTime.IsZero() && !endTime.IsZero() {
|
||||
if period == "day" {
|
||||
trendData, err = s.userRepo.GetSystemDailyUserStats(ctx, startTime, endTime)
|
||||
trendData, err = s.userRepo.GetSystemDailyCertificationStats(ctx, startTime, endTime)
|
||||
} else if period == "month" {
|
||||
trendData, err = s.userRepo.GetSystemMonthlyUserStats(ctx, startTime, endTime)
|
||||
trendData, err = s.userRepo.GetSystemMonthlyCertificationStats(ctx, startTime, endTime)
|
||||
}
|
||||
if err != nil {
|
||||
s.logger.Error("获取认证趋势数据失败", zap.Error(err))
|
||||
@@ -1698,16 +1704,35 @@ func (s *StatisticsApplicationServiceImpl) getCertificationStats(ctx context.Con
|
||||
// 默认获取最近7天的数据
|
||||
endDate := time.Now()
|
||||
startDate := endDate.AddDate(0, 0, -7)
|
||||
trendData, err = s.userRepo.GetSystemDailyUserStats(ctx, startDate, endDate)
|
||||
trendData, err = s.userRepo.GetSystemDailyCertificationStats(ctx, startDate, endDate)
|
||||
if err != nil {
|
||||
s.logger.Error("获取认证每日趋势失败", zap.Error(err))
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
// 获取今日认证用户数(基于is_certified字段,东八时区)
|
||||
loc, _ := time.LoadLocation("Asia/Shanghai") // 东八时区
|
||||
now := time.Now().In(loc)
|
||||
today := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, loc) // 当天0点
|
||||
tomorrow := today.AddDate(0, 0, 1) // 次日0点
|
||||
|
||||
var certifiedToday int64
|
||||
todayCertStats, err := s.userRepo.GetSystemDailyCertificationStats(ctx, today, tomorrow)
|
||||
if err == nil && len(todayCertStats) > 0 {
|
||||
// 累加今日所有认证用户数
|
||||
for _, stat := range todayCertStats {
|
||||
if count, ok := stat["count"].(int64); ok {
|
||||
certifiedToday += count
|
||||
} else if count, ok := stat["count"].(int); ok {
|
||||
certifiedToday += int64(count)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stats := map[string]interface{}{
|
||||
"total_certified": userStats.CertifiedUsers,
|
||||
"certified_today": userStats.TodayRegistrations, // 今日注册的用户
|
||||
"certified_today": certifiedToday, // 今日认证的用户数(基于is_certified字段)
|
||||
"success_rate": successRate,
|
||||
"daily_trend": trendData,
|
||||
}
|
||||
@@ -1723,9 +1748,11 @@ func (s *StatisticsApplicationServiceImpl) getSystemApiCallStats(ctx context.Con
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 获取今日API调用次数
|
||||
today := time.Now().Truncate(24 * time.Hour)
|
||||
tomorrow := today.Add(24 * time.Hour)
|
||||
// 获取今日API调用次数(东八时区)
|
||||
loc, _ := time.LoadLocation("Asia/Shanghai") // 东八时区
|
||||
now := time.Now().In(loc)
|
||||
today := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, loc) // 当天0点
|
||||
tomorrow := today.AddDate(0, 0, 1) // 次日0点
|
||||
todayCalls, err := s.apiCallRepo.GetSystemCallsByDateRange(ctx, today, tomorrow)
|
||||
if err != nil {
|
||||
s.logger.Error("获取今日API调用次数失败", zap.Error(err))
|
||||
@@ -1780,8 +1807,11 @@ func (s *StatisticsApplicationServiceImpl) getSystemFinanceStats(ctx context.Con
|
||||
}
|
||||
|
||||
// 获取今日消费金额
|
||||
today := time.Now().Truncate(24 * time.Hour)
|
||||
tomorrow := today.Add(24 * time.Hour)
|
||||
loc, _ := time.LoadLocation("Asia/Shanghai") // 东八时区
|
||||
now := time.Now().In(loc)
|
||||
today := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, loc) // 当天0点
|
||||
tomorrow := today.AddDate(0, 0, 1) // 次日0点
|
||||
|
||||
todayConsumption, err := s.walletTransactionRepo.GetSystemAmountByDateRange(ctx, today, tomorrow)
|
||||
if err != nil {
|
||||
s.logger.Error("获取今日消费金额失败", zap.Error(err))
|
||||
@@ -2359,8 +2389,10 @@ func (s *StatisticsApplicationServiceImpl) AdminGetConsumptionDomainStatistics(c
|
||||
}
|
||||
|
||||
// 获取今日消费金额
|
||||
today := time.Now().Truncate(24 * time.Hour)
|
||||
tomorrow := today.Add(24 * time.Hour)
|
||||
loc, _ := time.LoadLocation("Asia/Shanghai") // 东八时区
|
||||
now := time.Now().In(loc)
|
||||
today := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, loc) // 当天0点
|
||||
tomorrow := today.AddDate(0, 0, 1) // 次日0点
|
||||
todayConsumption, err := s.walletTransactionRepo.GetSystemAmountByDateRange(ctx, today, tomorrow)
|
||||
if err != nil {
|
||||
s.logger.Error("获取今日消费金额失败", zap.Error(err))
|
||||
@@ -2459,8 +2491,10 @@ func (s *StatisticsApplicationServiceImpl) AdminGetRechargeDomainStatistics(ctx
|
||||
}
|
||||
|
||||
// 获取今日充值金额
|
||||
today := time.Now().Truncate(24 * time.Hour)
|
||||
tomorrow := today.Add(24 * time.Hour)
|
||||
loc, _ := time.LoadLocation("Asia/Shanghai") // 东八时区
|
||||
now := time.Now().In(loc)
|
||||
today := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, loc) // 当天0点
|
||||
tomorrow := today.AddDate(0, 0, 1) // 次日0点
|
||||
todayRecharge, err := s.rechargeRecordRepo.GetSystemAmountByDateRange(ctx, today, tomorrow)
|
||||
if err != nil {
|
||||
s.logger.Error("获取今日充值金额失败", zap.Error(err))
|
||||
|
||||
Reference in New Issue
Block a user