From 24675ed93c0e3e577d68939cadc8e835dfec560f Mon Sep 17 00:00:00 2001 From: zhaoxiang Date: Fri, 23 Feb 2018 16:30:55 +0800 Subject: [PATCH] =?UTF-8?q?modified=20=E5=AE=8C=E6=88=90=E5=BA=94=E7=94=A8?= =?UTF-8?q?=E5=88=86=E7=BB=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/controller/AppGroup.php | 122 ++++++++++++++++++++++ application/adminRoute.php | 24 +++++ 2 files changed, 146 insertions(+) diff --git a/application/admin/controller/AppGroup.php b/application/admin/controller/AppGroup.php index cf930e5..db96a48 100644 --- a/application/admin/controller/AppGroup.php +++ b/application/admin/controller/AppGroup.php @@ -8,5 +8,127 @@ namespace app\admin\controller; +use app\model\ApiAppGroup; +use app\util\ReturnCode; + class AppGroup extends Base { + /** + * 获取接口组列表 + * @author zhaoxiang + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\ModelNotFoundException + * @throws \think\exception\DbException + */ + public function index() { + $limit = $this->request->get('size', config('apiAdmin.ADMIN_LIST_DEFAULT')); + $start = $limit * ($this->request->get('page', 1) - 1); + $keywords = $this->request->get('keywords', ''); + $type = $this->request->get('type', ''); + $status = $this->request->get('status', ''); + + $where = []; + if ($status === '1' || $status === '0') { + $where['status'] = $status; + } + if ($type) { + switch ($type) { + case 1: + $where['hash'] = $keywords; + break; + case 2: + $where['name'] = ['like', "%{$keywords}%"]; + break; + } + } + + $listInfo = (new ApiAppGroup())->where($where)->limit($start, $limit)->select(); + $count = (new ApiAppGroup())->where($where)->count(); + $listInfo = $this->buildArrFromObj($listInfo); + + return $this->buildSuccess([ + 'list' => $listInfo, + 'count' => $count + ]); + } + + /** + * 获取全部有效的接口组 + * @author zhaoxiang + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\ModelNotFoundException + * @throws \think\exception\DbException + */ + public function getAll() { + $listInfo = (new ApiAppGroup())->where(['status' => 1])->select(); + + return $this->buildSuccess([ + 'list' => $listInfo + ]); + } + + /** + * 接口组状态编辑 + * @return array + * @author zhaoxiang + */ + public function changeStatus() { + $id = $this->request->get('id'); + $status = $this->request->get('status'); + $res = ApiAppGroup::update([ + 'status' => $status + ], [ + 'id' => $id + ]); + if ($res === false) { + return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败'); + } else { + return $this->buildSuccess([]); + } + } + + /** + * 添加接口组 + * @author zhaoxiang + * @return array + */ + public function add() { + $postData = $this->request->post(); + $res = ApiAppGroup::create($postData); + if ($res === false) { + return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败'); + } else { + return $this->buildSuccess([]); + } + } + + /** + * 接口组编辑 + * @author zhaoxiang + * @return array + */ + public function edit() { + $postData = $this->request->post(); + $res = ApiAppGroup::update($postData); + if ($res === false) { + return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败'); + } else { + return $this->buildSuccess([]); + } + } + + /** + * 接口组删除 + * @author zhaoxiang + * @return array + */ + public function del() { + $hash = $this->request->get('hash'); + if (!$hash) { + return $this->buildFailed(ReturnCode::EMPTY_PARAMS, '缺少必要参数'); + } + ApiAppGroup::destroy(['hash' => $hash]); + + return $this->buildSuccess([]); + } } diff --git a/application/adminRoute.php b/application/adminRoute.php index be160a9..a6ca600 100644 --- a/application/adminRoute.php +++ b/application/adminRoute.php @@ -187,6 +187,30 @@ return [ 'admin/InterfaceGroup/changeStatus', ['method' => 'get', 'after_behavior' => $afterBehavior] ], + 'AppGroup/index' => [ + 'admin/AppGroup/index', + ['method' => 'get', 'after_behavior' => $afterBehavior] + ], + 'AppGroup/add' => [ + 'admin/AppGroup/add', + ['method' => 'post', 'after_behavior' => $afterBehavior] + ], + 'AppGroup/edit' => [ + 'admin/AppGroup/edit', + ['method' => 'post', 'after_behavior' => $afterBehavior] + ], + 'AppGroup/del' => [ + 'admin/AppGroup/del', + ['method' => 'get', 'after_behavior' => $afterBehavior] + ], + 'AppGroup/getAll' => [ + 'admin/AppGroup/getAll', + ['method' => 'get', 'after_behavior' => $afterBehavior] + ], + 'AppGroup/changeStatus' => [ + 'admin/AppGroup/changeStatus', + ['method' => 'get', 'after_behavior' => $afterBehavior] + ], '__miss__' => ['admin/Miss/index'], ], ];