SystemMenusDao.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\dao\system;
  12. use app\dao\BaseDao;
  13. use app\model\system\SystemMenus;
  14. /**
  15. * 菜单dao层
  16. * Class SystemMenusDao
  17. * @package app\dao\system
  18. */
  19. class SystemMenusDao extends BaseDao
  20. {
  21. /**
  22. * 设置模型
  23. * @return string
  24. */
  25. protected function setModel(): string
  26. {
  27. return SystemMenus::class;
  28. }
  29. /**
  30. * 获取权限菜单列表
  31. * @param array $where
  32. * @param array $field
  33. * @return \think\Collection
  34. * @throws \think\db\exception\DataNotFoundException
  35. * @throws \think\db\exception\DbException
  36. * @throws \think\db\exception\ModelNotFoundException
  37. */
  38. public function getMenusRoule(array $where, ?array $field = [])
  39. {
  40. if (!$field) {
  41. $field = ['id', 'menu_name', 'icon', 'pid', 'sort', 'menu_path', 'is_show', 'header', 'is_header', 'is_show_path'];
  42. }
  43. $res = $this->search($where)->field($field)->order('sort DESC,id DESC')->failException(false)->select();
  44. return $res;
  45. }
  46. /**
  47. * 获取菜单中的唯一权限
  48. * @param array $where
  49. * @return array
  50. */
  51. public function getMenusUnique(array $where)
  52. {
  53. return $this->search($where)->where('unique_auth', '<>', '')->column('unique_auth', '');
  54. }
  55. /**
  56. * 根据访问地址获得菜单名
  57. * @param string $rule
  58. * @return mixed
  59. */
  60. public function getVisitName(string $rule)
  61. {
  62. return $this->search(['url' => $rule])->value('menu_name');
  63. }
  64. /**
  65. * 获取后台菜单列表并分页
  66. * @param array $where
  67. * @return \think\Collection
  68. * @throws \think\db\exception\DataNotFoundException
  69. * @throws \think\db\exception\DbException
  70. * @throws \think\db\exception\ModelNotFoundException
  71. */
  72. public function getMenusList(array $where)
  73. {
  74. $where = array_merge($where, ['is_del' => 0]);
  75. return $this->search($where)->order('sort DESC,id ASC')->select();
  76. }
  77. /**
  78. * 菜单总数
  79. * @param array $where
  80. * @return int
  81. */
  82. public function countMenus(array $where)
  83. {
  84. $where = array_merge($where, ['is_del' => 0]);
  85. return $this->count($where);
  86. }
  87. /**
  88. * 指定条件获取某些菜单的名称以数组形式返回
  89. * @param array $where
  90. * @param string $field
  91. * @param string $key
  92. * @return array
  93. */
  94. public function column(array $where, string $field, string $key)
  95. {
  96. return $this->search($where)->column($field, $key);
  97. }
  98. /**菜单列表
  99. * @param array $where
  100. * @param int $type
  101. * @return \think\Collection
  102. * @throws \think\db\exception\DataNotFoundException
  103. * @throws \think\db\exception\DbException
  104. * @throws \think\db\exception\ModelNotFoundException
  105. */
  106. public function menusSelect(array $where, $type = 1)
  107. {
  108. if ($type == 1) {
  109. return $this->search($where)->field('id,pid,menu_name,menu_path,unique_auth,sort')->order('sort DESC')->select();
  110. } else {
  111. return $this->search($where)->group('pid')->column('pid');
  112. }
  113. }
  114. /**
  115. * 搜索列表
  116. * @param int $type
  117. * @return \think\Collection
  118. * @throws \think\db\exception\DataNotFoundException
  119. * @throws \think\db\exception\DbException
  120. * @throws \think\db\exception\ModelNotFoundException
  121. */
  122. public function getSearchList($type = 1)
  123. {
  124. return $this->search(['is_show' => 1, 'auth_type' => 1, 'is_del' => 0, 'is_show_path' => 0])->where('type', $type)
  125. ->field('id,pid,menu_name,menu_path,unique_auth,sort')->order('sort DESC')->select();
  126. }
  127. }