diff --git a/application/admin/controller/App.php b/application/admin/controller/App.php index 10e8befeb964d07da2aa9c9aaab0b48795a4c8da..ff148d010a5c97ce6a61febb0c4e0c3a8892d8f2 100644 --- a/application/admin/controller/App.php +++ b/application/admin/controller/App.php @@ -90,7 +90,7 @@ class App extends Base { if ($id) { $res = AdminApp::update($data, ['id' => $id]); if ($res === false) { - return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败'); + return $this->buildFailed(ReturnCode::DB_SAVE_ERROR); } } @@ -124,9 +124,9 @@ class App extends Base { } $res = AdminApp::create($data); if ($res === false) { - return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败'); + return $this->buildFailed(ReturnCode::DB_SAVE_ERROR); } else { - return $this->buildSuccess([]); + return $this->buildSuccess(); } } @@ -144,11 +144,15 @@ class App extends Base { 'id' => $id ]); if ($res === false) { - return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败'); + return $this->buildFailed(ReturnCode::DB_SAVE_ERROR); } else { $appInfo = AdminApp::get($id); cache('AccessToken:' . $appInfo['app_secret'], null); - return $this->buildSuccess([]); + if($oldWiki = cache('WikiLogin:' . $id)) { + cache('WikiLogin:' . $oldWiki, null); + } + + return $this->buildSuccess(); } } @@ -176,11 +180,15 @@ class App extends Base { } $res = AdminApp::update($data, ['id' => $postData['id']]); if ($res === false) { - return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败'); + return $this->buildFailed(ReturnCode::DB_SAVE_ERROR); } else { $appInfo = AdminApp::get($postData['id']); cache('AccessToken:' . $appInfo['app_secret'], null); - return $this->buildSuccess([]); + if($oldWiki = cache('WikiLogin:' . $postData['id'])) { + cache('WikiLogin:' . $oldWiki, null); + } + + return $this->buildSuccess(); } } @@ -198,7 +206,10 @@ class App extends Base { cache('AccessToken:' . $appInfo['app_secret'], null); AdminApp::destroy($id); + if($oldWiki = cache('WikiLogin:' . $id)) { + cache('WikiLogin:' . $oldWiki, null); + } - return $this->buildSuccess([]); + return $this->buildSuccess(); } } diff --git a/application/admin/controller/AppGroup.php b/application/admin/controller/AppGroup.php index 3f393827be270c0363682d79a5d5ed890cd760e2..c8f6a7ef03a284d001cd5ad37c45052afe4084f7 100644 --- a/application/admin/controller/AppGroup.php +++ b/application/admin/controller/AppGroup.php @@ -80,9 +80,9 @@ class AppGroup extends Base { 'id' => $id ]); if ($res === false) { - return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败'); + return $this->buildFailed(ReturnCode::DB_SAVE_ERROR); } else { - return $this->buildSuccess([]); + return $this->buildSuccess(); } } @@ -95,9 +95,9 @@ class AppGroup extends Base { $postData = $this->request->post(); $res = AdminAppGroup::create($postData); if ($res === false) { - return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败'); + return $this->buildFailed(ReturnCode::DB_SAVE_ERROR); } else { - return $this->buildSuccess([]); + return $this->buildSuccess(); } } @@ -110,9 +110,9 @@ class AppGroup extends Base { $postData = $this->request->post(); $res = AdminAppGroup::update($postData); if ($res === false) { - return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败'); + return $this->buildFailed(ReturnCode::DB_SAVE_ERROR); } else { - return $this->buildSuccess([]); + return $this->buildSuccess(); } } @@ -134,6 +134,6 @@ class AppGroup extends Base { AdminAppGroup::destroy(['hash' => $hash]); - return $this->buildSuccess([]); + return $this->buildSuccess(); } } diff --git a/application/admin/controller/Auth.php b/application/admin/controller/Auth.php index 708802f978ccb7a9e71b4076bf32dfaea89287ae..cce7462dd068dacb019a87adda2ffbbdc6450e10 100644 --- a/application/admin/controller/Auth.php +++ b/application/admin/controller/Auth.php @@ -109,7 +109,7 @@ class Auth extends Base { unset($postData['rules']); $res = AdminAuthGroup::create($postData); if ($res === false) { - return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败'); + return $this->buildFailed(ReturnCode::DB_SAVE_ERROR); } else { if ($rules) { $insertData = []; @@ -124,7 +124,7 @@ class Auth extends Base { (new AdminAuthRule())->saveAll($insertData); } - return $this->buildSuccess([]); + return $this->buildSuccess(); } } @@ -141,9 +141,9 @@ class Auth extends Base { 'status' => $status ]); if ($res === false) { - return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败'); + return $this->buildFailed(ReturnCode::DB_SAVE_ERROR); } else { - return $this->buildSuccess([]); + return $this->buildSuccess(); } } @@ -164,9 +164,9 @@ class Auth extends Base { unset($postData['rules']); $res = AdminAuthGroup::update($postData); if ($res === false) { - return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败'); + return $this->buildFailed(ReturnCode::DB_SAVE_ERROR); } else { - return $this->buildSuccess([]); + return $this->buildSuccess(); } } @@ -199,7 +199,7 @@ class Auth extends Base { AdminAuthGroup::destroy($id); AdminAuthRule::destroy(['group_id' => $id]); - return $this->buildSuccess([]); + return $this->buildSuccess(); } /** @@ -226,9 +226,9 @@ class Auth extends Base { 'uid' => $uid ]); if ($res === false) { - return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败'); + return $this->buildFailed(ReturnCode::DB_SAVE_ERROR); } else { - return $this->buildSuccess([]); + return $this->buildSuccess(); } } diff --git a/application/admin/controller/Base.php b/application/admin/controller/Base.php index ea9d5525d631d2cb58aab5a0b4001b0b588adbdd..ee8996d62fc490fd1ec31cd715981054defeaec4 100644 --- a/application/admin/controller/Base.php +++ b/application/admin/controller/Base.php @@ -22,13 +22,13 @@ class Base extends Controller { $this->userInfo = $this->request->API_ADMIN_USER_INFO; } - public function buildSuccess($data, $msg = '操作成功', $code = ReturnCode::SUCCESS) { + public function buildSuccess($data = [], $msg = '操作成功', $code = ReturnCode::SUCCESS) { $return = [ 'code' => $code, 'msg' => $msg, 'data' => $data ]; - if ($this->debug) { + if (config('app.app_debug') && $this->debug) { $return['debug'] = $this->debug; } @@ -56,13 +56,13 @@ class Base extends Controller { cache('Login:' . $apiAuth, json_encode($this->userInfo), config('apiadmin.ONLINE_TIME')); } - public function buildFailed($code, $msg, $data = []) { + public function buildFailed($code, $msg = '操作失败', $data = []) { $return = [ 'code' => $code, 'msg' => $msg, 'data' => $data ]; - if ($this->debug) { + if (config('app.app_debug') && $this->debug) { $return['debug'] = $this->debug; } diff --git a/application/admin/controller/Fields.php b/application/admin/controller/Fields.php index 70c22cba0f701c6d9e5a0bb1e9bd4469f42abd5a..fe51246887332bbf21f4eab1c8738b9be9ee241b 100644 --- a/application/admin/controller/Fields.php +++ b/application/admin/controller/Fields.php @@ -104,9 +104,9 @@ class Fields extends Base { cache('ResponseFieldsRule:' . $postData['hash'], null); if ($res === false) { - return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败'); + return $this->buildFailed(ReturnCode::DB_SAVE_ERROR); } else { - return $this->buildSuccess('操作成功'); + return $this->buildSuccess(); } } @@ -127,9 +127,9 @@ class Fields extends Base { cache('ResponseFieldsRule:' . $postData['hash'], null); if ($res === false) { - return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败'); + return $this->buildFailed(ReturnCode::DB_SAVE_ERROR); } else { - return $this->buildSuccess([]); + return $this->buildSuccess(); } } @@ -152,7 +152,7 @@ class Fields extends Base { AdminFields::destroy($id); - return $this->buildSuccess([]); + return $this->buildSuccess(); } /** @@ -200,7 +200,7 @@ class Fields extends Base { cache('RequestFields:Rule:' . $hash, null); cache('ResponseFieldsRule:' . $hash, null); - return $this->buildSuccess([]); + return $this->buildSuccess(); } private function handle($data, &$dataArr, $prefix = 'data', $index = 'data') { diff --git a/application/admin/controller/InterfaceGroup.php b/application/admin/controller/InterfaceGroup.php index bc14a085f246b00f8e032ea41747e6642c268b2d..9bbf7975371fc1d6aa675d3e29f9aa736ca68130 100644 --- a/application/admin/controller/InterfaceGroup.php +++ b/application/admin/controller/InterfaceGroup.php @@ -79,9 +79,9 @@ class InterfaceGroup extends Base { 'id' => $id ]); if ($res === false) { - return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败'); + return $this->buildFailed(ReturnCode::DB_SAVE_ERROR); } else { - return $this->buildSuccess([]); + return $this->buildSuccess(); } } @@ -94,9 +94,9 @@ class InterfaceGroup extends Base { $postData = $this->request->post(); $res = AdminGroup::create($postData); if ($res === false) { - return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败'); + return $this->buildFailed(ReturnCode::DB_SAVE_ERROR); } else { - return $this->buildSuccess([]); + return $this->buildSuccess(); } } @@ -109,9 +109,9 @@ class InterfaceGroup extends Base { $postData = $this->request->post(); $res = AdminGroup::update($postData); if ($res === false) { - return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败'); + return $this->buildFailed(ReturnCode::DB_SAVE_ERROR); } else { - return $this->buildSuccess([]); + return $this->buildSuccess(); } } @@ -153,6 +153,6 @@ class InterfaceGroup extends Base { AdminGroup::destroy(['hash' => $hash]); - return $this->buildSuccess([]); + return $this->buildSuccess(); } } diff --git a/application/admin/controller/InterfaceList.php b/application/admin/controller/InterfaceList.php index 29901bab5479ed9755ab300e6aa142922ceb6a02..64b39cf50c4774d50269ca7c19091c5e6b9d44f2 100644 --- a/application/admin/controller/InterfaceList.php +++ b/application/admin/controller/InterfaceList.php @@ -78,9 +78,9 @@ class InterfaceList extends Base { $res = AdminList::create($postData); if ($res === false) { - return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败'); + return $this->buildFailed(ReturnCode::DB_SAVE_ERROR); } else { - return $this->buildSuccess([]); + return $this->buildSuccess(); } } @@ -98,11 +98,11 @@ class InterfaceList extends Base { 'hash' => $hash ]); if ($res === false) { - return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败'); + return $this->buildFailed(ReturnCode::DB_SAVE_ERROR); } else { cache('ApiInfo:' . $hash, null); - return $this->buildSuccess([]); + return $this->buildSuccess(); } } @@ -119,11 +119,11 @@ class InterfaceList extends Base { $res = AdminList::update($postData); if ($res === false) { - return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败'); + return $this->buildFailed(ReturnCode::DB_SAVE_ERROR); } else { cache('ApiInfo:' . $postData['hash'], null); - return $this->buildSuccess([]); + return $this->buildSuccess(); } } @@ -166,7 +166,7 @@ class InterfaceList extends Base { cache('ApiInfo:' . $hash, null); - return $this->buildSuccess([]); + return $this->buildSuccess(); } /** @@ -183,14 +183,14 @@ class InterfaceList extends Base { $tplOriginStr = file_get_contents($tplPath); $listInfo = AdminList::all(['status' => 1]); - $tplStr = ''; + $tplStr = []; foreach ($listInfo as $value) { - $tplStr .= 'Route::rule(\'' . addslashes($value->hash) . '\',\'api/' . addslashes($value->api_class) . '\', \'' . $methodArr[$value->method] . '\')->middleware([\'ApiAuth\', \'ApiPermission\', \'RequestFilter\', \'ApiLog\']);'; + array_push($tplStr, 'Route::rule(\'' . addslashes($value->hash) . '\',\'api/' . addslashes($value->api_class) . '\', \'' . $methodArr[$value->method] . '\')->middleware([\'ApiAuth\', \'ApiPermission\', \'RequestFilter\', \'ApiLog\']);'); } - $tplOriginStr = str_replace(['{$API_RULE}'], [$tplStr], $tplOriginStr); + $tplOriginStr = str_replace(['{$API_RULE}'], [implode($tplStr, "\n ")], $tplOriginStr); file_put_contents($apiRoutePath, $tplOriginStr); - return $this->buildSuccess([]); + return $this->buildSuccess(); } } diff --git a/application/admin/controller/Log.php b/application/admin/controller/Log.php index df9d32fee6470277379592cabe5ccc73bc50bfcc..be8e98f214eca8e01984e4deee2fcb679a1c3b1a 100644 --- a/application/admin/controller/Log.php +++ b/application/admin/controller/Log.php @@ -64,7 +64,7 @@ class Log extends Base { } AdminUserAction::destroy($id); - return $this->buildSuccess([]); + return $this->buildSuccess(); } diff --git a/application/admin/controller/Menu.php b/application/admin/controller/Menu.php index c94f49601a772902b9e02f9aa050da262f266e61..784f73a147f6a19a88739bd925f986a739158654 100644 --- a/application/admin/controller/Menu.php +++ b/application/admin/controller/Menu.php @@ -27,7 +27,7 @@ class Menu extends Base { return $this->buildSuccess([ 'list' => $list - ], '登录成功'); + ]); } /** @@ -42,9 +42,9 @@ class Menu extends Base { } $res = AdminMenu::create($postData); if ($res === false) { - return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败'); + return $this->buildFailed(ReturnCode::DB_SAVE_ERROR); } else { - return $this->buildSuccess([]); + return $this->buildSuccess(); } } @@ -61,9 +61,9 @@ class Menu extends Base { 'hide' => $status ]); if ($res === false) { - return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败'); + return $this->buildFailed(ReturnCode::DB_SAVE_ERROR); } else { - return $this->buildSuccess([]); + return $this->buildSuccess(); } } @@ -79,9 +79,9 @@ class Menu extends Base { } $res = AdminMenu::update($postData); if ($res === false) { - return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败'); + return $this->buildFailed(ReturnCode::DB_SAVE_ERROR); } else { - return $this->buildSuccess([]); + return $this->buildSuccess(); } } @@ -101,7 +101,7 @@ class Menu extends Base { } else { AdminMenu::destroy($id); - return $this->buildSuccess([]); + return $this->buildSuccess(); } } diff --git a/application/admin/controller/Miss.php b/application/admin/controller/Miss.php index 4f7a164239b7cfcaa4dac01c7a31479c021d492e..dd325287195bd13bf59576825c0bbed7af127922 100644 --- a/application/admin/controller/Miss.php +++ b/application/admin/controller/Miss.php @@ -6,9 +6,9 @@ use app\util\ReturnCode; class Miss extends Base { public function index() { if ($this->request->isOptions()) { - return $this->buildSuccess([]); + return $this->buildSuccess(); } else { - return $this->buildFailed(ReturnCode::INVALID, '接口地址异常', []); + return $this->buildFailed(ReturnCode::INVALID, '接口地址异常'); } } } diff --git a/application/admin/controller/User.php b/application/admin/controller/User.php index b78017d153b8e2f13b77cf6844692f499bdc06b1..97e1401df8c01b8e93d084e3508674ed59d3b77c 100644 --- a/application/admin/controller/User.php +++ b/application/admin/controller/User.php @@ -95,14 +95,14 @@ class User extends Base { } $res = AdminUser::create($postData); if ($res === false) { - return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败'); + return $this->buildFailed(ReturnCode::DB_SAVE_ERROR); } else { AdminAuthGroupAccess::create([ 'uid' => $res->id, 'group_id' => $groups ]); - return $this->buildSuccess([]); + return $this->buildSuccess(); } } @@ -160,9 +160,13 @@ class User extends Base { 'status' => $status ]); if ($res === false) { - return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败'); + return $this->buildFailed(ReturnCode::DB_SAVE_ERROR); } else { - return $this->buildSuccess([]); + if($oldAdmin = cache('Login:' . $id)) { + cache('Login:' . $oldAdmin, null); + } + + return $this->buildSuccess(); } } @@ -186,7 +190,7 @@ class User extends Base { } $res = AdminUser::update($postData); if ($res === false) { - return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败'); + return $this->buildFailed(ReturnCode::DB_SAVE_ERROR); } else { $has = AdminAuthGroupAccess::get(['uid' => $postData['id']]); if ($has) { @@ -201,8 +205,11 @@ class User extends Base { 'group_id' => $groups ]); } + if($oldAdmin = cache('Login:' . $postData['id'])) { + cache('Login:' . $oldAdmin, null); + } - return $this->buildSuccess([]); + return $this->buildSuccess(); } } @@ -232,13 +239,16 @@ class User extends Base { unset($postData['head_img']); $res = AdminUser::update($postData); if ($res === false) { - return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败'); + return $this->buildFailed(ReturnCode::DB_SAVE_ERROR); } else { $userData = AdminUserData::get(['uid' => $postData['id']]); $userData->head_img = $headImg; $userData->save(); + if($oldWiki = cache('WikiLogin:' . $postData['id'])) { + cache('WikiLogin:' . $oldWiki, null); + } - return $this->buildSuccess([]); + return $this->buildSuccess(); } } @@ -259,8 +269,11 @@ class User extends Base { } AdminUser::destroy($id); AdminAuthGroupAccess::destroy(['uid' => $id]); + if($oldAdmin = cache('Login:' . $id)) { + cache('Login:' . $oldAdmin, null); + } - return $this->buildSuccess([]); + return $this->buildSuccess(); } diff --git a/application/api/controller/Base.php b/application/api/controller/Base.php index fad6eaae6ca6afdae5c563114e05452f816e312d..3cf4c5d2c8a91ac7e498163fbf5c74383d66a476 100644 --- a/application/api/controller/Base.php +++ b/application/api/controller/Base.php @@ -20,30 +20,30 @@ class Base extends Controller { // $this->userInfo = ''; 这部分初始化用户信息可以参考admin模块下的Base去自行处理 } - public function buildSuccess($data, $msg = '操作成功', $code = ReturnCode::SUCCESS) { + public function buildSuccess($data = [], $msg = '操作成功', $code = ReturnCode::SUCCESS) { $return = [ 'code' => $code, 'msg' => $msg, 'data' => $data ]; - if ($this->debug) { + if (config('app.app_debug') && $this->debug) { $return['debug'] = $this->debug; } - return json($return); + return $return; } - public function buildFailed($code, $msg, $data = []) { + public function buildFailed($code, $msg = '操作失败', $data = []) { $return = [ 'code' => $code, 'msg' => $msg, 'data' => $data ]; - if ($this->debug) { + if (config('app.app_debug') && $this->debug) { $return['debug'] = $this->debug; } - return json($return); + return $return; } protected function debug($data) { diff --git a/application/util/ExceptionHandle.php b/application/util/ExceptionHandle.php new file mode 100644 index 0000000000000000000000000000000000000000..c13768373a16005470acb5b52d3279cce9a658d5 --- /dev/null +++ b/application/util/ExceptionHandle.php @@ -0,0 +1,24 @@ + + */ + +namespace app\util; + +use Exception; +use think\exception\Handle; + +/** + * Class ExceptionHandle + * @package app\util + * 异常处理handle类 + * Detail see: https://www.kancloud.cn/manual/thinkphp5_1/354092 + */ +class ExceptionHandle extends Handle { + + public function render(Exception $e) { + return parent::render($e)->header(config('apiadmin.CROSS_DOMAIN')); + } +} diff --git a/application/wiki/controller/Api.php b/application/wiki/controller/Api.php index 0837d2c0f323cfd97b04211f5a167b81e13bc3df..95ba5c70680b5eaf6046ffa82636ab488abd7055 100644 --- a/application/wiki/controller/Api.php +++ b/application/wiki/controller/Api.php @@ -114,7 +114,9 @@ class Api extends Base { foreach ($item as $apiItem) { $_listInfo['api_info'][] = $apiInfo[$apiItem]; } - $listInfo[] = $_listInfo; + if (isset($_listInfo['api_info'])) { + $listInfo[] = $_listInfo; + } } } diff --git a/application/wiki/controller/Base.php b/application/wiki/controller/Base.php index a18656ed9ae962186e55c6700908b101752cbbfd..6a4e5b7ef5424ba6571feb2a6ea10337b7a93c7f 100644 --- a/application/wiki/controller/Base.php +++ b/application/wiki/controller/Base.php @@ -20,24 +20,24 @@ class Base extends Controller { $this->appInfo = $this->request->API_WIKI_USER_INFO; } - public function buildSuccess($data, $msg = '操作成功', $code = ReturnCode::SUCCESS) { + public function buildSuccess($data = [], $msg = '操作成功', $code = ReturnCode::SUCCESS) { $return = [ 'code' => $code, 'msg' => $msg, 'data' => $data ]; - return json($return); + return $return; } - public function buildFailed($code, $msg, $data = []) { + public function buildFailed($code, $msg = '操作失败', $data = []) { $return = [ 'code' => $code, 'msg' => $msg, 'data' => $data ]; - return json($return); + return $return; } } diff --git a/config/app.php b/config/app.php index bde326aa0063c43345611b55ff1b017d2a1b4722..d599a2165ddb6773f9f2b232acb10e5c55a9c90a 100644 --- a/config/app.php +++ b/config/app.php @@ -141,6 +141,6 @@ return [ // 显示错误信息 'show_error_msg' => false, // 异常处理handle类 留空使用 \think\exception\Handle - 'exception_handle' => '', + 'exception_handle' => '\\app\\util\\ExceptionHandle', ];