Auth.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace app\admin\controller;
  3. use think\Db;
  4. class Auth extends Base
  5. {
  6. public $userId;
  7. public $orgId;
  8. public $rolesId;
  9. protected function initialize()
  10. {
  11. if(!is_login()){
  12. if(request()->isAjax()){
  13. $this->error('未登录,请先登录');
  14. }else{
  15. $url = request()->domain().'/common/login.html';
  16. $this->redirect($url);
  17. }
  18. }
  19. $this->userId = is_login();
  20. $this->orgId = cur_org_id();
  21. $user = session('user_auth');
  22. $this->rolesId = !empty($user)&&isset($user['rolesId'])?$user['rolesId']:0;
  23. $this->assign('rolesId',$this->rolesId);
  24. // 检查是否有紧急事件
  25. $info = Db::name('burst_record')
  26. ->where('user_id',$this->userId)
  27. ->where('status',1)
  28. ->where('del',0)
  29. ->find();
  30. if($info){
  31. $this->redirect(url('Bursting/index'));
  32. }
  33. parent::initialize();
  34. }
  35. public function getTableField($table,$where,$field){
  36. $val = Db::name($table)
  37. ->where($where)
  38. ->value($field);
  39. return $val;
  40. }
  41. }