From fac54d32870b36c449cab381694713a33a6b9415 Mon Sep 17 00:00:00 2001 From: wucongxing <815046773@qq.com> Date: Wed, 23 Aug 2023 17:19:17 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=8E=B7=E5=8F=96=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E5=9C=B0=E5=9D=80=E3=80=82=E4=BF=AE=E6=94=B9=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E6=A3=80=E6=B5=8B=E6=9C=BA=E6=9E=84=E5=90=88=E4=BD=9C?= =?UTF-8?q?=E5=8C=BB=E7=94=9F=E5=88=97=E8=A1=A8=E6=8E=A5=E5=8F=A3=EF=BC=8C?= =?UTF-8?q?=E6=8B=86=E5=88=86=E4=B8=BA=E4=B8=A4=E4=B8=AA=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/DetectionController.php | 6 ++ app/Controller/UserController.php | 11 ++ app/Request/DetectionRequest.php | 10 ++ app/Services/DetectionService.php | 133 ++++++------------------- app/Services/UserService.php | 65 ++++++++++++ config/routes.php | 6 +- 6 files changed, 123 insertions(+), 108 deletions(-) diff --git a/app/Controller/DetectionController.php b/app/Controller/DetectionController.php index 9cdba87..24b7e9e 100644 --- a/app/Controller/DetectionController.php +++ b/app/Controller/DetectionController.php @@ -3,6 +3,7 @@ namespace App\Controller; use App\Request\DetectionRequest; +use App\Request\UserRequest; use App\Services\DetectionService; use Psr\Container\ContainerExceptionInterface; use Psr\Container\NotFoundExceptionInterface; @@ -35,9 +36,14 @@ class DetectionController extends AbstractController /** * 获取检测机构合作医生列表 * @return ResponseInterface + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface */ public function getDetectionDoctorList(): ResponseInterface { + $request = $this->container->get(DetectionRequest::class); + $request->scene('getDetectionDoctorList')->validateResolved(); + $detectionService = new DetectionService(); $data = $detectionService->getDetectionDoctorList(); return $this->response->json($data); diff --git a/app/Controller/UserController.php b/app/Controller/UserController.php index d161ca9..6de89b5 100644 --- a/app/Controller/UserController.php +++ b/app/Controller/UserController.php @@ -178,4 +178,15 @@ class UserController extends AbstractController $data = $UserService->postLocation(); return $this->response->json($data); } + + /** + * 获取用户地址 + * @return ResponseInterface + */ + public function getLocation(): ResponseInterface + { + $UserService = new UserService(); + $data = $UserService->getLocation(); + return $this->response->json($data); + } } \ No newline at end of file diff --git a/app/Request/DetectionRequest.php b/app/Request/DetectionRequest.php index 34694bd..e244678 100644 --- a/app/Request/DetectionRequest.php +++ b/app/Request/DetectionRequest.php @@ -29,6 +29,12 @@ class DetectionRequest extends FormRequest 'detection_bar_code', 'detection_pic', ], + 'getDetectionDoctorList' => [ // 绑定检测管 + 'province_id', + 'city_id', + 'county_id', + 'company_id' + ], ]; /** @@ -53,6 +59,8 @@ class DetectionRequest extends FormRequest 'doctor_id' => 'required', 'client_type' => 'required|integer|min:1|max:2', 'detection_bar_code' => 'required', + 'province_id' => 'required_with:city_id,county_id', + 'city_id' => 'required_with:county_id', ]; } @@ -73,6 +81,8 @@ class DetectionRequest extends FormRequest 'client_type.min' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR), 'client_type.max' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR), 'detection_bar_code.required' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR), + 'province_id.required_with' => "请选择省份", + 'city_id.required_with' => "请选择城市", ]; } } diff --git a/app/Services/DetectionService.php b/app/Services/DetectionService.php index 1a1cb5d..d5aef0c 100644 --- a/app/Services/DetectionService.php +++ b/app/Services/DetectionService.php @@ -112,116 +112,41 @@ class DetectionService extends BaseService return fail(); } - // 返回数据 - $response_data = array( - "area" => [ - "province_id" => "", - "province" => "", - "city_id" => "", - "city" => "", - "county_id" => "", - "county" => "", - ], - "doctors" => [], - ); - // 搜索数据 $hospital_params = array(); - if (empty($province_id) && empty($city_id) && empty($county_id)){ - // 获取用户定位地址数据 + if (!empty($province_id)){ $params = array(); - $params['user_id'] = $user_info['user_id']; - $user_location = UserLocation::getOne($params); - if (!empty($user_location)){ - // 处理省市区对应 - if (!empty($user_location['province']) && !empty($user_location['city'])){ - $params = array(); - $params['area_name'] = $user_location['province']; - $params['area_type'] = 2; - $area_province = Area::getOne($params); - if (!empty($area_province)){ - $response_data['area']['province_id'] = $area_province['area_id']; - $response_data['area']['province'] = $area_province['area_name']; - - // 搜索条件 - $hospital_params['province_id'] = $area_province['area_id']; - } - - if (!empty($response_data['area']['province_id'])){ - $params = array(); - $params['area_name'] = $user_location['city']; - $params['parent_id'] = $response_data['area']['province_id']; - $params['area_type'] = 3; - $area_city = Area::getOne($params); - if (!empty($area_city)){ - $response_data['area']['city_id'] = $area_city['area_id']; - $response_data['area']['city'] = $area_city['area_name']; - - // 搜索条件 - $hospital_params['city_id'] = $area_city['area_id']; - } - } - } - - if (!empty($response_data['area']['city_id']) && !empty($user_location['county'])){ - $params = array(); - $params['area_name'] = $user_location['county']; - $params['parent_id'] = $response_data['area']['city_id']; - $params['area_type'] = 4; - $area_county = Area::getOne($params); - if (!empty($area_county)){ - $response_data['area']['county_id'] = $area_county['area_id']; - $response_data['area']['county'] = $area_county['area_name']; - - // 搜索条件 - $hospital_params['county_id'] = $area_county['area_id']; - } - } + $params['area_id'] = $province_id; + $params['area_type'] = 2; + $area_province = Area::getOne($params); + if (!empty($area_province)){ + // 搜索条件 + $hospital_params['province_id'] = $area_province['area_id']; } - } else{ - if (!empty($province_id)){ - $params = array(); - $params['area_id'] = $province_id; - $params['area_type'] = 2; - $area_province = Area::getOne($params); - if (!empty($area_province)){ - $response_data['area']['province_id'] = $area_province['area_id']; - $response_data['area']['province'] = $area_province['area_name']; + } - // 搜索条件 - $hospital_params['province_id'] = $area_province['area_id']; - } + if (!empty($city_id)){ + $params = array(); + $params['area_id'] = $city_id; + $params['parent_id'] = $province_id; + $params['area_type'] = 3; + $area_city = Area::getOne($params); + if (!empty($area_city)){ + // 搜索条件 + $hospital_params['city_id'] = $area_city['area_id']; } + } - if (!empty($response_data['area']['province_id']) && !empty($city_id)){ - $params = array(); - $params['area_id'] = $city_id; - $params['parent_id'] = $response_data['area']['province_id']; - $params['area_type'] = 3; - $area_city = Area::getOne($params); - if (!empty($area_city)){ - $response_data['area']['city_id'] = $area_city['area_id']; - $response_data['area']['city'] = $area_city['area_name']; - - // 搜索条件 - $hospital_params['city_id'] = $area_city['area_id']; - } - } - - if (!empty($response_data['area']['city_id']) && !empty($county_id)){ - $params = array(); - $params['area_id'] = $county_id; - $params['parent_id'] = $response_data['area']['city_id']; - $params['area_type'] = 4; - $area_county = Area::getOne($params); - if (!empty($area_county)){ - $response_data['area']['county_id'] = $area_county['area_id']; - $response_data['area']['county'] = $area_county['area_name']; - - // 搜索条件 - $hospital_params['county_id'] = $area_county['area_id']; - } + if (!empty($county_id)){ + $params = array(); + $params['area_id'] = $county_id; + $params['parent_id'] = $city_id; + $params['area_type'] = 4; + $area_county = Area::getOne($params); + if (!empty($area_county)){ + // 搜索条件 + $hospital_params['county_id'] = $area_county['area_id']; } } @@ -251,11 +176,9 @@ class DetectionService extends BaseService $value['avatar'] = addAliyunOssWebsite($value['avatar']); } - - $response_data['doctors'] = $user_doctors->toArray(); } - return success($response_data); + return success($user_doctors->toArray()); } /** diff --git a/app/Services/UserService.php b/app/Services/UserService.php index 8fa73d7..8c8f11c 100644 --- a/app/Services/UserService.php +++ b/app/Services/UserService.php @@ -3,6 +3,7 @@ namespace App\Services; use App\Constants\HttpEnumCode; +use App\Model\Area; use App\Model\Popup; use App\Model\SubTemplate; use App\Model\User; @@ -621,6 +622,70 @@ class UserService extends BaseService return success(); } + /** + * 获取用户地址 + * @return array + */ + public function getLocation(): array + { + $user_info = $this->request->getAttribute("userInfo") ?? []; + + // 定义返回数据 + $area = [ + "province_id" => "", + "province" => "", + "city_id" => "", + "city" => "", + "county_id" => "", + "county" => "", + ]; + + $params = array(); + $params['user_id'] = $user_info['user_id']; + $user_location = UserLocation::getOne($params); + if (empty($user_location)){ + return success($area); + } + + // 处理省市区对应 + if (!empty($user_location['province']) && !empty($user_location['city'])){ + $params = array(); + $params['area_name'] = $user_location['province']; + $params['area_type'] = 2; + $area_province = Area::getOne($params); + if (!empty($area_province)){ + $area['province_id'] = $area_province['area_id']; + $area['province'] = $area_province['area_name']; + } + + if (!empty($area['province_id'])){ + $params = array(); + $params['area_name'] = $user_location['city']; + $params['parent_id'] = $area['province_id']; + $params['area_type'] = 3; + $area_city = Area::getOne($params); + if (!empty($area_city)){ + $area['city_id'] = $area_city['area_id']; + $area['city'] = $area_city['area_name']; + } + } + } + + if (!empty($area['city_id']) && !empty($user_location['county'])){ + $params = array(); + $params['area_name'] = $user_location['county']; + $params['parent_id'] = $area['city_id']; + $params['area_type'] = 4; + $area_county = Area::getOne($params); + if (!empty($area_county)){ + $area['county_id'] = $area_county['area_id']; + $area['county'] = $area_county['area_name']; + } + } + + return success($area); + } + /** * 通过user_id获取用户openid * @param string|int $user_id diff --git a/config/routes.php b/config/routes.php index 57b50d7..494b22e 100644 --- a/config/routes.php +++ b/config/routes.php @@ -686,9 +686,9 @@ Router::addGroup('/user', function () { // 上报用户地址 Router::post('/location', [UserController::class, 'postLocation']); -// -// // 获取用户地址 -// Router::get('/location', [UserController::class, 'getLocation']); + + // 获取用户地址 + Router::get('/location', [UserController::class, 'getLocation']); }); // 获取患者问诊病例