This commit is contained in:
molong
2022-05-24 16:10:50 +08:00
parent a37870c93b
commit d8e43f9e93
63 changed files with 2169 additions and 230 deletions

View File

@@ -1,2 +1,36 @@
<?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;
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[] = (int) $v[$pk];
array_merge($array, getChilds($data, $v[$pk]));
}
}
return $array;
}