add:新增模型获取所有子节点方法

This commit is contained in:
JaguarJack 2020-11-04 10:05:50 +08:00
parent 0b5c883012
commit 97b7f73ff2

View File

@ -1,7 +1,6 @@
<?php <?php
namespace catcher; namespace catcher;
use catcher\library\excel\CatchExcel;
use catcher\library\excel\Excel; use catcher\library\excel\Excel;
use catcher\library\excel\ExcelContract; use catcher\library\excel\ExcelContract;
use think\facade\Cache; use think\facade\Cache;
@ -83,4 +82,28 @@ class CatchModelCollection extends Collection
{ {
return Cache::store($store)->set($key, $this->items, $ttl); return Cache::store($store)->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;
}
} }