新增获取家庭成员接口

This commit is contained in:
彭桃 2023-03-21 11:24:42 +08:00
parent 123bf308e2
commit 31265bb9c0
2 changed files with 98 additions and 0 deletions
app/api

@ -1677,6 +1677,102 @@ class Maintainentry extends BaseController
// $crops_msg = [];
// }
// 获取养殖信息
$www['user_id'] = $user_id;
$breed = Db::table('fa_szxc_breed')->where($www)->count();
$crops_msg = Db::table('fa_szxc_planting')->where($www)->count();
$return['yz_num'] = $breed; //养殖种类
$return['crops_num'] = $crops_msg;//种植种类
$return['land_area'] = $planting['land_area'] ??0;//土地面积
$return['address_name'] = $res[0]['address_name'] ?? '';
$return['name'] = $name;
$return['family_num'] = Db::table('fa_szxc_information_usermsg')->where($map)->count();
$return['is_set_hz'] = $is_set_hz;
$return['avatar'] = Db::connect('shop')->table('eb_user')->where('uid', $user_id)->value('avatar');
$return['data'] = $res;
$this->apiSuccess('获取成功', $return, 1);
}
// 获取家庭成员
public function getFamilyBy(){
//用户id
$user_id = get_params('user_id');
if(empty($user_id)){
$this->apiError('缺少参数');
}
// 获取户主id
$f_where[] = ['user_ids','find in set',$user_id];
$family_arr = Db::table('fa_szxc_family')->where($f_where)->find();
if ($family_arr) {
$map[] = ['user_id','in',$family_arr['user_ids']];
} else {
$where['user_id'] = $user_id;
$where['status'] = 1;
$householder_id = Db::table('fa_szxc_information_usermsg')->where($where)->value('householder_id');
if ($householder_id) {
$map[] = ['householder_id','=',$householder_id];
$map[] = ['status','=',1];
} else {
$map[] = ['user_id','=',$user_id];
$map[] = ['status','=',1];
}
}
// 获取家庭的人员信息
$res = Db::table('fa_szxc_information_usermsg')->where($map)
->order('is_hz desc')
->field("id,user_id,name,age,gender,family_num,political_outlook,householder_id,is_hz,address_name,family_relation,phone")
->withAttr('avatar', function ($value, $data) {
return Db::connect('shop')->table('eb_user')->where('uid', $data['user_id'])->value('avatar');
})
->select()->toArray();
if ($res){
// 获取户主id
$where['user_id'] = $user_id;
$where['status'] = 1;
$name = Db::table('fa_szxc_information_usermsg')->where($where)->value('name');
$is_set_hz = 0;
foreach ($res as $k=>$v){
if($v['is_hz']==1){
$is_set_hz = 1;
$res[$k]['householder_name'] = '本人';
$res[$k]['avatar'] = 'https://lihai001.oss-cn-chengdu.aliyuncs.com/uploads/20230129/0dc8d0a0f3bcc168550ef263a9a170dc.png';
}else{
$msg= Db::table('fa_szxc_information_usermsg')->where('user_id',$v['householder_id'])->value('name');
$res[$k]['householder_name'] = $msg?:'暂无户主';
}
if($v['householder_id']){
$res[$k]['is_family'] = 1;
}else{
$res[$k]['is_family'] = 0;
}
$is_planting = Db::table('fa_szxc_information_planting')->where('user_id',$v['user_id'])->field('id')->find();
if($is_planting){
$res[$k]['is_planting'] = 1;
}else{
$res[$k]['is_planting'] = 0;
}
if($v['gender'] == 1){
$res[$k]['gender'] = '男';
}else{
$res[$k]['gender'] = '女';
}
$family_relationship = $v['family_relation'];
$family_relationship_name=Db::table('fa_category')->where('id',$family_relationship)->field('name')->find();
$res[$k]['family_relationship']=$family_relationship_name?$family_relationship_name['name'] :'';
$political_outlook=Db::table('fa_category')->where('id',$v['political_outlook'])->field('name')->find();
$res[$k]['political_outlook'] = $political_outlook?$political_outlook['name']:'无';
}
}
// 获取种植信息
$www['user_id'] = $user_id;
$planting = Db::table('fa_szxc_information_planting')->where($www)->field('id,crops_msg,land_area')->find();
// if($planting && $planting['crops_msg']){
// $crops_msg = json_decode($planting['crops_msg'], 1);
// $crops_msg = array_filter(array_column($crops_msg,'name'));
// }else{
// $crops_msg = [];
// }
// 获取养殖信息
$www['user_id'] = $user_id;
$breed = Db::table('fa_szxc_breed')->where($www)->count();

@ -114,6 +114,8 @@ Route::group('/',function () {
//红白喜事轮播图
Route::get('Slide/get_slide_two', 'Slide/get_slide_two');
Route::get('User/index', 'User/index');
// 接受家庭邀请
Route::post('Maintainentry/receive_invitations', 'Maintainentry/receive_invitations');
})->middleware(\app\api\middleware\Auth::class);
Route::group('/',function () {