diff --git a/extend/catcher/CatchModelCollection.php b/extend/catcher/CatchModelCollection.php index 3545132..14274f7 100644 --- a/extend/catcher/CatchModelCollection.php +++ b/extend/catcher/CatchModelCollection.php @@ -1,7 +1,6 @@ set($key, $this->items, $ttl); } + + /** + * 获取当前级别下的所有子级 + * + * @time 2020年11月04日 + * @param array $ids + * @param string $parentFields + * @param string $column + * @return array + */ + public function getAllChildrenIds(array $ids, $parentFields = 'parent_id', $column = 'id') + { + array_walk($ids, function (&$item){ + $item = intval($item); + }); + + $childDepartmentIds = $this->whereIn($parentFields, $ids)->column($column); + + if (!empty($childDepartmentIds)) { + $childDepartmentIds = array_merge($childDepartmentIds, $this->getAllChildrenIds($childDepartmentIds)); + } + + return $childDepartmentIds; + } } \ No newline at end of file