['except' => ['getcategory'] ] ]; /** * 获取已录入信息 * * @ApiTitle (获取已录入信息) * @ApiSummary (获取已录入信息) * @ApiMethod (GET) * @ApiRoute (/api/Maintainentry/pickUpInfo) * @ApiHeaders (name=token, type=string, required=true, description="请求的Token") * @ApiParams (name="page", type="integer", required=true, description="页数") * @ApiParams (name="name", type="string", required=false, description="用户名") * @ApiParams (name="limit", type="string", required=false, description="每页条数") * @ApiParams (name="idcard", type="string", required=false, description="身份证号") * @ApiReturnParams (name="code", type="integer", required=true, sample="0") * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功") * @ApiReturnParams (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据返回") * @ApiReturn { * "code": 1, * "msg": "获取成功", * "time": "1668664754", * "data": { * "total_num": 555, * "now_num": 1, * "data": [ * { * "id": 1, * "name": "张三", * "age": 42, * "gender": "男", * "family_num": null, * "political_outlook": null, * "householder_id": 1 * } * ] * } * } */ public function pickUpInfo() { //村id $village_id = Db::table('fa_szxc_information_useraddress')->where('user_id',$this->request->uid)->value('village_id'); //获取当前村总人数 $map['village_id'] = $village_id; $total = Db::table('fa_szxc_information_useraddress')->where($map)->count(); //获取已录入人数 $www[] = ['village_id','=',$village_id]; $www[] = ['status','=','1']; // $www[] = ['enter_id','=',$this->request->uid]; $have = Db::table('fa_szxc_information_usermsg')->where($www)->count(); $man_num = Db::table('fa_szxc_information_usermsg')->where($www)->where('gender',1)->count(); $woman_num = Db::table('fa_szxc_information_usermsg')->where($www)->where('gender',2)->count(); $page = get_params('page')??1; $limit = get_params('limit')??10; // $name = get_params('name', ''); $idcard = get_params('keyword'); // if ($name) { // $where['name'] = ['like', '%' . $name . '%']; //搜索姓名 // } if ($idcard) { $where[] = ['name','like', '%' . $idcard . '%']; // 搜索身份证 } $where[] = ['village_id','=',$village_id]; $where[] = ['status','=',1]; $type = get_params('type'); if ($type==2){ $where[] = ['is_hz','=',1]; } // 获取已录入的人员信息 $res = Db::table('fa_szxc_information_usermsg')->where($where) ->order('id desc') ->field("id,user_id,name,age,gender,family_num,political_outlook,householder_id,is_hz,address_name,phone") ->page($page, $limit) ->withAttr('householder_name',function ($data,$value){ if($value['is_hz']==1){ return '本人'; }else{ $msg= Db::table('fa_szxc_information_usermsg')->where('user_id',$value['householder_id'])->value('name'); return $msg??'暂无户主'; } }) ->withAttr('family_num',function ($data,$value){ if($value['householder_id']){ $is_family = Db::table('fa_szxc_information_usermsg')->where('householder_id',$value['householder_id'])->count(); }else{ $is_family = 1; } return $is_family; }) ->withAttr('is_family',function ($data,$value){ if($value['householder_id']){ return 1; }else{ return 0; } }) ->withAttr('is_planting',function ($data,$value){ $is_planting = Db::table('fa_szxc_information_planting')->where('user_id',$value['user_id'])->find(); if($is_planting){ return 1; }else{ return 0; } }) ->withAttr('political_outlook',function ($data,$value){ $political_outlook=Db::table('fa_category')->where('id',$value['political_outlook'])->find(); return $political_outlook?$political_outlook['name']:'无'; }) ->withAttr('gender',function ($data,$value){ if ($value['gender']==1){ return '男'; }else{ return '女'; } }) ->withAttr('avatar',function ($data,$value){ if($value['is_hz']==1){ return 'https://lihai001.oss-cn-chengdu.aliyuncs.com/uploads/20230129/0dc8d0a0f3bcc168550ef263a9a170dc.png'; }else{ $msg= Db::connect('shop')->table('eb_user')->where('uid',$value['user_id'])->value('avatar'); return $msg??''; } }) ->select(); $return['total_num'] = $total; $return['now_num'] = $have; $return['man_num'] = $man_num; $return['woman_num'] = $woman_num; $return['data'] = $res; $this->apiSuccess('获取成功', $return, 1); } /** * 获取家庭成员列表 * * @ApiTitle (获取家庭成员列表) * @ApiSummary (获取家庭成员列表) * @ApiMethod (GET) * @ApiRoute (/api/Maintainentry/getFamily) * @ApiHeaders (name=token, type=string, required=true, description="请求的Token") * @ApiParams (name="user_id", type="integer", required=true, description="用户id") * @ApiReturnParams (name="code", type="integer", required=true, sample="0") * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功") * @ApiReturnParams (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据返回") * @ApiReturn { * "code": 1, * "msg": "获取成功", * "time": "1668742364", * "data": { * "yz_num": 0, * "crops_num": 2, * "land_area": "5", * "address_name": "龙马潭区石洞镇顺江村1组", * "data": [ * { * "id": 18, * "user_id": 22, * "name": "王七", * "age": 55, * "gender": "男", * "family_num": null, * "political_outlook": "群众", * "householder_id": 1, * "is_hz": 0, * "address_name": "龙马潭区石洞镇顺江村1组" * }, * { * "id": 17, * "user_id": 21, * "name": "王七", * "age": 55, * "gender": "男", * "family_num": null, * "political_outlook": "群众", * "householder_id": 1, * "is_hz": 0, * "address_name": "龙马潭区石洞镇顺江村1组" * } * ] * } * } */ public function getFamily() { //用户id $user_id = get_params('user_id'); if (empty($user_id)) { $this->apiSuccess('缺少参数', null, '0'); } // 获取户主id $where['user_id'] = $user_id; $where['status'] = 1; $householder_id = Db::table('fa_szxc_information_usermsg')->where($where)->value('householder_id'); $name = Db::table('fa_szxc_information_usermsg')->where($where)->value('name'); 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('id desc') ->field("id,user_id,phone,name,age,gender,family_num,political_outlook,householder_id,is_hz,address_name,family_relation") ->select()->toArray(); if ($res){ if($householder_id){ $is_family = Db::table('fa_szxc_information_usermsg')->where('householder_id',$householder_id)->count(); }else{ $is_family = 1; } foreach ($res as $k=>$v){ if($v['is_hz']==1){ $res[$k]['householder_name'] = '本人'; }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(); $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'] = $is_family; $return['data'] = $res; $this->apiSuccess('获取成功', $return, 1); } /** * 获取个人信息 * * @ApiTitle (获取个人信息) * @ApiSummary (获取个人信息) * @ApiMethod (GET) * @ApiRoute (/api/Maintainentry/getUserMsg) * @ApiHeaders (name=token, type=string, required=true, description="请求的Token") * @ApiParams (name="user_id", type="integer", required=true, description="用户id") * @ApiReturnParams (name="code", type="integer", required=true, sample="0") * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功") * @ApiReturnParams (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据返回") * @ApiReturn { * "code": 1, * "msg": "获取成功", * "time": "1668750751", * "data": { * "id": 17, * "user_id": 21, * "name": "王七", * "age": 55, * "gender": "男", * "phone": "13666666666", * "idcard": "510504185612345678", * "nation": "汉族", * "education": null, * "occupation": null, * "family_num": null, * "political_outlook": "群众", * "householder_id": 1, * "is_hz": 0, * "address_name": "龙马潭区石洞镇顺江村1组", * "house_msg": null, * "car_msg": null * } * } */ public function getUserMsg() { //用户id $user_id = get_params('user_id'); if (empty($user_id)) { $this->apiSuccess('缺少参数', null, '0'); } //Db::table('fa_szxc_information_usermsg')->where($map) // $map['user_id'] = $user_id; // $map['status'] = 1; // 获取人员信息 $res = Db::table('fa_szxc_information_usermsg')->where('status',1)->where('user_id',$user_id) ->field("id,user_id,name,age,gender,gender as gender_id,phone,idcard,nation,nation as nation_id, education,education as education_id,occupation,occupation as occupation_id,family_num, political_outlook,political_outlook as political_outlook_id,householder_id,is_hz,address_name,house_msg,house_msg as house_id, car_msg,car_msg as car_id,family_relation,family_relation as family_relation_id,marital_status,marital_status as marriage_id") ->withAttr('address_info',function ($data,$value){ $find=Db::table('fa_szxc_information_useraddress')->where('user_id',$value['user_id'])->find(); return $find; }) ->withAttr('gender',function ($data,$value){ if ($value['gender']==1){ return '男'; }else{ return '女'; } }) ->withAttr('nation',function ($data,$value){ $find=Db::table('fa_category')->where('id',$value['nation'])->find(); return $find?$find['name']:''; }) ->withAttr('family_relation',function ($data,$value){ $find=Db::table('fa_category')->where('id',$value['family_relation'])->find(); return $find?$find['name']:''; }) ->withAttr('political_outlook',function ($data,$value){ $find=Db::table('fa_category')->where('id',$value['political_outlook'])->find(); return $find?$find['name']:''; }) ->withAttr('education',function ($data,$value){ $find=Db::table('fa_category')->where('id',$value['education'])->find(); return $find?$find['name']:''; }) ->withAttr('occupation',function ($data,$value){ $find=Db::table('fa_category')->where('id',$value['occupation'])->find(); return $find?$find['name']:''; }) ->withAttr('house_msg',function ($data,$value){ $find=Db::table('fa_category')->where('id',$value['house_msg'])->find(); return $find?$find['name']:''; }) ->withAttr('car_msg',function ($data,$value){ $find=Db::table('fa_category')->where('id',$value['car_msg'])->find(); return $find?$find['name']:''; }) ->withAttr('marital_status',function ($data,$value){ $find=Db::table('fa_category')->where('id',$value['marital_status'])->find(); return $find?$find['name']:''; }) ->find(); if ($res) { $this->apiSuccess('获取成功', $res, 1); } else { $this->apiSuccess('暂无数据', null, '0'); } } /** * 修改个人信息 * * @ApiTitle (修改个人信息) * @ApiSummary (修改个人信息) * @ApiMethod (POST) * @ApiRoute (/api/Maintainentry/changeUserMsg) * @ApiHeaders (name=token, type=string, required=true, description="请求的Token") * @ApiParams (name="user_id", type="integer", required=true, description="用户id") * @ApiParams (name="name", type="integer", required=true, description="姓名") * @ApiParams (name="nation", type="integer", required=true, description="民族") * @ApiParams (name="political_outlook", type="integer", required=true, description="政治面貌") * @ApiParams (name="phone", type="integer", required=true, description="联系电话") * @ApiParams (name="idcard", type="integer", required=true, description="身份证号") * @ApiParams (name="gender", type="integer", required=true, description="性别") * @ApiParams (name="age", type="integer", required=true, description="年龄") * @ApiParams (name="address_name", type="integer", required=true, description="村组名称") * @ApiParams (name="house_msg", type="integer", required=true, description="房屋情况") * @ApiParams (name="car_msg", type="integer", required=true, description="车辆情况") * @ApiReturnParams (name="code", type="integer", required=true, sample="0") * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功") * @ApiReturnParams (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据返回") * @ApiReturn { * "code": 1, * "msg": "修改成功", * "time": "1668757016", * "data": [] * } */ public function changeUserMsg() { //用户id $user_id = get_params('user_id'); $post = get_params(); if (empty($user_id)) { $this->apiError('缺少参数'); } try { validate('Maintainentry.edit')->check($post); } catch (\Exception $e) { $this->apiError($e->getMessage()); } $map['user_id'] = $user_id; $oldmsg = Db::table('fa_szxc_information_usermsg')->where($map)->find(); if($oldmsg['phone'] != $post['phone']){ // 判断手机号是否已经注册 $is_mobile=Db::connect('shop')->table('eb_user')->where('phone',$post['phone'])->find(); if ($is_mobile) { $this->apiError('手机号已被使用'); } } if($oldmsg['idcard'] != $post['idcard']){ //判断身份证号是否已被使用 $InformationUsermsg = Db::table('fa_szxc_information_usermsg')->where('idcard',$post['idcard'])->field('idcard')->find(); if ($InformationUsermsg) { $this->apiError('身份证号已被使用'); } } if ($post['householder_id']==$user_id) { $data['is_hz']=1; } // 修改人员信息 $data['name'] = $post['name']; $data['nation'] = $post['nation_id']; $data['political_outlook'] = $post['political_outlook_id']; $data['phone'] = $post['phone']; $data['idcard'] = $post['idcard']; $data['gender'] = $post['gender_id']; $data['age'] = $post['age']; // $data['address_name'] = $post['address_name']; $data['house_msg'] = $post['house_id']; $data['car_msg'] = $post['car_id']; $data['occupation'] = $post['occupation_id']; $data['education'] = $post['education_id']; $data['family_relation'] = $post['family_relation_id']; $data['householder_id'] = empty($post['householder_id'])?0:$post['householder_id']; $data['updatetime'] = time(); $res = Db::table('fa_szxc_information_usermsg')->where($map)->update($data); if ($res) { $this->apiSuccess('修改成功', '修改成功'); } else { $this->apiSuccess('修改失败', '修改失败'); } } /** * 获取家庭信息 * * @ApiTitle (获取家庭信息) * @ApiSummary (获取家庭信息) * @ApiMethod (GET) * @ApiRoute (/api/Maintainentry/getFamilyMsg) * @ApiHeaders (name=token, type=string, required=true, description="请求的Token") * @ApiParams (name="user_id", type="integer", required=true, description="用户id") * @ApiReturnParams (name="code", type="integer", required=true, sample="0") * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功") * @ApiReturnParams (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据返回") * @ApiReturn { * "code": 1, * "msg": "获取成功", * "time": "1668758641", * "data": { * "id": 1, * "user_id": 1, * "name": "张三", * "age": 42, * "gender": "男", * "phone": null, * "idcard": "1351351351", * "householder_id": 1, * "is_hz": 1, * "address_name": "龙马潭区石洞镇顺江村1组", * "family_relation": "父子" * } * } */ public function getFamilyMsg() { //用户id $user_id = get_params('user_id'); if (empty($user_id)) { $this->apiSuccess('缺少参数', null, '0'); } // 获取户主id $map['user_id'] = $user_id; $map['status'] = 1; $householder_id = Db::table('fa_szxc_information_usermsg')->where($map)->field('householder_id,family_relation')->find(); if (empty($householder_id['householder_id'])) { $this->apiSuccess('未绑定户主', null, 1); } // 获取户主信息 $where['user_id'] = $householder_id['householder_id']; $where['status'] = 1; $res = Db::table('fa_szxc_information_usermsg')->where($where)->field("id,user_id,name,age,gender,phone,idcard,householder_id,is_hz,address_name")->find(); if ($res) { $res['family_relation'] = $householder_id['family_relation']; $this->apiSuccess('获取成功', $res, 1); } else { $this->apiSuccess('暂无数据', null, '0'); } } /** * 修改家庭信息 * * @ApiTitle (修改家庭信息) * @ApiSummary (修改家庭信息) * @ApiMethod (POST) * @ApiRoute (/api/Maintainentry/changeFamilyMsg) * @ApiHeaders (name=token, type=string, required=true, description="请求的Token") * @ApiParams (name="user_id", type="integer", required=true, description="用户id") * @ApiParams (name="householder_id", type="integer", required=true, description="户主id") * @ApiParams (name="family_relation", type="integer", required=true, description="与户主关系") * @ApiReturnParams (name="code", type="integer", required=true, sample="0") * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功") * @ApiReturnParams (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据返回") * @ApiReturn { * "code": 1, * "msg": "修改成功", * "time": "1668757016", * "data": [] * } */ public function changeFamilyMsg() { $post = get_params(); //用户id $user_id = get_params('user_id'); if (empty($user_id)) { $this->apiSuccess('缺少参数', null, '0'); } $map['user_id'] = $user_id; // 修改人员信息 $data['householder_id'] = $post['householder_id']; $data['family_relation'] = $post['family_relation']; $data['updatetime'] = time(); $res = Db::table('fa_szxc_information_usermsg')->where($map)->update($data); if ($res) { $this->apiSuccess('修改成功', '修改成功'); } else { $this->apiSuccess('修改失败'); } } /** * 获取种植信息 * * @ApiTitle (获取种植信息) * @ApiSummary (获取种植信息) * @ApiMethod (GET) * @ApiRoute (/api/Maintainentry/getPlantingMsg) * @ApiHeaders (name=token, type=string, required=true, description="请求的Token") * @ApiParams (name="user_id", type="integer", required=true, description="用户id") * @ApiReturnParams (name="code", type="integer", required=true, sample="0") * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功") * @ApiReturnParams (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据返回") * @ApiReturn { * "code": 1, * "msg": "获取成功", * "time": "1668993420", * "data": { * "id": 7, * "user_id": 21, * "tools_msg": [ * { * "name": "水稻", * "num": 20, * "mianji": 2 * }, * { * "name": "玉米", * "num": 30, * "mianji": 3 * } * ], * "crops_msg": [ * { * "name": "水稻", * "num": 20, * "mianji": 2 * }, * { * "name": "玉米", * "num": 30, * "mianji": 3 * } * ], * "createtime": 1668736746, * "land_area": "5", * "is_wz": null, * "nature_of_land": "国有", * "work_name": "张三", * "work_gender": "男", * "work_phone": null, * "work_relation": "本人" * } * } */ public function getPlantingMsg() { //用户id $user_id = get_params('user_id'); if (empty($user_id)) { $this->apiError('缺少参数'); } // 获取种植信息 $where['user_id'] = $user_id; $res = Db::table('fa_szxc_information_planting')->where($where)->field("id,user_id,tools_msg,crops_msg,createtime,land_area,is_wz,nature_of_land,work_name,work_gender,work_phone,work_relation,work_id,breed_area,breed_msg")->find(); if ($res) { $find=Db::table('fa_category')->where('id',$res['nature_of_land'])->find(); $res['nature_of_land_id']=$res['nature_of_land']; $res['nature_of_land']=$find['name']; $res['tools_msg'] = $res['tools_msg'] ? json_decode($res['tools_msg'], 1):[]; $res['crops_msg'] = $res['crops_msg'] ? json_decode($res['crops_msg'], 1):[]; $res['breed_msg'] = $res['breed_msg'] ? json_decode($res['breed_msg'], 1):[]; $this->apiSuccess('获取成功', $res, 1); } else { $this->apiError('暂无数据'); } } /** * 修改种植信息 * * @ApiTitle (修改种植信息) * @ApiSummary (修改种植信息) * @ApiMethod (POST) * @ApiRoute (/api/Maintainentry/changePlantingMsg) * @ApiHeaders (name=token, type=string, required=true, description="请求的Token") * @ApiParams (name="user_id", type="integer", required=true, description="用户id") * @ApiParams (name="tools_msg", type="integer", required=true, description="农机农具信息") * @ApiParams (name="crops_msg", type="integer", required=true, description="农作物信息") * @ApiParams (name="land_area", type="integer", required=true, description="土地面积") * @ApiParams (name="nature_of_land", type="integer", required=true, description="土地性质") * @ApiParams (name="is_wz", type="integer", required=true, description="土地外租") * @ApiParams (name="work_name", type="integer", required=true, description="劳动人姓名") * @ApiParams (name="work_gender", type="integer", required=true, description="劳动人口性别") * @ApiParams (name="work_phone", type="integer", required=false, description="劳动人联系方式") * @ApiParams (name="work_relation", type="integer", required=true, description="劳动人与户主关系") * @ApiParams (name="work_id", type="integer", required=true, description="劳动人id") * @ApiReturnParams (name="code", type="integer", required=true, sample="0") * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功") * @ApiReturnParams (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据返回") * @ApiReturn { * "code": 1, * "msg": "修改成功", * "time": "1668757016", * "data": [] * } */ public function changePlantingMsg() { $post = get_params(); $user_id = get_params('user_id'); if (empty($user_id)) { $this->apiError('缺少参数'); } $time = time(); $map[] = ['user_id','=',$user_id]; $find=Db::table('fa_szxc_information_planting')->where($map)->find(); // 新增写入种植表 Db::table('fa_szxc_planting')->where('user_id',$user_id)->delete(); $mianji = 0; if($post['crops_msg']){ $crops_msg_arr = json_decode($post['crops_msg'],1); foreach ($crops_msg_arr as $k=>$v){ // 根据名字查询分类 if($v['name']){ $type = Db::table('fa_szxc_planting_type')->where('name',$v['name'])->find(); if($type){ $planting_data['type_id'] = $type['id']; }else{ $type_data['name'] = $v['name']; $type_data['createtime'] = $time; $type_id = Db::table('fa_szxc_planting_type')->strict(false)->insertGetId($type_data); $planting_data['type_id'] = $type_id; } $planting_data['user_id'] = $user_id; $planting_data['num'] = $v['num']??0; $planting_data['measure'] = $v['mianji']??0; $planting_data['createtime'] = $time; Db::table('fa_szxc_planting')->strict(false)->insertGetId($planting_data); } // 计算面积 if($v['mianji']){ $mianji += $v['mianji']; } } } // 新增写入养殖表 Db::table('fa_szxc_breed')->where('user_id',$user_id)->delete(); // $mianji = 0; if(isset($post['breed_msg']) && !empty($post['breed_msg'])){ $breed_msg_arr = json_decode($post['breed_msg'],1); foreach ($breed_msg_arr as $k=>$v){ // 根据名字查询分类 if($v['name']){ $type = Db::table('fa_szxc_breed_type')->where('name',$v['name'])->find(); if($type){ $breed_data['type_id'] = $type['id']; }else{ $type_data['name'] = $v['name']; $type_data['createtime'] = $time; $type_id = Db::table('fa_szxc_breed_type')->strict(false)->insertGetId($type_data); $breed_data['type_id'] = $type_id; } $breed_data['user_id'] = $user_id; $breed_data['num'] = $v['num']??0; $breed_data['measure'] = $v['mianji']??0; $breed_data['createtime'] = $time; Db::table('fa_szxc_breed')->strict(false)->insertGetId($breed_data); } //// 计算面积 // if($v['mianji']){ // $mianji += $v['mianji']; // } } } $waste_land_area = $post['land_area'] - $mianji - $post['breed_area']; if($waste_land_area < 0){ $waste_land_area = 0; } if ($find) { // 修改人员信息 $data['tools_msg'] = $post['tools_msg']; $data['breed_msg'] = $post['breed_msg']??''; $data['breed_area'] = $post['breed_area']??''; $data['crops_msg'] = $post['crops_msg']; $data['land_area'] = $post['land_area']; $data['nature_of_land'] = $post['nature_of_land_id']; $data['is_wz'] = $post['is_wz']; // $data['work_name'] = $post['work_name']; // $data['work_gender'] = $post['work_gender']; // $data['work_phone'] = $post['work_phone'] ?? ''; // $data['work_relation'] = $post['work_relation']; // $data['work_id'] = $post['work_id']; $data['waste_land_area'] = $waste_land_area; $data['user_id'] = $user_id; $data['updatetime'] = time(); $res = Db::table('fa_szxc_information_planting')->where($map)->update($data); if ($res) { $this->apiSuccess('修改成功', '修改成功'); } else { $this->apiError('修改失败'); } }else{ // 修改人员信息 $data['tools_msg'] = $post['tools_msg']; $data['breed_msg'] = $post['breed_msg']??''; $data['breed_area'] = $post['breed_area']??''; $data['crops_msg'] = $post['crops_msg']; $data['land_area'] = $post['land_area']; $data['nature_of_land'] = $post['nature_of_land_id']; $data['is_wz'] = $post['is_wz']; // $data['work_name'] = $post['work_name']; // $data['work_gender'] = $post['work_gender']; // $data['work_phone'] = $post['work_phone'] ?? ''; // $data['work_relation'] = $post['work_relation']; // $data['work_id'] = $post['work_id']; $data['waste_land_area'] = $waste_land_area; $data['user_id'] = $user_id; $data['createtime'] = time(); $res = Db::table('fa_szxc_information_planting')->insert($data); if ($res) { $this->apiSuccess('保存成功', '保存成功'); } else { $this->apiError('保存失败'); } } } /** * 获取保险信息 * * @ApiTitle (获取保险信息) * @ApiSummary (获取保险信息) * @ApiMethod (GET) * @ApiRoute (/api/Maintainentry/getInsuranceMsg) * @ApiHeaders (name=token, type=string, required=true, description="请求的Token") * @ApiParams (name="user_id", type="integer", required=true, description="用户id") * @ApiReturnParams (name="code", type="integer", required=true, sample="0") * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功") * @ApiReturnParams (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据返回") * @ApiReturn { * "code": 1, * "msg": "获取成功", * "time": 1669019298, * "data": { * "id": 1, * "user_id": 3, * "endowment_insurance_status": "已买", * "is_subsidy": "是", * "insurance_reason": "", * "medical_insurance_type": "农村医保", * "whether_disabled": "否", * "disability_num": "", * "disability_type": "", * "disability_level": "", * "insurance_type": "农村社保", * "ny_insurance": "是", * "sy_insurance": "是" * } * } */ public function getInsuranceMsg() { //用户id $user_id = get_params('user_id'); if (empty($user_id)) { $this->apiError('缺少参数'); } // 获取种植信息 $where['user_id'] = $user_id; $res = Db::table('fa_szxc_information_insurance')->where($where) ->withAttr('endowment_insurance_status',function($value,$data){ if($value==1){ $find='已交'; }elseif($value==2){ $find='未交'; }else{ $find='代缴'; } return $find; }) ->withAttr('insurance_type',function($value,$data){ $find=Db::table('fa_category')->where('id',$value)->value('name'); return $find; }) ->withAttr('whether_disabled',function($value,$data){ $find=Db::table('fa_category')->where('id',$value)->value('name'); return $find; }) ->withAttr('disability_type',function($value,$data){ $find=Db::table('fa_category')->where('id',$value)->value('name'); return $find; }) ->withAttr('disability_level',function($value,$data){ $find=Db::table('fa_category')->where('id',$value)->value('name'); return $find; }) ->withAttr('ny_insurance',function($value,$data){ $find=Db::table('fa_category')->where('id',$value)->value('name'); return $find; }) ->withAttr('sy_insurance',function($value,$data){ $find=Db::table('fa_category')->where('id',$value)->value('name'); return $find; }) ->field("id,user_id,endowment_insurance_status,endowment_insurance_status as endowment_insurance_status_id,is_subsidy,insurance_reason,insurance_type,insurance_type as insurance_type_id, whether_disabled,whether_disabled as whether_disabled_id,disability_num,disability_type,disability_type as disability_type_id,disability_level,disability_level as disability_level_id,ny_insurance,ny_insurance as ny_insurance_id, sy_insurance,sy_insurance as sy_insurance_id") ->find(); if ($res) { $this->apiSuccess('获取成功', $res, 1); } else { $this->apiError('暂无数据'); } } /** * 修改保险信息 * * @ApiTitle (修改保险信息) * @ApiSummary (修改保险信息) * @ApiMethod (POST) * @ApiRoute (/api/Maintainentry/changeInsuranceMsg) * @ApiHeaders (name=token, type=string, required=true, description="请求的Token") * @ApiParams (name="user_id", type="integer", required=true, description="用户id") * @ApiParams (name="endowment_insurance_status", type="integer", required=true, description="养老保险状态") * @ApiParams (name="is_subsidy", type="integer", required=true, description="是否领取社保补贴") * @ApiParams (name="insurance_reason", type="integer", required=false, description="参保原因") * @ApiParams (name="medical_insurance_type", type="integer", required=true, description="医保类型") * @ApiParams (name="whether_disabled", type="integer", required=true, description="是否残疾") * @ApiParams (name="disability_num", type="integer", required=fasle, description="残疾证号") * @ApiParams (name="disability_type", type="integer", required=fasle, description="残疾类别") * @ApiParams (name="disability_level", type="integer", required=fasle, description="残疾等级") * @ApiParams (name="insurance_type", type="integer", required=true, description="参保类型") * @ApiParams (name="ny_insurance", type="integer", required=true, description="农业保险") * @ApiParams (name="sy_insurance", type="integer", required=true, description="商业保险") * @ApiReturnParams (name="code", type="integer", required=true, sample="0") * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功") * @ApiReturnParams (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据返回") * @ApiReturn { * "code": 1, * "msg": "修改成功", * "time": "1668757016", * "data": [] * } */ public function changeInsuranceMsg() { $post = get_params(); $user_id = get_params('user_id'); // try { // validate('Maintainentry.insurancemsg')->check($post); // } catch (\Exception $e) { // $this->apiError($e->getMessage()); // } if (empty($user_id)) { $this->apiError('缺少参数'); } $map['user_id'] = $user_id; $is_have = Db::table('fa_szxc_information_insurance')->where($map)->find(); if ($is_have) { // 修改信息 $data['endowment_insurance_status'] = $post['endowment_insurance_status_id']?? ''; $data['is_subsidy'] = 0; $data['insurance_reason'] = $post['insurance_reason'] ?? ''; // $data['insurance_type'] = $post['insurance_type_id']; // $data['whether_disabled'] = $post['whether_disabled']; $data['disability_num'] = $post['disability_num'] ?? ''; $data['disability_type'] = $post['disability_type_id']?? ''; $data['disability_level'] = $post['disability_level_id']?? ''; $data['insurance_type'] = $post['insurance_type_id']?? ''; $data['ny_insurance'] = $post['ny_insurance_id']?? ''; $data['sy_insurance'] = $post['sy_insurance_id']?? ''; $data['updatetime'] = time(); $res = Db::table('fa_szxc_information_insurance')->where($map)->update($data); if ($res) { $this->apiSuccess('修改成功', '修改成功'); } else { $this->apiError('修改失败'); } } else { //新增 $data['endowment_insurance_status'] = $post['endowment_insurance_status_id']?? ''; $data['is_subsidy'] = 0; $data['insurance_reason'] = $post['insurance_reason'] ?? ''; // $data['whether_disabled'] = $post['whether_disabled']; $data['disability_num'] = $post['disability_num'] ?? ''; $data['disability_type'] = $post['disability_type_id']?? ''; $data['disability_level'] = $post['disability_level_id']?? ''; $data['insurance_type'] = $post['insurance_type_id']?? ''; $data['ny_insurance'] = $post['ny_insurance_id']?? ''; $data['sy_insurance'] = $post['sy_insurance_id']?? ''; $data['createtime'] = time(); $data['user_id'] = $post['user_id']; $res = Db::table('fa_szxc_information_insurance')->strict(false)->insert($data); if ($res) { $this->apiSuccess('修改成功', '修改成功'); } else { $this->apiError('修改失败'); } } } /** * 获取健康信息 * * @ApiTitle (获取健康信息) * @ApiSummary (获取健康信息) * @ApiMethod (GET) * @ApiRoute (/api/Maintainentry/getHealthyMsg) * @ApiHeaders (name=token, type=string, required=true, description="请求的Token") * @ApiParams (name="user_id", type="integer", required=true, description="用户id") * @ApiReturnParams (name="code", type="integer", required=true, sample="0") * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功") * @ApiReturnParams (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据返回") * @ApiReturn { * "code": 1, * "msg": "获取成功", * "time": 1669019298, * "data": { * "id": 1, * "user_id": 3, * "endowment_insurance_status": "已买", * "is_subsidy": "是", * "insurance_reason": "", * "medical_insurance_type": "农村医保", * "whether_disabled": "否", * "disability_num": "", * "disability_type": "", * "disability_level": "", * "insurance_type": "农村社保", * "ny_insurance": "是", * "sy_insurance": "是" * } * } */ public function getHealthyMsg() { //用户id $user_id = get_params('user_id'); if (empty($user_id)) { $this->apiError('缺少参数'); } // 获取种植信息 $where['user_id'] = $user_id; $res = Db::table('fa_szxc_information_healthy')->where($where) ->withAttr('blood_type',function($value,$data){ $find=Db::table('fa_category')->where('id',$value)->value('name'); return $find; }) ->withAttr('drug_allergy',function($value,$data){ $find=Db::table('fa_category')->where('id',$value)->value('name'); return $find; }) ->withAttr('exposure_history',function($value,$data){ $find=Db::table('fa_category')->where('id',$value)->value('name'); return $find; }) ->withAttr('history_of_disease',function($value,$data){ $find=Db::table('fa_category')->where('id',$value)->value('name'); return $find; }) ->withAttr('genetic_name',function($value,$data){ $find=Db::table('fa_category')->where('id',$value)->value('name'); return $find; }) ->withAttr('cfpfss',function($value,$data){ $find=Db::table('fa_category')->where('id',$value)->value('name'); return $find; }) ->withAttr('poultry_corral',function($value,$data){ $find=Db::table('fa_category')->where('id',$value)->value('name'); return $find; }) ->withAttr('toilet_msg',function($value,$data){ $find=Db::table('fa_category')->where('id',$value)->value('name'); return $find; }) ->withAttr('family_history',function($value,$data){ $find=Db::table('fa_category')->where('id',$value)->value('name'); return $find; }) ->withAttr('fuel_type',function($value,$data){ $find=Db::table('fa_category')->where('id',$value)->value('name'); return $find; }) ->withAttr('drinking_water',function($value,$data){ $find=Db::table('fa_category')->where('id',$value)->value('name'); return $find; }) ->withAttr('familial_diseases',function($value,$data){ $find=Db::table('fa_category')->where('id',$value)->value('name'); return $find; }) ->withAttr('history_of_surgery',function($value,$data){ if($value==1){ $find='有'; }else{ $find='无'; } return $find; }) ->field("id,user_id,medical_insurance_type,insurance_type,blood_type,blood_type as blood_type_id,drug_allergy,drug_allergy as drug_allergy_id,exposure_history,exposure_history as exposure_history_id,history_of_disease,history_of_disease as history_of_disease_id, history_of_surgery,history_of_surgery as history_of_surgery_id,family_history,family_history as family_history_id,familial_diseases,familial_diseases as familial_diseases_id,genetic_history,genetic_name,genetic_name as genetic_name_id,whether_disabled,cfpfss,cfpfss as cfpfss_id,fuel_type,fuel_type as fuel_type_id,drinking_water,drinking_water as drinking_water_id, toilet_msg,toilet_msg as toilet_msg_id,poultry_corral,poultry_corral as poultry_corral_id") ->find(); if ($res) { $this->apiSuccess('获取成功', $res, 1); } else { $this->apiError('暂无数据'); } } /** * 修改健康信息 * * @ApiTitle (修改健康信息) * @ApiSummary (修改健康信息) * @ApiMethod (POST) * @ApiRoute (/api/Maintainentry/changeHealthyMsg) * @ApiHeaders (name=token, type=string, required=true, description="请求的Token") * @ApiParams (name="user_id", type="integer", required=true, description="用户id") * @ApiParams (name="endowment_insurance_status", type="integer", required=true, description="养老保险状态") * @ApiParams (name="is_subsidy", type="integer", required=true, description="是否领取社保补贴") * @ApiParams (name="insurance_reason", type="integer", required=false, description="参保原因") * @ApiParams (name="medical_insurance_type", type="integer", required=true, description="医保类型") * @ApiParams (name="whether_disabled", type="integer", required=true, description="是否残疾") * @ApiParams (name="disability_num", type="integer", required=fasle, description="残疾证号") * @ApiParams (name="disability_type", type="integer", required=fasle, description="残疾类别") * @ApiParams (name="disability_level", type="integer", required=fasle, description="残疾等级") * @ApiParams (name="insurance_type", type="integer", required=true, description="参保类型") * @ApiParams (name="ny_insurance", type="integer", required=true, description="农业保险") * @ApiParams (name="sy_insurance", type="integer", required=true, description="商业保险") * @ApiReturnParams (name="code", type="integer", required=true, sample="0") * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功") * @ApiReturnParams (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据返回") * @ApiReturn { * "code": 1, * "msg": "修改成功", * "time": "1668757016", * "data": [] * } */ public function changeHealthyMsg() { $post = get_params(); $user_id = get_params('user_id'); if (empty($user_id)) { $this->apiError('缺少参数'); } $map['user_id'] = $user_id; $is_have = Db::table('fa_szxc_information_healthy')->where($map)->find(); if ($is_have) { // 修改信息 // $data['medical_insurance_type'] = $post['medical_insurance_type']; // $data['insurance_type'] = $post['insurance_type']; $data['blood_type'] = $post['blood_type_id']?? ''; $data['drug_allergy'] = $post['drug_allergy_id']?? ''; $data['exposure_history'] = $post['exposure_history_id']?? ''; $data['history_of_disease'] = $post['history_of_disease_id']?? ''; $data['history_of_surgery'] = $post['history_of_surgery_id']?? ''; $data['family_history'] = $post['family_history_id']?? ''; $data['familial_diseases'] = $post['familial_diseases_id']?? ''; $data['genetic_history'] = 0; $data['genetic_name'] = $post['genetic_name_id']?? ''; // $data['whether_disabled'] = $post['whether_disabled']; $data['cfpfss'] = $post['cfpfss_id']?? ''; $data['fuel_type'] = $post['fuel_type_id']?? ''; $data['drinking_water'] = $post['drinking_water_id']?? ''; $data['toilet_msg'] = $post['toilet_msg_id']?? ''; $data['poultry_corral'] = $post['poultry_corral_id']?? ''; $data['updatetime'] = time(); $res = Db::table('fa_szxc_information_healthy')->where($map)->update($data); if ($res) { $this->apiSuccess('修改成功', '修改成功'); } else { $this->apiError('修改失败'); } } else { //新增 $data['blood_type'] = $post['blood_type_id']?? ''; $data['drug_allergy'] = $post['drug_allergy_id']?? ''; $data['exposure_history'] = $post['exposure_history_id']?? ''; $data['history_of_disease'] = $post['history_of_disease_id']?? ''; $data['history_of_surgery'] = $post['history_of_surgery_id']?? ''; $data['family_history'] = $post['family_history_id']?? ''; $data['familial_diseases'] = $post['familial_diseases_id']?? ''; $data['genetic_history'] = 0; $data['genetic_name'] = $post['genetic_name_id']?? ''; // $data['whether_disabled'] = $post['whether_disabled']; $data['cfpfss'] = $post['cfpfss_id']?? ''; $data['fuel_type'] = $post['fuel_type_id']?? ''; $data['drinking_water'] = $post['drinking_water_id']?? ''; $data['toilet_msg'] = $post['toilet_msg_id']?? ''; $data['poultry_corral'] = $post['poultry_corral_id']?? ''; $data['createtime'] = time(); $data['user_id'] = $post['user_id']; $res = Db::table('fa_szxc_information_healthy')->strict(false)->insert($data); if ($res) { $this->apiSuccess('修改成功','修改成功'); } else { $this->apiError('修改失败'); } } } /** * 新增录入接口 * * @ApiTitle (新增录入接口) * @ApiSummary (新增录入接口) * @ApiMethod (POST) * @ApiRoute (/api/Maintainentry/newEntry) * @ApiHeaders (name=token, type=string, required=true, description="请求的Token") * @ApiParams (name="page", type="integer", required=true, description="页数") * @ApiParams (name="name", type="string", required=false, description="用户名") * @ApiParams (name="limit", type="string", required=false, description="每页条数") * @ApiParams (name="idcard", type="string", required=false, description="身份证号") * @ApiReturnParams (name="code", type="integer", required=true, sample="0") * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功") * @ApiReturnParams (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据返回") * @ApiReturn ({ 'code':'1', 'msg':'返回成功' }) */ public function newEntry() { $post = get_params(); // try { // validate('Maintainentry.add')->check($post); // } catch (\Exception $e) { // $this->apiError($e->getMessage()); // } if ($post) { Db::startTrans(); // 获取录入人地址 $add = Db::table('fa_szxc_information_useraddress')->where('user_id',$this->request->uid)->find(); if(empty($add)){ $this->apiError('录入出错,请联系系统管理员'); } //判断手机号是否已经注册 $is_mobile = Db::connect('shop')->table('eb_user')->where('phone',$post['phone'])->find(); if ($is_mobile) { $this->apiError('手机号已被使用'); } //判断身份证号是否已被使用 $InformationUsermsg = Db::table('fa_szxc_information_usermsg')->where('idcard',$post['idcard'])->field('idcard')->find(); if ($InformationUsermsg) { $this->apiError('身份证号已被使用'); } // 组装地址名 if ($add['area_id'] != '') { $area_name = Db::table('fa_geo_area')->where('area_code', $add['area_id'])->value('area_name'); } if ($add['street_id'] != '') { $street_name = Db::table('fa_geo_street')->where('street_code', $add['street_id'])->value('street_name'); } if ($add['village_id'] != '') { $village = Db::table('fa_geo_village')->where('village_code', $add['village_code'])->value('village_name'); } if ($add['brigade_id'] != '') { $brigade_name = Db::table('fa_geo_brigade')->where('id', $add['brigade_id'])->value('brigade_name'); } $post['address_name'] = $area_name.$street_name.$village.$brigade_name; $village_code = $add['village_code']; try { $mobile = $post['phone']; $ip = request()->ip(); $time = time(); // 注册用户 $params = [ 'account' => $mobile, 'pwd' => password_hash(123456, PASSWORD_BCRYPT), 'nickname' => substr($mobile, 0, 3) . '****' . substr($mobile, 7, 4), 'avatar' => '', 'phone' => $mobile, 'last_ip' =>$ip ]; //写入用户表 $userid = Db::connect('shop')->table('eb_user')->strict(false)->insertGetId($params); //写入用户信息表 $post['user_id'] = 0; $post['createtime'] = $time; $post['enter_id'] = $this->request->uid; $post['gender']= $post['gender_id']; $post['nation']=$post['nation_id']; $post['political_outlook']=$post['zzmm_id']; $post['marital_status']=$post['marriage_id']; $post['area_id'] = $add['area_id']; $post['street_id'] = $add['street_id']; $post['village_id'] = $add['village_id']; $post['brigade_id'] = $add['brigade_id']; if($post['is_hz']==1){ $post['householder_id']=$userid; } Db::table('fa_szxc_information_usermsg')->strict(false)->insert($post); //写入用户地区表 $address_data['user_id'] = $userid; $address_data['area_id'] = $add['area_id']; $address_data['street_id'] = $add['street_id']; $address_data['village_id'] = $add['village_id']; $address_data['brigade_id'] = $add['brigade_id']; $address_data['village_code'] =$village_code; $address_data['createtime'] = date('Y-m-d H:i:s'); Db::table('fa_szxc_information_useraddress')->strict(false)->insert($address_data); // if($post['is_hz'] == 0){ //写入家庭关系表 $family_relations['user_id'] = $userid; //用户id $family_relations['householder_id'] = $post['householder_id']; //户主id $family_relations['family_name'] = $post['name']; //家庭成员姓名 $family_relations['family_relationship'] = $post['family_relation'];; //家庭成员与户主关系 $family_relations['family_gender'] = $post['gender_id']; //家庭成员性别 $family_relations['family_phone'] = $mobile; //家庭成员联系方式 $family_relations['family_age'] = $post['age']; //家庭成员年龄 $family_relations['createtime'] = $time;//创建时间 Db::table('fa_szxc_family_relations')->strict(false)->insert($family_relations); // } // 写入家庭成员表 $my_user_id = $post['householder_id']; $f_where[] = ['user_ids','find in set',$my_user_id]; $family_arr = Db::table('fa_szxc_family')->where($f_where)->find(); if($family_arr){ $u_data['user_ids'] = \think\facade\Db::raw("concat(user_ids ,"."',".$userid."')"); $u_data['updatetime'] = $time; Db::table('fa_szxc_family')->where('id',$family_arr['id'])->update($u_data); }else{ $szxc_family['user_ids'] = $my_user_id.','.$userid; $szxc_family['createtime'] = $time; Db::table('fa_szxc_family')->strict(false)->insert($szxc_family); } //判断土地是否外租,0没有外租 if ($post['is_waizu'] == 0) { // 新增写入种植表 Db::table('fa_szxc_planting')->where('user_id',$userid)->delete(); $mianji = 0; if($post['crops_msg']){ $crops_msg_arr = json_decode($post['crops_msg'],1); foreach ($crops_msg_arr as $k=>$v){ // 根据名字查询分类 if($v['name']){ $type = Db::table('fa_szxc_planting_type')->where('name',$v['name'])->find(); if($type){ $planting_data['type_id'] = $type['id']; }else{ $type_data['name'] = $v['name']; $type_data['createtime'] = $time; $type_id = Db::table('fa_szxc_planting_type')->strict(false)->insertGetId($type_data); $planting_data['type_id'] = $type_id; } $planting_data['user_id'] = $userid; $planting_data['num'] = $v['num']??0; $planting_data['measure'] = $v['mianji']??0; $planting_data['createtime'] = $time; Db::table('fa_szxc_planting')->strict(false)->insertGetId($planting_data); } // 计算面积 if($v['mianji']){ $mianji += $v['mianji']; } } } // 新增写入养殖表 Db::table('fa_szxc_breed')->where('user_id',$userid)->delete(); if(isset($post['breed_msg']) && !empty($post['breed_msg'])){ $breed_msg_arr = json_decode($post['breed_msg'],1); foreach ($breed_msg_arr as $k=>$v){ // 根据名字查询分类 if($v['name']){ $type = Db::table('fa_szxc_breed_type')->where('name',$v['name'])->find(); if($type){ $breed_data['type_id'] = $type['id']; }else{ $type_data['name'] = $v['name']; $type_data['createtime'] = $time; $type_id = Db::table('fa_szxc_breed_type')->strict(false)->insertGetId($type_data); $breed_data['type_id'] = $type_id; } $breed_data['user_id'] = $userid; $breed_data['num'] = $v['num']??0; $breed_data['measure'] = $v['mianji']??0; $breed_data['createtime'] = $time; Db::table('fa_szxc_breed')->strict(false)->insertGetId($breed_data); } //// 计算面积 // if($v['mianji']){ // $mianji += $v['mianji']; // } } } if(!isset($post['breed_area'])){ $post['breed_area'] = 0; } $waste_land_area = $post['land_area'] - $mianji - $post['breed_area']; if($waste_land_area < 0){ $waste_land_area = 0; } // 写入种植信息表 $cropsarr['user_id'] = $userid; //用户id $cropsarr['tools_msg'] = $post['tools_msg'];//农机农具信息 $cropsarr['crops_msg'] = $post['crops_msg'];//农作物信息 $cropsarr['land_area'] = $post['land_area'];//土地面积 $cropsarr['nature_of_land'] = $post['nature_of_land'];//土地性质 // $cropsarr['work_name'] = $post['work_name'];//劳动人姓名 // $cropsarr['work_gender'] = $post['work_gender'];//劳动人口性别 // $cropsarr['work_relation'] = $post['work_relation'];//劳动人与户主关系 // $cropsarr['work_id'] = $post['work_id'];//劳动人id $cropsarr['waste_land_area'] = $waste_land_area;//荒地面积 $cropsarr['breed_msg'] = $post['breed_msg']??'';//养殖详情信息 $cropsarr['breed_area'] = $post['breed_area']??'';//养殖面积 $cropsarr['createtime'] = $time;//创建时间 Db::table('fa_szxc_information_planting')->strict(false)->insert($cropsarr); } Db::commit(); $this->apiSuccess('录入成功','录入成功'); } catch (ValidateException | PDOException | Exception $e) { Db::rollback(); $this->apiError($e->getMessage()); } } else { $this->apiError('缺少参数'); } } /** * 获取密码加密后的字符串 * @param string $password 密码 * @param string $salt 密码盐 * @return string */ public function getEncryptPassword($password, $salt = '') { return md5(md5($password) . $salt); } /** * 获取分类 * */ public function getcategory() { // 分类标识 $type = get_params('type'); if (empty($type)) { $this->apiError('缺少参数'); } else { $where[] = ['pid','<>',0]; $where[] = ['type','=',$type]; $where[] = ['status','=','normal']; $result = Db::table('fa_category')->where($where)->field('id,name,weigh')->order('weigh desc')->select(); if ($result) { $this->apiSuccess('获取成功', $result, 1); } else { $this->apiError('暂无数据'); } } } /** * 用户新增录入接口 * * @ApiTitle (用户新增录入接口) * @ApiSummary (用户新增录入接口) * @ApiMethod (POST) * @ApiRoute (/api/Maintainentry/userEntry) * @ApiHeaders (name=token, type=string, required=true, description="请求的Token") * @ApiParams (name="page", type="integer", required=true, description="页数") * @ApiParams (name="name", type="string", required=false, description="用户名") * @ApiParams (name="limit", type="string", required=false, description="每页条数") * @ApiParams (name="idcard", type="string", required=false, description="身份证号") * @ApiReturnParams (name="code", type="integer", required=true, sample="0") * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功") * @ApiReturnParams (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据返回") * @ApiReturn ({ 'code':'1', 'msg':'返回成功' }) */ public function userEntry() { $post = get_params(); // try { // validate('Maintainentry.myadd')->check($post); // } catch (\Exception $e) { // $this->apiError($e->getMessage()); // } if ($post) { //// 验证验证码 // if (! Sms::check($post['phone'], $post['captcha'], 'mobilelogin')) { // $this->apiError(__('Captcha is incorrect')); // } Db::startTrans(); // 获取录入人地址 $add = Db::table('fa_szxc_information_useraddress')->where('user_id',$this->request->uid)->find(); if(empty($add)){ $this->apiError('录入出错,请联系系统管理员'); } // 判断手机号是否已经注册 $is_mobile = Db::connect('shop')->table('eb_user')->where('phone',$post['phone'])->find(); if ($is_mobile) { $this->apiError('手机号已被使用'); } //判断身份证号是否已被使用 $InformationUsermsg = Db::table('fa_szxc_information_usermsg')->where('idcard',$post['idcard'])->field('idcard')->find(); if ($InformationUsermsg) { $this->apiError('身份证号已被使用'); } // 组装地址名 if ($add['area_id'] != '') { $area_name = Db::table('fa_geo_area')->where('area_code', $add['area_id'])->value('area_name'); } if ($add['street_id'] != '') { $street_name = Db::table('fa_geo_street')->where('street_code', $add['street_id'])->value('street_name'); } if ($add['village_id'] != '') { $village = Db::table('fa_geo_village')->where('village_code', $add['village_code'])->value('village_name'); } if ($add['brigade_id'] != '') { $brigade_name = Db::table('fa_geo_brigade')->where('id', $add['brigade_id'])->value('brigade_name'); } $post['address_name'] = $area_name.$street_name.$village.$brigade_name; $village_code = $add['village_code']; try { $mobile = $post['phone']; $ip = request()->ip(); $time = time(); // 注册用户 $params = [ 'account' => $mobile, 'pwd' => password_hash(123456, PASSWORD_BCRYPT), 'nickname' => substr($mobile, 0, 3) . '****' . substr($mobile, 7, 4), 'avatar' => '', 'phone' => $mobile, 'last_ip' =>$ip ]; //写入用户表 $userid = Db::connect('shop')->table('eb_user')->strict(false)->insertGetId($params); //写入用户信息表 $post['user_id'] = $userid; $post['createtime'] = $time; $post['enter_id'] = $this->request->uid; $post['gender']= $post['gender_id']; $post['nation']=$post['nation_id']; $post['political_outlook']=$post['zzmm_id']; $post['marital_status']=$post['marriage_id']; $post['area_id'] = $add['area_id']; $post['street_id'] = $add['street_id']; $post['village_id'] = $add['village_id']; $post['brigade_id'] = $add['brigade_id']; Db::table('fa_szxc_information_usermsg')->strict(false)->insert($post); //写入用户地区表 $address_data['user_id'] = $userid; $address_data['area_id'] = $add['area_id']; $address_data['street_id'] = $add['street_id']; $address_data['village_id'] = $add['village_id']; $address_data['brigade_id'] = $add['brigade_id']; $address_data['village_code'] =$village_code; $address_data['createtime'] = date('Y-m-d H:i:s'); Db::table('fa_szxc_information_useraddress')->strict(false)->insert($address_data); // 写入家庭成员表 $my_user_id = $this->request->uid; $f_where[] = ['user_ids','find in set',$my_user_id]; $family_arr = Db::table('fa_szxc_family')->where($f_where)->find(); if($family_arr){ $u_data['user_ids'] = \think\facade\Db::raw("concat(user_ids ,"."',".$userid."')"); $u_data['updatetime'] = $time; Db::table('fa_szxc_family')->where('id',$family_arr['id'])->update($u_data); // 如果已经设置户主,更新当前人员户主ID if($family_arr['householder_id']){ $h_data['householder_id'] = $family_arr['householder_id']; Db::table('fa_szxc_information_usermsg')->where('user_id',$userid)->update($h_data); } }else{ $szxc_family['user_ids'] = $my_user_id.','.$userid; $szxc_family['createtime'] = $time; Db::table('fa_szxc_family')->strict(false)->insert($szxc_family); } Db::commit(); $this->apiSuccess('录入成功','录入成功'); } catch (ValidateException | PDOException | Exception $e) { Db::rollback(); $this->apiError($e->getMessage()); } } else { $this->apiError('缺少参数'); } } // 获取我的家庭成员 public function getmyFamily(){ //用户id $user_id = $this->request->uid; // 获取户主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(); $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 setFamily(){ $user_id = get_params('user_id'); if (empty($user_id)) { $this->apiError('缺少参数'); } $f_where[] = ['user_ids','find in set',$user_id]; $family_arr = Db::table('fa_szxc_family')->where($f_where)->find(); if($family_arr){ if($family_arr['householder_id']){ $this->apiError('已经设置户主'); }else{ Db::startTrans(); try { $map[] = ['user_id','in',$family_arr['user_ids']]; // 更新家庭成员表 Db::table('fa_szxc_family')->where('id',$family_arr['id'])->update(['householder_id'=>$user_id]); // 更新用户信息表 $hz_data['householder_id'] = $user_id; $hz_data['is_hz'] = 0; Db::table('fa_szxc_information_usermsg')->where($map)->update($hz_data); $hz_data['is_hz'] = 1; Db::table('fa_szxc_information_usermsg')->where('user_id',$user_id)->update($hz_data); Db::commit(); $this->apiSuccess('设置成功','设置成功'); } catch (ValidateException | \PDOException | Exception $e) { Db::rollback(); $this->apiError($e->getMessage()); } } }else{ Db::startTrans(); try { $map[] = ['user_id','=',$user_id]; // 更新用户信息表 $hz_data['householder_id'] = $user_id; $hz_data['is_hz'] = 1; Db::table('fa_szxc_information_usermsg')->where($map)->update($hz_data); Db::commit(); $this->apiSuccess('设置成功','设置成功'); } catch (ValidateException | \PDOException | Exception $e) { Db::rollback(); $this->apiError($e->getMessage()); } } } // 验证手机号、身份证是否使用 public function is_have($phone=0,$idcard=0,$captcha=0){ // 验证验证码 // if (! Sms::check($phone, $captcha, 'mobilelogin')) { // $this->apiError(__('验证码不正确')); // } // 判断手机号是否已经注册 $is_mobile = Db::connect('shop')->table('eb_user')->where('phone',$phone)->find(); if ($is_mobile) { $this->apiError('手机号已被使用'); } //判断是否已被使用 $is_phone = Db::table('fa_szxc_information_usermsg')->where('phone',$phone)->field('phone')->find(); if ($is_phone) { $this->apiError('手机号已被使用'); } //判断身份证号是否已被使用 $InformationUsermsg = Db::table('fa_szxc_information_usermsg')->where('idcard',$idcard)->field('idcard')->find(); if ($InformationUsermsg) { $this->apiError('身份证号已被使用'); } $this->apiSuccess('验证通过','验证通过'); } // 接收家庭成员邀请 public function receive_invitations(){ $params = get_params(); //用户id $user_id = $this->request->uid; $user = Db::table('fa_szxc_information_usermsg')->where('user_id',$user_id)->find(); if($user){ if($user['householder_id']){ $this->apiError('已有户主不能接收邀请'); }else{ $hz = Db::table('fa_szxc_information_usermsg')->where('user_id',$params['user_id'])->find(); if(!$hz){ $this->apiError('邀请人未找到'); } if($hz['is_hz'] != 1){ $this->apiError('不是户主,不能邀请'); } Db::startTrans(); try { $hz_id = $params['hz_id']; //户主id // 修改用户户主 $data['householder_id'] = $hz_id; //户主id $data['is_hz'] = 0; Db::table('fa_szxc_information_usermsg')->where('user_id',$user_id)->update($data); //写入家庭成员表 $my_user_id = $hz_id; $f_where[] = ['user_ids','find in set',$my_user_id]; $family_arr = Db::table('fa_szxc_family')->where($f_where)->find(); $time = time(); if($family_arr){ $u_data['user_ids'] = \think\facade\Db::raw("concat(user_ids ,"."',".$user_id."')"); $u_data['updatetime'] = $time; Db::table('fa_szxc_family')->where('id',$family_arr['id'])->update($u_data); }else{ $szxc_family['user_ids'] = $my_user_id.','.$user_id; $szxc_family['householder_id'] = $hz_id; $szxc_family['createtime'] = $time; Db::table('fa_szxc_family')->strict(false)->insert($szxc_family); } $this->apiSuccess('操作成功'); } catch (ValidateException | \PDOException | Exception $e) { Db::rollback(); $this->apiError($e->getMessage()); } } }else{ $this->apiError('未找到该用户'); } } }