优化用户资料卡成就摘要查询
This commit is contained in:
@@ -194,6 +194,23 @@ class AchievementService
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取用户资料卡使用的成就摘要。
|
||||
*
|
||||
* @return array{unlocked_count: int, total_count: int, recent: array<int, array<string, mixed>>}
|
||||
*/
|
||||
public function profileSummaryForUser(User $user): array
|
||||
{
|
||||
return [
|
||||
'unlocked_count' => (int) UserAchievement::query()
|
||||
->where('user_id', $user->id)
|
||||
->whereNotNull('achieved_at')
|
||||
->count(),
|
||||
'total_count' => count(AchievementCatalog::definitions()),
|
||||
'recent' => $this->recentUnlockedForUser($user, 5)->values()->all(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 聚合单个用户所有成就进度。
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user