model=new AdminMenu(); } public function list() { $ACtion = RoleAction::where('role_id','=', $this->roleid)->findOrEmpty(); if($ACtion->isEmpty())return success('角色无权限!'); $data= $this->model->name("view_menu")->where('aid',"in",$ACtion->action_conllect)->where(['status'=>1,"cstatus"=>1,"is_display"=>1]) ->order("weight desc,id asc,cweight desc,cid asc")->select(); $list=[]; $act=[]; foreach ($data as $value){ $list[$value["id"]]['menu_name']=$value['menu_name']; $list[$value["id"]]['menu_img']=$value['menu_img']; $list[$value["id"]]['menu_route']=$value['menu_route']; $list[$value["id"]]['is_display']=$value['is_display']; $list[$value["id"]]['status']=$value['status']; $temp = []; $temp['menu_name']=$value['cname']; $temp['menu_img']=$value['cmenu_img']; $temp['menu_route']=$value['cmenu_route']; $temp['menu_url']=$value['cmenu_url']; $temp['menu_url']=$value['cmenu_url']; $temp['status']=$value['cstatus']; $temp['is_private']=$value['cprivate']; $temp['is_display']=$value['cis_display']; $list[$value["id"]]['child'][$value['cid']]=$temp; $act[$value['id']][$value['cid']][]=$value['acode']; $list[$value["id"]]['child'][$value['cid']]['action']= $act[$value['id']][$value['cid']]; } array_walk($list,function (&$value){ $value['child']= array_values($value['child']); }); return success("获取成功",array_values($list)); } /** * 显示创建资源表单页. * * @return \think\Response */ public function MenuEdit(){ $post =$this->request->param(["id"=>"","name"=>"","url"=>"","route"=>"","img"=>"","pid"=>0,'weight'=>1, "is_display"=>0,"private"=>0],'post','trim'); $valid=Validate::rule([ "id|菜单id"=>"number|gt:0", "name|菜单名称"=>"require|max:255", "url|菜单地址"=>"max:255", "pid|父级id"=>"require|number", "route|菜单路由"=>"max:255" ]); if($valid->check($post)==false) return error($valid->getError()); $menu = $this->model->where("id","=",$post['id'])->findOrEmpty(); $message=$menu->isEmpty()?'新建':'编辑'; if($post['pid']!=0 &&$post['route']=="")return error("子级菜单路由不能为空"); $menu->menu_name=$post['name']; $menu->menu_url=$post['url']; $menu->menu_route=$post['route']; $menu->menu_img=$post['img']; $menu->pid=$post['pid']; $menu->is_display=$post['is_display']; $menu->is_private=$post['private']; $menu->weight=$post['weight']; $menu->status=1; $result =$menu->save(); return $result ? success("{$message}成功"): error("{$message}失败"); } /** * 保存新建的资源 * * @param \think\Request $request * @return \think\Response */ public function MenuStatus(){ $post =$this->request->param(['id'=>'','status'=>1],"post","trim"); $valid=Validate::rule([ 'id|菜单id'=>'require|number|gt:0', 'status|菜单状态'=>'require|number|in:0,1' ]); if($valid->check($post)==false) return error($valid->getError()); $menu = $this->model->where('id','=',$post['id'])->findOrEmpty(); if($menu->isEmpty()==false)return error("菜单信息不存在"); $menu->status=$post['status']; $result =$menu->save(); return $result ? success("{$this->model->status_cn[$post['status']]}成功"): error("{$this->model->status_cn[$post['status']]}失败"); } /**所有菜单 */ public function MenuAllList(){ return success("获取成功",$this->model->GetMenuTree()); } /**删除菜单 * @return \think\response\Json|void * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function MenuDel(){ $id =$this->request->post("id/d"); $menu = $this->model->where("id","=",$id)->findOrEmpty(); if($menu->isEmpty())return error("菜单不信息不存在"); $menu->is_del=1; $result =$menu->save(); return $result ? success("删除成功"): error("删除失败"); } /**删除菜单功能 * @return \think\response\Json|void * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function MenuActionDel(){ $id =$this->request->post('id/d'); $menu = \app\bug\model\Action::where("id","=",$id)->findOrEmpty(); if($menu->isEmpty())return error('菜单功能信息不存在'); $result =$menu->delete(); return $result ? success('删除成功'): error('删除失败'); } }