['except' => [] ] ]; public function __construct(App $app) { parent::__construct($app); $this->model = Db::table('fa_szxc_party_branch_pay_user'); $this->validate = new BranchPayUserValdate(); } public function index($id,$page=1,$search='',$type=0) { $find=Db::table('fa_szxc_party_branch_pay_list')->where('id',$id)->find(); if (!$find) return $this->edit('清单数据不存在'); $where=[ ['branch_id','=',$find['branch_id']], ['status','=', 1] ]; if ($search!=''){ $userall=Db::table('fa_user')->where('nickname','like', $search . '%')->field('id')->select(); if ($userall){ $ids=[]; foreach ($userall as $user){ $ids[]=$user['id']; } $where[]=['user_id','in',implode(',',$ids)]; }else{ return $this->apiError('查询内容不存在'); } } if ($type>0){ $where[]=['is_pay','=',$type]; } $select=Db::table('fa_szxc_party_branch_pay_user')->where($where) ->withAttr('user',function ($value, $data){ $user = Db::table('fa_user')->where('id',$data['user_id'])->field('nickname,avatar')->find(); return $user; }) ->page($page)->limit(20)->select(); $count=Db::table('fa_szxc_party_info')->where('party_branch',$id)->count(); $data['info']=$find; $data['list']=$select; $data['count']=$count; return $this->apiSuccess('ok',$data); } public function add($id,$page=1){ $find=Db::table('fa_szxc_party_branch_pay_list')->where('id',$id)->find(); $strtotime1=strtotime($find['start_time']); $strtotime2=strtotime($find['end_time']); $m=date('m',$strtotime1); $ms=date('m',$strtotime2); $m_count=$ms-$m; if (!$find) return $this->edit('清单数据不存在'); $select=Db::table('fa_szxc_party_info')->where('party_branch',$find['branch_id']) ->withAttr('user_info',function($data,$value){ $user = Db::table('fa_user')->where('id',$value['user_id'])->field('nickname,avatar')->find(); return $user; })->field('id,user_id,branch_pay') ->select(); $data_list=$select->toArray(); foreach($data_list as $key=>$value){ $data_list[$key]['month_pay_count']= $value['branch_pay']*$m_count; $data_list[$key]['month_count']=$m_count; } $count=Db::table('fa_szxc_party_info')->where('party_branch',$find['branch_id'])->count(); $data['info']=$find; $data['list']=$data_list; $data['count']=$count; return $this->apiSuccess('ok',$data); } public function post(){ $input=get_params(); foreach ($input as $k=>$v){ $res=$this->validate->check($v); if (!$res){ return $this->apiError($this->validate->getError()); } } $res=$this->model->saveAll($input); if ($res){ return $this->apiSuccess('添加成功'); }else{ return $this->apiError('添加失败'); } } public function edit($id){ $find=$this->model->where('id',$id)->find(); return $this->apiSuccess('ok',$find); } public function put($id){ $input=get_params();; $res=$this->validate->check($input); if (!$res){ return $this->apiError($this->validate->getError()); } $res=$this->model->where('id',$id)->update($input); if ($res){ return $this->apiSuccess('修改成功'); }else{ return $this->apiError('修改失败'); } } public function delete($id){ $res=$this->model->where('id',$id)->update(['status'=>0]); if ($res){ return $this->apiSuccess('删除成功'); }else{ return $this->apiError('删除失败'); } } }