更新
This commit is contained in:
94
app/services/auth/UsersLogService.php
Normal file
94
app/services/auth/UsersLogService.php
Normal file
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\services\auth;
|
||||
|
||||
use app\model\auth\Users;
|
||||
use app\model\auth\UsersLog;
|
||||
use xin\helper\Server;
|
||||
|
||||
class UsersLogService{
|
||||
|
||||
/**
|
||||
* @title 获取用户操作日志
|
||||
*
|
||||
* @param [type] $request
|
||||
* @return void
|
||||
*/
|
||||
public function getUserLogList($request){
|
||||
$param = $request->param();
|
||||
$map = [];
|
||||
if(isset($param['method']) && $param['method']){
|
||||
$map[] = ['method', '=', strtoupper($param['method'])];
|
||||
}
|
||||
if(isset($param['date']) && $param['date'] && count($param['date']) == 2){
|
||||
$map[] = ['create_time', 'BETWEEN TIME', $param['date']];
|
||||
}
|
||||
|
||||
$list = UsersLog::with(['user'])->where($map)->order('create_time desc')->paginate($request->pageConfig);
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 用户操作记录
|
||||
*
|
||||
* @param [type] $request
|
||||
* @param integer $code
|
||||
* @return void
|
||||
*/
|
||||
public function record($request, $code = 200){
|
||||
$param = array_merge($request->get(), $request->post());
|
||||
|
||||
if(!isset($request->user['uid'])){
|
||||
return false;
|
||||
}
|
||||
$data = [
|
||||
'uid' => isset($request->user['uid']) ? $request->user['uid'] : '',
|
||||
'title' => self::getCurrentTitle($request),
|
||||
'route' => $request->baseUrl(),
|
||||
'params' => json_encode($param),
|
||||
'method' => $request->method(),
|
||||
'client_ip' => Server::getRemoteIp(),
|
||||
'browser' => $request->header('user-agent'),
|
||||
'code' => $code
|
||||
];
|
||||
if($data['route'] == '/admin/system/log/index'){
|
||||
return false;
|
||||
}
|
||||
UsersLog::create($data);
|
||||
}
|
||||
|
||||
protected static function getCurrentTitle($request) {
|
||||
$mate = '';
|
||||
$controller = strtr(strtolower($request->controller()), '.', '\\');
|
||||
$action = $request->action();
|
||||
$class = "\\app\\controller\\" . $controller;
|
||||
if (class_exists($class)) {
|
||||
$reflection = new \ReflectionClass($class);
|
||||
$group_doc = self::Parser($reflection->getDocComment());
|
||||
if (isset($group_doc['title'])) {
|
||||
$mate = $group_doc['title'];
|
||||
}
|
||||
$method = $reflection->getMethods(\ReflectionMethod::IS_FINAL | \ReflectionMethod::IS_PUBLIC);
|
||||
foreach ($method as $key => $v) {
|
||||
if ($action == $v->name) {
|
||||
$title_doc = self::Parser($v->getDocComment());
|
||||
if (isset($title_doc['title'])) {
|
||||
$mate = isset($title_doc['title']) ? $title_doc['title'] : '';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $mate;
|
||||
}
|
||||
|
||||
protected static function Parser($text) {
|
||||
$doc = new \doc\Doc();
|
||||
return $doc->parse($text);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user