From 81a25427da239058194addfd86bdef4e19349b13 Mon Sep 17 00:00:00 2001 From: zhaoxiang <756958008@qq.com> Date: Wed, 28 Feb 2018 20:32:15 +0800 Subject: [PATCH 1/5] =?UTF-8?q?fixed=20=E4=BF=AE=E5=A4=8DApiLog=E8=AE=B0?= =?UTF-8?q?=E5=BD=95=E6=9D=83=E9=99=90BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 - runtime/index.html | 0 2 files changed, 1 deletion(-) create mode 100644 runtime/index.html diff --git a/.gitignore b/.gitignore index 59f2927..9f11b75 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1 @@ .idea/ -runtime/ \ No newline at end of file diff --git a/runtime/index.html b/runtime/index.html new file mode 100644 index 0000000..e69de29 From b0fc40155c276370523ef30aabe4a1763ecc0a7f Mon Sep 17 00:00:00 2001 From: zhaoxiang <756958008@qq.com> Date: Wed, 28 Feb 2018 21:34:45 +0800 Subject: [PATCH 2/5] =?UTF-8?q?added=20=E6=93=8D=E4=BD=9C=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E7=9A=84=E5=B1=95=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/controller/Log.php | 76 ++++++++++++++++++++++++++++ application/adminRoute.php | 8 +++ application/model/ApiUserAction.php | 13 +++++ 3 files changed, 97 insertions(+) create mode 100644 application/admin/controller/Log.php create mode 100644 application/model/ApiUserAction.php diff --git a/application/admin/controller/Log.php b/application/admin/controller/Log.php new file mode 100644 index 0000000..165fb62 --- /dev/null +++ b/application/admin/controller/Log.php @@ -0,0 +1,76 @@ + + */ + +namespace app\admin\controller; + + +use app\model\ApiAuthGroupAccess; +use app\model\ApiUser; +use app\model\ApiUserAction; +use app\model\ApiUserData; +use app\util\ReturnCode; +use app\util\Tools; + +class Log extends Base { + + /** + * 获取操作日志列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\ModelNotFoundException + * @throws \think\exception\DbException + * @author zhaoxiang + */ + public function index() { + + $limit = $this->request->get('size', config('apiAdmin.ADMIN_LIST_DEFAULT')); + $start = $limit * ($this->request->get('page', 1) - 1); + $type = $this->request->get('type', ''); + $keywords = $this->request->get('keywords', ''); + + $where = []; + if ($type) { + switch ($type) { + case 1: + $where['url'] = ['like', "%{$keywords}%"]; + break; + case 2: + $where['nickname'] = ['like', "%{$keywords}%"]; + break; + case 3: + $where['uid'] = $keywords; + break; + } + } + + $listInfo = (new ApiUserAction())->where($where)->order('addTime', 'DESC')->limit($start, $limit)->select(); + $count = (new ApiUserAction())->where($where)->count(); + $listInfo = Tools::buildArrFromObj($listInfo); + + return $this->buildSuccess([ + 'list' => $listInfo, + 'count' => $count + ]); + } + + /** + * 删除日志 + * @return array + * @author zhaoxiang + */ + public function del() { + $id = $this->request->get('id'); + if (!$id) { + return $this->buildFailed(ReturnCode::EMPTY_PARAMS, '缺少必要参数'); + } + ApiUserAction::destroy($id); + + return $this->buildSuccess([]); + + } + +} diff --git a/application/adminRoute.php b/application/adminRoute.php index ba9a527..2090467 100644 --- a/application/adminRoute.php +++ b/application/adminRoute.php @@ -215,6 +215,14 @@ return [ 'admin/AppGroup/changeStatus', ['method' => 'get', 'after_behavior' => $afterBehavior] ], + 'Log/index' => [ + 'admin/Log/index', + ['method' => 'get', 'after_behavior' => $afterBehavior] + ], + 'Log/del' => [ + 'admin/Log/del', + ['method' => 'get', 'after_behavior' => $afterBehavior] + ], '__miss__' => ['admin/Miss/index'], ], ]; diff --git a/application/model/ApiUserAction.php b/application/model/ApiUserAction.php new file mode 100644 index 0000000..f6d267e --- /dev/null +++ b/application/model/ApiUserAction.php @@ -0,0 +1,13 @@ + + */ + +namespace app\model; + + +class ApiUserAction extends Base { + +} From ec990e967c289636b16c0e4ce737bf718ae0217b Mon Sep 17 00:00:00 2001 From: zhaoxiang <756958008@qq.com> Date: Wed, 28 Feb 2018 21:58:16 +0800 Subject: [PATCH 3/5] =?UTF-8?q?added=20=E6=93=8D=E4=BD=9C=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E7=9A=84=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/behavior/AdminLog.php | 52 ++++++++++++++++++++ application/admin/behavior/ApiAuth.php | 8 ++- application/admin/behavior/ApiPermission.php | 4 +- application/adminRoute.php | 8 ++- 4 files changed, 63 insertions(+), 9 deletions(-) create mode 100644 application/admin/behavior/AdminLog.php diff --git a/application/admin/behavior/AdminLog.php b/application/admin/behavior/AdminLog.php new file mode 100644 index 0000000..f9c5e27 --- /dev/null +++ b/application/admin/behavior/AdminLog.php @@ -0,0 +1,52 @@ + + */ + +namespace app\admin\behavior; + + +use app\model\ApiMenu; +use app\model\ApiUserAction; +use app\util\ReturnCode; +use think\Request; + +class AdminLog { + + /** + * 后台操作日志记录 + * @author zhaoxiang + * @return \think\response\Json + * @throws \think\Exception + * @throws \think\exception\DbException + */ + public function run() { + $header = config('apiAdmin.CROSS_DOMAIN'); + $request = Request::instance(); + $route = $request->routeInfo(); + $userToken = $request->header('ApiAuth', ''); + $userInfo = cache($userToken); + $userInfo = json_decode($userInfo, true); + $menuInfo = ApiMenu::get(['url' => $route['route']]); + + if ($menuInfo) { + $menuInfo = $menuInfo->toArray(); + } else { + $data = ['code' => ReturnCode::INVALID, 'msg' => '当前路由非法:'. $route['route'], 'data' => []]; + + return json($data, 200, $header); + } + + ApiUserAction::create([ + 'actionName' => $menuInfo['name'], + 'uid' => $userInfo['id'], + 'nickname' => $userInfo['nickname'], + 'addTime' => time(), + 'url' => $route['route'], + 'data' => json_encode($request->param()) + ]); + } + +} diff --git a/application/admin/behavior/ApiAuth.php b/application/admin/behavior/ApiAuth.php index 2e583b1..db8ee55 100644 --- a/application/admin/behavior/ApiAuth.php +++ b/application/admin/behavior/ApiAuth.php @@ -13,8 +13,6 @@ use think\Request; class ApiAuth { - private $exclude = []; - /** * 默认行为函数 * @return \think\response\Json @@ -23,9 +21,9 @@ class ApiAuth { public function run() { $request = Request::instance(); $header = config('apiAdmin.CROSS_DOMAIN'); - $userToken = $request->header('ApiAuth', ''); - if ($userToken) { - $userInfo = cache($userToken); + $ApiAuth = $request->header('ApiAuth', ''); + if ($ApiAuth) { + $userInfo = cache($ApiAuth); $userInfo = json_decode($userInfo, true); if (!$userInfo || !isset($userInfo['id'])) { $data = ['code' => ReturnCode::AUTH_ERROR, 'msg' => 'ApiAuth不匹配', 'data' => []]; diff --git a/application/admin/behavior/ApiPermission.php b/application/admin/behavior/ApiPermission.php index 4a59613..547ca24 100644 --- a/application/admin/behavior/ApiPermission.php +++ b/application/admin/behavior/ApiPermission.php @@ -29,8 +29,8 @@ class ApiPermission { $request = Request::instance(); $route = $request->routeInfo(); $header = config('apiAdmin.CROSS_DOMAIN'); - $userToken = $request->header('ApiAuth', ''); - $userInfo = cache($userToken); + $ApiAuth = $request->header('ApiAuth', ''); + $userInfo = cache($ApiAuth); $userInfo = json_decode($userInfo, true); if (!$this->checkAuth($userInfo['id'], $route['route'])) { $data = ['code' => ReturnCode::INVALID, 'msg' => '非常抱歉,您没有权限怎么做!', 'data' => []]; diff --git a/application/adminRoute.php b/application/adminRoute.php index 2090467..10947cc 100644 --- a/application/adminRoute.php +++ b/application/adminRoute.php @@ -1,11 +1,15 @@ [ 'Login/index' => [ 'admin/Login/index', - ['method' => 'post'] + ['method' => 'post', 'after_behavior' => '\app\admin\behavior\AdminLog'] ], 'Login/logout' => [ 'admin/Login/logout', From c4a20b9a165da380378f335f7091fa251ed5a86c Mon Sep 17 00:00:00 2001 From: zhaoxiang <756958008@qq.com> Date: Wed, 28 Feb 2018 22:08:39 +0800 Subject: [PATCH 4/5] =?UTF-8?q?modified=20=E5=8E=BB=E9=99=A4=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E7=9A=84Log=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/adminRoute.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/adminRoute.php b/application/adminRoute.php index 10947cc..195b650 100644 --- a/application/adminRoute.php +++ b/application/adminRoute.php @@ -9,7 +9,7 @@ return [ '[admin]' => [ 'Login/index' => [ 'admin/Login/index', - ['method' => 'post', 'after_behavior' => '\app\admin\behavior\AdminLog'] + ['method' => 'post'] ], 'Login/logout' => [ 'admin/Login/logout', From 07d4907bee0dc2bce4094ba3390cfc884ac094c6 Mon Sep 17 00:00:00 2001 From: zhaoxiang <756958008@qq.com> Date: Sat, 3 Mar 2018 00:04:19 +0800 Subject: [PATCH 5/5] =?UTF-8?q?modified=20=E4=BC=98=E5=8C=96=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E8=B7=AF=E7=94=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/wiki/apiRoute.php | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 application/wiki/apiRoute.php diff --git a/application/wiki/apiRoute.php b/application/wiki/apiRoute.php new file mode 100644 index 0000000..6f97d7f --- /dev/null +++ b/application/wiki/apiRoute.php @@ -0,0 +1,8 @@ +