model = new VoteCommentModel(); $this->validate = new VoteCommentValdate(); } public function index($search='',$vote_id=1,$page=1) { $select=Db::name('szxc_party_vote_comment') ->withAttr('user_info',function ($data,$value){ $find=Db::name('user')->where('id',$value['user_id'])->field('nickname,avatar')->find(); $data = $find; $data['user_type_info']='党员'; return $data; }) ->withAttr('reply',function ($data,$value){ if ($value['reply']==null){ $find='无'; }else{ $find=$value['reply']; } return $find; }) ->where('vote_id', $vote_id)->where('status', 1)->where('type',1)->page($page)->limit(20)->select(); $select_type2=Db::name('szxc_party_vote_comment') ->withAttr('user_info',function ($data,$value){ $find=Db::name('user')->where('id',$value['user_id'])->field('nickname,avatar')->find(); $data = $find; $data['user_type_info']='党员'; return $data; }) ->withAttr('reply',function ($data,$value){ if ($value['reply']==null){ $find='无'; }else{ $find=$value['reply']; } return $find; }) ->where('vote_id', $vote_id)->where('status', 1)->where('type',2)->page($page)->limit(20)->select(); $select_type3=Db::name('szxc_party_vote_comment') ->withAttr('user_info',function ($data,$value){ $find=Db::name('user')->where('id',$value['user_id'])->field('nickname,avatar')->find(); $data = $find; $data['user_type_info']='党员'; return $data; }) ->withAttr('reply',function ($data,$value){ if ($value['reply']==null){ $find='无'; }else{ $find=$value['reply']; } return $find; }) ->where('vote_id', $vote_id)->where('status', 1)->where('type',3)->page($page)->limit(20)->select(); return $this->success('ok',['list1'=>$select,'list2'=>$select_type2,'list3'=>$select_type3]); } public function add(){ } public function post(){ $input=$this->request->post();; $res=$this->validate->check($input); if (!$res){ return $this->error($this->validate->getError()); } $useraddress = Db::name('szxc_information_useraddress')->where('user_id', $this->auth->id)->where('status', 1)->find(); if ($useraddress) { $input['county'] = $useraddress['area_id']; $input['township'] = $useraddress['street_id']; $input['village'] = $useraddress['village_id']; } $input['user_id']=1; $input['add_time']=date('Y-m-d H:i:s'); $res=$this->model->save($input); if ($res){ return $this->success('评论成功'); }else{ return $this->error('添加失败'); } } public function edit($id){ $find=$this->model->with('user')->where('id',$id)->find(); return $this->success('ok',$find); } public function put($id){ $input=$this->request->post();; $res=$this->validate->check($input); if (!$res){ return $this->error($this->validate->getError()); } $input['user_id'] = 1; $res=$this->model->where('id',$id)->update($input); if ($res){ return $this->success('修改成功'); }else{ return $this->error('修改失败'); } } public function delete($id){ $res=$this->model->where('id',$id)->update(['status'=>0]); if ($res){ return $this->success('删除成功'); }else{ return $this->error('删除失败'); } } }