SystemMenusDao.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. var_dump(SystemMenus::getLastSql());
  45. return $res;
  46. }
  47. /**
  48. * 获取菜单中的唯一权限
  49. * @param array $where
  50. * @return array
  51. */
  52. public function getMenusUnique(array $where)
  53. {
  54. return $this->search($where)->where('unique_auth', '<>', '')->column('unique_auth', '');
  55. }
  56. /**
  57. * 根据访问地址获得菜单名
  58. * @param string $rule
  59. * @return mixed
  60. */
  61. public function getVisitName(string $rule)
  62. {
  63. return $this->search(['url' => $rule])->value('menu_name');
  64. }
  65. /**
  66. * 获取后台菜单列表并分页
  67. * @param array $where
  68. * @return \think\Collection
  69. * @throws \think\db\exception\DataNotFoundException
  70. * @throws \think\db\exception\DbException
  71. * @throws \think\db\exception\ModelNotFoundException
  72. */
  73. public function getMenusList(array $where)
  74. {
  75. $where = array_merge($where, ['is_del' => 0]);
  76. return $this->search($where)->order('sort DESC,id ASC')->select();
  77. }
  78. /**
  79. * 菜单总数
  80. * @param array $where
  81. * @return int
  82. */
  83. public function countMenus(array $where)
  84. {
  85. $where = array_merge($where, ['is_del' => 0]);
  86. return $this->count($where);
  87. }
  88. /**
  89. * 指定条件获取某些菜单的名称以数组形式返回
  90. * @param array $where
  91. * @param string $field
  92. * @param string $key
  93. * @return array
  94. */
  95. public function column(array $where, string $field, string $key)
  96. {
  97. return $this->search($where)->column($field, $key);
  98. }
  99. /**菜单列表
  100. * @param array $where
  101. * @param int $type
  102. * @return \think\Collection
  103. * @throws \think\db\exception\DataNotFoundException
  104. * @throws \think\db\exception\DbException
  105. * @throws \think\db\exception\ModelNotFoundException
  106. */
  107. public function menusSelect(array $where, $type = 1)
  108. {
  109. if ($type == 1) {
  110. return $this->search($where)->field('id,pid,menu_name,menu_path,unique_auth,sort')->order('sort DESC')->select();
  111. } else {
  112. return $this->search($where)->group('pid')->column('pid');
  113. }
  114. }
  115. /**
  116. * 搜索列表
  117. * @param int $type
  118. * @return \think\Collection
  119. * @throws \think\db\exception\DataNotFoundException
  120. * @throws \think\db\exception\DbException
  121. * @throws \think\db\exception\ModelNotFoundException
  122. */
  123. public function getSearchList($type = 1)
  124. {
  125. return $this->search(['is_show' => 1, 'auth_type' => 1, 'is_del' => 0, 'is_show_path' => 0])->where('type', $type)
  126. ->field('id,pid,menu_name,menu_path,unique_auth,sort')->order('sort DESC')->select();
  127. }
  128. }