<?php

namespace app\admin\model;

use think\facade\Session;

class NavModel
{
    public function getNavs($roles = ''){
        $permissions = new PermissionModel();
        $user = Session::get('user');

        if(!empty($roles)){
            $data = $permissions->where(['is_nav'=>1,'status'=>1])->field('id,pid,title,is_nav,nav_url,nav_icon')->order('sort desc')->all($roles)->toArray();
        } else if( empty($roles) && $user['is_admin']){
            $data = $permissions->where(['is_nav'=>1,'status'=>1])->field('id,pid,title,is_nav,nav_url,nav_icon')->order('sort desc')->all()->toArray();
        } else {
            $data = [];
        }
        if(!empty($data))
            $data = getNodesTree($data);

        return $data;
    }


}