AdminBaseController.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace app\admin;
  3. use app\BaseController;
  4. use app\common\model\AdminModel;
  5. use app\common\model\MenuModel;
  6. use think\facade\Session;
  7. use think\facade\View;
  8. /**
  9. * 控制器基础类
  10. */
  11. class AdminBaseController extends BaseController
  12. {
  13. // 初始化
  14. protected function initialize()
  15. {
  16. // 验证登陆信息
  17. $access_admin = session('access_admin');
  18. if (!$access_admin) {
  19. $this->adminReturn('请重新登录');
  20. }
  21. // 验证权限
  22. if ($access_admin['role'] != AdminModel::ROLE_SUPER && $this->request->controller() != 'Home') {
  23. $url = mb_strtolower($this->request->controller() . '/' . $this->request->action());
  24. $check = MenuModel::where('urlstr', $url)->find();
  25. if (!empty($check)) {
  26. $url_ids = explode(',',$access_admin['powerids']);
  27. if (!in_array($check['id'],$url_ids)) {
  28. $this->adminReturn('您没有访问权限');
  29. }
  30. if ($check['status'] == MenuModel::STATUS_DISABLE) {
  31. $this->adminReturn('您没有访问权限');
  32. }
  33. }
  34. }
  35. $lay = mb_strtolower($this->request->controller()) . '-' . $this->request->action();
  36. $lay_table = "lay-{$lay}-table";
  37. $lay_btn = "lay-{$lay}-btn";
  38. View::assign([
  39. 'lay_table' => $lay_table,
  40. 'lay_btn' => $lay_btn,
  41. ]);
  42. }
  43. /**
  44. * 返回
  45. */
  46. protected function adminReturn($msg)
  47. {
  48. if ($this->request->isAjax()) {
  49. ajax_return(1001, $msg);
  50. } else {
  51. $content = '<script language="javascript" type="text/javascript"> top.location.href="/admin/login/index"; </script>';
  52. $response = \think\Response::create($content);
  53. throw new \think\exception\HttpResponseException($response);
  54. }
  55. }
  56. }