From 230be2ffb7d5acd30d7e2b0a2155e735d9ea8fa8 Mon Sep 17 00:00:00 2001 From: zhaoxiang <756958008@qq.com> Date: Mon, 12 Dec 2016 20:49:32 +0800 Subject: [PATCH] =?UTF-8?q?modified=20=E5=AE=8C=E5=96=84APP=E6=94=AF?= =?UTF-8?q?=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/controller/ApiManager.php | 310 ++++++++++++++++++++ application/admin/controller/AppManager.php | 5 + application/admin/controller/KeyManager.php | 14 +- 3 files changed, 321 insertions(+), 8 deletions(-) create mode 100644 application/admin/controller/ApiManager.php diff --git a/application/admin/controller/ApiManager.php b/application/admin/controller/ApiManager.php new file mode 100644 index 0000000..ad374c0 --- /dev/null +++ b/application/admin/controller/ApiManager.php @@ -0,0 +1,310 @@ + + */ + +namespace app\admin\controller; + + +use app\admin\model\Api; + +class ApiManager extends Base { + + public function index(){ + $data = Api::all(); + $table = [ + 'tempType' => 'table', + 'header' => [ + [ + 'field' => 'name', + 'info' => '应用名称' + ], + [ + 'field' => 'info', + 'info' => '应用描述' + ], + [ + 'field' => 'type', + 'info' => '参与方式' + ], + [ + 'field' => 'status', + 'info' => '状态' + ] + ], + 'topButton' => [ + [ + 'href' => 'AppManager/add', + 'class'=> 'btn-success', + 'info'=> '新增', + 'icon' => 'fa fa-plus', + 'confirm' => 0, + ], + [ + 'href' => 'AppManager/del', + 'class'=> 'btn-danger ajax-delete', + 'info'=> '删除', + 'icon' => 'fa fa-trash', + 'confirm' => 1, + ] + ], + 'rightButton' => [ + [ + 'info' => '启用', + 'href' => 'AppManager/open', + 'class'=> 'btn-success ajax-put-url', + 'param'=> [$this->primaryKey], + 'icon' => 'fa fa-check', + 'confirm' => 1, + 'show' => ['status', 0] + ], + [ + 'info' => '禁用', + 'href' => 'AppManager/close', + 'class'=> 'btn-warning ajax-put-url', + 'param'=> [$this->primaryKey], + 'icon' => 'fa fa-close', + 'confirm' => 1, + 'show' => ['status', 1] + ], + [ + 'info' => '编辑', + 'href' => 'AppManager/edit', + 'class'=> 'btn-primary', + 'param'=> [$this->primaryKey], + 'icon' => 'fa fa-pencil', + 'confirm' => 0, + 'show' => '' + ], + [ + 'info' => '删除', + 'href' => 'AppManager/del', + 'class'=> 'btn-danger ajax-delete', + 'param'=> [$this->primaryKey], + 'icon' => 'fa fa-trash', + 'confirm' => 1, + 'show' => '' + ] + ], + 'typeRule' => [ + 'type' => [ + 'module' => 'label', + 'rule' => [ + [ + 'info' => '监视方式', + 'class' => 'label label-info' + ], + [ + 'info' => '网关方式', + 'class' => 'label label-primary' + ] + ] + ], + 'status' => [ + 'module' => 'label', + 'rule' => [ + [ + 'info' => '禁用', + 'class' => 'label label-danger' + ], + [ + 'info' => '启用', + 'class' => 'label label-success' + ] + ] + ] + ], + 'data' => $data + ]; + $table = $this->_prepareTemplate($table); + $this->result($table, ReturnCode::GET_TEMPLATE_SUCCESS); + } + + public function add(){ + if( $this->request->isPost() ){ + $appModel = new App(); + $result = $appModel->allowField(true)->save($this->request->post()); + if(false === $result){ + $this->error($appModel->getError()); + }else{ + $this->success('操作成功!', url('AppManager/index')); + } + }else{ + $form = [ + 'formTitle' => $this->menuInfo['name'], + 'tempType' => 'add', + 'formAttr' => [ + 'target' => url('AppManager/add'), + 'formId' => 'add-AppManager-form', + 'backUrl' => url('AppManager/index'), + ], + 'formList' => [ + [ + 'module' => 'text', + 'description' => '', + 'info' => '应用名称:', + 'attr' => [ + 'name' => 'name', + 'value' => '', + 'placeholder' => '' + ] + ], + [ + 'module' => 'text', + 'description' => '', + 'info' => '基础链接:', + 'attr' => [ + 'name' => 'baseUrl', + 'value' => '', + 'placeholder' => '' + ] + ], + [ + 'module' => 'select', + 'description' => '', + 'info' => '参与方式:', + 'attr' => [ + 'name' => 'type', + 'value' => '', + 'options' => [ + '监视方式', + '网关方式' + ] + ] + ], + [ + 'module' => 'textarea', + 'description' => '', + 'info' => '应用描述:', + 'attr' => [ + 'name' => 'info', + 'value' => '', + 'placeholder' => '' + ] + ] + ] + ]; + $this->result($form, ReturnCode::GET_TEMPLATE_SUCCESS); + } + } + + public function open(){ + if( $this->request->isPut() ){ + $id = $this->request->put($this->primaryKey); + $appObj = App::get([$this->primaryKey => $id]); + if( is_null($appObj) ){ + $this->error('当前应用不存在',''); + }else{ + $appObj->status = 1; + $appObj->save(); + $this->success('操作成功', url('AppManager/index')); + } + } + } + + public function close(){ + if( $this->request->isPut() ){ + $id = $this->request->put($this->primaryKey); + $appObj = App::get([$this->primaryKey => $id]); + if( is_null($appObj) ){ + $this->error('当前应用不存在',''); + }else{ + $appObj->status = 0; + $appObj->save(); + $this->success('操作成功', url('AppManager/index')); + } + } + } + + public function del(){ + if( $this->request->isDelete() ){ + $key = $this->request->delete($this->primaryKey); + $delNum = App::destroy($key); + if( $delNum ){ + $this->success('操作成功!', url('AppManager/index')); + } + } + $this->error('操作失败!'); + } + + public function edit(){ + if( $this->request->isPut() ){ + if( empty($this->request->put('name')) ){ + $this->error('应用名称不能为空', ''); + } + $data = $this->request->put(); + $appMemberModel = new App(); + $appMemberModel->update($data); + $this->success('操作成功!', url('AppManager/index')); + }else{ + $detail = App::get($this->request->get($this->primaryKey))->toArray(); + $form = [ + 'formTitle' => $this->menuInfo['name'], + 'tempType' => 'edit', + 'formAttr' => [ + 'target' => url('AppManager/edit'), + 'formId' => 'edit-AppManager-form', + 'backUrl' => url('AppManager/index'), + ], + 'formList' => [ + [ + 'module' => 'hidden', + 'description' => '', + 'info' => '', + 'attr' => [ + 'name' => $this->primaryKey, + 'value' => $detail[$this->primaryKey], + 'placeholder' => '' + ] + ], + [ + 'module' => 'text', + 'description' => '', + 'info' => '应用名称:', + 'attr' => [ + 'name' => 'name', + 'value' => $detail['name'], + 'placeholder' => '' + ] + ], + [ + 'module' => 'text', + 'description' => '', + 'info' => '基础链接:', + 'attr' => [ + 'name' => 'baseUrl', + 'value' => $detail['baseUrl'], + 'placeholder' => '' + ] + ], + [ + 'module' => 'select', + 'description' => '', + 'info' => '参与方式:', + 'attr' => [ + 'name' => 'type', + 'value' => $detail['type'], + 'options' => [ + '监视方式', + '网关方式' + ] + ] + ], + [ + 'module' => 'textarea', + 'description' => '', + 'info' => '应用描述:', + 'attr' => [ + 'name' => 'info', + 'value' => $detail['info'], + 'placeholder' => '' + ] + ] + ] + ]; + $this->result($form, ReturnCode::GET_TEMPLATE_SUCCESS); + } + } + +} \ No newline at end of file diff --git a/application/admin/controller/AppManager.php b/application/admin/controller/AppManager.php index f6a3e8f..93a2163 100644 --- a/application/admin/controller/AppManager.php +++ b/application/admin/controller/AppManager.php @@ -118,6 +118,11 @@ class AppManager extends Base { ], 'data' => $data ]; + $appListCache = []; + foreach ( $data as $key => $value ){ + $appListCache[$value['id']] = $value['name']; + } + cache( CacheType::APP_LIST_KEY, $appListCache ); $table = $this->_prepareTemplate($table); $this->result($table, ReturnCode::GET_TEMPLATE_SUCCESS); } diff --git a/application/admin/controller/KeyManager.php b/application/admin/controller/KeyManager.php index 8933968..a2a2b98 100644 --- a/application/admin/controller/KeyManager.php +++ b/application/admin/controller/KeyManager.php @@ -127,10 +127,9 @@ class KeyManager extends Base { } }else{ $apps = cache(CacheType::APP_LIST_KEY); - //TODO::等待应用配置开发完成开放APP验证 -// if( !$apps ){ -// $this->error('请先配置应用!', url('AppManager/index')); -// } + if( !$apps ){ + $this->error('请先配置应用!', url('AppManager/index')); + } $filters = cache(CacheType::FILTER_LIST_KEY); $filters[-1] = '不限制'; $sk = \StrOrg::randString(64); @@ -221,10 +220,9 @@ class KeyManager extends Base { $this->success('操作成功!', url('KeyManager/index')); }else{ $apps = cache(CacheType::APP_LIST_KEY); - //TODO::等待应用配置开发完成开放APP验证 -// if( !$apps ){ -// $this->error('请先配置应用!', url('AppManager/index')); -// } + if( !$apps ){ + $this->error('请先配置应用!', url('AppManager/index')); + } $filters = cache(CacheType::FILTER_LIST_KEY); $filters[-1] = '不限制'; $detail = Keys::get($this->request->get($this->primaryKey))->toArray();