CommonController.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2018/2/26/026
  6. * Time: 9:56
  7. */
  8. namespace frontend\base;
  9. use yii\web\Controller;
  10. use Yii;
  11. class CommonController extends Controller
  12. {
  13. public function init()
  14. {
  15. parent::init(); // TODO: Change the autogenerated stub
  16. // \common\api\IpInfoServer::LimitIp();
  17. //判断手机
  18. $mobile = is_mobile();
  19. if($mobile === true)
  20. {
  21. $strUrl = '';
  22. if(isset($_SERVER['REQUEST_URI']) && $_SERVER['REQUEST_URI'] != 'fresh/home')
  23. {
  24. $strUrl = $_SERVER['REQUEST_URI'];
  25. }
  26. header('Location:http://m.yigouf.com'.$strUrl);
  27. exit ;
  28. }
  29. $server = new \common\api\HttpServer();
  30. Yii::$app->queue->push(
  31. new \common\fm\HttpRequestRecord(['equipment'=>2,'ip'=>Yii::$app->request->userIP,
  32. 'referer'=> $server->GetReferer(),'self_url'=> $server->GetCurUrl(),'agent'=>$server->getAgentInfo()])
  33. );
  34. $view = Yii::$app->view;
  35. $hostName = Yii::$app->request->getHostName();
  36. $num = substr_count($hostName,'.');
  37. switch ($num)
  38. {
  39. case 1:
  40. $view->params['main_city_url'] = $hostName;
  41. break;
  42. case 2:
  43. $hostName = explode('.',$hostName);
  44. $view->params['main_city_url'] = $hostName[1].'.'.$hostName[2];;
  45. break;
  46. }
  47. $city = new \common\models\CategoryCity();
  48. $city->pid = 0;
  49. $city->state = 1;
  50. $view->params['main_city'] = $city->getList([]);
  51. //国内
  52. $city->pid = 0;
  53. $city->state = 1;
  54. $city->del = 1;
  55. $city->abroad = 1;
  56. $view->params['city_within'] = $city->getList([]);
  57. //国外
  58. $city->abroad = 2;
  59. $view->params['city_abroad'] = $city->getList([]);
  60. $view->params['nav_cityname'] = '全国';
  61. if(Yii::$app->hostserver->hostId != 0)
  62. {
  63. $view->params['nav_cityname'] = $city->FindById(Yii::$app->hostserver->hostId)['city_name'];
  64. }
  65. //导航栏
  66. $sysmenu = new \common\models\Frontend();
  67. $sysmenu->pid = 4;
  68. $view->params['sysmenu'] = $sysmenu->SonList(7,['name','url','icon','function']);
  69. // echo '维护中';
  70. // exit;
  71. }
  72. // public function beforeAction($action)
  73. // {
  74. // if(empty(Yii::$app->session['user_info'])){
  75. // echo "<script>alert('请登录!');window.parent.location.href='".'/public/login'."'</script>";
  76. // return false;
  77. // }
  78. //
  79. // //异地登录
  80. // $model = new \backend\server\Checkauthority();
  81. // $unique = $model->UniqueToken();
  82. // // if($unique == false)
  83. // // {
  84. // // echo "<script>alert('检测到该账号已在别的电脑登录!');window.parent.location.href='".'/public/logout'."'</script>";
  85. // // return false;
  86. // // }
  87. // //超级管理员
  88. // if(Yii::$app->session['user_info']['user'] === Yii::$app->params['UserSuperadministrator']) return true;
  89. //
  90. //
  91. // //权限控制
  92. // $controller = strtolower(Yii::$app->controller->id);
  93. // $action = strtolower(Yii::$app->controller->action->id);
  94. // if($model->Comparison($controller,$action) === true)
  95. // {
  96. // return true;
  97. // }
  98. //
  99. // if(Yii::$app->request->isAjax)
  100. // {
  101. // $list['code'] = 500;
  102. // $list['msg'] = '暂无操作权限';
  103. // $list['data'] = '';
  104. // echo json_encode($list);
  105. // return false;
  106. // }
  107. //// echo '<script>alert("暂无权限操作!")</script>';
  108. // return false;
  109. // }
  110. }