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] =?UTF-8?q?added=20=E6=93=8D=E4=BD=9C=E6=97=A5=E5=BF=97?= =?UTF-8?q?=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 { + +}