优化用户资料卡成就摘要查询

This commit is contained in:
pllx
2026-04-30 16:45:46 +08:00
parent ffd8789e67
commit 82dbc19319
3 changed files with 45 additions and 8 deletions
+17
View File
@@ -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(),
];
}
/**
* 聚合单个用户所有成就进度。
*