AdminBaseController.php 1.9 KB

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