修复一处bug

This commit is contained in:
molong
2021-07-18 21:12:01 +08:00
parent 189cc771c8
commit 45b39943ef

View File

@@ -1,79 +1,79 @@
<?php <?php
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ] // | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved. // | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn> // | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\model; namespace app\model;
use think\Model; use think\Model;
use xin\helper\Server; use xin\helper\Server;
/** /**
* @title: 用户日志模型 * @title: 用户日志模型
*/ */
class MemberLog extends Model { class MemberLog extends Model {
protected $type = [ protected $type = [
'param' => 'json', 'param' => 'json',
'visite_time' => 'timestamp', 'visite_time' => 'timestamp',
]; ];
public static function record($request) { public static function record($request) {
$data = [ $data = [
'uid' => $request->user['uid'] ? $request->user['uid'] : 0, 'uid' => isset($request->user['uid']) ? $request->user['uid'] : 0,
'title' => self::getCurrentTitle($request), 'title' => self::getCurrentTitle($request),
'url' => $request->baseUrl(), 'url' => $request->baseUrl(),
'param' => $request->param(), 'param' => $request->param(),
'method' => $request->method(), 'method' => $request->method(),
'visite_time' => $request->time(), 'visite_time' => $request->time(),
'client_ip' => Server::getRemoteIp(), 'client_ip' => Server::getRemoteIp(),
'create_time' => time(), 'create_time' => time(),
]; ];
self::create($data); self::create($data);
} }
public function getMemberLogList($request) { public function getMemberLogList($request) {
$param = $request->param(); $param = $request->param();
$map = []; $map = [];
$order = "id desc"; $order = "id desc";
return self::with(['user'])->where($map)->order($order)->paginate($request->pageConfig); return self::with(['user'])->where($map)->order($order)->paginate($request->pageConfig);
} }
public function user() { public function user() {
return $this->hasOne('Member', 'uid', 'uid')->field('uid,nickname,username'); return $this->hasOne('Member', 'uid', 'uid')->field('uid,nickname,username');
} }
protected static function getCurrentTitle($request) { protected static function getCurrentTitle($request) {
$mate = ''; $mate = '';
$controller = strtr(strtolower($request->controller()), '.', '\\'); $controller = strtr(strtolower($request->controller()), '.', '\\');
$action = $request->action(); $action = $request->action();
$class = "\\app\\controller\\" . $controller; $class = "\\app\\controller\\" . $controller;
if (class_exists($class)) { if (class_exists($class)) {
$reflection = new \ReflectionClass($class); $reflection = new \ReflectionClass($class);
$group_doc = self::Parser($reflection->getDocComment()); $group_doc = self::Parser($reflection->getDocComment());
if (isset($group_doc['title'])) { if (isset($group_doc['title'])) {
$mate = $group_doc['title']; $mate = $group_doc['title'];
} }
$method = $reflection->getMethods(\ReflectionMethod::IS_FINAL | \ReflectionMethod::IS_PUBLIC); $method = $reflection->getMethods(\ReflectionMethod::IS_FINAL | \ReflectionMethod::IS_PUBLIC);
foreach ($method as $key => $v) { foreach ($method as $key => $v) {
if ($action == $v->name) { if ($action == $v->name) {
$title_doc = self::Parser($v->getDocComment()); $title_doc = self::Parser($v->getDocComment());
if (isset($title_doc['title'])) { if (isset($title_doc['title'])) {
$mate = $title_doc['title']; $mate = $title_doc['title'];
} }
} }
} }
} }
return $mate; return $mate;
} }
protected static function Parser($text) { protected static function Parser($text) {
$doc = new \doc\Doc(); $doc = new \doc\Doc();
return $doc->parse($text); return $doc->parse($text);
} }
} }