This commit is contained in:
2025-09-15 21:15:23 +08:00
parent 6874f67c45
commit cfad2bce09
3 changed files with 33 additions and 25 deletions

View File

@@ -596,7 +596,7 @@ func (r *GormUserRepository) GetUserCallRankingByConsumption(ctx context.Context
return results, nil
}
// GetRechargeRanking 获取充值排行
// GetRechargeRanking 获取充值排行(排除赠送,只统计成功状态)
func (r *GormUserRepository) GetRechargeRanking(ctx context.Context, period string, limit int) ([]map[string]interface{}, error) {
var sql string
var args []interface{}
@@ -612,6 +612,8 @@ func (r *GormUserRepository) GetRechargeRanking(ctx context.Context, period stri
LEFT JOIN enterprise_infos ei ON u.id = ei.user_id
LEFT JOIN recharge_records rr ON u.id = rr.user_id
AND DATE(rr.created_at) = CURRENT_DATE
AND rr.status = 'success'
AND rr.recharge_type != 'gift'
WHERE u.deleted_at IS NULL
GROUP BY u.id, ei.company_name, u.username, u.phone
HAVING COALESCE(SUM(rr.amount), 0) > 0
@@ -629,6 +631,8 @@ func (r *GormUserRepository) GetRechargeRanking(ctx context.Context, period stri
LEFT JOIN enterprise_infos ei ON u.id = ei.user_id
LEFT JOIN recharge_records rr ON u.id = rr.user_id
AND DATE_TRUNC('month', rr.created_at) = DATE_TRUNC('month', CURRENT_DATE)
AND rr.status = 'success'
AND rr.recharge_type != 'gift'
WHERE u.deleted_at IS NULL
GROUP BY u.id, ei.company_name, u.username, u.phone
HAVING COALESCE(SUM(rr.amount), 0) > 0
@@ -645,6 +649,8 @@ func (r *GormUserRepository) GetRechargeRanking(ctx context.Context, period stri
FROM users u
LEFT JOIN enterprise_infos ei ON u.id = ei.user_id
LEFT JOIN recharge_records rr ON u.id = rr.user_id
AND rr.status = 'success'
AND rr.recharge_type != 'gift'
WHERE u.deleted_at IS NULL
GROUP BY u.id, ei.company_name, u.username, u.phone
HAVING COALESCE(SUM(rr.amount), 0) > 0