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"=>0,"action_name"=>"","action_desc"=>"","status"=>1,"action_code"=>""], "post","trim"); $valid = Validate::rule([ "id|主键Id"=>"number|egt:0", "action_name|功能名称"=>"require|max:255|unique:app\bug\model\ActionList,action_name", "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('未找到数据'); $message = $post['id']>0?"修改":"添加"; try{ $isf->save($post); return success("功能{$message}成功"); }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()); } } }