diff --git a/app/Dictionary/WeChat/MiniProgram/SubscribeId.php b/app/Dictionary/WeChat/MiniProgram/SubscribeId.php index d270928..1e1aa35 100644 --- a/app/Dictionary/WeChat/MiniProgram/SubscribeId.php +++ b/app/Dictionary/WeChat/MiniProgram/SubscribeId.php @@ -20,11 +20,20 @@ enum SubscribeId: string case REGISTRATION_CANCEL = 'fVaoPnY6MOpKXbpnrGcPqcLl8dv-aRBNfCGeOlgL8bA'; - case OUTPATIENT_PAYMENT_SUCCESS = 'IlYVy2NNv7v6sg-s_Y6OYS4bRlulosztG0fn7LW4qcQ'; + case VISIT_REMIND = 'PidheHDjaf--SIu4-wsDT2uFA_0gjDhq_BU0fABa_w0'; + + case REGISTRATION_STOP_REMIND = '4y86hYFZ7vMxm4_5_aXTYLdMH-iRoZJAieBGIjOrfgI'; + + case OUTPATIENT_PAYMENT_SUCCESS = 'IlYVy2NNv7v6sg-s_Y6OYarcQhXA1lCI7DvH9Oyowmo'; case OUTPATIENT_PAYMENT_FAILURE = 'ayUD7DXCxZAlhWZ7YiWnHvUXf3AqS_6xkWlbCMC40ek'; - case VISIT_REMIND = 'PidheHDjaf--SIu4-wsDT2uFA_0gjDhq_BU0fABa_w0'; + case OUTPATIENT_PENDING_PAYMENT_REMIND = 'SYt004fWSk_KC-6R4SL2EfvyslHR9WMwjW3Z1AhhXhA'; + + case INSPECT_REPORT_RELEASE_REMIND = 's80lhpfTVcEMAdsyA--5qxWWmZ4GqUqSMFavyBga5D0'; + + case CHECK_REPORT_RELEASE_REMIND = 'UTBnJt7Y2LZJD4Eqne-qmr8wCGB_B_ADMM7sGirrmD0'; + /** * Label string @@ -39,9 +48,13 @@ enum SubscribeId: string self::REGISTRATION_SUCCESS => '挂号成功通知', self::REGISTRATION_FAILURE => '挂号失败通知', self::REGISTRATION_CANCEL => '取消预约挂号通知', + self::VISIT_REMIND => '就诊提醒', + self::REGISTRATION_STOP_REMIND => '停诊通知', self::OUTPATIENT_PAYMENT_SUCCESS => '门诊缴费成功通知', self::OUTPATIENT_PAYMENT_FAILURE => '门诊缴费失败通知', - self::VISIT_REMIND => '就诊提醒', + self::OUTPATIENT_PENDING_PAYMENT_REMIND => '待缴费提醒', + self::INSPECT_REPORT_RELEASE_REMIND => '检验报告通知', + self::CHECK_REPORT_RELEASE_REMIND => '检查报告通知', }; } } diff --git a/app/Http/Controllers/Hospital/IntroduceController.php b/app/Http/Controllers/Hospital/IntroduceController.php index 72556e6..492a06d 100644 --- a/app/Http/Controllers/Hospital/IntroduceController.php +++ b/app/Http/Controllers/Hospital/IntroduceController.php @@ -31,7 +31,7 @@ class IntroduceController extends Controller ->orderBy('sort', 'DESC') ->orderBy('id', 'ASC') ->get(); - $category_lists = $category_lists->keyBy('category_id')->map(function ($value) { return (array)$value; })->toArray(); + $category_lists = $category_lists->keyBy('category_id')->map(function ($value) { return $value->toArray(); })->toArray(); $department_lists = Department::select('dept_id', 'dept_name', 'category_id') ->where('is_enable', 1) @@ -165,7 +165,7 @@ class IntroduceController extends Controller public function navigationDetails(Request $request): JsonResponse { $navigation_details = Navigation::select('area_id', 'area_name', 'longitude', 'latitude', 'address', 'telephone', 'traffic', 'guide') - ->where('area_id', '01') + ->where('area_id', '1') ->where('is_enable', 1) ->first(); @@ -186,7 +186,7 @@ class IntroduceController extends Controller */ public function newLists(Request $request): JsonResponse { - $new_lists = News::select('title', 'image', 'sort', 'published_at') + $new_lists = News::select('id', 'title', 'image', 'sort', 'published_at') ->where('is_display', 1) ->where('published_at', '<=', date('Y-m-d H:i:s')) ->orderBy('sort', 'DESC') @@ -198,8 +198,8 @@ class IntroduceController extends Controller throw new GeneralException('找不到新闻动态'); } - foreach ($new_lists as $v) { - $v['image'] = getAdminUploadImageUrl((string) $v['image']); + foreach ($new_lists as $k => $v) { + $new_lists[$k]['image'] = getAdminUploadImageUrl((string) $v['image']); } return jsonResponse(Response::HTTP_OK, 'success.', $new_lists); @@ -214,7 +214,7 @@ class IntroduceController extends Controller */ public function newDetails(Request $request, int $new_id): JsonResponse { - $details = News::select('title', 'image', 'sort', 'published_at', 'content') + $details = News::select('id', 'title', 'image', 'sort', 'published_at', 'content') ->where('id', $new_id) ->where('is_display', 1) ->where('published_at', '<=', date('Y-m-d H:i:s')) @@ -237,7 +237,7 @@ class IntroduceController extends Controller */ public function healthLectureLists(Request $request): JsonResponse { - $lecture_lists = HealthLecture::select('title', 'speaker', 'lecture_date', 'sort') + $lecture_lists = HealthLecture::select('id', 'title', 'speaker', 'lecture_date', 'sort') ->where('is_display', 1) ->orderBy('sort', 'DESC') ->orderBy('lecture_date', 'DESC') @@ -261,7 +261,7 @@ class IntroduceController extends Controller */ public function healthLectureDetails(Request $request, int $lecture_id): JsonResponse { - $details = HealthLecture::select('title', 'speaker', 'lecture_date', 'sort', 'content') + $details = HealthLecture::select('id', 'title', 'speaker', 'lecture_date', 'sort', 'content') ->where('id', $lecture_id) ->where('is_display', 1) ->first() diff --git a/app/Http/Controllers/Message/TriggerController.php b/app/Http/Controllers/Message/TriggerController.php new file mode 100644 index 0000000..180a95e --- /dev/null +++ b/app/Http/Controllers/Message/TriggerController.php @@ -0,0 +1,160 @@ +trigger_logic = new TriggerLogic(); + } + + /** + * 挂号停诊消息 + * @param Request $request + * @return JsonResponse + */ + public function registerStopRemind(Request $request): JsonResponse + { + $validated = Validator::make($request->all(), [ + 'patient_id' => 'required', + 'reg_date' => 'required|date_format:Y-m-d', + 'begin_time' => 'required|date_format:H:i', + 'end_time' => 'required|date_format:H:i', + 'dept_name' => 'required', + 'doctor_name' => 'required', + 'tips' => 'required|max:20', + ],[ + 'patient_id.required' => '请传入患者ID', + 'reg_date.required' => '请传入看诊日期', + 'reg_date.date_format' => '请传入正确的看诊日期', + 'begin_time.required' => '请传入看诊开始时间段', + 'begin_time.date_format' => '请传入正确的看诊开始时间段', + 'end_time.required' => '请传入看诊结束时间段', + 'end_time.date_format' => '请传入正确的看诊结束时间段', + 'dept_name.required' => '请传入科室名称', + 'doctor_name.required' => '请传入医生名称', + 'tips.required' => '请传入提示信息', + 'tips.max' => '提示信息长度不得超过20', + ]); + + if ($validated->fails()) { + return jsonResponseToHis(Response::HTTP_OK, 1, $validated->errors()->first()); + } + + $validated = $request->safe()->only(['patient_id', 'reg_date', 'begin_time', 'end_time', 'dept_name', 'doctor_name', 'tips']); + + [$result, $message] = $this->trigger_logic->registerStopRemind( + $validated['patient_id'], + $validated['reg_date'], + $validated['begin_time'], + $validated['end_time'], + $validated['dept_name'], + $validated['doctor_name'], + $validated['tips'], + ); + + return jsonResponseToHis(Response::HTTP_OK, $result, $message); + } + + /** + * 待缴费提醒 + * @param Request $request + * @return JsonResponse + */ + public function pendingPaymentRemind(Request $request): JsonResponse + { + $validated = Validator::make($request->all(), [ + 'patient_id' => 'required', + 'dept_name' => 'required', + 'fee' => 'required|numeric', + 'fee_type' => 'required', + 'tips_message' => 'required|max:20', + ],[ + 'patient_id.required' => '请传入患者ID', + 'dept_name.required' => '请传入科室名称', + 'fee.required' => '请传入待缴纳处方费用', + 'fee.numeric' => '待缴纳处方费用必须传入数字', + 'fee_type.required' => '请传入待缴纳处方类型', + 'tips_message.required' => '请传入提示信息', + 'tips.max' => '提示信息长度不得超过20', + ]); + + if ($validated->fails()) { + return jsonResponseToHis(Response::HTTP_OK, 1, $validated->errors()->first()); + } + + $validated = $request->safe()->only(['patient_id', 'dept_name', 'fee', 'fee_type', 'tips_message']); + + [$result, $message] = $this->trigger_logic->pendingPaymentRemind( + $validated['patient_id'], + $validated['dept_name'], + $validated['fee'], + $validated['fee_type'], + $validated['tips'], + ); + + return jsonResponseToHis(Response::HTTP_OK, $result, $message); + } + + /** + * 报告发布提醒 + * @param Request $request + * @return JsonResponse + */ + public function reportReleaseRemind(Request $request): JsonResponse + { + $validated = Validator::make($request->all(), [ + 'patient_id' => 'required', + 'report_type' => 'required|in:1,2', + 'item_name' => 'required', + 'report_time' => 'required|date_format:Y-m-d H:i:s', + 'report_serial_no' => 'required', + 'dept_name' => 'required', + 'remark' => 'required|max:20', + ],[ + 'patient_id.required' => '请传入患者ID', + 'report_type.required' => '请传入报告类型', + 'report_type.in' => '请传入正确的报告类型', + 'item_name.required' => '请传入报告名称', + 'report_time.required' => '请传入报告时间', + 'report_time.date_format' => '报告时间格式错误', + 'report_serial_no.required' => '请传入报告流水号', + 'remark.required' => '请传入备注信息', + 'remark.max' => '备注信息长度不得超过20', + ]); + + if ($validated->fails()) { + return jsonResponseToHis(Response::HTTP_OK, 1, $validated->errors()->first()); + } + + $validated = $request->safe()->only(['patient_id', 'report_type', 'item_name', 'report_time', 'report_serial_no', 'dept_name', 'remark']); + + [$result, $message] = $this->trigger_logic->reportReleaseRemind( + $validated['patient_id'], + $validated['report_type'], + $validated['item_name'], + $validated['report_time'], + $validated['report_serial_no'], + $validated['dept_name'], + $validated['remark'] + ); + + return jsonResponseToHis(Response::HTTP_OK, $result, $message); + } +} diff --git a/app/Http/Logics/Message/TriggerLogic.php b/app/Http/Logics/Message/TriggerLogic.php new file mode 100644 index 0000000..6554a2e --- /dev/null +++ b/app/Http/Logics/Message/TriggerLogic.php @@ -0,0 +1,94 @@ +patient_model = new Patient(); + } + + + /** + * 挂号停诊 + * @param string $patient_id + * @param string $reg_date + * @param string $begin_time + * @param string $end_time + * @param string $dept_name + * @param string $doctor_name + * @param string $tips_message + * @return array + */ + public function registerStopRemind(string $patient_id, string $reg_date, string $begin_time, string $end_time, string $dept_name, string $doctor_name, string $tips_message): array + { + $info = $this->patient_model->getPatientInfoByPatientId($patient_id); + if (empty($info)) { + return [false, '未找到该患者绑定信息']; + } + + $this->sendRegistrationStopRemindMessage($info, $reg_date, $begin_time, $end_time, $dept_name, $doctor_name, $tips_message); + + return [true, '成功,已加入推送队列。']; + } + + /** + * 待缴费提醒 + * @param string $patient_id + * @param string $dept_name + * @param string $fee + * @param string $fee_type + * @param string $tips_message + * @return array + */ + public function pendingPaymentRemind(string $patient_id, string $dept_name, string $fee, string $fee_type, string $tips_message): array + { + $info = $this->patient_model->getPatientInfoByPatientId($patient_id); + if (empty($info)) { + return [false, '未找到该患者绑定信息']; + } + + $this->sendPendingPaymentRemindMessage($info, $dept_name, $fee, $fee_type, $tips_message); + + return [true, '成功,已加入推送队列。']; + } + + /** + * 报告发布提醒 + * @param string $patient_id + * @param int $report_type + * @param string $item_name + * @param string $report_time + * @param string $report_serial_no + * @param string $dept_name + * @param string $remark + * @return array + */ + public function reportReleaseRemind(string $patient_id, int $report_type, string $item_name, string $report_time, string $report_serial_no, string $dept_name, string $remark = ''): array + { + $info = $this->patient_model->getPatientInfoByPatientId($patient_id); + if (empty($info)) { + return [false, '未找到该患者绑定信息']; + } + + $this->sendReportReleaseRemindMessage($info, $report_type, $item_name, $report_time, $report_serial_no, $dept_name, $remark); + + return [true, '成功,已加入推送队列。']; + } +} diff --git a/app/Http/Logics/Notify/NotifyLogic.php b/app/Http/Logics/Notify/NotifyLogic.php index e8e24c9..940716b 100644 --- a/app/Http/Logics/Notify/NotifyLogic.php +++ b/app/Http/Logics/Notify/NotifyLogic.php @@ -155,7 +155,7 @@ class NotifyLogic if (isset($response['success']) && $response['success'] === true) { // 成功流程 - $order_info->orderConfirm($order_info->order_id, $response['response']['visitNo'], $response); + $order_info->orderConfirm($order_info->order_id, $response['response']['visitNo'], $response['response']); // 支付平台业务确认 $this->unifyConfirm($notify['out_trade_no'], $response['response']['visitNo'], $notify['openid'], $notify['transaction_id']); @@ -218,7 +218,7 @@ class NotifyLogic // 保存返回信息 if (isset($response['success']) && $response['success'] === true) { // 成功流程 - $order_info->orderConfirm($order_info->order_id, $response['response']['hosTranNo'], $response); + $order_info->orderConfirm($order_info->order_id, $response['response']['hosTranNo'], $response['response']); // 支付平台业务确认 $this->unifyConfirm($notify['out_trade_no'], $response['response']['hosTranNo'], $notify['openid'], $notify['transaction_id']); diff --git a/app/Http/Logics/Registration/RecordLogic.php b/app/Http/Logics/Registration/RecordLogic.php index fe61565..138e301 100644 --- a/app/Http/Logics/Registration/RecordLogic.php +++ b/app/Http/Logics/Registration/RecordLogic.php @@ -142,7 +142,6 @@ class RecordLogic throw new GeneralException($response['msg'] ?? '退号失败,请重新再试!', Response::HTTP_BAD_REQUEST); } - // 创建退款单 $refund_order_id = $this->order_model->getRefundOrderId($order_id); $refund_order_info = $this->order_model->createRefundOReverseOrder( diff --git a/app/Http/Middleware/IntranetAccess.php b/app/Http/Middleware/IntranetAccess.php new file mode 100644 index 0000000..9dc5395 --- /dev/null +++ b/app/Http/Middleware/IntranetAccess.php @@ -0,0 +1,39 @@ +header("x-forwarded-for"); + if($forwarded){ + $ip = explode(',',$forwarded)[0]; + }else{ + $ip = request()->ip(); + } + + if( + $ip != '::1' && + $ip != '127.0.0.1' && + !str_starts_with($ip, "10.") && + !str_starts_with($ip, "172.") && + !str_starts_with($ip, "192.") + ) { + return response('Not Found.', 404); + } + + return $next($request); + } + +} diff --git a/app/Http/Resources/Registration/Record/RecordListsResource.php b/app/Http/Resources/Registration/Record/RecordListsResource.php index 3ca756e..8af8dac 100644 --- a/app/Http/Resources/Registration/Record/RecordListsResource.php +++ b/app/Http/Resources/Registration/Record/RecordListsResource.php @@ -24,6 +24,8 @@ class RecordListsResource extends JsonResource 'patient_name' => $v['patientName'], 'dept_id' => $v['depId'], 'dept_name' => $v['depName'], + 'doctor_id' => $v['doctorId'], + 'doctor_name' => $v['doctorName'], 'rank_id' => $v['rankId'], 'rank_name' => $v['rankName'] ?? '', 'start_time' => $v['startTime'] ?? '', diff --git a/app/Utils/Helpers.php b/app/Utils/Helpers.php index 0bb7c64..30194ca 100644 --- a/app/Utils/Helpers.php +++ b/app/Utils/Helpers.php @@ -805,6 +805,6 @@ if (!function_exists('getAdminUploadImageUrl')) { return ''; } - return (string) url('/images/uploads/'. $image); + return asset('images/uploads/' . $image, true); } } diff --git a/app/Utils/Traits/SendSubscribeMessage.php b/app/Utils/Traits/SendSubscribeMessage.php index 11fa631..542377d 100644 --- a/app/Utils/Traits/SendSubscribeMessage.php +++ b/app/Utils/Traits/SendSubscribeMessage.php @@ -7,6 +7,7 @@ use App\Dictionary\SendMessage\Type; use App\Dictionary\WeChat\MiniProgram\SubscribeId; use App\Jobs\SendWeChatMessageJob; use App\Models\Order as OrderModel; +use App\Models\Patient as PatientModel; use App\Models\RegistrationRecord; use App\Models\SendMessageJob; @@ -266,4 +267,120 @@ trait SendSubscribeMessage SendWeChatMessageJob::dispatch($message); } + + // --------------------- 主动触发 订阅消息 --------------------- + + /** + * 发送医生停诊提醒消息 -- his触发 + * @param PatientModel $patient + * @param string $reg_date 挂号日期 + * @param string $begin_time 挂号开始时间段 + * @param string $end_time 挂号结束时间段 + * @param string $dept_name 科室名称 + * @param string $doctor_name 医生名称 + * @param string $tips 温馨提示信息 + * @return void + */ + public function sendRegistrationStopRemindMessage(PatientModel $patient, string $reg_date, string $begin_time, string $end_time, string $dept_name, string $doctor_name, string $tips_message): void + { + $subscribe_id = SubscribeId::REGISTRATION_STOP_REMIND; + $data = [ + 'touser' => $patient->open_id, + 'template_id' => $subscribe_id->value, + 'page' => '', + 'data' => [ + 'thing17' => ['value' => $patient->name], + 'time10' => ['value' => $reg_date. ' '. $begin_time . '~'. $end_time],// 就诊时段 + 'character_string11' => ['value' => $patient->patient_number], + 'thing15' => ['value' => $dept_name. '('. $doctor_name. ')'], // 科室医生 + 'thing1' => ['value' => $tips_message ?: '您预约的就诊医生已停诊,费用已原路退回。'],// 温馨提示 + ], + 'miniprogram_state' => config('custom.mini_program_message_state') + ]; + + $message = self::getSendMessageJob()->insertMessageJobs(0, 0, Type::SINGLE_SUBSCRIBE, $subscribe_id, $data, ''); + + SendWeChatMessageJob::dispatch($message); + } + + /** + * 发送待缴费提醒消息 -- his触发 + * @param PatientModel $patient 患者名称 + * @param string $dept_name 科室名称 + * @param string $fee 费用金额 + * @param string $fee_type 费用类型 + * @param string $tips_message 提示消息,20个字内 + * @return void + */ + public function sendPendingPaymentRemindMessage(PatientModel $patient, string $dept_name, string $fee, string $fee_type, string $tips_message): void + { + $subscribe_id = SubscribeId::OUTPATIENT_PENDING_PAYMENT_REMIND; + $data = [ + 'touser' => $patient->open_id, + 'template_id' => $subscribe_id->value, + 'page' => 'pagesA/outpatient/outPayList', + 'data' => [ + 'name1' => ['value' => $patient->name], + 'thing3' => ['value' => $dept_name], + 'amount5' => ['value' => $fee. '元'], + 'thing7' => ['value' => $tips_message], + 'thing6' => ['value' => $fee_type], + ], + 'miniprogram_state' => config('custom.mini_program_message_state') + ]; + + $message = self::getSendMessageJob()->insertMessageJobs(0, 0, Type::SINGLE_SUBSCRIBE, $subscribe_id, $data, ''); + + SendWeChatMessageJob::dispatch($message); + } + + /** + * 发送报告发布提醒消息 -- his触发 + * @param PatientModel $patient + * @param int $report_type 报告类型 1 检验 2检查 + * @param string $item_name 检查/检验项目名称 + * @param string $report_time 检查/检验时间 + * @param string $report_serial_no 报告流水号 + * @param string $dept_name 科室名称 + * @param string $remark 备注 + * @return void + */ + public function sendReportReleaseRemindMessage(PatientModel $patient, int $report_type, string $item_name, string $report_time, string $report_serial_no, string $dept_name, string $remark = ''): void + { + if($report_type === 1) { + $subscribe_id = SubscribeId::INSPECT_REPORT_RELEASE_REMIND; + $page = ''; + + $data = [ + 'phrase2' => ['value' => $patient->name], + 'thing3' => ['value' => $item_name], // 检验项目 + 'date5' => ['value' => date('Y-m-d H:i:s', strtotime($report_time))], // 检验时间 + 'character_string8' => ['value' => $report_serial_no], // 报告流水号 + 'thing10' => ['value' => $dept_name], // 科室 + ]; + } else { + $subscribe_id = SubscribeId::CHECK_REPORT_RELEASE_REMIND; + $page = ''; + + $data = [ + 'thing3' => ['value' => $patient->name], + 'thing2' => ['value' => $item_name], // 检查项目 + 'time3' => ['value' => date('Y-m-d H:i:s', strtotime($report_time))], // 报告时间 + 'thing4' => ['value' => $remark ?: '您的检查报告已出,请点击查看。'], // 备注 + ]; + } + + $data = [ + 'touser' => $patient->open_id, + 'template_id' => $subscribe_id->value, + 'page' => $page, + 'data' => $data, + 'miniprogram_state' => config('custom.mini_program_message_state') + ]; + + $message = self::getSendMessageJob()->insertMessageJobs(0, 0, Type::SINGLE_SUBSCRIBE, $subscribe_id, $data, ''); + + SendWeChatMessageJob::dispatch($message); + } + } diff --git a/app/Utils/Transfer/HisHttpClient/ClientMockHttpTransfer.php b/app/Utils/Transfer/HisHttpClient/ClientMockHttpTransfer.php index 331d1df..2d6d5ff 100644 --- a/app/Utils/Transfer/HisHttpClient/ClientMockHttpTransfer.php +++ b/app/Utils/Transfer/HisHttpClient/ClientMockHttpTransfer.php @@ -152,7 +152,7 @@ class ClientMockHttpTransfer extends HttpTransferAbstract private function mockConfirmRegister(array $params): self { $date = &$params['json']['date']; - $this->transfer_response = '{"status":200,"success":true,"msg":"成功","msgDev":null,"response":{"visitNo":"5358197","waitNum":"","treaID":"1-4","date":"2025-01-22","startTime":"16:30","endTime":"17:00","oppatNo":"288712335574","depLocation":"请到一楼儿童保健门诊","transNo":"","hzrs":"1"}}'; + $this->transfer_response = '{"status":200,"success":true,"msg":"成功","msgDev":null,"response":{"visitNo":"5358197","waitNum":"","treaID":"1-4","date":"'. $date. '","startTime":"16:30","endTime":"17:00","oppatNo":"288712335574","depLocation":"请到一楼儿童保健门诊","transNo":"","hzrs":"1"}}'; return $this; }