SystemMenusDao.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 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. * @param array $menusIds
  31. * @return bool
  32. * @author 等风来
  33. * @email 136327134@qq.com
  34. * @date 2023/4/13
  35. */
  36. public function deleteMenus(array $menusIds)
  37. {
  38. return $this->getModel()->whereIn('id', $menusIds)->delete();
  39. }
  40. /**
  41. * 获取权限菜单列表
  42. * @param array $where
  43. * @param array $field
  44. * @return \think\Collection
  45. * @throws \think\db\exception\DataNotFoundException
  46. * @throws \think\db\exception\DbException
  47. * @throws \think\db\exception\ModelNotFoundException
  48. */
  49. public function getMenusRoule(array $where, ?array $field = [])
  50. {
  51. if (!$field) {
  52. $field = ['id', 'menu_name', 'icon', 'pid', 'sort', 'menu_path', 'is_show', 'header', 'is_header', 'is_show_path', 'is_show'];
  53. }
  54. return $this->search($where)->field($field)->order('sort DESC,id DESC')->failException(false)->select();
  55. }
  56. /**
  57. * 获取菜单中的唯一权限
  58. * @param array $where
  59. * @return array
  60. */
  61. public function getMenusUnique(array $where)
  62. {
  63. return $this->search($where)->where('unique_auth', '<>', '')->column('unique_auth', '');
  64. }
  65. /**
  66. * 根据访问地址获得菜单名
  67. * @param string $rule
  68. * @return mixed
  69. */
  70. public function getVisitName(string $rule)
  71. {
  72. return $this->search(['url' => $rule])->value('menu_name');
  73. }
  74. /**
  75. * 获取后台菜单列表并分页
  76. * @param array $where
  77. * @return \think\Collection
  78. * @throws \think\db\exception\DataNotFoundException
  79. * @throws \think\db\exception\DbException
  80. * @throws \think\db\exception\ModelNotFoundException
  81. */
  82. public function getMenusList(array $where, array $field = ['*'])
  83. {
  84. $where = array_merge($where, ['is_del' => 0]);
  85. return $this->search($where)->field($field)->order('sort DESC,id ASC')->select();
  86. }
  87. /**
  88. * 菜单总数
  89. * @param array $where
  90. * @return int
  91. */
  92. public function countMenus(array $where)
  93. {
  94. $where = array_merge($where, ['is_del' => 0]);
  95. return $this->count($where);
  96. }
  97. /**
  98. * 指定条件获取某些菜单的名称以数组形式返回
  99. * @param array $where
  100. * @param string $field
  101. * @param string $key
  102. * @return array
  103. */
  104. public function column(array $where, string $field, string $key = '')
  105. {
  106. return $this->search($where)->column($field, $key);
  107. }
  108. /**菜单列表
  109. * @param array $where
  110. * @param int $type
  111. * @return \think\Collection
  112. * @throws \think\db\exception\DataNotFoundException
  113. * @throws \think\db\exception\DbException
  114. * @throws \think\db\exception\ModelNotFoundException
  115. */
  116. public function menusSelect(array $where, $type = 1)
  117. {
  118. if ($type == 1) {
  119. return $this->search($where)->field('id,pid,menu_name,menu_path,unique_auth,sort')->order('sort DESC,id DESC')->select();
  120. } else {
  121. return $this->search($where)->group('pid')->column('pid');
  122. }
  123. }
  124. /**
  125. * 搜索列表
  126. * @throws \think\db\exception\DataNotFoundException
  127. * @throws \think\db\exception\DbException
  128. * @throws \think\db\exception\ModelNotFoundException
  129. */
  130. public function getSearchList()
  131. {
  132. return $this->search(['is_show' => 1, 'auth_type' => 1, 'is_del' => 0, 'is_show_path' => 0])
  133. ->field('id,pid,menu_name,menu_path,unique_auth,sort')->order('sort DESC,id DESC')->select();
  134. }
  135. /**
  136. * @param string $path
  137. * @param string $method
  138. * @return bool
  139. * @author 等风来
  140. * @email 136327134@qq.com
  141. * @date 2023/4/20
  142. */
  143. public function deleteMenu(string $path, string $method)
  144. {
  145. return $this->getModel()->where('api_url', $path)->where('methods', $method)->delete();
  146. }
  147. }