load->library('session'); $this->load->_model('Model_setting','setting'); $this->load->_model('Model_user','user'); $this->load->_model("Model_zzrecord_logs",'zzrecord_logs'); $this->load->helper('url'); } } // END Lin_Controller class //前台页面控制器 abstract class Start_Controller extends Lin_Controller { public $data; function __construct() { parent::__construct(); $setting = $this->setting->get_settings(); if(!isset($_SESSION['api']) && $this->uri->slash_segment(1) != "/" && $this->uri->slash_segment(1) != "phone/" && $this->uri->slash_segment(1) != "apt/" && $this->uri->slash_segment(1) != "outbound/" && $this->uri->slash_segment(2) != "isorder/" && $this->uri->slash_segment(2) != "waybill/" && $this->uri->slash_segment(2) != "apple/" && $this->uri->slash_segment(2) != "query/" && $this->uri->slash_segment(2) != "fhd/" && $this->uri->slash_segment(2) != "kc/" && $this->uri->slash_segment(2) != "syns/" && $this->uri->slash_segment(1) != "api/" && $this->uri->slash_segment(2) != "khjz/" && $this->uri->slash_segment(2) != "khjzfs/" && $this->uri->slash_segment(2) != "webhook/" && $this->uri->slash_segment(2) != "ttwebhook/" && $this->uri->slash_segment(2) != "sq/" && $this->uri->slash_segment(2) != "kcpd/"&& $this->uri->slash_segment(1) != "errorlog/" && $this->uri->slash_segment(1) != "apiexpress/" && $this->uri->slash_segment(1) != "apiexpressv1/" && $this->uri->slash_segment(1) != "apitt/" && $this->uri->slash_segment(1) != "queueCbt/" && $this->uri->slash_segment(1) != "zzjobs/" && ( $this->uri->slash_segment(1) != "queueOne/") && ( $this->uri->slash_segment(1) != "queueu9/") && ( $this->uri->slash_segment(1) != "apipf/") && ( $this->uri->slash_segment(1) != "apismt/") && ( $this->uri->slash_segment(1) != "queue/") && ( $this->uri->slash_segment(2) != "tjadd/") && ( $this->uri->slash_segment(2) != "xr/") && ( $this->uri->slash_segment(2) != "yswaybill/") && ( $this->uri->slash_segment(2) != "shopfxlist/")&& ( $this->uri->slash_segment(2) != "cjgx/") && ($this->uri->slash_segment(1) != "whlabelstockup/") )//如果有api { $this->session->sess_destroy(); header("Location:/"); exit("需要添加api免检"); } if(isset($_SESSION['api'])) { $u = $this->user->get_api($_SESSION['api']); if(!$u && $this->uri->slash_segment(1) != "/") { $cont = $this->uri->slash_segment(1); $action = $this->uri->slash_segment(2); if( (strpos($cont,"user") !== false) && (strpos($action,"tc") !== false) ){ header("Location:/"); die("需要重新登录"); }else{ unset($_SESSION['api']); $this->session->sess_destroy(); die("

当前帐号信息变动,请点击右上角的退出。重新登录

"); } } else if($this->uri->slash_segment(1) == "/") { header("Location:/user/"); exit("需要到user里"); } } if(!empty($u)){ // $this->zzrecord_logs->insert([ // 'fpdata'=>json_encode($u), // 'data_int'=>$u['id'], // 'data_str'=>date("Y-m-d H:i:s",time()) // ]); if(!empty($u['id'])){ $this->user->save(['lasttime'=>time()],$u['id']); } } $this->load->library('template'); //设置前台模板路径 $this->template->_init($setting['theme']); //载入自定义函数 $this->load->library('common'); //设置控制器分享参数 $this->setting->primaryKey = 'skey'; //基本信息 $this->data['userkz'] = (isset($u['download']))?$u['download']:1; $this->data['theme'] = '/template/'.$setting['theme'].'/'; $this->data['route'] = $this->uri->segment(1); $this->config->set_item('index_page',''); //后缀index.php为空 $this->config->set_item('url_suffix','');//路径后缀.htmml为空 } /** 载入模版 */ function _template($template, $data = array() ) { $this->template->assign($data); $this->template->display($template); } //前台提示信息 function _message($msg, $goto = '',$auto = true,$fix = '') { if($goto == '') { $goto = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : site_url(); } else { $goto = strpos($goto,'http') !== false ? $goto : site_url($goto); } $goto .= $fix; $this->_template('sys_message',array('msg'=>$msg,'goto'=>$goto,'auto'=>$auto,'ver'=>STAR_NAME.' '.STAR_VERSION)); echo $this->output->get_output(); exit(); } } //后台控制器扩展 abstract class Admin_Controller extends Lin_Controller { public $template_path; public $logined; function __construct() { parent::__construct(); $this->template_path = APPPATH.'views/'; //后台视图路径 //设置后台模板路径 $this->config->set_item('url_suffix',''); //强制不使用伪静态 $this->load->library('session'); //check user login status $this->logined = $this->_check_login(); //载入超级变量 if($this->logined) { $this->_set_s(); } } function _check_login() { if (!$this->session->userdata('uid') ) { $setting = $this->setting->get_settings(); $redirect = $this->uri->uri_string(); //获取后台入口路径 } else { return 1; } } function _check_permit($action = '') { if(!$this->acl->permit($action)) { $this->_message('对不起,你没有访问这里的权限!','',false); } } function _show($template, $data = array()) { $this->load->view($template,$data); } function _template($template, $data = array()) { $cr = ''; $this->load->view($template,$data); $this->output->append_output($cr); } function _set_s(){ $this->load->_model('Model_login'); $this->load->library('common'); $this->S['admin'] = $this->Model_login->get_userid($this->session->userdata('uid')); } } // END Admin_Controller class function made_admin_url($uri,$qs = '') { return site_url('gold'.'/'.$uri).($qs == '' ? '' : '?'.$qs); } abstract class Lyapi_Controller extends CI_Controller { public $cache; public $userinfo; function __construct() { parent::__construct(); $this->load->driver('cache'); $this->cache = $this->cache; // header('Access-Control-Allow-Origin: *'); // header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS'); // header('Access-Control-Allow-Headers: Content-Type, Authorization, X-Requested-With,Auth-Token'); // if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') { // header('HTTP/1.1 200 OK'); // exit(); // } $uri_path = $this->uri->uri_string(); // if($uri_path != "lyapi/v1/user/login"){ // $this->_check_api_auth(); // } if(!in_array($uri_path,["lyapi/v1/user/login","lyapi/v1/wechat/wxlogin"])){ $this->_check_api_auth(); } } function _check_api_auth(){ $auth_token = $this->input->get_request_header('Auth-Token', TRUE); if(empty($auth_token)){ $this->_json_error('请登录',401); } $cache_info = $this->cache->get($auth_token); if(empty($cache_info)){ $this->_json_error('请重新登录',401); } $this->userinfo = $cache_info; $power_name = $this->input->get('p',true); if(!in_array($power_name, $cache_info['power'])){ if($power_name != "gy"){ $this->_json_error('没有权限',403); } } } /** * 统一返回 JSON 错误并终止脚本 */ protected function _json_error($msg, $code = 401,$data = []) { ob_clean(); exit(json_encode([ 'code' => $code, 'msg'=>$msg, 'data' => $data ],JSON_UNESCAPED_UNICODE)); } }