From 97b7f73ff21f9c0c0b716a736a1d0800176a7f63 Mon Sep 17 00:00:00 2001 From: JaguarJack Date: Wed, 4 Nov 2020 10:05:50 +0800 Subject: [PATCH] =?UTF-8?q?add:=E6=96=B0=E5=A2=9E=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E6=89=80=E6=9C=89=E5=AD=90=E8=8A=82=E7=82=B9?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- extend/catcher/CatchModelCollection.php | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) 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