Lin_Controller.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. /** STAR 核心控制类扩展 */
  3. define('IN_STAR',TRUE);
  4. define('STAR_NAME','STAR');
  5. define('STAR_VERSION','V1.0.00');
  6. define('STAR_BUILDTIME','201801011');
  7. // ------------------------------------------------------------------------
  8. class Lin_Controller extends CI_Controller {
  9. public $setting;
  10. public $S;
  11. //初始化扩展控制类
  12. function __construct()
  13. {
  14. parent::__construct();
  15. //载入配置
  16. $this->load->library('session');
  17. $this->load->_model('Model_setting','setting');
  18. $this->load->_model('Model_user','user');
  19. $this->load->_model("Model_zzrecord_logs",'zzrecord_logs');
  20. $this->load->helper('url');
  21. }
  22. }
  23. // END Lin_Controller class
  24. //前台页面控制器
  25. abstract class Start_Controller extends Lin_Controller {
  26. public $data;
  27. function __construct()
  28. {
  29. parent::__construct();
  30. $setting = $this->setting->get_settings();
  31. 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
  32. {
  33. $this->session->sess_destroy();
  34. header("Location:/");
  35. exit("需要添加api免检");
  36. }
  37. if(isset($_SESSION['api']))
  38. {
  39. $u = $this->user->get_api($_SESSION['api']);
  40. if(!$u && $this->uri->slash_segment(1) != "/")
  41. {
  42. $cont = $this->uri->slash_segment(1);
  43. $action = $this->uri->slash_segment(2);
  44. if( (strpos($cont,"user") !== false) && (strpos($action,"tc") !== false) ){
  45. header("Location:/");
  46. die("需要重新登录");
  47. }else{
  48. unset($_SESSION['api']);
  49. $this->session->sess_destroy();
  50. die("<h1>当前帐号信息变动,请点击右上角的退出。重新登录</h1>");
  51. }
  52. }
  53. else if($this->uri->slash_segment(1) == "/")
  54. {
  55. header("Location:/user/");
  56. exit("需要到user里");
  57. }
  58. }
  59. if(!empty($u)){
  60. // $this->zzrecord_logs->insert([
  61. // 'fpdata'=>json_encode($u),
  62. // 'data_int'=>$u['id'],
  63. // 'data_str'=>date("Y-m-d H:i:s",time())
  64. // ]);
  65. if(!empty($u['id'])){
  66. $this->user->save(['lasttime'=>time()],$u['id']);
  67. }
  68. }
  69. $this->load->library('template');
  70. //设置前台模板路径
  71. $this->template->_init($setting['theme']);
  72. //载入自定义函数
  73. $this->load->library('common');
  74. //设置控制器分享参数
  75. $this->setting->primaryKey = 'skey';
  76. //基本信息
  77. $this->data['userkz'] = (isset($u['download']))?$u['download']:1;
  78. $this->data['theme'] = '/template/'.$setting['theme'].'/';
  79. $this->data['route'] = $this->uri->segment(1);
  80. $this->config->set_item('index_page',''); //后缀index.php为空
  81. $this->config->set_item('url_suffix','');//路径后缀.htmml为空
  82. }
  83. /** 载入模版 */
  84. function _template($template, $data = array() )
  85. {
  86. $this->template->assign($data);
  87. $this->template->display($template);
  88. }
  89. //前台提示信息
  90. function _message($msg, $goto = '',$auto = true,$fix = '')
  91. {
  92. if($goto == '')
  93. {
  94. $goto = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : site_url();
  95. }
  96. else
  97. {
  98. $goto = strpos($goto,'http') !== false ? $goto : site_url($goto);
  99. }
  100. $goto .= $fix;
  101. $this->_template('sys_message',array('msg'=>$msg,'goto'=>$goto,'auto'=>$auto,'ver'=>STAR_NAME.' '.STAR_VERSION));
  102. echo $this->output->get_output();
  103. exit();
  104. }
  105. }
  106. //后台控制器扩展
  107. abstract class Admin_Controller extends Lin_Controller {
  108. public $template_path;
  109. public $logined;
  110. function __construct()
  111. {
  112. parent::__construct();
  113. $this->template_path = APPPATH.'views/'; //后台视图路径
  114. //设置后台模板路径
  115. $this->config->set_item('url_suffix',''); //强制不使用伪静态
  116. $this->load->library('session');
  117. //check user login status
  118. $this->logined = $this->_check_login();
  119. //载入超级变量
  120. if($this->logined)
  121. {
  122. $this->_set_s();
  123. }
  124. }
  125. function _check_login()
  126. {
  127. if (!$this->session->userdata('uid') )
  128. {
  129. $setting = $this->setting->get_settings();
  130. $redirect = $this->uri->uri_string(); //获取后台入口路径
  131. }
  132. else
  133. {
  134. return 1;
  135. }
  136. }
  137. function _check_permit($action = '')
  138. {
  139. if(!$this->acl->permit($action))
  140. {
  141. $this->_message('对不起,你没有访问这里的权限!','',false);
  142. }
  143. }
  144. function _show($template, $data = array())
  145. {
  146. $this->load->view($template,$data);
  147. }
  148. function _template($template, $data = array())
  149. {
  150. $cr = '</body></html>';
  151. $this->load->view($template,$data);
  152. $this->output->append_output($cr);
  153. }
  154. function _set_s(){
  155. $this->load->_model('Model_login');
  156. $this->load->library('common');
  157. $this->S['admin'] = $this->Model_login->get_userid($this->session->userdata('uid'));
  158. }
  159. }
  160. // END Admin_Controller class
  161. function made_admin_url($uri,$qs = '')
  162. {
  163. return site_url('gold'.'/'.$uri).($qs == '' ? '' : '?'.$qs);
  164. }
  165. abstract class Lyapi_Controller extends CI_Controller {
  166. public $cache;
  167. public $userinfo;
  168. function __construct()
  169. {
  170. parent::__construct();
  171. $this->load->driver('cache');
  172. $this->cache = $this->cache;
  173. // header('Access-Control-Allow-Origin: *');
  174. // header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS');
  175. // header('Access-Control-Allow-Headers: Content-Type, Authorization, X-Requested-With,Auth-Token');
  176. // if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
  177. // header('HTTP/1.1 200 OK');
  178. // exit();
  179. // }
  180. $uri_path = $this->uri->uri_string();
  181. // if($uri_path != "lyapi/v1/user/login"){
  182. // $this->_check_api_auth();
  183. // }
  184. if(!in_array($uri_path,["lyapi/v1/user/login","lyapi/v1/wechat/wxlogin","lyapi/v1/yyys/lyysmsghz"])){
  185. $this->_check_api_auth();
  186. }
  187. }
  188. function _check_api_auth(){
  189. $auth_token = $this->input->get_request_header('Auth-Token', TRUE);
  190. if(empty($auth_token)){
  191. $this->_json_error('请登录',401);
  192. }
  193. $cache_info = $this->cache->get($auth_token);
  194. if(empty($cache_info)){
  195. $this->_json_error('请重新登录',401);
  196. }
  197. $this->userinfo = $cache_info;
  198. $power_name = $this->input->get('p',true);
  199. if(!in_array($power_name, $cache_info['power'])){
  200. if($power_name != "gy"){
  201. $this->_json_error('没有权限',403);
  202. }
  203. }
  204. }
  205. /**
  206. * 统一返回 JSON 错误并终止脚本
  207. */
  208. protected function _json_error($msg, $code = 401,$data = []) {
  209. ob_clean();
  210. exit(json_encode([
  211. 'code' => $code,
  212. 'msg'=>$msg,
  213. 'data' => $data
  214. ],JSON_UNESCAPED_UNICODE));
  215. }
  216. }