From 1b876750b11b213da285979ef604bf2cf6a442db Mon Sep 17 00:00:00 2001 From: zhaoxiang <756958008@qq.com> Date: Tue, 20 Feb 2018 02:39:48 +0800 Subject: [PATCH] =?UTF-8?q?modified=20=E5=AE=8C=E6=88=90=E5=BA=94=E7=94=A8?= =?UTF-8?q?=E7=BC=96=E8=BE=91=E7=AD=89=E5=85=A8=E9=83=A8=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/controller/App.php | 50 ++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 11 deletions(-) diff --git a/application/admin/controller/App.php b/application/admin/controller/App.php index cfed1d1..c7a0a96 100644 --- a/application/admin/controller/App.php +++ b/application/admin/controller/App.php @@ -59,6 +59,7 @@ class App extends Base { * 获取AppId,AppSecret,接口列表,应用接口权限细节 * @author zhaoxiang * @return array + * @throws \think\Exception * @throws \think\exception\DbException */ public function getAppInfo() { @@ -72,7 +73,8 @@ class App extends Base { $res['groupInfo']['default'] = '默认分组'; $id = $this->request->get('id', 0); if ($id) { - + $appInfo = ApiApp::get($id)->toArray(); + $res['app_detail'] = json_decode($appInfo['app_api_show'], true); } else { $res['app_id'] = mt_rand(1, 9) . Strs::randString(7, 1); $res['app_secret'] = Strs::randString(32); @@ -82,13 +84,28 @@ class App extends Base { } /** - * 新增菜单 + * 新增应用 * @return array * @author zhaoxiang */ public function add() { $postData = $this->request->post(); - $res = ApiMenu::create($postData); + $data = [ + 'app_id' => $postData['app_id'], + 'app_secret' => $postData['app_secret'], + 'app_name' => $postData['app_name'], + 'app_info' => $postData['app_info'], + 'app_api' => '', + 'app_api_show' => '', + ]; + if (isset($postData['app_api']) && $postData['app_api']) { + $data['app_api_show'] = json_encode($postData['app_api']); + foreach ($postData['app_api'] as $value) { + $data['app_api'] .= implode(',', $value) . ','; + } + $data['app_api'] = trim($data['app_api'], ','); + } + $res = ApiApp::create($data); if ($res === false) { return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败'); } else { @@ -123,7 +140,23 @@ class App extends Base { */ public function edit() { $postData = $this->request->post(); - $res = ApiMenu::update($postData); + $data = [ + 'id' => $postData['id'], + 'app_id' => $postData['app_id'], + 'app_secret' => $postData['app_secret'], + 'app_name' => $postData['app_name'], + 'app_info' => $postData['app_info'], + 'app_api' => '', + 'app_api_show' => '', + ]; + if (isset($postData['app_api']) && $postData['app_api']) { + $data['app_api_show'] = json_encode($postData['app_api']); + foreach ($postData['app_api'] as $value) { + $data['app_api'] .= implode(',', $value) . ','; + } + $data['app_api'] = trim($data['app_api'], ','); + } + $res = ApiApp::update($data); if ($res === false) { return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败'); } else { @@ -141,13 +174,8 @@ class App extends Base { if (!$id) { return $this->buildFailed(ReturnCode::EMPTY_PARAMS, '缺少必要参数'); } - $childNum = ApiMenu::where(['fid' => $id])->count(); - if ($childNum) { - return $this->buildFailed(ReturnCode::INVALID, '当前菜单存在子菜单,不可以被删除!'); - } else { - ApiMenu::destroy($id); + ApiApp::destroy($id); - return $this->buildSuccess([]); - } + return $this->buildSuccess([]); } }