diff --git a/app/Controller/PatientCenterController.php b/app/Controller/PatientCenterController.php index 585dc34..01c4d71 100644 --- a/app/Controller/PatientCenterController.php +++ b/app/Controller/PatientCenterController.php @@ -10,17 +10,5 @@ use Psr\Http\Message\ResponseInterface; */ class PatientCenterController extends AbstractController { - /** - * 删除我的医生 - * 首页-个人中心 - * @return ResponseInterface - */ - public function deleteMyDoctor(): ResponseInterface - { - $patientFamilyService = new MyDoctorService(); - $data = $patientFamilyService->deleteMyDoctor(); - - return $this->response->json($data); - } } \ No newline at end of file diff --git a/app/Controller/UserPatientController.php b/app/Controller/UserPatientController.php index 0b955a7..652c382 100644 --- a/app/Controller/UserPatientController.php +++ b/app/Controller/UserPatientController.php @@ -3,6 +3,7 @@ namespace App\Controller; use App\Request\UserPatientRequest; +use App\Services\MyDoctorService; use App\Services\UserPatientService; use Psr\Container\ContainerExceptionInterface; use Psr\Container\NotFoundExceptionInterface; @@ -34,4 +35,33 @@ class UserPatientController extends AbstractController $data = $UserPatientService->getPatientCenterInfo(); return $this->response->json($data); } + + /** + * 获取患者优惠卷列表 + * @return ResponseInterface + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface + */ + public function getPatientCouponlist(): ResponseInterface + { + $request = $this->container->get(UserPatientRequest::class); + $request->scene('getPatientCouponlist')->validateResolved(); + + $UserPatientService = new UserPatientService(); + $data = $UserPatientService->getPatientCouponlist(); + return $this->response->json($data); + } + + /** + * 删除服务过患者的医生 + * 首页-个人中心 + * @return ResponseInterface + */ + public function deletePatientDoctor(): ResponseInterface + { + $UserPatientService = new UserPatientService(); + $data = $UserPatientService->deletePatientDoctor(); + return $this->response->json($data); + } + } \ No newline at end of file diff --git a/app/Model/PatientHistoryInquiry.php b/app/Model/PatientHistoryInquiry.php index b3c6c88..119866e 100644 --- a/app/Model/PatientHistoryInquiry.php +++ b/app/Model/PatientHistoryInquiry.php @@ -10,6 +10,7 @@ use Hyperf\Database\Model\Collection; use Hyperf\Database\Model\Relations\BelongsTo; use Hyperf\Database\Model\Relations\HasOne; use Hyperf\Database\Model\Relations\HasOneThrough; +use Hyperf\DbConnection\Db; use Hyperf\Snowflake\Concern\Snowflake; /** @@ -104,7 +105,7 @@ class PatientHistoryInquiry extends Model /** * 获取首页用户历史问诊数据 - * 关联表:user_doctor + * 限制数量 * @param array $params * @param array $fields * @param int $limit @@ -119,6 +120,24 @@ class PatientHistoryInquiry extends Model ->where($params) ->limit($limit) ->get($fields); + + } + + /** + * 获取首页用户历史问诊数据 + * @param array $params + * @param array $fields + * @return Collection|array|\Hyperf\Utils\Collection + */ + public static function getIndexHistoryDoctorList(array $params, array $fields = ["*"]): Collection|array|\Hyperf\Utils\Collection + { + return self::with([ + "UserDoctor:doctor_id,user_name,avatar,hospital_id", + "UserDoctor.Hospital:hospital_id,hospital_name" + ]) + ->where($params) + ->get($fields); + } /** diff --git a/app/Request/UserPatientRequest.php b/app/Request/UserPatientRequest.php index 4651460..577ce38 100644 --- a/app/Request/UserPatientRequest.php +++ b/app/Request/UserPatientRequest.php @@ -10,7 +10,9 @@ use Hyperf\Validation\Request\FormRequest; class UserPatientRequest extends FormRequest { protected array $scenes = [ - + 'getPatientCouponlist' => [ // 获取患者优惠卷列表 + 'user_coupon_status', + ], ]; /** @@ -27,7 +29,7 @@ class UserPatientRequest extends FormRequest public function rules(): array { return [ - + 'user_coupon_status' => 'required|integer|min:0|max:2', ]; } @@ -37,7 +39,10 @@ class UserPatientRequest extends FormRequest public function messages(): array { return [ - + 'user_coupon_status.required' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR), + 'user_coupon_status.integer' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR), + 'user_coupon_status.min' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR), + 'user_coupon_status.max' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR), ]; } } diff --git a/app/Services/CouponService.php b/app/Services/CouponService.php index ce03edf..fbfb3d4 100644 --- a/app/Services/CouponService.php +++ b/app/Services/CouponService.php @@ -11,28 +11,23 @@ use App\Model\UserCoupon; class CouponService extends BaseService { /** - * 获取用户可用优惠卷-列表 + * 获取用户某状态全部优惠卷-列表 * @param string|int $user_id 用户id - * @param string|int $inquiry_type 订单类型(1:专家问诊 2:快速问诊 3:公益问诊 4:问诊购药) - * @param int $coupon_client 使用平台(1:小程序) + * @param array $inquiry_type [1,2,3,4,5]适用范围(1:全部 2:快速问诊 3:专家问诊 4:公益问诊 5:问诊购药) + * @param int $user_coupon_status 状态(0:未使用 1:已使用 3:已过期) * @return array */ - public function getUserUsableCouponList(string|int $user_id, string|int $inquiry_type, int $coupon_client = 1): array + public function getUserCouponStatusList(string|int $user_id, array $inquiry_type, int $user_coupon_status): array { - // 问诊类型需加1 - $inquiry_type = $inquiry_type + 1; - $params = array(); $params[] = ['user_id','=',$user_id]; - $params[] = ['user_coupon_status','=',0];// 状态(0:未使用 1:已使用 3:已过期) - $params[] = ['valid_start_time','>',date('Y-m-d H:i:s',time())]; // 有效使用时间 - $params[] = ['valid_end_time','<',date('Y-m-d H:i:s',time())]; // 过期使用时间 + $params[] = ['user_coupon_status','=',$user_coupon_status];// 状态(0:未使用 1:已使用 3:已过期) $coupon_params = array(); - $coupon_params[] = ['coupon_client','=',$coupon_client]; + $coupon_params[] = ['coupon_client','=',1]; $coupon_params[] = ['coupon_status','=',1]; // 状态(1:正常 2:强制失效 3:结束 4:删除) - $application_scope_params = [1,$inquiry_type]; // 适用范围(1:全部 2:快速问诊 3:专家问诊 4:公益问诊 5:问诊购药) + $application_scope_params = $inquiry_type; // 适用范围(1:全部 2:快速问诊 3:专家问诊 4:公益问诊 5:问诊购药) $user_coupon = UserCoupon::getWithCouponList($params,$coupon_params,$application_scope_params); if (empty($user_coupon)){ diff --git a/app/Services/IndexService.php b/app/Services/IndexService.php index 6e1d240..0508cb5 100644 --- a/app/Services/IndexService.php +++ b/app/Services/IndexService.php @@ -145,14 +145,16 @@ class IndexService extends BaseService $params["module_status"] = 1; $module = ModuleModel::getList($params); + $PatientDoctorService = new PatientDoctorService(); + // 我的医生 $my_doctor = []; if (!empty($user_info)) { - $my_doctor = $this->getIndexPatientDoctor($user_info['client_user_id']); + $my_doctor = $PatientDoctorService->getIndexPatientDoctorLimit($user_info['client_user_id']); } // 推荐医生 - $recommend_doctor = $this->getIndexRecommendDoctor(); + $recommend_doctor = $PatientDoctorService->getIndexRecommendDoctorLimit(); $result = array(); $result["banner"] = $banner ?? [];// banner @@ -220,117 +222,7 @@ class IndexService extends BaseService return success($data); } - /** - * 患者端-首页-我的医生-限制条数 - * @param string $patient_id - * @return array - */ - protected function getIndexPatientDoctor(string $patient_id): array - { - $results = array(); - $params = array(); - $params['patient_id'] = $patient_id; - $params['history_status'] = 1; - $patient_history_doctors = PatientHistoryInquiryModel::getIndexHistoryDoctorLimit($params); - if (!empty($patient_history_doctors)) { - foreach ($patient_history_doctors as $patient_history_doctor) { - if (empty($patient_history_doctor['userDoctor'])) { - continue; - } - // 组合数据 - $data = array(); - $data['doctor_id'] = $patient_history_doctor['userDoctor']['doctor_id']; - $data['user_name'] = $patient_history_doctor['userDoctor']['user_name']; - $data['avatar'] = addAliyunOssWebsite($patient_history_doctor['userDoctor']['avatar']); - $data['hospital_name'] = ""; - if (!empty($patient_history_doctor['userDoctor']['Hospital'])) { - $data['hospital_name'] = $patient_history_doctor['userDoctor']['Hospital']['hospital_name']; - } - // 按照天来计算,当日为1,前一天为2 未服务过为0 - if (empty($patient_history_doctor['created_at'])) { - $data['days'] = 0; - } else { - $data['days'] = ceil((strtotime(date('Y-m-d', strtotime('+1 day'))) - strtotime($patient_history_doctor['created_at'])) / 86400); - } - - $results[] = $data; - - unset($data); - } - } - return $results; - } - - /** - * 患者端-首页-推荐医生-限制条数 - * @return array - */ - protected function getIndexRecommendDoctor(): array - { - $results = array(); - - // 推荐医生 - $fields = [ - "doctor_id", - "user_id", - "user_name", - "status", - "multi_point_status", - "avatar", - "doctor_title", - "department_custom_name", - "hospital_id", - "is_online", - "is_img_expert_reception", - "is_img_welfare_reception", - "be_good_at", - ]; - - $recommend_doctors = UserDoctorModel::getIndexRecommendDoctorLimit(5, $fields); - if (empty($recommend_doctors)) { - return success(); - } - - foreach ($recommend_doctors as $recommend_doctor) { - $data = array(); - $data['doctor_id'] = $recommend_doctor['doctor_id']; - $data['user_id'] = $recommend_doctor['user_id']; - $data['user_name'] = $recommend_doctor['user_name']; - $data['status'] = $recommend_doctor['status']; - $data['multi_point_status'] = $recommend_doctor['multi_point_status']; // 医生多点执业认证状态(0:未认证 1:认证通过 2:审核中 3:认证失败) - $data['avatar'] = addAliyunOssWebsite($recommend_doctor['avatar']); - $data['doctor_title'] = empty($recommend_doctor['doctor_title']) ? "" : DoctorTitleCode::getMessage($recommend_doctor['doctor_title']); - $data['department_custom_name'] = $recommend_doctor['department_custom_name']; - $data['is_online'] = $recommend_doctor['is_online']; - $data['is_img_welfare_reception'] = $recommend_doctor['is_img_welfare_reception']; - $data['be_good_at'] = $recommend_doctor['be_good_at']; - $data['hospital_name'] = $recommend_doctor['Hospital']['hospital_name']; - $data['hospital_level_name'] = $recommend_doctor['Hospital']['hospital_level_name']; - - // 处理接诊价格 - $data['price'] = 0; - $data['free_clinic_price'] = 0; - foreach ($recommend_doctor['DoctorInquiryConfig'] as $doctor_inquiry_config) { - if ($doctor_inquiry_config['inquiry_mode'] == 1){ - if ($doctor_inquiry_config['inquiry_type'] == 1) { - // 专家问诊 - $data['price'] = $doctor_inquiry_config['inquiry_price']; - } - - if ($doctor_inquiry_config['inquiry_type'] == 3) { - // 公益 - $data['free_clinic_price'] = $doctor_inquiry_config['inquiry_price']; - } - } - } - - $results[] = $data; - - unset($data); - } - return success($results); - } } \ No newline at end of file diff --git a/app/Services/MyDoctorService.php b/app/Services/MyDoctorService.php index c489fcf..52b6cc5 100644 --- a/app/Services/MyDoctorService.php +++ b/app/Services/MyDoctorService.php @@ -7,42 +7,5 @@ use App\Model\PatientHistoryInquiry; class MyDoctorService extends BaseService { - /** - * 删除我的医生 - * 首页-个人中心 - * @return array - */ - public function deleteMyDoctor(): array - { - $history_inquiry_id = $this->request->route('history_inquiry_id'); - $user_info = $this->request->getAttribute("userInfo") ?? []; - - $params = array(); - $params['history_inquiry_id'] = $history_inquiry_id; - $params['patient_id'] = $user_info['client_user_id']; - - $patient_history_inquiry = PatientHistoryInquiry::getOne($params); - if (empty($patient_history_inquiry)){ - return fail(HttpEnumCode::HTTP_ERROR, "数据不存在"); - } - - if ($patient_history_inquiry['history_status'] == 0){ - return success(); - } - - $params = array(); - $patient_history_inquiry['history_inquiry_id'] = $history_inquiry_id; - - $data = array(); - $data['history_status'] = 0; - - $res = PatientHistoryInquiry::edit($params,$data); - if (!$res){ - return fail(HttpEnumCode::SERVER_ERROR); - } - - return success(); - - } } \ No newline at end of file diff --git a/app/Services/PatientDoctorService.php b/app/Services/PatientDoctorService.php index be17397..5ebc6f1 100644 --- a/app/Services/PatientDoctorService.php +++ b/app/Services/PatientDoctorService.php @@ -14,6 +14,7 @@ use App\Model\PatientHistoryInquiry as PatientHistoryInquiryModel; use App\Model\SystemInquiryConfig; use App\Model\SystemInquiryTime; use App\Model\UserDoctor; +use App\Model\UserDoctor as UserDoctorModel; class PatientDoctorService extends BaseService { @@ -437,4 +438,134 @@ class PatientDoctorService extends BaseService return success(); } + + /** + * 获取首页服务过患者的医生 + * 限制条数 + * @param string $patient_id + * @return array + */ + public function getIndexPatientDoctorLimit(string $patient_id): array + { + $results = array(); + + $params = array(); + $params['patient_id'] = $patient_id; + $params['history_status'] = 1; + $patient_history_doctors = PatientHistoryInquiryModel::getIndexHistoryDoctorLimit($params); + if (!empty($patient_history_doctors)) { + foreach ($patient_history_doctors as $patient_history_doctor) { + if (empty($patient_history_doctor['userDoctor'])) { + continue; + } + + if (count($results) > 5){ + // 超出5个 + continue; + } + + // 检测是否重复,如果重复,删除最早的一个数据 + foreach ($results as $key => $result){ + if ($patient_history_doctor['doctor_id'] == $result['doctor_id']){ + unset($results[$key]); + } + } + + // 组合数据 + $data = array(); + $data['doctor_id'] = $patient_history_doctor['userDoctor']['doctor_id']; + $data['user_name'] = $patient_history_doctor['userDoctor']['user_name']; + $data['avatar'] = addAliyunOssWebsite($patient_history_doctor['userDoctor']['avatar']); + $data['hospital_name'] = ""; + if (!empty($patient_history_doctor['userDoctor']['Hospital'])) { + $data['hospital_name'] = $patient_history_doctor['userDoctor']['Hospital']['hospital_name']; + } + + // 按照天来计算,当日为1,前一天为2 未服务过为0 + if (empty($patient_history_doctor['created_at'])) { + $data['days'] = 0; + } else { + $data['days'] = ceil((strtotime(date('Y-m-d', strtotime('+1 day'))) - strtotime($patient_history_doctor['created_at'])) / 86400); + } + + $results[] = $data; + + unset($data); + } + } + + $results = array_merge($results); + return $results; + } + + /** + * 获取首页推荐医生 + * 限制条数 + * @return array + */ + public function getIndexRecommendDoctorLimit(): array + { + $results = array(); + + // 推荐医生 + $fields = [ + "doctor_id", + "user_id", + "user_name", + "status", + "multi_point_status", + "avatar", + "doctor_title", + "department_custom_name", + "hospital_id", + "is_online", + "is_img_expert_reception", + "is_img_welfare_reception", + "be_good_at", + ]; + + $recommend_doctors = UserDoctorModel::getIndexRecommendDoctorLimit(5, $fields); + if (empty($recommend_doctors)) { + return success(); + } + + foreach ($recommend_doctors as $recommend_doctor) { + $data = array(); + $data['doctor_id'] = $recommend_doctor['doctor_id']; + $data['user_id'] = $recommend_doctor['user_id']; + $data['user_name'] = $recommend_doctor['user_name']; + $data['status'] = $recommend_doctor['status']; + $data['multi_point_status'] = $recommend_doctor['multi_point_status']; // 医生多点执业认证状态(0:未认证 1:认证通过 2:审核中 3:认证失败) + $data['avatar'] = addAliyunOssWebsite($recommend_doctor['avatar']); + $data['doctor_title'] = empty($recommend_doctor['doctor_title']) ? "" : DoctorTitleCode::getMessage($recommend_doctor['doctor_title']); + $data['department_custom_name'] = $recommend_doctor['department_custom_name']; + $data['is_online'] = $recommend_doctor['is_online']; + $data['is_img_welfare_reception'] = $recommend_doctor['is_img_welfare_reception']; + $data['be_good_at'] = $recommend_doctor['be_good_at']; + $data['hospital_name'] = $recommend_doctor['Hospital']['hospital_name']; + $data['hospital_level_name'] = $recommend_doctor['Hospital']['hospital_level_name']; + + // 处理接诊价格 + $data['price'] = 0; + $data['free_clinic_price'] = 0; + foreach ($recommend_doctor['DoctorInquiryConfig'] as $doctor_inquiry_config) { + if ($doctor_inquiry_config['inquiry_mode'] == 1){ + if ($doctor_inquiry_config['inquiry_type'] == 1) { + // 专家问诊 + $data['price'] = $doctor_inquiry_config['inquiry_price']; + } + + if ($doctor_inquiry_config['inquiry_type'] == 3) { + // 公益 + $data['free_clinic_price'] = $doctor_inquiry_config['inquiry_price']; + } + } + } + + $results[] = $data; + + unset($data); + } + return success($results); + } } \ No newline at end of file diff --git a/app/Services/UserPatientService.php b/app/Services/UserPatientService.php index 153c101..a058bfe 100644 --- a/app/Services/UserPatientService.php +++ b/app/Services/UserPatientService.php @@ -5,9 +5,11 @@ namespace App\Services; use App\Constants\HttpEnumCode; use App\Model\Coupon; use App\Model\OrderInquiry; +use App\Model\PatientHistoryInquiry; use App\Model\UserCoupon; use App\Model\UserPatient; use App\Utils\Mask; +use Hyperf\DbConnection\Db; /** * 患者 @@ -97,6 +99,99 @@ class UserPatientService extends BaseService return success($user_patient->toArray()); } + /** + * 获取患者优惠卷列表 + * @return array + */ + public function getPatientCouponlist(): array + { + $user_info = $this->request->getAttribute("userInfo") ?? []; + + $user_coupon_status = $this->request->input('user_coupon_status'); + + // 获取患者信息 + $fields = [ + 'patient_id', + 'user_id', + 'user_name', + 'mobile', + 'avatar', + ]; + $params = array(); + $params['patient_id'] = $user_info['client_user_id']; + $user_patient = UserPatient::getOne($params,$fields); + if (empty($user_patient)){ + return fail(HttpEnumCode::HTTP_ERROR, "非法用户"); + } + + $CouponService = new CouponService(); + + $user_coupon = $CouponService->getUserCouponStatusList($user_patient['user_id'],[1,2,3,4,5],$user_coupon_status); + + $result = []; + foreach ($user_coupon as $item){ + $data = array(); + $data['user_coupon_id'] = $item['user_coupon_id']; + $data['coupon_id'] = $item['coupon_id']; + $data['user_coupon_status'] = $item['user_coupon_status']; + + if ($item['user_coupon_status'] == 0){ + // 未使用 + if ($item['valid_end_time'] <= date('Y-m-d H:i:s',time())){ + // 已过期 + $data['user_coupon_status'] = 3; + } + } + + $data['coupon_use_date'] = $item['coupon_use_date']; + $data['valid_start_time'] = $item['valid_start_time']; + $data['valid_end_time'] = $item['valid_end_time']; + $data['coupon_name'] = $item['coupon']['coupon_name']; + $data['coupon_price'] = $item['coupon']['coupon_price']; + $data['application_scope'] = $item['coupon']['application_scope']; + + $result[] = $data; + } + + unset($user_coupon); + + return success($result); + } + + /** + * 删除服务过患者的医生 + * 首页-个人中心 + * @return array + */ + public function deletePatientDoctor(): array + { + $user_info = $this->request->getAttribute("userInfo") ?? []; + + $doctor_id = $this->request->route('doctor_id'); + + $params = array(); + $params['doctor_id'] = $doctor_id; + $params['patient_id'] = $user_info['client_user_id']; + $params['history_status'] = 1; // + + $patient_history_inquiry = PatientHistoryInquiry::getList($params); + if (empty($patient_history_inquiry)){ + return fail(); + } + + + $params['doctor_id'] = $doctor_id; + $params['patient_id'] = $user_info['client_user_id']; + $params['history_status'] = 1; // + + $data = array(); + $data['history_status'] = 0; + + PatientHistoryInquiry::edit($params,$data); + + return success(); + } + /** * 获取用户可领取优惠卷 * @param string|int $user_id @@ -175,4 +270,5 @@ class UserPatientService extends BaseService return ""; } + } \ No newline at end of file diff --git a/config/routes.php b/config/routes.php index 6f303c3..eb63da6 100644 --- a/config/routes.php +++ b/config/routes.php @@ -183,12 +183,10 @@ Router::addGroup('/patient', function () { Router::get('/info', [UserPatientController::class, 'getPatientCenterInfo']); }); - - - // 个人中心-我的医生 - Router::addGroup('/my_doctor', function () { - // 删除我的医生 - Router::delete('/{history_inquiry_id:\d+}', [PatientCenterController::class, 'deleteMyDoctor']); + // 我的福利 + Router::addGroup('/coupon', function () { + // 获取患者优惠卷列表 + Router::get('', [UserPatientController::class, 'getPatientCouponlist']); }); // 问诊 @@ -216,6 +214,9 @@ Router::addGroup('/patient', function () { Router::addGroup('/doctor', function () { // 医生详情简介-详情中的简介 Router::get('/profile/{doctor_id:\d+}', [PatientDoctorController::class, 'getDoctorProfile']); + + // 删除服务过患者的医生 + Router::delete('/{doctor_id:\d+}', [UserPatientController::class, 'deletePatientDoctor']); }); // 家庭成员