| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 | <?php/** * +---------------------------------------------------------------------- * | 管理员日志模型 * +---------------------------------------------------------------------- */namespace app\common\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()    {        // 入库信息        $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');        // 标题处理        $route = strtolower(preg_replace('/(?<=[a-z])([A-Z])/', '_$1', Request::controller())) . '/' . strtolower(preg_replace('/(?<=[a-z])([A-Z])/', '_$1', Request::action()));                $active =  \app\common\model\SysMenu::where('url', $route)->find();        $title =  $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                ]);            }        }    }}
 |