| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288 | <?phpnamespace app\common\model;use think\Db;use tools\Phptree;class Menu extends Base{    protected $autoWriteTimestamp = false;    public function updates(){        $data = request()->post();        return $this->updateInfo($data,'Menu','');    }    // 获取所有权限    public function getAllMenuTree(){        $map[] = ['id','not in',[37,38,39,47,48]];        $map[] = ['del','=',0];        $lists = Db::name('menu')            ->where('enable',1)            ->where($map)            ->field('id,title,pid')            ->order('sort asc,id asc')            ->select();        $lists = $lists?$lists:[];        foreach ($lists as $k=>$v){            $pids = [];            $pid = $v['pid'];            while (true){                if($pid == 0){                    break;                }else{                    $pids[] = 'sub_'.$pid;                    $cc = Db::name('menu')                        ->where('id',$pid)                        ->find();                    if(!$cc){                        break;                    }                    $pid = $cc['pid'];                }            }            $lists[$k]['pids'] = $pids?implode(' ',$pids):'';        }        $tree = Phptree::makeTree(($lists), array(            'primary_key'=>'id',            'parent_key'=>'pid',            'expanded' => true,            'children_key' => 'children'        ));        return $tree;    }    // 获取某组织的所有权限    public function getOrgAllMenuTree($orgId){        $auths = model('Org')->getOrgAuths($orgId,1);        $lists = [];        if($auths){            $map[] = ['id','not in',[37,38,39,47,48]];            $map[] = ['del','=',0];            $lists = Db::name('menu')                ->where('enable',1)                ->where('id','in',$auths)                ->where($map)                ->field('id,title,pid')                ->order('sort asc,id asc')                ->select();            $lists = $lists?$lists:[];            foreach ($lists as $k=>$v){                $pids = [];                $pid = $v['pid'];                while (true){                    if($pid == 0){                        break;                    }else{                        $pids[] = 'sub_'.$pid;                        $cc = Db::name('menu')                            ->where('id',$pid)                            ->find();                        if(!$cc){                            break;                        }                         $pid = $cc['pid'];                    }                }                $lists[$k]['pids'] = $pids?implode(' ',$pids):'';            }        }        $tree = Phptree::makeTree(($lists), array(            'primary_key'=>'id',            'parent_key'=>'pid',            'expanded' => true,            'children_key' => 'children'        ));        return $tree;    }    // 根据角色和组织获取用户菜单项    public function getMenuTree($rolesId,$orgId){        $map[] = ['enable','=',1];        $map[] = ['del','=',0];        $map[] = ['is_btn','=',0];        if($rolesId == 1){ // 超级管理员        }else if($rolesId == 2){ //总公司管理员            $auths = model('Org')->getOrgAuths($orgId,1);            if($auths){                $map[] = ['id','in',$auths];            }else{                $map[] = ['id','=',0];            }        }else{ // 项目管理员            $auths = model('Roles')->getRolesAuths($rolesId,1);            if($auths){                $map[] = ['id','in',$auths];            }else{                $map[] = ['id','=',0];            }        }        if($rolesId!=1){            /*3.只有admin管理员可见            系统设置: 菜单管理、配置管理、安卓版本管理、苹果版本管理、            模块管理、这些项目,在权限分配里面就不要出现了,不需要分配*/            $map[] = ['id','not in',[37,38,39,47,48]];        }        $lists = Db::name('menu')            ->where($map)            ->field('id,title,url,icons,pid,img,des')            ->order('sort asc,id asc')            ->select();        $lists = $lists?$lists:[];//        $first = [//            'id' => -1,//            'title' => '系统首页',//            'url' => $this->getNavUrl('Index/def'),//            'icons' => 'fa fa-home',//            'pid' => 0,//        ];        $arr = [];        foreach ($lists as $k=>$v){            $v['url'] = $this->getNavUrl($v['url']);            $arr[] = $v;        }        $tree = list_to_tree($arr, 'pid', 'child');        return $tree;    }    /**     * 获取导航URL     * @param  string $url 导航URL     * @return string      解析或的url     */    public function getNavUrl($url){        switch ($url) {            case 'http://' === substr($url, 0, 7):            case 'https://' === substr($url, 0, 8):            case '#' === substr($url, 0, 1):                break;            default:                $url = url($url);                break;        }        return $url;    }    // 根据角色和组织获取用户菜单项    public function getMenuTree1($rolesId,$orgId,$search){        $map[] = ['enable','=',1];        $map[] = ['del','=',0];        $map[] = ['is_btn','=',0];        if($rolesId == 1){ // 超级管理员        }else if($rolesId == 2){ //总公司管理员            $auths = model('Org')->getOrgAuths($orgId,1);            if($auths){                $map[] = ['id','in',$auths];            }else{                $map[] = ['id','=',0];            }        }else{ // 项目管理员            $auths = model('Roles')->getRolesAuths($rolesId,1);            if($auths){                $map[] = ['id','in',$auths];            }else{                $map[] = ['id','=',0];            }        }        if($rolesId!=1){            /*3.只有admin管理员可见            系统设置: 菜单管理、配置管理、安卓版本管理、苹果版本管理、            模块管理、这些项目,在权限分配里面就不要出现了,不需要分配*/            $map[] = ['id','not in',[37,38,39,47,48]];        }        if($search !=''){            $map[] = ['title','like','%'.$search.'%'];        }        $lists = Db::name('menu')            ->where($map)            ->field('id,title,url,icons,pid')            ->order('sort asc,id asc')            ->select();        $lists = $lists?$lists:[];//        $first = [//            'id' => -1,//            'title' => '系统首页',//            'url' => $this->getNavUrl('Index/def'),//            'icons' => 'fa fa-home',//            'pid' => 0,//        ];//        $arr[] = $first;        $arr = [];        foreach ($lists as $k=>$v){            $v['url'] = $this->getNavUrl($v['url']);            $arr[] = $v;        }//        $tree = list_to_tree($arr, 'pid', 'child');        return $arr;    }    // 根据角色和组织获取用户菜单项    public function getMenuTree2($rolesId,$orgId,$search,$pid=0){        $map[] = ['enable','=',1];        $map[] = ['del','=',0];        $map[] = ['is_btn','=',0];        if($pid == 500){            $map[] = ['pid','=',500];        }        if($rolesId == 1){ // 超级管理员        }else if($rolesId == 2){ //总公司管理员            $auths = model('Org')->getOrgAuths($orgId,1);            if($auths){                $map[] = ['id','in',$auths];            }else{                $map[] = ['id','=',0];            }        }else{ // 项目管理员            $auths = model('Roles')->getRolesAuths($rolesId,1);            if($auths){                $map[] = ['id','in',$auths];            }else{                $map[] = ['id','=',0];            }        }        if($rolesId!=1){            /*3.只有admin管理员可见            系统设置: 菜单管理、配置管理、安卓版本管理、苹果版本管理、            模块管理、这些项目,在权限分配里面就不要出现了,不需要分配*/            $map[] = ['id','not in',[37,38,39,47,48]];        }        if($search !=''){            $map[] = ['title','like','%'.$search.'%'];        }        $lists = Db::name('menu')            ->where($map)            ->field('id,title,url,icons,pid')            ->order('sort asc,id asc')            ->fetchSql()            ->select();        halt($lists);        $lists = $lists?$lists:[];//        $first = [//            'id' => -1,//            'title' => '系统首页',//            'url' => $this->getNavUrl('Index/def'),//            'icons' => 'fa fa-home',//            'pid' => 0,//        ];//        $arr[] = $first;        $arr = [];        foreach ($lists as $k=>$v){            $v['url'] = $this->getNavUrl($v['url']);            $arr[] = $v;        }//        $tree = list_to_tree($arr, 'pid', 'child');        return $arr;    }}
 |