|
|
- /**
- * 获取所有菜单
- * @return array
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- static public function getMenuAll(){
- $res=self::where('hid',0)->field('id,pid,url,icon,title,sort,group')->order('pid', 'asc')->select()->toArray();
- return self::makeArr($res);
- }
- /**
- * 递归循环
- * @param $res 总数组
- * @param int $pid 父级id
- * @return array
- */
- static public function makeArr($res, $pid=0){
- $arr = [];
- $item['pid']=$pid;
- $data=self::screen($res,$item);
- foreach ($data as $key=>$val){
- $ite['pid']=$val['id'];
- $result = self::screen($res,$ite);
- if (!empty($result)){
- $val['child']= self::makeArr($res,$val['id']);
- }
- $arr[] = $val;
- }
- return $arr;
- }
- /**
- * 数组键值对查询 返回查询数组
- * @param $res
- * @param $val
- * @return array
- */
- static public function screen($res,$val){
- return array_filter($res,function ($var) use ($val){
- if($var['pid']==$val['pid']) return true;
- });
- }
复制代码
|
|