where('user_level', '>', 0) ->where('user_level', '<', $superLevel) ->orderByDesc('user_level') ->orderBy('id') ->limit($topN) ->get(); }); // 2. 修为榜 (以 exp_num 为尊) $topExp = Cache::remember('leaderboard:top_exp', $ttl, function () use ($superLevel, $topN) { return User::select('id', 'username', 'usersf', 'exp_num', 'sex', 'user_level') ->where('exp_num', '>', 0) ->where('user_level', '<', $superLevel) ->orderByDesc('exp_num') ->orderBy('id') ->limit($topN) ->get(); }); // 3. 财富榜 (以 jjb-交友币 为尊) $topWealth = Cache::remember('leaderboard:top_wealth', $ttl, function () use ($superLevel, $topN) { return User::select('id', 'username', 'usersf', 'jjb', 'sex', 'user_level') ->where('jjb', '>', 0) ->where('user_level', '<', $superLevel) ->orderByDesc('jjb') ->orderBy('id') ->limit($topN) ->get(); }); // 4. 魅力榜 (以 meili 为尊) $topCharm = Cache::remember('leaderboard:top_charm', $ttl, function () use ($superLevel, $topN) { return User::select('id', 'username', 'usersf', 'meili', 'sex', 'user_level') ->where('meili', '>', 0) ->where('user_level', '<', $superLevel) ->orderByDesc('meili') ->orderBy('id') ->limit($topN) ->get(); }); // ── 今日榜(5分钟缓存,数据来自 user_currency_logs 流水表)── $todayTtl = 60 * 5; $today = today()->toDateString(); $todayExp = Cache::remember("leaderboard:today_exp:{$today}", $todayTtl, fn () => $this->currencyService->todayLeaderboard('exp', $topN, $today) ); $todayGold = Cache::remember("leaderboard:today_gold:{$today}", $todayTtl, fn () => $this->currencyService->todayLeaderboard('gold', $topN, $today) ); $todayCharm = Cache::remember("leaderboard:today_charm:{$today}", $todayTtl, fn () => $this->currencyService->todayLeaderboard('charm', $topN, $today) ); return view('leaderboard.index', compact( 'topLevels', 'topExp', 'topWealth', 'topCharm', )); } /** * 今日风云榜独立页(经验/金币/魅力今日排行) */ public function todayIndex(): View { $todayTtl = 60 * 5; $today = today()->toDateString(); $topN = (int) \App\Models\Sysparam::getValue('leaderboard_limit', '20'); $todayExp = Cache::remember("leaderboard:today_exp:{$today}", $todayTtl, fn () => $this->currencyService->todayLeaderboard('exp', $topN, $today) ); $todayGold = Cache::remember("leaderboard:today_gold:{$today}", $todayTtl, fn () => $this->currencyService->todayLeaderboard('gold', $topN, $today) ); $todayCharm = Cache::remember("leaderboard:today_charm:{$today}", $todayTtl, fn () => $this->currencyService->todayLeaderboard('charm', $topN, $today) ); return view('leaderboard.today', compact('todayExp', 'todayGold', 'todayCharm')); } /** * 用户个人流水日志页(查询自己的经验/金币/魅力操作历史) */ public function myLogs(): View { $user = auth()->user(); $currency = request('currency'); $days = (int) request('days', 7); $logs = $this->currencyService->userLogs($user->id, $currency ?: null, $days); return view('leaderboard.my-logs', compact('logs', 'user', 'currency', 'days')); } }