feature: main page - ranking list

This commit is contained in:
antv
2026-07-06 16:44:03 +07:00
parent 618dcef37f
commit e163d2f349
3 changed files with 142 additions and 7 deletions
+24 -6
View File
@@ -115,8 +115,13 @@ class UserService implements UserServiceInterface
->whereColumn('msnv', 'user.msnv')
->whereBetween('date', [$startOfMonth, $endOfMonth])
])
->orderByDesc('score')
->get();
->get()
->filter(fn($u) => $u->score > 0)
->sortBy([
['score', 'desc'],
['msnv', 'asc']
])
->values();
$currentRank = 0;
$prevScore = null;
@@ -157,8 +162,13 @@ class UserService implements UserServiceInterface
->whereColumn('msnv', 'user.msnv')
->whereBetween('date', [$startOfMonth, $endOfMonth])
])
->orderByDesc('score')
->get();
->get()
->filter(fn($u) => $u->score > 0)
->sortBy([
['score', 'desc'],
['msnv', 'asc']
])
->values();
$prevScore = null;
$rank = 1;
@@ -181,15 +191,23 @@ class UserService implements UserServiceInterface
$currentUserRankItem = $userItem;
}
if ($index < 5) {
if ($index < 4) {
$rankers[] = $userItem;
}
$rank++;
}
$showCurrentUserAtBottom = false;
if ($currentUserRankItem) {
$currentUserIndex = $users->search(fn($u) => $u->msnv == $currentUser->msnv);
if ($currentUserIndex !== false && $currentUserIndex >= 4) {
$showCurrentUserAtBottom = true;
}
}
return [
'rankers' => $rankers,
'currentUserRankItem' => $currentUserRankItem
'currentUserRankItem' => $showCurrentUserAtBottom ? $currentUserRankItem : null
];
}
}