diff --git a/app/Controller/DetectionController.php b/app/Controller/DetectionController.php index e832871..ce55016 100644 --- a/app/Controller/DetectionController.php +++ b/app/Controller/DetectionController.php @@ -36,4 +36,20 @@ class DetectionController extends AbstractController $data = $detectionService->getDetectionProject(); return $this->response->json($data); } + + /** + * 获取检测机构合作医生列表 + * @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); + } } \ No newline at end of file diff --git a/app/Model/UserDoctor.php b/app/Model/UserDoctor.php index c7a505e..7cca6e2 100644 --- a/app/Model/UserDoctor.php +++ b/app/Model/UserDoctor.php @@ -363,4 +363,32 @@ class UserDoctor extends Model { return self::where($params)->decrement($field,$numeral); } + + /** + * 获取先思达合作医生列表 + * @param array $params + * @param array $hospital_params + * @param array $fields + * @return array|Collection + */ + public static function getDiagnoCoopDoctorList(array $params,array $hospital_params,array $fields = ['*']): array|Collection + { + return self::with([ + "Hospital:hospital_id,hospital_name,hospital_level_name" + ]) + ->whereHas('Hospital', function ($query) use ($hospital_params) { + $query->where($hospital_params); + }) +// ->when($keyword, function ($query, $keyword) { +// $query->where(function ($query) use ($keyword) { +// $query->orwhere("user_name", 'like', '%' . $keyword . '%'); +// $query->orwhere("department_custom_name", 'like', '%' . $keyword . '%'); +// $query->orWhereHas('Hospital', function ($query) use ($keyword) { +// $query->where('hospital_name', 'like', '%' . $keyword . '%'); +// }); +// }); +// }) + ->where($params) + ->get($fields); + } } diff --git a/app/Request/DetectionRequest.php b/app/Request/DetectionRequest.php index 39d736a..db33471 100644 --- a/app/Request/DetectionRequest.php +++ b/app/Request/DetectionRequest.php @@ -13,6 +13,9 @@ class DetectionRequest extends FormRequest 'getDetectionProjectList' => [ // 获取合作公司检测项目列表 'company_id', ], + 'getDetectionDoctorList' => [ // 获取检测机构合作医生列表 + 'company_id', + ], ]; /** diff --git a/app/Services/DetectionService.php b/app/Services/DetectionService.php index bbaf9ef..08d3b3f 100644 --- a/app/Services/DetectionService.php +++ b/app/Services/DetectionService.php @@ -2,8 +2,11 @@ namespace App\Services; +use App\Model\Area; use App\Model\BasicCompany; use App\Model\DetectionProject; +use App\Model\UserDoctor; +use App\Model\UserLocation; class DetectionService extends BaseService { @@ -67,4 +70,119 @@ class DetectionService extends BaseService return success($detection_project->toArray()); } + + /** + * 获取检测机构合作医生列表 + * @return array + */ + public function getDetectionDoctorList(): array + { + $company_id = $this->request->input("company_id",1); + $user_info = $this->request->getAttribute("userInfo") ?? []; + + // 获取合作公司数据 + $params = array(); + $params['company_id'] = $company_id; + $basic_company = BasicCompany::getOne($params); + if (empty($basic_company)){ + return fail(); + } + + // 返回数据 + $response_data = array( + "area" => [ + "province_id" => "", + "province" => "", + "city_id" => "", + "city" => "", + "county_id" => "", + "county" => "", + ], + "doctors" => [], + ); + + // 搜索数据 + $hospital_params = array(); + + // 获取用户定位地址数据 + $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 = array(); + $params['status'] = 1; + $params['idcard_status'] = 1; + $params['iden_auth_status'] = 1; + $params['is_sys_diagno_cooperation'] = 1; + + $fields = [ + "doctor_id", + "user_id", + "user_name", + "avatar", + "doctor_title", + ]; + $user_doctors = UserDoctor::getDiagnoCoopDoctorList($params,$hospital_params,$fields); + if (!empty($user_doctors)){ + foreach ($user_doctors as &$value){ + $doctor = array(); + if (!empty($value['Hospital'])){ + $doctor['hospital_name'] = $value['Hospital']['hospital_name']; + } + + unset($value['Hospital']); + } + + $response_data['doctors'] = $user_doctors->toArray(); + } + + return success($response_data); + } } \ No newline at end of file diff --git a/config/routes.php b/config/routes.php index 19c8f15..dc9c6ab 100644 --- a/config/routes.php +++ b/config/routes.php @@ -272,7 +272,7 @@ Router::addGroup('/patient', function () { Router::post('', [InquiryController::class, 'addDetectionOrder']); // 获取检测机构合作医生列表 - Router::get('/doctor', [InquiryController::class, 'getDetectionDoctor']); + Router::get('/doctor', [DetectionController::class, 'getDetectionDoctorList']); // 获取合作公司检测项目列表 Router::get('/project', [DetectionController::class, 'getDetectionProjectList']);