酒店预订平台
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

66 lines
1.5 KiB

  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: nizongfeng
  5. * Date: 2021/11/30
  6. * Time: 11:31
  7. */
  8. namespace app\admin\dao;
  9. use app\admin\command\Util;
  10. use app\admin\model\AuthGroup;
  11. use think\Exception;
  12. class GroupDao
  13. {
  14. /**
  15. * 获取顶级部门 非超管
  16. * @param $id
  17. * @return mixed
  18. */
  19. public function getTopGroup($id){
  20. if ($id == 1) {
  21. return $id;
  22. }
  23. try {
  24. $model = new AuthGroup();
  25. $result = $model->where(["id" => $id])->find();
  26. if ($result == null) {
  27. return $id;
  28. }
  29. $info = $result->toArray();
  30. if ($info['pid']==1) {
  31. return $id;
  32. }
  33. return $this->getTopGroup($info['pid']);
  34. } catch (Exception $e) {
  35. return $id;
  36. }
  37. }
  38. /**
  39. * 获取所有子节点的ID
  40. * @param $id
  41. * @return array
  42. */
  43. public function getSubGroup($id){
  44. try {
  45. $idArr = [$id];
  46. $model = new AuthGroup();
  47. $result = $model->where(["pid" => $id])->select();
  48. if ($result == null) {
  49. return $idArr;
  50. }
  51. $list = $result->toArray();
  52. foreach ($list as $info) {
  53. $subIdArr = $this->getSubGroup($info['id']);
  54. $idArr = array_merge($idArr, $subIdArr);
  55. }
  56. return $idArr;
  57. } catch (Exception $e) {
  58. return $idArr;
  59. }
  60. }
  61. }