SysMenu.php 2.9 KB

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