diff --git a/app/Command/ReportPreProductOrderCommand.php b/app/Command/ReportPreProductOrderCommand.php index eeeceee..2476920 100644 --- a/app/Command/ReportPreProductOrderCommand.php +++ b/app/Command/ReportPreProductOrderCommand.php @@ -5,6 +5,8 @@ declare(strict_types=1); namespace App\Command; use App\Model\OrderProduct; +use App\Model\UserPatient; +use App\Services\MessagePush; use App\Services\OrderPrescriptionService; use App\Services\OrderProductService; use Hyperf\Command\Command as HyperfCommand; @@ -68,7 +70,7 @@ class ReportPreProductOrderCommand extends HyperfCommand $redis_value = $redis->get($redis_key); $redis->incr($redis_key); if(!empty($redis_value)){ - if ($redis_value >= 2){ + if ($redis_value >= 100){ // 存储上报失败 $this->savaReportFail($item['order_product_id'],"超出最大上报次数"); @@ -80,6 +82,14 @@ class ReportPreProductOrderCommand extends HyperfCommand $OrderProductService = new OrderProductService(); $OrderProductService->OrderProductRefund($item['order_product_id'],"药品订单退款"); + // 获取患者用户id + $user_id = $this->getPatientUserId($item['patient_id']); + if (!empty($user_id)){ + // 发送站内、订阅、短信消息-药品订单退款成功 + $MessagePush = new MessagePush($user_id); + $MessagePush->refundProductSuccess($item['order_product_id']); + } + // 清空缓存 $redis->del($redis_key); @@ -99,12 +109,7 @@ class ReportPreProductOrderCommand extends HyperfCommand try { // 上报处方平台 $orderPrescriptionService = new OrderPrescriptionService(); - $res = $orderPrescriptionService->reportPrescription($item['order_product_id']); - if (!$res){ - // 上报失败 - $this->line("上报失败"); - continue; - } + $orderPrescriptionService->reportPrescription($item['order_product_id']); // 存储上报成功 $this->savaReportSuccess($item['order_product_id']); @@ -114,7 +119,7 @@ class ReportPreProductOrderCommand extends HyperfCommand Db::rollBack(); // 记录失败次数 $redis->incr($redis_key); - $this->line("商品订单上报处方平台失败:失败原因" . $e->getMessage()); + $this->line("上报失败:失败原因" . $e->getMessage()); } // 清空缓存 @@ -139,6 +144,7 @@ class ReportPreProductOrderCommand extends HyperfCommand $fields = [ 'order_product_id', + 'patient_id', ]; $order_product = OrderProduct::getList($params,$fields); @@ -202,4 +208,22 @@ class ReportPreProductOrderCommand extends HyperfCommand $data['cancel_remarks'] = $cancel_remarks; // 订单取消备注(自动添加) OrderProduct::edit($params,$data); } + + /** + * 获取患者用户id + * @param string $patient_id + * @return string + */ + protected function getPatientUserId(string $patient_id): string + { + // 获取患者数据 + $params = array(); + $params['patient_id'] = $patient_id; + $user_patient = UserPatient::getOne($params); + if (empty($user_patient)){ + return ""; + } + + return $user_patient['user_id']; + } } diff --git a/app/Command/getPrescriptionOrderStatusCommand.php b/app/Command/getPrescriptionOrderStatusCommand.php index b485537..85c68d2 100644 --- a/app/Command/getPrescriptionOrderStatusCommand.php +++ b/app/Command/getPrescriptionOrderStatusCommand.php @@ -6,6 +6,8 @@ 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; @@ -45,13 +47,17 @@ class getPrescriptionOrderStatusCommand extends HyperfCommand $this->line("获取处方平台订单数据结束,无可执行的商品订单"); return; } -// dump($order_product_ids);die; + + foreach ($order_product_ids as $item) { - if ($item['order_product_id'] != "504371738743726081"){ + if ($item['order_product_id'] != "504656990619947008"){ continue; } Db::beginTransaction(); + // 是否执行了退款-预定义变量 + $is_refund = 0; + $this->line("本次请求订单号:" . $item['order_product_id']); // 获取药品订单处方数据 @@ -84,7 +90,7 @@ class getPrescriptionOrderStatusCommand extends HyperfCommand continue; } - if ($result['status'] == "CFD03" || $result['status'] == "CFD04"){ + if ($result['status'] == "CFD03" || $result['status'] == "CFD04" || $result['status'] == "CFD06" || $result['status'] == "CFD07"){ // 药师审核未通过/库存不足 // 检测药品订单数据 $res = $this->checkPreFailedOrderStatus($order_prescription); @@ -96,13 +102,17 @@ class getPrescriptionOrderStatusCommand extends HyperfCommand // 修改失败时药品订单数据 if ($result['status'] == "CFD03"){ $this->savePreFailedOrderStatus($order_prescription,"复核失败"); - }else{ + }elseif($result['status'] == "CFD04"){ $this->savePreFailedOrderStatus($order_prescription,"库存不足"); + }else{ + $this->savePreFailedOrderStatus($order_prescription,"订单取消"); } // 执行退款 $OrderProductService = new OrderProductService(); $OrderProductService->OrderProductRefund($item['order_product_id'],"订单退款"); + + $is_refund = 1; } if ($result['status'] == "CFD05"){ @@ -132,30 +142,6 @@ class getPrescriptionOrderStatusCommand extends HyperfCommand $this->savePreSuccessOrderStatus($order_prescription,$result['deliveryId'],$logistics_company_code); } - if ($result['status'] == "CFD06"){ - // 已取消 - // 检测药品订单数据 - $res = $this->checkPreFailedOrderStatus($order_prescription); - if (!$res){ - Db::rollBack(); - continue; - } - - // 修改药品订单数据 - $this->savePreFailedOrderStatus($order_prescription,"订单取消"); - - // 执行退款 - $OrderProductService = new OrderProductService(); - $OrderProductService->OrderProductRefund($item['order_product_id'],"订单退款"); - } - - if ($result['status'] == "CFD07"){ - // 申请退款 - $OrderProductService = new OrderProductService(); - $OrderProductService->OrderProductRefund($item['order_product_id'],"订单退款"); - } - - $this->line("获取处方平台订单数据结束:处理完毕"); Db::commit(); @@ -164,6 +150,21 @@ class getPrescriptionOrderStatusCommand extends HyperfCommand // 记录失败次数 $this->line("获取处方平台订单数据失败:" . $e->getMessage()); } + + // 检测是否需要发送通知 + if ($is_refund == 1){ + try { + // 获取患者用户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("获取处方平台订单数据全部处理结束"); @@ -189,6 +190,7 @@ class getPrescriptionOrderStatusCommand extends HyperfCommand 'order_product_id', 'order_product_no', 'order_prescription_id', + 'patient_id', ]; $order_product = OrderProduct::getStatusList($params,$order_product_status,$fields); @@ -368,4 +370,22 @@ class getPrescriptionOrderStatusCommand extends HyperfCommand return $company_code; } + + /** + * 获取患者用户id + * @param string $patient_id + * @return string + */ + protected function getPatientUserId(string $patient_id): string + { + // 获取患者数据 + $params = array(); + $params['patient_id'] = $patient_id; + $user_patient = UserPatient::getOne($params); + if (empty($user_patient)){ + return ""; + } + + return $user_patient['user_id']; + } } diff --git a/app/Controller/CallBackController.php b/app/Controller/CallBackController.php index 7fba011..685477c 100644 --- a/app/Controller/CallBackController.php +++ b/app/Controller/CallBackController.php @@ -543,7 +543,6 @@ class CallBackController extends AbstractController // 发送站内、订阅、短信消息-药品订单退款成功 $MessagePush = new MessagePush($user_patient['user_id']); - $MessagePush->refundProductSuccess($order_product['order_product_id']); }catch (\Exception $e) { // 验证失败 diff --git a/app/Services/MessagePush.php b/app/Services/MessagePush.php index 02f023c..58d05a4 100644 --- a/app/Services/MessagePush.php +++ b/app/Services/MessagePush.php @@ -738,7 +738,7 @@ class MessagePush extends BaseService $sub_data = array(); $sub_data['push_user_id'] = $this->user['user_id']; $sub_data['wx_template_id'] = "gQO5vhPQfdnvXtK0XnGns1XqNhQpOrXTjdl-5HWWMUw";//药品订单取消通知 - $sub_data['params']['page'] = "pages/orderDetail/orderDetail?order_inquiry_id={$this->order_inquiry['order_inquiry_id']}"; + $sub_data['params']['page'] = "pages/medinceOrderDetail/medinceOrderDetail?order_product_id={$order_product_id}"; $sub_data['params']['data'] = [ "character_string3" => $order_product['order_product_no'],// 订单号 diff --git a/app/Services/OrderPrescriptionService.php b/app/Services/OrderPrescriptionService.php index 9f4d3f3..22ec251 100644 --- a/app/Services/OrderPrescriptionService.php +++ b/app/Services/OrderPrescriptionService.php @@ -604,7 +604,7 @@ class OrderPrescriptionService extends BaseService // 获取商品订单列表数据 $params = array(); - $params['order_inquiry_id'] = $order_prescription['order_inquiry_id']; + $params['order_product_id'] = $order_product['order_product_id']; $order_product_item = OrderProductItem::getList($params); if (empty($order_product_item)) { throw new BusinessException("上报处方平台失败:商品订单列表数据错误"); @@ -837,12 +837,10 @@ class OrderPrescriptionService extends BaseService $result = $Prescription->reportPrescription($arg); if ($result['resultCode'] != "1000"){ if(!empty($result['resultDesc'])){ - Log::getInstance()->info("上报处方平台失败:" .$result['resultDesc']); - return false; + throw new BusinessException("上报处方平台失败:" .$result['resultDesc']); } - Log::getInstance()->info("上报处方平台失败:操作编码:" . $result['resultCode']); - return false; + throw new BusinessException("上报处方平台失败:操作编码:" . $result['resultCode']); } return true; diff --git a/app/Services/UserService.php b/app/Services/UserService.php index f8a5840..ce0c906 100644 --- a/app/Services/UserService.php +++ b/app/Services/UserService.php @@ -380,7 +380,7 @@ class UserService extends BaseService return fail(HttpEnumCode::HTTP_ERROR, $e->getMessage()); } - return success(); + return success($user_ship_address->toArray()); } /**