123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- <?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);
- }
- }
- }
|