diff --git a/app/Amqp/Consumer/AssignPharmacistConsumer.php b/app/Amqp/Consumer/AssignPharmacistConsumer.php index a13c092..960fe46 100644 --- a/app/Amqp/Consumer/AssignPharmacistConsumer.php +++ b/app/Amqp/Consumer/AssignPharmacistConsumer.php @@ -117,8 +117,11 @@ class AssignPharmacistConsumer extends ConsumerMessage * 分配失败 * @param string $order_prescription_id * @param string $doctor_user_id + * @param string $patient_user_id * @param string $order_inquiry_id * @return void + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface */ public function reject(string $order_prescription_id, string $doctor_user_id, string $patient_user_id, string $order_inquiry_id): void { diff --git a/app/Amqp/Consumer/AutoCompleteInquiryDelayDirectConsumer.php b/app/Amqp/Consumer/AutoCompleteInquiryDelayDirectConsumer.php index c2e73e4..734601b 100644 --- a/app/Amqp/Consumer/AutoCompleteInquiryDelayDirectConsumer.php +++ b/app/Amqp/Consumer/AutoCompleteInquiryDelayDirectConsumer.php @@ -25,6 +25,10 @@ use PhpAmqpLib\Message\AMQPMessage; use Psr\Container\ContainerExceptionInterface; use Psr\Container\NotFoundExceptionInterface; +/** + * 自动完成问诊订单 + * 延迟队列 + */ #[Consumer(nums: 1)] class AutoCompleteInquiryDelayDirectConsumer extends ConsumerMessage { diff --git a/app/Amqp/Consumer/AutoPharmacistCaVerifyDelayDirectConsumer.php b/app/Amqp/Consumer/AutoPharmacistCaVerifyDelayDirectConsumer.php index 6ab73e8..2a28d1e 100644 --- a/app/Amqp/Consumer/AutoPharmacistCaVerifyDelayDirectConsumer.php +++ b/app/Amqp/Consumer/AutoPharmacistCaVerifyDelayDirectConsumer.php @@ -128,8 +128,6 @@ class AutoPharmacistCaVerifyDelayDirectConsumer extends ConsumerMessage } } - // 下载医生签章文件 - Db::beginTransaction(); try { Log::getInstance("queue-AutoPharmacistCaVerify")->info("检测执行次数"); @@ -139,7 +137,7 @@ class AutoPharmacistCaVerifyDelayDirectConsumer extends ConsumerMessage Log::getInstance("queue-AutoPharmacistCaVerify")->error("错误:超出最大执行次数或检测错误"); // 修改处方表为未通过 - $this->modifyOrderPrescription($data['order_prescription_id'],2,"请联系平台客服,请勿重开处方"); + $this->modifyOrderPrescription($data['order_prescription_id'], 2, "请联系平台客服,请勿重开处方"); // 医生-开具的处方审核未通过 $MessagePush = new MessagePush($user_doctor['user_id'], $order_prescription['order_inquiry_id']); @@ -149,14 +147,35 @@ class AutoPharmacistCaVerifyDelayDirectConsumer extends ConsumerMessage $MessagePush = new MessagePush($user_patient['user_id'], $order_prescription['order_inquiry_id']); $MessagePush->patientPrescriptionVerifyFail(); - Db::commit(); return Result::ACK; } - if (time() < 1682251200){ - Db::rollBack(); - return Result::REQUEUE; + + }catch (\Exception $e){ + // 检测次数失败 + Log::getInstance("queue-AutoPharmacistCaVerify")->info("错误:" . $e->getMessage()); + return Result::ACK; + } + + // 下载医生签章文件 + Db::beginTransaction(); + try { + + + // 检测执行次数 + $res = $this->checkHandleNumber($data['prescription_file_id']); + if (!$res) { + Log::getInstance("queue-AutoPharmacistCaVerify")->error("错误:超出最大执行次数或检测错误"); + + // 修改处方表为未通过 + $this->modifyOrderPrescription($data['order_prescription_id'],2,"请联系平台客服,请勿重开处方"); + + + + Db::commit(); + } + // 获取处方文件数据 $params = array(); $params['prescription_file_id'] = $data['prescription_file_id']; diff --git a/app/Command/ReportPreProductOrderCommand.php b/app/Command/ReportPreProductOrderCommand.php index 6d1dd31..1cd272f 100644 --- a/app/Command/ReportPreProductOrderCommand.php +++ b/app/Command/ReportPreProductOrderCommand.php @@ -4,11 +4,13 @@ declare(strict_types=1); namespace App\Command; +use App\Model\OrderPrescription; use App\Model\OrderProduct; use App\Model\UserPatient; use App\Services\MessagePush; use App\Services\OrderPrescriptionService; use App\Services\OrderProductService; +use App\Utils\Log; use Hyperf\Command\Command as HyperfCommand; use Hyperf\Command\Annotation\Command; use Hyperf\DbConnection\Db; @@ -41,20 +43,20 @@ class ReportPreProductOrderCommand extends HyperfCommand */ public function handle() { - $this->line("上报处方平台商品订单开始"); + $this->line("开始"); try { // 获取可上报商品订单 $order_product_ids = $this->getExecProductOrder(); if (empty($order_product_ids)){ - $this->line("上报处方平台商品订单结束,无可上报的商品订单"); + $this->line("结束,无可上报的商品订单"); return; } // 获取缓存 $redis = $this->container->get(Redis::class); } catch (\Exception $e) { - $this->line("上报处方平台商品订单失败:" . $e->getMessage()); + $this->line("错误:" . $e->getMessage()); return; } @@ -63,62 +65,50 @@ class ReportPreProductOrderCommand extends HyperfCommand Db::beginTransaction(); - $redis_key = "ReportPreProductOrder" . $item['order_product_id']; - - // 处理超出最大执行次数/退款问题 try { - $redis_value = $redis->get($redis_key); - $redis->incr($redis_key); - if(!empty($redis_value)){ - if ($redis_value >= 2){ - // 存储上报失败 - $this->savaReportFail($item['order_product_id'],"超出最大上报次数"); + // 检测执行次数 + $res = $this->checkHandleNumber($item['order_product_id']); + if (!$res) { + Log::getInstance("queue-AutoPharmacistCaVerify")->error("错误:超出最大执行次数或检测错误"); - // 修改失败时药品订单数据 - $this->savePreFailedOrderStatus($item['order_product_id'],"复核失败"); + // 修改药品订单表上报处方平台状态 + $this->saveOrderProductPeportPreStatus($item['order_product_id'],2,"超出最大上报次数"); - // 退款 - $this->line("超出最大执行次数,执行退款"); - $OrderProductService = new OrderProductService(); - $OrderProductService->OrderProductRefund($item['order_product_id'],"药品订单退款"); + // 修改失败时药品订单数据 + $this->savePreFailedOrderStatus($item['order_product_id'],"复核失败"); - // 清空缓存 - $redis->del($redis_key); + // 退款 + $OrderProductService = new OrderProductService(); + $OrderProductService->OrderProductRefund($item['order_product_id'],"药品订单退款"); - Db::commit(); - continue; - } + Db::commit(); + continue; } - - Db::commit(); - } catch (\Exception $e) { + }catch(\Exception $e){ Db::rollBack(); // 记录失败次数 - $this->line("商品订单上报处方平台失败:失败原因" . $e->getMessage()); + $this->line("错误:" . $e->getMessage()); + continue; } - // 处理上报处方平台问题 try { // 上报处方平台 $orderPrescriptionService = new OrderPrescriptionService(); $orderPrescriptionService->reportPrescription($item['order_product_id']); - // 存储上报成功 - $this->savaReportSuccess($item['order_product_id']); + // 修改药品订单表上报处方平台状态 + $this->saveOrderProductPeportPreStatus($item['order_product_id'],1); - // 清空缓存 - $redis->del($redis_key); - - $this->line("商品订单上报处方平台成功"); + $this->line("成功"); Db::commit(); continue; } catch (\Exception $e) { Db::rollBack(); - $this->line("上报失败:失败原因" . $e->getMessage()); + $this->line("错误" . $e->getMessage()); continue; } } - $this->line("商品订单上报处方平台全部结束"); + $this->line("全部结束"); } /** @@ -135,7 +125,9 @@ class ReportPreProductOrderCommand extends HyperfCommand $fields = [ 'order_product_id', + 'user_id', 'patient_id', + 'order_prescription_id', ]; $order_product = OrderProduct::getList($params,$fields); @@ -147,38 +139,24 @@ class ReportPreProductOrderCommand extends HyperfCommand } /** - * 存储上报失败 - * @param string $order_product_id 商品订单id - * @param string $report_pre_fail_reason 上报失败原因 + * 修改药品订单表上报处方平台状态 + * @param string $order_product_id + * @param int $report_pre_status + * @param string $report_pre_fail_reason * @return void */ - protected function savaReportFail(string $order_product_id,string $report_pre_fail_reason = ""): void + protected function saveOrderProductPeportPreStatus(string $order_product_id,int $report_pre_status,string $report_pre_fail_reason = ""): void { $params = array(); $params['order_product_id'] = $order_product_id; $data = array(); - $data['report_pre_status'] = 2; // 上报处方平台状态(0:未上报 1:已上报 2:上报失败)) - if (!empty($report_pre_fail_reason)){ - $data['report_pre_fail_reason'] = $report_pre_fail_reason; - } - OrderProduct::edit($params,$data); - } - - /** - * 存储上报成功 - * @param string $order_product_id 商品订单id - * @return void - */ - protected function savaReportSuccess(string $order_product_id): void - { - $params = array(); - $params['order_product_id'] = $order_product_id; - - $data = array(); - $data['report_pre_status'] = 1; // 上报处方平台状态(0:未上报 1:已上报 2:上报失败)) + $data['report_pre_status'] = $report_pre_status; // 上报处方平台状态(0:未上报 1:已上报 2:上报失败)) $data['report_pre_time'] = date('Y-m-d H:i:s',time()); // 上报处方平台时间 - $data['report_pre_fail_reason'] = ""; // 上报失败原因 置为空 + if (!empty($report_pre_fail_reason)){ + $data['report_pre_fail_reason'] = ""; // 上报失败原因 置为空 + } + OrderProduct::edit($params,$data); } @@ -200,4 +178,37 @@ class ReportPreProductOrderCommand extends HyperfCommand OrderProduct::edit($params,$data); } + /** + * 检测执行次数 + * @param string $order_product_id + * @return bool + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface + */ + protected function checkHandleNumber(string $order_product_id): bool + { + try { + $redis = $this->container->get(Redis::class); + + $redis_key = "ReportPreProductOrder" . $order_product_id; + $redis_value = $redis->get($redis_key); + if (empty($redis_value)) { + $redis->set($redis_key, 1, 60 * 60 * 24 * 5); + return true; + } + + // 执行次数过多 + if ($redis_value > 3) { + // 加入短信队列,通知管理员 + + return false; + } + + $redis->incr($redis_key); + } catch (\Exception $e) { + return false; + } + + return true; + } } diff --git a/app/Command/getPrescriptionOrderStatusCommand.php b/app/Command/getPrescriptionOrderStatusCommand.php index c6c4d1c..38da7c4 100644 --- a/app/Command/getPrescriptionOrderStatusCommand.php +++ b/app/Command/getPrescriptionOrderStatusCommand.php @@ -52,9 +52,6 @@ class getPrescriptionOrderStatusCommand extends HyperfCommand foreach ($order_product_ids as $item) { Db::beginTransaction(); - // 是否执行了退款-预定义变量 - $is_refund = 0; - $this->line("本次请求订单号:" . $item['order_product_id']); // 获取药品订单处方数据 @@ -108,9 +105,6 @@ class getPrescriptionOrderStatusCommand extends HyperfCommand // 执行退款 $OrderProductService = new OrderProductService(); $OrderProductService->OrderProductRefund($item['order_product_id'],"订单退款"); - - // 标记为执行了退款 - $is_refund = 1; } if ($result['status'] == "CFD05"){ @@ -157,23 +151,6 @@ class getPrescriptionOrderStatusCommand extends HyperfCommand // 记录失败次数 $this->line("获取处方平台订单数据失败:" . $e->getMessage()); } - - // 检测是否执行了退款 - if ($is_refund == 1){ - try { - $this->line("发送消息推送"); - - // 获取患者用户id - $user_id = $this->getPatientUserId($item['patient_id']); - if (!empty($user_id)){ - // 发送站内、订阅、短信消息-药品订单退款成功 - $MessagePush = new MessagePush($user_id); - $MessagePush->refundProductSuccess($item['order_product_id']); - } - }catch(\Exception $e){ - $this->line("发送消息推送失败:" . $e->getMessage()); - } - } } $this->line("获取处方平台订单数据全部处理结束"); diff --git a/app/Services/MessagePush.php b/app/Services/MessagePush.php index c84b161..52bec07 100644 --- a/app/Services/MessagePush.php +++ b/app/Services/MessagePush.php @@ -17,6 +17,7 @@ use App\Model\Product; use App\Model\SystemInquiryConfig; use App\Model\User; use App\Model\UserDoctor; +use App\Utils\Log; use Hyperf\Amqp\Producer; use Hyperf\Utils\ApplicationContext; use Psr\Container\ContainerExceptionInterface; @@ -1300,7 +1301,7 @@ class MessagePush extends BaseService $params['order_prescription_id'] = $order_prescription_id; $order_prescription = OrderPrescription::getOne($params); if (empty($order_prescription)) { - throw new BusinessException("加入推送队列失败:处方数据为空"); + return false; } // 订阅 @@ -1337,7 +1338,8 @@ class MessagePush extends BaseService throw new BusinessException("加入推送队列失败" . json_encode($data,JSON_UNESCAPED_UNICODE)); } } catch (\Exception $e) { - throw new BusinessException("加入推送队列失败" . $e->getMessage()); + Log::getInstance("MessagePush")->error("错误:" . $e->getMessage()); + return false; } return true;