SystemMenusDao.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. $where['no_model'] = sys_config('model_checkbox', ['seckill', 'bargain', 'combination']);
  55. return $this->search($where)->field($field)->order('sort DESC,id DESC')->failException(false)->select();
  56. }
  57. /**
  58. * 获取菜单中的唯一权限
  59. * @param array $where
  60. * @return array
  61. */
  62. public function getMenusUnique(array $where)
  63. {
  64. $where['no_model'] = sys_config('model_checkbox', ['seckill', 'bargain', 'combination']);
  65. return $this->search($where)->where('unique_auth', '<>', '')->column('unique_auth', '');
  66. }
  67. /**
  68. * 根据访问地址获得菜单名
  69. * @param string $rule
  70. * @return mixed
  71. */
  72. public function getVisitName(string $rule)
  73. {
  74. return $this->search(['url' => $rule])->value('menu_name');
  75. }
  76. /**
  77. * 获取后台菜单列表并分页
  78. * @param array $where
  79. * @return \think\Collection
  80. * @throws \think\db\exception\DataNotFoundException
  81. * @throws \think\db\exception\DbException
  82. * @throws \think\db\exception\ModelNotFoundException
  83. */
  84. public function getMenusList(array $where, array $field = ['*'])
  85. {
  86. $where = array_merge($where, ['is_del' => 0]);
  87. $where['no_model'] = sys_config('model_checkbox', ['seckill', 'bargain', 'combination']);
  88. return $this->search($where)->field($field)->order('sort DESC,id ASC')->select();
  89. }
  90. /**
  91. * 菜单总数
  92. * @param array $where
  93. * @return int
  94. */
  95. public function countMenus(array $where)
  96. {
  97. $where = array_merge($where, ['is_del' => 0]);
  98. return $this->count($where);
  99. }
  100. /**
  101. * 指定条件获取某些菜单的名称以数组形式返回
  102. * @param array $where
  103. * @param string $field
  104. * @param string $key
  105. * @return array
  106. */
  107. public function column(array $where, string $field, string $key = '')
  108. {
  109. $where['no_model'] = sys_config('model_checkbox', ['seckill', 'bargain', 'combination']);
  110. return $this->search($where)->column($field, $key);
  111. }
  112. /**菜单列表
  113. * @param array $where
  114. * @param int $type
  115. * @return \think\Collection
  116. * @throws \think\db\exception\DataNotFoundException
  117. * @throws \think\db\exception\DbException
  118. * @throws \think\db\exception\ModelNotFoundException
  119. */
  120. public function menusSelect(array $where, $type = 1)
  121. {
  122. $where['no_model'] = sys_config('model_checkbox', ['seckill', 'bargain', 'combination']);
  123. if ($type == 1) {
  124. return $this->search($where)->field('id,pid,menu_name,menu_path,unique_auth,sort')->order('sort DESC,id DESC')->select();
  125. } else {
  126. return $this->search($where)->group('pid')->column('pid');
  127. }
  128. }
  129. /**
  130. * 搜索列表
  131. * @throws \think\db\exception\DataNotFoundException
  132. * @throws \think\db\exception\DbException
  133. * @throws \think\db\exception\ModelNotFoundException
  134. */
  135. public function getSearchList()
  136. {
  137. $where['no_model'] = sys_config('model_checkbox', ['seckill', 'bargain', 'combination']);
  138. return $this->search(['is_show' => 1, 'auth_type' => 1, 'is_del' => 0, 'is_show_path' => 0])
  139. ->field('id,pid,menu_name,menu_path,unique_auth,sort')->order('sort DESC,id DESC')->select();
  140. }
  141. /**
  142. * @param string $path
  143. * @param string $method
  144. * @return bool
  145. * @author 等风来
  146. * @email 136327134@qq.com
  147. * @date 2023/4/20
  148. */
  149. public function deleteMenu(string $path, string $method)
  150. {
  151. return $this->getModel()->where('api_url', $path)->where('methods', $method)->delete();
  152. }
  153. }