feat: 实现挂机修仙、排行榜、大厅重构与全站留言板系统
- (Phase 8) 后台各维度管理与配置 - (Phase 9) 全自动静默挂机修仙升级 - (Phase 9) 四大维度风云排行榜页面 - (Phase 10) 全站留言板与悄悄话私信功能 - 运行 Pint 代码格式化
This commit is contained in:
71
app/Http/Controllers/LeaderboardController.php
Normal file
71
app/Http/Controllers/LeaderboardController.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:全局风云排行榜控制器
|
||||
* 各种维度(等级、经验、交友币、魅力)的前20名抓取与缓存展示。
|
||||
*
|
||||
* @author ChatRoom Laravel
|
||||
*
|
||||
* @version 1.0.0
|
||||
*/
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class LeaderboardController extends Controller
|
||||
{
|
||||
/**
|
||||
* 渲染排行榜主视角
|
||||
*/
|
||||
public function index(): View
|
||||
{
|
||||
// 缓存 15 分钟,防止每秒几百个人看排行榜把数据库扫死
|
||||
// 选用 remember 则在过期时自动执行闭包查询并重置缓存
|
||||
$ttl = 60 * 15;
|
||||
|
||||
// 1. 境界榜 (以 user_level 为尊)
|
||||
$topLevels = Cache::remember('leaderboard:top_levels', $ttl, function () {
|
||||
return User::select('id', 'username', 'headface', 'user_level', 'sex', 'sign')
|
||||
->where('user_level', '>', 0)
|
||||
->orderByDesc('user_level')
|
||||
->orderBy('id')
|
||||
->limit(20)
|
||||
->get();
|
||||
});
|
||||
|
||||
// 2. 修为榜 (以 exp_num 为尊)
|
||||
$topExp = Cache::remember('leaderboard:top_exp', $ttl, function () {
|
||||
return User::select('id', 'username', 'headface', 'exp_num', 'sex', 'user_level', 'sign')
|
||||
->where('exp_num', '>', 0)
|
||||
->orderByDesc('exp_num')
|
||||
->orderBy('id')
|
||||
->limit(20)
|
||||
->get();
|
||||
});
|
||||
|
||||
// 3. 财富榜 (以 jjb-交友币 为尊)
|
||||
$topWealth = Cache::remember('leaderboard:top_wealth', $ttl, function () {
|
||||
return User::select('id', 'username', 'headface', 'jjb', 'sex', 'user_level', 'sign')
|
||||
->where('jjb', '>', 0)
|
||||
->orderByDesc('jjb')
|
||||
->orderBy('id')
|
||||
->limit(20)
|
||||
->get();
|
||||
});
|
||||
|
||||
// 4. 魅力榜 (以 meili 为尊)
|
||||
$topCharm = Cache::remember('leaderboard:top_charm', $ttl, function () {
|
||||
return User::select('id', 'username', 'headface', 'meili', 'sex', 'user_level', 'sign')
|
||||
->where('meili', '>', 0)
|
||||
->orderByDesc('meili')
|
||||
->orderBy('id')
|
||||
->limit(20)
|
||||
->get();
|
||||
});
|
||||
|
||||
return view('leaderboard.index', compact('topLevels', 'topExp', 'topWealth', 'topCharm'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user