mirror of
https://gitee.com/apiadmin/ApiAdmin.git
synced 2025-04-06 03:58:00 +08:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
02ec86dd39
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1 @@
|
|||||||
.idea/
|
.idea/
|
||||||
runtime/
|
|
52
application/admin/behavior/AdminLog.php
Normal file
52
application/admin/behavior/AdminLog.php
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* 后台操作日志记录
|
||||||
|
* @since 2018-02-28
|
||||||
|
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace app\admin\behavior;
|
||||||
|
|
||||||
|
|
||||||
|
use app\model\ApiMenu;
|
||||||
|
use app\model\ApiUserAction;
|
||||||
|
use app\util\ReturnCode;
|
||||||
|
use think\Request;
|
||||||
|
|
||||||
|
class AdminLog {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 后台操作日志记录
|
||||||
|
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
||||||
|
* @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())
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -13,8 +13,6 @@ use think\Request;
|
|||||||
|
|
||||||
class ApiAuth {
|
class ApiAuth {
|
||||||
|
|
||||||
private $exclude = [];
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 默认行为函数
|
* 默认行为函数
|
||||||
* @return \think\response\Json
|
* @return \think\response\Json
|
||||||
@ -23,9 +21,9 @@ class ApiAuth {
|
|||||||
public function run() {
|
public function run() {
|
||||||
$request = Request::instance();
|
$request = Request::instance();
|
||||||
$header = config('apiAdmin.CROSS_DOMAIN');
|
$header = config('apiAdmin.CROSS_DOMAIN');
|
||||||
$userToken = $request->header('ApiAuth', '');
|
$ApiAuth = $request->header('ApiAuth', '');
|
||||||
if ($userToken) {
|
if ($ApiAuth) {
|
||||||
$userInfo = cache($userToken);
|
$userInfo = cache($ApiAuth);
|
||||||
$userInfo = json_decode($userInfo, true);
|
$userInfo = json_decode($userInfo, true);
|
||||||
if (!$userInfo || !isset($userInfo['id'])) {
|
if (!$userInfo || !isset($userInfo['id'])) {
|
||||||
$data = ['code' => ReturnCode::AUTH_ERROR, 'msg' => 'ApiAuth不匹配', 'data' => []];
|
$data = ['code' => ReturnCode::AUTH_ERROR, 'msg' => 'ApiAuth不匹配', 'data' => []];
|
||||||
|
@ -29,8 +29,8 @@ class ApiPermission {
|
|||||||
$request = Request::instance();
|
$request = Request::instance();
|
||||||
$route = $request->routeInfo();
|
$route = $request->routeInfo();
|
||||||
$header = config('apiAdmin.CROSS_DOMAIN');
|
$header = config('apiAdmin.CROSS_DOMAIN');
|
||||||
$userToken = $request->header('ApiAuth', '');
|
$ApiAuth = $request->header('ApiAuth', '');
|
||||||
$userInfo = cache($userToken);
|
$userInfo = cache($ApiAuth);
|
||||||
$userInfo = json_decode($userInfo, true);
|
$userInfo = json_decode($userInfo, true);
|
||||||
if (!$this->checkAuth($userInfo['id'], $route['route'])) {
|
if (!$this->checkAuth($userInfo['id'], $route['route'])) {
|
||||||
$data = ['code' => ReturnCode::INVALID, 'msg' => '非常抱歉,您没有权限怎么做!', 'data' => []];
|
$data = ['code' => ReturnCode::INVALID, 'msg' => '非常抱歉,您没有权限怎么做!', 'data' => []];
|
||||||
|
76
application/admin/controller/Log.php
Normal file
76
application/admin/controller/Log.php
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* 后台操作日志管理
|
||||||
|
* @since 2018-02-06
|
||||||
|
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
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 <zhaoxiang051405@gmail.com>
|
||||||
|
*/
|
||||||
|
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 <zhaoxiang051405@gmail.com>
|
||||||
|
*/
|
||||||
|
public function del() {
|
||||||
|
$id = $this->request->get('id');
|
||||||
|
if (!$id) {
|
||||||
|
return $this->buildFailed(ReturnCode::EMPTY_PARAMS, '缺少必要参数');
|
||||||
|
}
|
||||||
|
ApiUserAction::destroy($id);
|
||||||
|
|
||||||
|
return $this->buildSuccess([]);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,5 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
$afterBehavior = ['\app\admin\behavior\ApiAuth', '\app\admin\behavior\ApiPermission'];
|
$afterBehavior = [
|
||||||
|
'\app\admin\behavior\ApiAuth',
|
||||||
|
'\app\admin\behavior\ApiPermission',
|
||||||
|
'\app\admin\behavior\AdminLog'
|
||||||
|
];
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'[admin]' => [
|
'[admin]' => [
|
||||||
@ -215,6 +219,14 @@ return [
|
|||||||
'admin/AppGroup/changeStatus',
|
'admin/AppGroup/changeStatus',
|
||||||
['method' => 'get', 'after_behavior' => $afterBehavior]
|
['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'],
|
'__miss__' => ['admin/Miss/index'],
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
13
application/model/ApiUserAction.php
Normal file
13
application/model/ApiUserAction.php
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @since 2018-02-11
|
||||||
|
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace app\model;
|
||||||
|
|
||||||
|
|
||||||
|
class ApiUserAction extends Base {
|
||||||
|
|
||||||
|
}
|
8
application/wiki/apiRoute.php
Normal file
8
application/wiki/apiRoute.php
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Api路由
|
||||||
|
*/
|
||||||
|
use think\Route;
|
||||||
|
|
||||||
|
Route::miss('api/Index/index');
|
||||||
|
$afterBehavior = ['\app\api\behavior\ApiAuth', '\app\api\behavior\ApiPermission', '\app\api\behavior\RequestFilter'];
|
0
runtime/index.html
Normal file
0
runtime/index.html
Normal file
Loading…
x
Reference in New Issue
Block a user