SysMenu.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. namespace app\model;
  3. use think\Model;
  4. use think\facade\Db;
  5. class SysMenu extends Model
  6. {
  7. public static function getUserMenuList($rid)
  8. {
  9. if ($rid === 1) { // 超级管理员
  10. $data = self::field('id, pid, name, url, type, icon')->select();
  11. } else {
  12. $roleModel = new SysRole();
  13. $permission_ids = $roleModel->getpermissionIds($rid);
  14. $data = self::where('id', 'IN', $permission_ids)->field('id, pid, name, url, icon')->select();
  15. }
  16. return list_tree($data);
  17. }
  18. public static function queryButtonPermissionsByRoleid($rid)
  19. {
  20. if ($rid === 1) { // 超级管理员
  21. $data = self::where('type', 2)->column('url');
  22. } else {
  23. $roleModel = new SysRole();
  24. $permission_ids = $roleModel->getpermissionIds($rid);
  25. $data = self::where('id', 'IN', $permission_ids)->where('type', 2)->column('url');
  26. }
  27. return $data;
  28. }
  29. /**
  30. * 面包屑
  31. */
  32. public static function getBreadCrumb($route)
  33. {
  34. $active = \app\model\SysMenu::where('url', $route)->find();
  35. $active_pid = 0;
  36. $breadCrumb = [];
  37. if ($active) {
  38. $active_pid = $active->pid;
  39. $result = \app\model\SysMenu::find($active_pid);
  40. // 如果还有上级
  41. if ($result) {
  42. $res = \app\model\SysMenu::find($result->pid);
  43. // 如果还有上级
  44. if ($res) {
  45. $active_pid = $result->pid;
  46. $breadCrumb[] = [
  47. 'url' => $res['url'],
  48. 'title' => $res['name'],
  49. ];
  50. }
  51. $breadCrumb[] = [
  52. 'url' => $result['url'],
  53. 'title' => $result['name'],
  54. ];
  55. }
  56. $breadCrumb[] = [
  57. 'url' => $active['url'],
  58. 'title' => $active['name'],
  59. ];
  60. } else {
  61. $breadCrumb[] = [
  62. 'url' => null,
  63. 'title' => '我的桌面',
  64. ];
  65. }
  66. return [
  67. 'active_pid' => $active_pid,
  68. 'breadCrumb' => $breadCrumb
  69. ];
  70. }
  71. /**
  72. * 后台首页快捷方式
  73. */
  74. public static function getIndexButton()
  75. {
  76. return self::where('index_button', 1)->where('type', 1)->select();
  77. }
  78. public static function getMenuList()
  79. {
  80. return self::where('type', 1)->select();
  81. }
  82. }