CommonController.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2018/2/26/026
  6. * Time: 9:56
  7. */
  8. namespace backend\base;
  9. use yii\web\Controller;
  10. use Yii;
  11. class CommonController extends Controller
  12. {
  13. public function beforeAction($action)
  14. {
  15. if(empty(Yii::$app->session['user_info'])){
  16. echo "<script>window.parent.location.href='".'/public/login'."'</script>";
  17. return false;
  18. }
  19. //异地登录
  20. $model = new \backend\server\Checkauthority();
  21. $unique = $model->UniqueToken();
  22. // if($unique == false)
  23. // {
  24. // echo "<script>alert('检测到该账号已在别的电脑登录!');window.parent.location.href='".'/public/logout'."'</script>";
  25. // return false;
  26. // }
  27. //超级管理员
  28. // if(Yii::$app->session['user_info']['user'] === Yii::$app->params['UserSuperadministrator']) return true;
  29. //权限控制
  30. $controller = strtolower(Yii::$app->controller->id);
  31. $action = strtolower(Yii::$app->controller->action->id);
  32. if(Yii::$app->session['user_info']['user'] === Yii::$app->params['UserSuperadministrator'] || $model->Comparison($controller,$action) === true )
  33. {
  34. $record = new \common\models\UserOperationrecord();
  35. $record->uid = Yii::$app->session['user_info']['uid'];
  36. $record->controller = $controller;
  37. $record->action = $action;
  38. $record->save();
  39. return true;
  40. }
  41. if(Yii::$app->request->isAjax)
  42. {
  43. $list['code'] = 500;
  44. $list['msg'] = '暂无操作权限';
  45. $list['data'] = '';
  46. echo json_encode($list);
  47. return false;
  48. }
  49. // echo '<script>alert("暂无权限操作!")</script>';
  50. return false;
  51. }
  52. }