|
|
@@ -31,31 +31,28 @@ class FarmHouseRanking extends Ranking
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 处理请求,获取排名数据
|
|
|
+ * 获取排名数据
|
|
|
*
|
|
|
- * @param Request $request
|
|
|
+ * @param string $option
|
|
|
*
|
|
|
- * @return mixed|void
|
|
|
+ * @return array
|
|
|
*/
|
|
|
- public function handle(Request $request)
|
|
|
+ protected function getData($option)
|
|
|
{
|
|
|
- $sortType = $request->get('option', 'count');
|
|
|
-
|
|
|
// 获取最新的统计数据
|
|
|
$latestStats = FarmDailyStats::orderBy('stats_date', 'desc')->first();
|
|
|
-
|
|
|
+
|
|
|
if (!$latestStats) {
|
|
|
- $this->withContent([]);
|
|
|
- return;
|
|
|
+ return [];
|
|
|
}
|
|
|
|
|
|
$houseData = [];
|
|
|
-
|
|
|
+
|
|
|
// 收集房屋数据
|
|
|
for ($level = 1; $level <= 10; $level++) {
|
|
|
$field = "house_level_{$level}";
|
|
|
$count = $latestStats->$field ?? 0;
|
|
|
-
|
|
|
+
|
|
|
if ($count > 0) {
|
|
|
$houseData[] = [
|
|
|
'level' => $level,
|
|
|
@@ -66,7 +63,7 @@ class FarmHouseRanking extends Ranking
|
|
|
}
|
|
|
|
|
|
// 根据选择的排序方式排序
|
|
|
- if ($sortType === 'level') {
|
|
|
+ if ($option === 'level') {
|
|
|
// 按等级排序
|
|
|
usort($houseData, function($a, $b) {
|
|
|
return $a['level'] - $b['level'];
|
|
|
@@ -88,12 +85,12 @@ class FarmHouseRanking extends Ranking
|
|
|
$rankingData = [];
|
|
|
foreach ($houseData as $index => $item) {
|
|
|
$rankingData[] = [
|
|
|
- 'name' => $item['label'],
|
|
|
- 'value' => $item['value'] . '个',
|
|
|
- 'ratio' => $item['ratio'] . '%',
|
|
|
+ 'rank' => ($index + 1),
|
|
|
+ 'title' => $item['label'],
|
|
|
+ 'number' => $item['value'] . '个 (' . $item['ratio'] . '%)',
|
|
|
];
|
|
|
}
|
|
|
|
|
|
- $this->withContent($rankingData);
|
|
|
+ return $rankingData;
|
|
|
}
|
|
|
}
|