title('财富排行榜'); $this->dropdown([ 'all' => '全部时间', '30' => '最近 30 天', '7' => '最近 7 天', ]); } /** * 处理请求 * * @param Request $request * @return mixed|void */ public function handle(Request $request) { $timeRange = $request->get('option', 'all'); $data = $this->getWealthRankingData($timeRange); // 卡片内容 $this->withContent($data); } /** * 获取财富排行榜数据 * * @param string $timeRange 时间范围 * @return array */ protected function getWealthRankingData(string $timeRange): array { try { $houseLogic = new HouseLogic(); // 使用public方法获取财富排行榜数据,传入虚拟用户ID $rankDto = $houseLogic->getWealthRankList(0, 1, 20); // 转换为Ranking组件需要的格式 $rankingData = []; foreach ($rankDto->list as $index => $item) { $rank = $index + 1; $userId = $item->userId ?? 0; $nickname = $item->nickname ?: "用户{$userId}"; $balance = $item->wealth ?? 0; $houseLevel = $item->houseLevel ?? 0; // 格式化钻石数量显示 $formattedBalance = number_format($balance); $rankingData[] = [ 'rank' => $rank, 'title' => "ID:{$userId} {$nickname}", 'number' => "{$formattedBalance}钻石 ({$houseLevel}级房屋)", ]; } return $rankingData; } catch (\Exception $e) { Log::error('获取财富排行榜数据失败', [ 'time_range' => $timeRange, 'error' => $e->getMessage(), 'trace' => $e->getTraceAsString() ]); return []; } } }