fix: 排行榜返回完整统计字段并跟随后台排序方案

This commit is contained in:
XingQue
2026-07-01 19:32:29 +08:00
parent 3394fef79b
commit 7f7859c2a4
2 changed files with 148 additions and 7 deletions

View File

@@ -13,6 +13,7 @@ from rank.reward_services import (
SORT_FIELD_LABELS,
build_reward_payload,
claim_reward,
enrich_rank_stats,
list_my_pending_claims,
query_club_rank_rows,
query_group_rank_rows,
@@ -53,9 +54,10 @@ def _load_display_maps(yonghuids, shenfen):
return nick_map, avatar_map
def _format_rank_list(rows, shenfen, sort_field, sort_label):
def _format_rank_list(rows, shenfen, sort_field, sort_label, riqi='', club_id=''):
yonghuids = [r['yonghuid'] for r in rows]
nick_map, avatar_map = _load_display_maps(yonghuids, shenfen)
stats_map = enrich_rank_stats(shenfen, yonghuids, riqi, club_id or '')
club_map = {}
try:
from rank.reward_services import load_user_club_map
@@ -86,6 +88,9 @@ def _format_rank_list(rows, shenfen, sort_field, sort_label):
'metric_label': sort_label,
'metric_is_int': is_int,
}
extra = stats_map.get(uid) or {}
for k, v in extra.items():
item[k] = v
item[sort_field] = item['metric_value']
result.append(item)
return result
@@ -180,16 +185,21 @@ class PhbJlPhbView(APIView):
if fanwei == 'club':
rows = query_club_rank_rows(club_id, shenfen, sort_field, riqi)
enrich_club = club_id
else:
rows = query_group_rank_rows(shenfen, sort_field, riqi)
enrich_club = ''
result_list = _format_rank_list(rows, shenfen, sort_field, sort_label)
result_list = _format_rank_list(
rows, shenfen, sort_field, sort_label, riqi=riqi, club_id=enrich_club,
)
reward = build_reward_payload(club_id, shenfen, riqi, request.user.UserUID)
# 仅俱乐部榜展示各行奖金(集团总榜名次与俱乐部分奖名次不同,不可混用)
rank_rewards = reward.get('rank_rewards') or {}
tier_rewards = reward.get('tier_rewards') or {}
if fanwei == 'club' and reward.get('scheme_enabled'):
tiers = reward.get('tiers') or []
if fanwei == 'club' and (reward.get('scheme_enabled') or tiers):
for item in result_list:
mc = item['mingci']
settled = rank_rewards.get(mc)