request->post(); $token = isset($post['token']) ? trim($post['token']) : ""; if($token==""){ return error_show(101,'token不能为空'); } $effetc = VerifyTokens($token); if(!empty($effetc) && $effetc['code']!=0){ return error_show($effetc['code'],$effetc['message']); } $guserinfo =GetUserInfo($token); if(isset($guserinfo['code']) && $guserinfo['code']!=0){ return error_show($guserinfo['code'],$guserinfo['message']); } $role = Db::name("role_action")->where("role_id","=",$guserinfo['data']['roleid'])->find(); if($role==false){ return app_show(0,"获取成功",[]); } $data= Db::name("view_menu")->where('aid',"in",explode(",",$role['action_conllect']))->where(['status'=>1,"cstatus"=>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"]]['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']; $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 app_show(0,"获取成功",array_values($list)); } /** * @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 MenuAdd(){ $post =$this->request->post(); $token = isset($post['token']) ? trim($post['token']) : ""; if($token==""){ return error_show(101,'token不能为空'); } $effetc = VerifyTokens($token); if(!empty($effetc) && $effetc['code']!=0){ return error_show($effetc['code'],$effetc['message']); } $name = isset($post['menu_name']) ?trim($post['menu_name']) :""; if($name==""){ return error_show(1002,"菜单名称不能为空"); } $url = isset($post['menu_url']) ?trim($post['menu_url']) :""; $route = isset($post['menu_route']) ?trim($post['menu_route']) :""; $code = isset($post['menu_code']) ?trim($post['menu_code']) :""; $img = isset($post['menu_img']) ?trim($post['menu_img']) :""; $pid = isset($post['pid']) ?intval($post['pid']) :0; $private = isset($post['private']) ?intval($post['private']) :0; $weight = isset($post['weight']) ?floatval($post['weight']) :1; if($pid!=0 && $route==""){ return error_show(1002,"子级菜单路由不能为空"); } $data=[ "menu_name"=>$name, "menu_url"=>$url, "menu_route"=>$route, "menu_code"=>$code, "menu_img"=>$img, "pid"=>$pid, "weight"=>$weight, "is_show"=>1, "is_private"=>$private, "status"=>1, "addtime"=>date("Y-m-d H:i:s"), "updatetime"=>date("Y-m-d H:i:s"), ]; $result = AdminMenu::create($data); return $result ? app_show(0,"添加成功"): error_show(1003,"添加失败"); } public function MenuEdit(){ $post =$this->request->post(); $token = isset($post['token']) ? trim($post['token']) : ""; if($token==""){ return error_show(101,'token不能为空'); } $effetc = VerifyTokens($token); if(!empty($effetc) && $effetc['code']!=0){ return error_show($effetc['code'],$effetc['message']); } $id = isset($post['id']) ?intval($post['id']) :""; if($id!=""){ $menu = Db::name("admin_menu")->where("id","=",$id)->find(); if($menu==false){ return error_show(1003,"菜单不信息不存在"); } } $name = isset($post['name']) ?trim($post['name']) :""; if($name==""){ return error_show(1002,"菜单名称不能为空"); } $url = isset($post['url']) ?trim($post['url']) :""; $route = isset($post['route']) ?trim($post['route']) :""; $code = isset($post['menu_code']) ?trim($post['menu_code']) :""; $img = isset($post['img']) ?trim($post['img']) :""; $pid = isset($post['pid']) ?intval($post['pid']) :0; $weight = isset($post['weight']) ?floatval($post['weight']) :1; $status = isset($post['is_show']) ? intval($post['is_show']) : 0; $private = isset($post['private']) ?intval($post['private']) :(isset($menu['is_private']) ? $menu['is_private'] : 0); if($pid!=0 && $route==""){ return error_show(1002,"子级菜单路由不能为空"); } $data=[ "menu_name"=>$name, "menu_url"=>$url, "menu_route"=>$route, "menu_code"=>$code, "menu_img"=>$img, "pid"=>$pid, 'is_show'=>$status, "is_private"=>$private, 'status'=>1, "weight"=>$weight, "updatetime"=>date("Y-m-d H:i:s"), ]; $message="新建"; if($id!=""){ $message="编辑"; $data['id']=$id; } $result = Db::name("admin_menu")->save($data); return $result ? app_show(0,"{$message}成功"): error_show(1003,"{$message}失败"); } public function MenuDel(){ $post =$this->request->post(); $token = isset($post['token']) ? trim($post['token']) : ""; if($token==""){ return error_show(101,'token不能为空'); } $effetc = VerifyTokens($token); if(!empty($effetc) && $effetc['code']!=0){ return error_show($effetc['code'],$effetc['message']); } $id = isset($post['id']) ?intval($post['id']) :""; $menu = Db::name("admin_menu")->where("id","=",$id)->find(); if($menu==false){ return error_show(1003,"菜单不信息不存在"); } $menu['is_show']=0; $menu['status']=0; $menu['updatetime']=date("Y-m-d H:i:s"); $result = Db::name("admin_menu")->save($menu); return $result ? app_show(0,"删除成功"): error_show(1003,"删除失败"); } public function MenuStatus(){ $post =$this->request->post(); $token = isset($post['token']) ? trim($post['token']) : ""; if($token==""){ return error_show(101,'token不能为空'); } $effetc = VerifyTokens($token); if(!empty($effetc) && $effetc['code']!=0){ return error_show($effetc['code'],$effetc['message']); } $id = isset($post['id']) ?intval($post['id']) :""; $menu = Db::name("admin_menu")->where("id","=",$id)->find(); if($menu==false){ return error_show(1003,"菜单信息不存在"); } $statu = isset($post['status'])&&$post['status']!="" ? intval($post['status']) :""; if($statu===""){ return error_show(1003,"菜单状态不能为空"); } $menu['status']=$statu; $menu['updatetime']=date("Y-m-d H:i:s"); $result = Db::name("admin_menu")->save($menu); return $result ? app_show(0,"状态更新成功"): error_show(1003,"状态更新失败"); } public function MenuAllList(){ $post =$this->request->post(); $token = isset($post['token']) ? trim($post['token']) : ""; if($token==""){ return error_show(101,'token不能为空'); } $effetc = VerifyTokens($token); if(!empty($effetc) && $effetc['code']!=0){ return error_show($effetc['code'],$effetc['message']); } $data = Db::name("admin_menu")->where(['pid'=>0])->order("weight desc,id asc")->select(); $l=[]; foreach ($data as $key=>$value){ $temp=[]; $temp = Db::name("admin_menu")->where(['pid'=>$value['id']])->order("weight desc,id asc")->select(); $value['child']=$temp; $l[]=$value; } return app_show(0,"获取成功",$l); } /** * @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 ActionList(){ $post =$this->request->post(); $token = isset($post['token']) ? trim($post['token']) : ""; if($token==""){ return error_show(101,'token不能为空'); } $effetc =VerifyTokens($token); if(!empty($effetc) && $effetc['code']!=0){ return error_show($effetc['code'],$effetc['message']); } $pageid = isset($post['id']) ? intval($post['id']) : ""; if($pageid==""){ return error_show(1001,'页面id不能为空'); } $condition = ['menuid'=>$pageid]; $data=Db::name('action')->alias("a")->leftJoin("cfp_action_list l","a.action_code=l.action_code")->field ("a.*,action_name")->where($condition)->select(); return app_show(0,"获取成功",$data); } public function ActionSave(){ $post =$this->request->post(); $token = isset($post['token']) ? trim($post['token']) : ""; if($token==""){ return error_show(101,'token不能为空'); } $effetc = VerifyTokens($token); if(!empty($effetc) && $effetc['code']!=0){ return error_show($effetc['code'],$effetc['message']); } $actid = isset($post['id']) ? intval($post['id']) : ""; if($actid==""){ return error_show(1001,'功能id不能为空'); } $menuid = isset($post['menuid']) ? intval($post['menuid']) : ""; if($menuid==""){ return error_show(1001,'页面menuid不能为空'); } $code = isset($post['action_code']) ? trim($post['action_code']) : ""; $status = isset($post['status']) ? intval($post['status']) : 1; if($code==""){ return error_show(1002,'功能code不能为空'); } $istrue =Db::name("action")->where(['menuid'=>$menuid,"action_code"=>$code])->find(); if($istrue && $istrue['id']!=$actid){ return error_show(1005,'此功能已存在'); } try{ $data = ['action_code'=>$code,'status'=>$status,"updatetime"=>date("Y-m-d H:i:s")]; $result=Db::name("action")->where("id","=",$actid)->save($data); if($result){ return app_show(0,"更新成功"); }else{ return error_show(1004,"更新失败"); } }catch (\Exception $e){ return error_show(1003,$e->getMessage()); } } /** * @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 ActionStatus(){ $post =$this->request->post(); $token = isset($post['token']) ? trim($post['token']) : ""; if($token==""){ return error_show(101,'token不能为空'); } $effetc = VerifyTokens($token); if(!empty($effetc) && $effetc['code']!=0){ return error_show($effetc['code'],$effetc['message']); } $actid = isset($post['id']) ? intval($post['id']) : ""; if($actid==""){ return error_show(1001,'功能id不能为空'); } $status = isset($post['status']) ? intval($post['status']) : 1; try{ $data = ['status'=>$status,"updatetime"=>date("Y-m-d H:i:s")]; $result=Db::name("action")->where("id","=",$actid)->save($data); if($result){ return app_show(0,"更新成功"); }else{ return error_show(1004,"更新失败"); } }catch (\Exception $e){ return error_show(1003,$e->getMessage()); } } /** * @return \think\response\Json|void * @throws \think\exception\DbException */ public function ActionAdd(){ $post =$this->request->post(); $token = isset($post['token']) ? trim($post['token']) : ""; if($token==""){ return error_show(101,'token不能为空'); } $effetc = VerifyTokens($token); if(!empty($effetc) && $effetc['code']!=0){ return error_show($effetc['code'],$effetc['message']); } $pageid = isset($post['menuid']) ? intval($post['menuid']) : ""; if($pageid==""){ return error_show(1001,'页面id不能为空'); } $code = isset($post['action_code']) ? trim($post['action_code']) : ""; $status = isset($post['status']) ? intval($post['status']) : 1; if($code==""){ return error_show(1002,'功能code不能为空'); } try{ $where = ['menuid'=>$pageid,'action_code'=>$code]; $true =Db::name("action")->where($where)->find(); $data = ['menuid'=>$pageid,'action_code'=>$code,'status'=>$status,"updatetime"=>date("Y-m-d H:i:s"),"addtime"=>date("Y-m-d H:i:s")]; if($true){ return error_show(1003,'此功能已存在'); }else{ Db::name("action")->insert($data); return app_show(0,"添加成功"); } }catch (\Exception $e){ return error_show(1005,$e->getMessage()); } } }