Files
sentos/app/common.php
2022-10-04 15:10:37 +08:00

37 lines
1.2 KiB
PHP

<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
use think\facade\Cache;
use sent\tree\Tree;
function getDepartmentChild($pid = 0){
$department = Cache::get('department');
if(!$department){
$department = \app\model\auth\Departments::where('status', '=', 1)->column('id,parent_id,title', 'id');
Cache::set('department', $department);
}
$res = getChilds($department, $pid, 'id', 'parent_id');
$res[] = (int) $pid; //把自己包含在内
return $res;
}
/**
* 获得所有的子
* @param [type] $id [description]
* @return [type] [description]
*/
function getChilds($data, $id = 0, $pk = 'id', $pid = 'parent_id') {
$array = [];
foreach ($data as $k => $v) {
if ($v[$pid] == $id) {
$array[] = $v[$pk];
$array = array_merge($array, getChilds($data, $v[$pk]));
}
}
return $array;
}