Lin_Controller.php 7.8 KB

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