<?php
namespace app\index\controller;

use app\index\model\ActionLogModel;
use think\Controller;

class Base extends Controller{
    const redis_host = 'tcp://lredis';
    const redis_port = 6379;
    const queue_name = 'net_access_queue';
    private $no_check = ['order/checkorder' , 'order/recordstore' , 'order/checkfcode' , 'order/recordfetch' , 'cabinet/getcabinetsboxs' , 'cabinet/boxchangestatus'];

    public function initialize(){
        $control = lcfirst(request()->controller());
        $action = lcfirst(request()->action());
        if(!in_array($control . '/' . $action , $this->no_check)){
            if(empty(session('username')) || empty(session('id'))){
                //登录超时
                json(json_error_exception('1005'))->send();
            }
        }
    }

    protected function action_log(){
        $control = lcfirst(request()->controller());
        $action = lcfirst(request()->action());

        $ActionLogModel = new ActionLogModel();
        $params['admin_id']             = session('id');
        $params['username']             = session('username');
        $params['content']              = $control . '/' . $action;
        $params['ip']                   = request()->ip();
        $params['date']                 = date("Y-m-d H:i:s");
        $ActionLogModel->save($params);
    }
}