modified 完善接口列表的过滤

This commit is contained in:
zhaoxiang 2019-06-30 00:50:00 +08:00
parent 2c4827f253
commit e0fea97d02

View File

@ -29,25 +29,24 @@ class InterfaceList extends Base {
$type = $this->request->get('type', ''); $type = $this->request->get('type', '');
$status = $this->request->get('status', ''); $status = $this->request->get('status', '');
$where = []; $obj = new AdminList();
if ($status === '1' || $status === '0') { if (strlen($status)) {
$where['status'] = $status; $obj = $obj->where('status', $status);
} }
if ($type) { if ($type) {
switch ($type) { switch ($type) {
case 1: case 1:
$where['hash'] = $keywords; $obj = $obj->where('hash', $keywords);
break; break;
case 2: case 2:
$where['info'] = ['like', "%{$keywords}%"]; $obj = $obj->whereLike('info', "%{$keywords}%");
break; break;
case 3: case 3:
$where['apiClass'] = ['like', "%{$keywords}%"]; $obj = $obj->whereLike('api_class', "%{$keywords}%");
break; break;
} }
} }
$listObj = (new AdminList())->where($where)->order('id', 'DESC') $listObj = $obj->order('id', 'DESC')->paginate($limit, false, ['page' => $start])->toArray();
->paginate($limit, false, ['page' => $start])->toArray();
return $this->buildSuccess([ return $this->buildSuccess([
'list' => $listObj['data'], 'list' => $listObj['data'],
@ -57,8 +56,8 @@ class InterfaceList extends Base {
/** /**
* 获取接口唯一标识 * 获取接口唯一标识
* @author zhaoxiang <zhaoxiang051405@gmail.com>
* @return array * @return array
* @author zhaoxiang <zhaoxiang051405@gmail.com>
*/ */
public function getHash() { public function getHash() {
$res['hash'] = uniqid(); $res['hash'] = uniqid();
@ -73,7 +72,7 @@ class InterfaceList extends Base {
*/ */
public function add() { public function add() {
$postData = $this->request->post(); $postData = $this->request->post();
if (!preg_match("/^[A-Za-z0-9_\/]+$/", $postData['apiClass'])) { if (!preg_match("/^[A-Za-z0-9_\/]+$/", $postData['api_class'])) {
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '真实类名只允许填写字母,数字和/'); return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '真实类名只允许填写字母,数字和/');
} }
@ -114,7 +113,7 @@ class InterfaceList extends Base {
*/ */
public function edit() { public function edit() {
$postData = $this->request->post(); $postData = $this->request->post();
if (!preg_match("/^[A-Za-z0-9_\/]+$/", $postData['apiClass'])) { if (!preg_match("/^[A-Za-z0-9_\/]+$/", $postData['api_class'])) {
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '真实类名只允许填写字母,数字和/'); return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '真实类名只允许填写字母,数字和/');
} }
@ -172,9 +171,9 @@ class InterfaceList extends Base {
/** /**
* 刷新接口路由 * 刷新接口路由
* @author zhaoxiang <zhaoxiang051405@gmail.com>
* @return array * @return array
* @throws \think\exception\DbException * @throws \think\exception\DbException
* @author zhaoxiang <zhaoxiang051405@gmail.com>
*/ */
public function refresh() { public function refresh() {
$apiRoutePath = ROOT_PATH . 'application/apiRoute.php'; $apiRoutePath = ROOT_PATH . 'application/apiRoute.php';