where(["id" => $id])->find(); if ($result == null) { return $id; } $info = $result->toArray(); if ($info['pid']==1) { return $id; } return $this->getTopGroup($info['pid']); } catch (Exception $e) { return $id; } } /** * 获取所有子节点的ID * @param $id * @return array */ public function getSubGroup($id){ try { $idArr = [$id]; $model = new AuthGroup(); $result = $model->where(["pid" => $id])->select(); if ($result == null) { return $idArr; } $list = $result->toArray(); foreach ($list as $info) { $subIdArr = $this->getSubGroup($info['id']); $idArr = array_merge($idArr, $subIdArr); } return $idArr; } catch (Exception $e) { return $idArr; } } }