|
<?php
namespace app\controller;
use app\BaseController;
use think\App;
use think\facade\Db;
class Base extends BaseController
{
protected $uid;
protected $username;
protected $limit;
public function __construct(App $app)
{
parent::__construct($app);
// //判断是否登陆
if (!session('?uid')) {
$this->error('您还没有登录, 请登录', '/login');
}
// // 登录用户信息
$this->uid = session('uid');
$this->username = session('username');
$this->limit = $this->request->cookie('limit') ? : 50;
//记录日志
$this->addLog();
}
/**
* 记录日志
*/
private function addLog()
{
$data = [];
$data['querystring'] = $this->app->request->query()?'?'.$this->app->request->query():'';
$data['c'] = $this->app->request->controller();
$data['a'] = $this->app->request->action();
$data['userid'] = $this->uid;
$data['username'] = $this->username;
$data['ip'] = $this->app->request->ip();
$data['time'] = time();
$arr = ['Index/index','SysLog/index'];
if (!in_array($data['c'].'/'.$data['a'], $arr)) {
Db::name('sys_log')->insert($data);
}
}
}
|