diff --git a/app/Services/PatientDoctorService.php b/app/Services/PatientDoctorService.php index c355852..45f93c2 100644 --- a/app/Services/PatientDoctorService.php +++ b/app/Services/PatientDoctorService.php @@ -15,6 +15,7 @@ use App\Model\SystemInquiryConfig; use App\Model\SystemInquiryTime; use App\Model\UserDoctor; use App\Model\UserDoctor as UserDoctorModel; +use Hyperf\DbConnection\Db; class PatientDoctorService extends BaseService { @@ -686,15 +687,27 @@ class PatientDoctorService extends BaseService 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); - } + Db::beginTransaction(); + try{ + $data = array(); + $data['patient_id'] = $user_info['client_user_id']; + $data['doctor_id'] = $doctor_id; + $patient_follow = PatientFollow::addPatientFollow($data); + if (empty($patient_follow)){ + Db::rollBack(); + return fail(HttpEnumCode::SERVER_ERROR); + } - return success(); + $params = array(); + $params['doctor_id'] = $doctor_id; + UserDoctor::inc($params,"number_of_fans"); + + Db::commit(); + return success(); + } catch (\Exception $e) { + Db::rollBack(); + return fail(HttpEnumCode::SERVER_ERROR, $e->getMessage()); + } } /** @@ -716,12 +729,23 @@ class PatientDoctorService extends BaseService return success(); } - $params = array(); - $params['patient_id'] = $user_info['client_user_id']; - $params['doctor_id'] = $doctor_id; - PatientFollow::deletePatientFollow($params); + Db::beginTransaction(); + try{ + $params = array(); + $params['patient_id'] = $user_info['client_user_id']; + $params['doctor_id'] = $doctor_id; + PatientFollow::deletePatientFollow($params); - return success(); + $params = array(); + $params['doctor_id'] = $doctor_id; + UserDoctor::dec($params,"number_of_fans"); + + Db::commit(); + return success(); + } catch (\Exception $e) { + Db::rollBack(); + return fail(HttpEnumCode::SERVER_ERROR, $e->getMessage()); + } } /**