| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 | <?php/** * +---------------------------------------------------------------------- * | 管理员日志模型 * +---------------------------------------------------------------------- */namespace app\model;// 引入框架内置类use think\Model;use think\facade\Request;use think\facade\Session;class SysLog extends Model{    // 获取列表    public static function queryPage(int $pageSize = 0)    {        $list = self::order('id desc')->paginate($pageSize);                return $list;    }    // 管理员日志记录    public static function record($route = "")    {        // 入库信息        $userid   = Session::get('adminuser.userid', 0);        $username   = Session::get('adminuser.username', '');        $url       = Request::url();        $title     = '';        $content   = Request::except(['s', '_pjax']); //s 变量为系统内置的变量,_pjax为js的变量,无记录的必要        $ip        = Request::ip();        $userAgent = Request::server('HTTP_USER_AGENT');        // 标题处理        $active = \app\model\SysMenu::where('url', $route)->find();        $title =  $active != null ? $active['name'] : "";        // 内容处理(过长的内容和涉及密码的内容不进行记录)        if ($content) {            foreach ($content as $k => $v) {                if (is_string($v) && strlen($v) > 200 || stripos($k, 'password') !== false || stripos($k, 'newpassword') !== false || stripos($k, 'repassword') !== false) {                    unset($content[$k]);                }            }        }        // 插入数据        if (!empty($title)) {            // 查询管理员上一条数据            $result = self::where('userid', '=', $userid)                ->order('id', 'desc')                ->find();            if ($result) {                if ($result->url != $url) {                    self::create([                        'title'      => $title ? $title : '',                        'username'   => $username,                        'content'    => ! is_scalar($content) ? json_encode($content, JSON_UNESCAPED_UNICODE) : $content,                        'url'        => $url,                        'userid'   => $userid,                        'user_agent' => $userAgent,                        'ip'         => $ip                    ]);                }            } else {                self::create([                    'title'      => $title ? $title : '',                    'username'   => $username,                    'content'    => ! is_scalar($content) ? json_encode($content, JSON_UNESCAPED_UNICODE) : $content,                    'url'        => $url,                    'userid'   => $userid,                    'user_agent' => $userAgent,                    'ip'         => $ip                ]);            }        }    }}
 |