thinkphp-无限分类下根据任意部门获取顶级部门ID

根据所得到的部门编号获取顶级部门ID:

参数 - department_id

表格组织架构:

tab_departments

department_id parent_id name

1  1  顶级  

2  1   第一级

.......

函数:

1 function getDepartmentId($department_id){
2     $departments = M('tab_departments')->getField('department_id,parent_id');
3 
4     while($departments[$department_id]>1){
5             $department_id = $departments[$department_id];
6     }
7 }

调用方法:

$department_id = session('department_id');//当前用户的岗位ID
$top_id = getDepartmentId($depatment_id);
dump($top_id);

 

posted @ 2017-01-07 17:43  Aylin-online  阅读(915)  评论(0编辑  收藏  举报