Skip to content

Commit 9b80102

Browse files
committed
fix(control): 根据条件查询不同效果
1 parent d8f2407 commit 9b80102

File tree

1 file changed

+63
-12
lines changed

1 file changed

+63
-12
lines changed

laravel/app/Http/Controllers/Bus/IndexController.php

Lines changed: 63 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use App\Http\Repository\BusRepository;
1212
use App\Http\Repository\NewBusRepository;
1313
use Illuminate\Http\Request;
14+
use Illuminate\Support\Facades\Cache;
1415

1516
class IndexController extends CommonController
1617
{
@@ -41,24 +42,74 @@ public function getList(Request $request)
4142
{
4243
$line = $request['linename'];
4344
$line = preg_replace('/快\b(\d)/', '快线$1号', $line);
44-
switch ($request['type']) {
45-
case '1':
46-
case 'new':
47-
$list = NewBusRepository::getInstent()->getLine($line);
48-
break;
49-
50-
default:
51-
$list = BusRepository::getInstent()->getList($line);
52-
// $list = [];
53-
if (empty($list)) {
54-
$list = NewBusRepository::getInstent()->getLine($line);
55-
}
45+
// 1. 前端直接传递 type 参数时先判断
46+
if (isset($request['type'])) {
47+
switch ($request['type']) {
48+
case '1':
49+
case 'new':
50+
$list = $this->getNewList($line);
51+
break;
52+
default:
53+
$list = $this->getOldList($line);
54+
// $list = [];
55+
if (empty($list)) {
56+
$list = $this->getNewList($line);
57+
}
58+
}
59+
} else {
60+
// 2. 根据后台配置查询不同的结果
61+
$default_open = Cache::get('default_open');
62+
switch ($default_open) {
63+
case '2': // 查询新版
64+
$list = $this->getNewList($line);
65+
break;
66+
case '3': // 先查老版再查新版
67+
$list = $this->getOldList($line);
68+
// $list = [];
69+
if (empty($list)) {
70+
$list = $this->getNewList($line);
71+
}
72+
break;
73+
case '4': // 先查新版再查老版
74+
$list = $this->getNewList($line);
75+
// $list = [];
76+
if (empty($list)) {
77+
$list = $this->getOldList($line);
78+
}
79+
break;
80+
default: // 查询老版
81+
$list = $this->getOldList($line);
82+
}
5683
}
5784

5885
// return $this->exportData($list);
5986
return $this->out(200, $list);
6087
}
6188

89+
/**
90+
* 获取老线路列表
91+
*
92+
* @param $line
93+
*
94+
* @return array
95+
*/
96+
private function getNewList($line)
97+
{
98+
return NewBusRepository::getInstent()->getLine($line);
99+
}
100+
101+
/**
102+
* 获取老线路列表
103+
*
104+
* @param $line
105+
*
106+
* @return array
107+
*/
108+
private function getOldList($line)
109+
{
110+
return BusRepository::getInstent()->getList($line);
111+
}
112+
62113
/**
63114
* 获取实时公交数据table列表 --- 根据data-href 地址,请求 szjt.gov.cn 查询实时公交数据,不能缓存
64115
* 获取实时公交数据table列表,数据来自 szjt.gov.cn,需要限制访问频率,1秒一次请求

0 commit comments

Comments
 (0)