model = new \app\bug\model\Action(); } /** 获取页面id下功能按钮 */ public function ActionList(){ $pageid =$this->request->post("id/d"); if($pageid=="")return error('页面id不能为空'); $condition = ['menuid'=>$pageid]; $data=$this->model->with(["actionInfo"])->where($condition)->select(); return success("获取成功",$data); } /** 新建功能按钮 * @return \think\Response|\think\response\Json|void */ public function ActionSave(){ $post =$this->request->param(["id","action_name"=>"","action_desc"=>"","status"=>0,"action_code"=>""], "post","trim"); $valid = Validate::rule([ "id|主键Id"=>"number|gt:0", "action_name|功能名称"=>"require|max:255|unique:action_list,action_name,{$post['id']}", "status|功能状态"=>"number|in:0,1", "action_code|功能编号"=>"require|max:255", "action_desc|功能描述"=>"max:255", ]); if($valid->check($post)==false)return error($valid->getError()); $isf= ActionList::where('id','=',$post['id'])->findOrEmpty(); if($post['id']>0 && $isf->isEmpty())return error('未找到数据'); try{ $isf->save($post); return success("功能添加成功"); }catch (\Exception $e){ return error($e->getMessage()); } } /** * 页面功能启禁用 * @return \think\Response|\think\response\Json|void */ public function ActionStatus(){ $post =$this->request->param(['id'=>0,'status'=>0],'post','trim'); $valid = Validate::rule([ 'id|主键Id'=>'require|number|gt:0', 'status|功能状态'=>'number|in:0,1' ]); if($valid->check($post)==false)return error($valid->getError()); $isf= $this->model->where('id','=',$post['id'])->findOrEmpty(); if($isf->isEmpty())return error('未找到数据'); try{ $isf->status=$post['status']; $result=$isf->save(); if($result==false) return error("{$this->model->status_cn[$isf->status]}失败"); return success("{$this->model->status_cn[$isf->status]}成功"); }catch (\Exception $e){ return error($e->getMessage()); } } /**页面功能添加 * @return \think\response\Json|void * @throws \think\exception\DbException */ public function ActionAdd(){ $post =$this->request->param(['menuid'=>0,'status'=>1,"action_code"=>""],'post','trim'); $valid = Validate::rule([ 'menuid|菜单Id'=>'require|number|gt:0', 'action_code|功能编号'=>'require|number|gt:0', 'status|功能状态'=>'number|in:0,1' ]); if($valid->check($post)==false)return error($valid->getError()); $isf = $this->model->where( ['menuid'=>$post['menuid'],'action_code'=>$post['action_code']])->findOrEmpty(); if($isf->isEmpty()==false) return error('此功能已存在'); try{ $result=$isf->save($post); if($result==false)return error("创建失败"); return success("创建成功"); }catch (\Exception $e){ return error($e->getMessage()); } } /** * @return \think\response\Json * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function index(){ $post =$this->request->post(); $data = Db::name("admin_menu")->where(["pid"=>0,"status"=>1,"is_del"=>0])->select(); $result = []; if(empty($data)){ return app_show(0,"获取成功",$result); } foreach ($data as $key=>$val){ $val["child"]=[]; $result[$val['id']] =$val; } $child =Db::name("admin_menu")->where([["pid","<>",0],['status',"=",1],["is_del","=",0]])->select(); foreach ($child as $k=>$value){ // $act = PasAction::all(['menuid'=>$value['id'],"status"=>1]); $act =Db::name("action")->alias("a")->leftJoin("action_list l","a.action_code=l.action_code")->field ("a.*,action_name")->where(['a.menuid'=>$value['id'],"a.status"=>1])->select(); $act_data = Db::name("action_field")->where(['menuid'=>$value['id'],"status"=>1])->select(); $value['action'] = $act; $value['action_data'] = $act_data; if(array_key_exists($value['pid'],$result)){ $result[$value['pid']]["child"][]=$value; } } return app_show(0,"获取成功",array_values($result)); } }