diff --git a/app/Controller/PatientDoctorController.php b/app/Controller/PatientDoctorController.php index 856ac04..4078855 100644 --- a/app/Controller/PatientDoctorController.php +++ b/app/Controller/PatientDoctorController.php @@ -95,4 +95,26 @@ class PatientDoctorController extends AbstractController $data = $PatientDoctorService->getDoctorEvaluationList(); return $this->response->json($data); } + + /** + * 新增关注医生 + * @return ResponseInterface + */ + public function addDoctorFollow(): ResponseInterface + { + $PatientDoctorService = new PatientDoctorService(); + $data = $PatientDoctorService->addDoctorFollow(); + return $this->response->json($data); + } + + /** + * 取消关注医生 + * @return ResponseInterface + */ + public function deleteDoctorFollow(): ResponseInterface + { + $PatientDoctorService = new PatientDoctorService(); + $data = $PatientDoctorService->deleteDoctorFollow(); + return $this->response->json($data); + } } \ No newline at end of file diff --git a/app/Model/PatientFollow.php b/app/Model/PatientFollow.php index 0635eb9..6c442ce 100644 --- a/app/Model/PatientFollow.php +++ b/app/Model/PatientFollow.php @@ -77,6 +77,25 @@ class PatientFollow extends Model return self::where($params)->exists(); } + /** + * 新增 + * @param array $data + * @return \Hyperf\Database\Model\Model|PatientFollow + */ + public static function addPatientFollow(array $data): \Hyperf\Database\Model\Model|PatientFollow + { + return self::create($data); + } + + /** + * @param array $params + * @return int|mixed + */ + public static function deletePatientFollow(array $params = []): mixed + { + return self::where($params)->delete(); + } + /** * 获取分页数据 * @param array $params diff --git a/app/Services/PatientDoctorService.php b/app/Services/PatientDoctorService.php index 9d9de88..d1db6a3 100644 --- a/app/Services/PatientDoctorService.php +++ b/app/Services/PatientDoctorService.php @@ -586,6 +586,63 @@ class PatientDoctorService extends BaseService return success($order_evaluation); } + /** + * 新增关注医生 + * @return array + */ + public function addDoctorFollow(): array + { + $user_info = $this->request->getAttribute("userInfo") ?? []; + + $doctor_id = $this->request->route('doctor_id'); + + $params = array(); + $params['patient_id'] = $user_info['client_user_id']; + $params['doctor_id'] = $doctor_id; + $res = PatientFollow::getExists($params); + if ($res){ + // 已关注,重复请求 + return success(); + } + + $data = array(); + $data['patient_id'] = $user_info['client_user_id']; + $data['doctor_id'] = $doctor_id; + $patient_follow = PatientFollow::addPatientFollow($data); + if (empty($patient_follow)){ + return fail(HttpEnumCode::SERVER_ERROR); + } + + return success(); + } + + /** + * 取消关注医生 + * @return array + */ + public function deleteDoctorFollow(): array + { + $user_info = $this->request->getAttribute("userInfo") ?? []; + + $doctor_id = $this->request->route('doctor_id'); + + $params = array(); + $params['patient_id'] = $user_info['client_user_id']; + $params['doctor_id'] = $doctor_id; + $res = PatientFollow::getExists($params); + if (!$res){ + // 未关注,执行取消关注 + return success(); + } + + $params = array(); + $params['patient_id'] = $user_info['client_user_id']; + $params['doctor_id'] = $doctor_id; + PatientFollow::deletePatientFollow($params); + + return success(); + } + /** * 获取首页服务过患者的医生 * 限制条数 diff --git a/config/routes.php b/config/routes.php index 81688ca..17d784e 100644 --- a/config/routes.php +++ b/config/routes.php @@ -231,6 +231,12 @@ Router::addGroup('/patient', function () { // 获取医生评价 Router::get('/evaluation/{doctor_id:\d+}', [PatientDoctorController::class, 'getDoctorEvaluationList']); + + // 新增关注医生 + Router::post('/follow/{doctor_id:\d+}', [PatientDoctorController::class, 'addDoctorFollow']); + + // 取消关注医生 + Router::delete('/follow/{doctor_id:\d+}', [PatientDoctorController::class, 'deleteDoctorFollow']); }); // 家庭成员 @@ -506,14 +512,6 @@ Router::post('/13', [CallBackController::class, 'imCallBack']); - - - - - -// 获取问诊价格列表-消息-无问诊消息时 -Router::post('/19', [CallBackController::class, 'imCallBack']); - // 获取系统消息列表-系统消息 Router::post('/20', [CallBackController::class, 'imCallBack']);