['except' => [] ] ]; public function __construct(App $app) { parent::__construct($app); $this->model = Db::table('fa_szxc_party_branch'); $this->validate = new BranchValdate(); } public function index($page=1) { $where=[ ['status','=', 1], ]; //根据个人村id进行查询 if ($this->request->uid) { $find = Db::table('fa_szxc_information_useraddress')->where('user_id', $this->request->uid)->find(); if ($find) { if ($find['auth_range']==1){ $where[] = ['village', '=', $find['village_id']]; }elseif ($find['auth_range']==2){ $where[] = ['township', '=', $find['street_id']]; }elseif ($find['auth_range']==3){ $where[] = ['county', '=', $find['area_id']]; } } } $select=Db::table('fa_szxc_party_branch')->where($where) ->withAttr('nickname',function ($value, $data){ $find= Db::connect('shop')->table('eb_user')->where('uid',$data['user_id'])->value('nickname'); return $find?:''; }) ->withAttr('two_nickname',function ($value, $data){ $find= Db::connect('shop')->table('eb_user')->where('uid',$data['user_id'])->value('nickname'); return $find?:''; }) ->withAttr('count',function ($value, $data){ $find= Db::table('fa_szxc_party_info')->where('party_branch',$data['id'])->where('branch_type',1)->count(); return $find; }) ->page($page)->limit(20)->select(); $branch_count=Db::table('fa_szxc_party_branch')->where('status', 1)->count(); $info_count=Db::table('fa_szxc_party_info')->where('status', 1)->where('branch_type',1)->count(); $info_count_two=Db::table('fa_szxc_party_info')->where('status', 1)->where('branch_type',2)->count(); $data=[ 'page'=>$page, 'branch_count'=>$branch_count,//支部总数 'info_count'=>$info_count,//党员总数 'info_count_two'=>$info_count_two,//预备役总数 'list' =>$select//党支部列表 ]; return $this->apiSuccess('ok',$data); } /** 党员信息 * @param $search * @param $page */ public function info($id) { $where=[ ['status','=', 1], ['user_id','=',$id], ]; $user_info=Db::table('fa_szxc_information_usermsg')->where($where) ->withAttr('category_info',function ($value, $data){ $find=Db::table('fa_category')->where('id',$data['marital_status'])->find(); $nation=Db::table('fa_category')->where('id',$data['nation'])->find(); $datas['marital']=$find['name']; $datas['nation']=$nation['name']; return $datas; }) ->withAttr('branch_info',function ($value, $data){ $find=Db::table('fa_szxc_party_branch')->where('id',$data['branch_id']) ->withAttr('user_nickname',function ($value, $data){ $find=Db::table('fa_szxc_information_usermsg')->where('user_id',$data['user_id'])->field('name')->find(); return $find?$find['name']:''; }) ->withAttr('two_user_nickname',function ($value, $data){ $find=Db::table('fa_szxc_information_usermsg')->where('user_id',$data['two_user_id'])->field('name')->find(); return $find?$find['name']:''; }) ->find(); return $find; }) ->withAttr('branch_user_info',function ($value, $data){ $find=Db::table('fa_szxc_party_info')->where('user_id',$data['user_id'])->find(); return $find; }) ->find(); return $this->apiSuccess('ok',$user_info); } public function info_save($id,$branch_id) { // $where=[ // ['status','=', 1], // ['user_id','=',$id], // ['branch_id','=',$id], // ]; $input=get_params(); $find=Db::table('fa_szxc_party_info')->where('user_id',$id)->find(); if ($find){ Db::table('fa_szxc_party_info')->where('user_id',$id)->update($input); return $this->apiSuccess('ok','修改成功'); }else{ $input['party_branch']=$branch_id; $input['user_id']=$id; Db::table('fa_szxc_party_info')->insert($input); return $this->apiSuccess('ok','添加成功'); }; } /** 党员管理 * @param $search * @param $page */ public function info_list($id,$search,$page=1) { $where=[ ['status','=', 1], ['party_branch','=', $id], ]; if ($search!=''){ $where[]=['title','like','%'.$search.'%']; } $branch=Db::table('fa_szxc_party_branch')->where('id',$id)->find(); $select = Db::table('fa_szxc_party_info')->withAttr('user_info', function ($value, $data) { $find = Db::connect('shop')->table('eb_user')->where('uid', $data['user_id'])->field('nickname,phone mobile,avatar')->find(); return $find; }) ->where($where)->page($page)->limit(20)->select(); $info_count=Db::table('fa_szxc_party_info')->where('status', 1)->where('branch_type',1)->count(); $info_count_two=Db::table('fa_szxc_party_info')->where('status', 1)->where('branch_type',2)->count(); $data=[ 'page'=>$page, 'branch'=>$branch, 'info_count'=>$info_count,//党员总数 'info_count_two'=>$info_count_two,//预备役总数 'list' =>$select//党员列表 ]; return $this->apiSuccess('ok',$data); } public function add(){ } public function post(){ $input=get_params(); $res=$this->validate->check($input); if (!$res){ return $this->apiError($this->validate->getError()); } $res=$this->model->save($input); if ($res){ return $this->apiSuccess('添加成功'); }else{ return $this->apiError('添加失败'); } } public function edit($id){ $find=Db::table('fa_szxc_party_branch')->where('id',$id)->where('status', 1) ->withAttr('nickname',function ($value, $data){ $find= Db::connect('shop')->table('eb_user')->where('uid',$data['user_id'])->value('nickname'); return $find?:''; }) ->withAttr('two_nickname',function ($value, $data){ $find= Db::connect('shop')->table('eb_user')->where('uid',$data['two_user_id'])->value('nickname'); return $find?:''; })->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('删除失败'); } } }