From 1d94c8597cf9b3f14707e591d9943fcdae2b47b5 Mon Sep 17 00:00:00 2001 From: wucongxing <815046773@qq.com> Date: Tue, 25 Apr 2023 14:57:22 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=85=B3=E6=B3=A8=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=EF=BC=8C=E6=96=B0=E5=A2=9E=E7=BB=B4=E6=8A=A4=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Services/PatientDoctorService.php | 50 ++++++++++++++++++++------- 1 file changed, 37 insertions(+), 13 deletions(-) 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()); + } } /**