diff --git a/app/Services/User/UserService.php b/app/Services/User/UserService.php
index 465f4af..f595a91 100644
--- a/app/Services/User/UserService.php
+++ b/app/Services/User/UserService.php
@@ -156,14 +156,15 @@ class UserService implements UserServiceInterface
$column = $type === 'sent' ? 'sent' : 'received';
- $users = User::where('status', User::STATUS_ACTIVE)
+ $allActiveUsers = User::where('status', User::STATUS_ACTIVE)
->addSelect([
'score' => Administration::selectRaw('COALESCE(SUM(' . $column . '), 0)')
->whereColumn('msnv', 'user.msnv')
->whereBetween('date', [$startOfMonth, $endOfMonth])
])
- ->get()
- ->filter(fn($u) => $u->score > 0)
+ ->get();
+
+ $rankedUsers = $allActiveUsers->filter(fn($u) => $u->score > 0)
->sortBy([
['score', 'desc'],
['msnv', 'asc']
@@ -177,7 +178,7 @@ class UserService implements UserServiceInterface
$rankers = [];
$currentUserRankItem = null;
- foreach ($users as $index => $userItem) {
+ foreach ($rankedUsers as $index => $userItem) {
$score = (int) $userItem->score;
if ($score !== $prevScore) {
$denseRank = $rank;
@@ -197,17 +198,18 @@ class UserService implements UserServiceInterface
$rank++;
}
- $showCurrentUserAtBottom = false;
- if ($currentUserRankItem) {
- $currentUserIndex = $users->search(fn($u) => $u->msnv == $currentUser->msnv);
- if ($currentUserIndex !== false && $currentUserIndex >= 4) {
- $showCurrentUserAtBottom = true;
+ if (!$currentUserRankItem) {
+ $currentUserModel = $allActiveUsers->first(fn($u) => $u->msnv == $currentUser->msnv);
+ if ($currentUserModel) {
+ $currentUserRankItem = clone $currentUserModel;
+ $currentUserRankItem->score = 0;
+ $currentUserRankItem->rank = 0;
}
}
return [
'rankers' => $rankers,
- 'currentUserRankItem' => $showCurrentUserAtBottom ? $currentUserRankItem : null
+ 'currentUserRankItem' => $currentUserRankItem
];
}
}
\ No newline at end of file
diff --git a/resources/views/user/partials/ranking_list.blade.php b/resources/views/user/partials/ranking_list.blade.php
index f1a63a7..c6e883f 100644
--- a/resources/views/user/partials/ranking_list.blade.php
+++ b/resources/views/user/partials/ranking_list.blade.php
@@ -1,45 +1,51 @@
-@if(count($rankers) > 0)
- @foreach($rankers as $item)
-
Chưa có xếp hạng cho tháng này
+Chưa có xếp hạng cho tháng này
-