<?php
namespace app\admin\model;
use think\Model;
class AuthRule extends Base{
public function getRules(){
$where = ['status'=>1];
$info = AuthRule::all($where);
foreach ($info as $v) {
$arr[] = [
'id' => $v['id'],
'pid' => $v['pid'],
'title' => $v['title'],
];
}
$info = $this->subtree($arr);
return $info;
}
public function getColumn($where){
$info = AuthRule::all($where);
$arr = [];
foreach($info as $v){
$arr[] = [
'id' => $v['id'],
'pid' => $v['pid'],
'title' => $v['title'],
'name' => $v['name'],
'condition' => $v['condition'],
'icon' => $v['icon'],
'level' => $v['level'],
];
}
$info = $this->subtree($arr);
array_shift($info);
return $info;
}
function subtree($arr=[],$id=0,$lev=1){
$subs=array() if(is_array($arr)){
foreach($arr as $v){
if($v['pid']==$id){
$v['lev']=$lev;
$v['cate']=$this->subtree($arr,$v['id'],$lev+1 );
$subs[]=$v;
}
}
}
return $subs;
}
}