model=new AdminMenu(); } //获取菜单 public function list(){ $param = $this->request->param(["relaComNo"=>"","level"=>""],"post","trim"); $condition = [ ['status','=',1], ['is_display','=',1], ['is_del','=',0] ]; $action = UserRole::getAllAction($this->uid,$param['relaComNo'],$this->level); if(isset($param['level']) && $param['level'] !== '') $condition[] = ['level','in',[0,$param['level']]]; else { if($this->level == 1) $condition[] = ['level','in',[0,1,2]]; else $condition[] = ['level','in',[0,$this->level]]; } $list=$this->model->GetMenuByActionArr($action,$condition); return success("获取成功",$list); } //创建\编辑菜单 public function create(){ $param=$this->request->param(["name"=>"","url"=>"","route"=>"","pid"=>"","level"=>"","img"=>"","is_display"=>"", "weight"=>"","private"=>"","menu_api"=>"",'id'=>0],"post","trim"); $valid = Validate::rule([ "name|菜单名称"=>"require|max:255", "url|菜单路由"=>"max:255", "route|菜单地址"=>"max:255", "pid|父级id"=>"require|number|egt:0", "id|菜单id"=>"number|egt:0", "level|菜单路由"=>"require|number|egt:0", "is_display|菜单是否显示"=>"require|number|in:0,1", "weight|菜单排序权重"=>"require|number", "private|菜单是否私有"=>"require|number|in:0,1", "img|菜单图标"=>"max:255", ]); if(!$valid->check($param)) return error($valid->getError()); $menu=$this->model->findOrEmpty($param['id']); if($param['id']>0){ if($menu->isEmpty()) return error("菜单不存在"); } $menu->menu_name = $param['name']; $menu->menu_url = $param['url']; $menu->menu_route = $param['route']; $menu->menu_img = $param['img']; $menu->pid = $param['pid']; $menu->is_display = $param['is_display']; $menu->is_private = $param['private']; $menu->level = $param['level']; $menu->weight = $param['weight']; $menu->menu_api = $param['menu_api']; $save= $menu->save(); if($save==false) return error("保存失败"); return success('保存成功'); } public function status(){ $param=$this->request->param(["id"=>0,"status"=>1],"post","trim"); $valid = Validate::rule([ "id|菜单id"=>"require|number|gt:0", "status|状态"=>"require|number|in:0,1", ]); if(!$valid->check($param)) return error($valid->getError()); $menu=$this->model->findOrEmpty($param['id']); if($menu->isEmpty()) return error("菜单不存在"); $menu->status = $param['status']; $save= $menu->save(); if($save==false) return error("保存失败"); return success('保存成功'); } //获取功能权限集合 public function GetMenuAction(){ $param = $this->request->param(["level"=>""],"post","trim"); $list=$this->model->GetMenuActionTree(); return success('获取成功',$list); } }