diff --git a/app/Services/InquiryService.php b/app/Services/InquiryService.php index c79fcae..c3071ce 100644 --- a/app/Services/InquiryService.php +++ b/app/Services/InquiryService.php @@ -885,42 +885,52 @@ class InquiryService extends BaseService throw new BusinessException("订单支付状态错误"); } - // 发起退款 - $WechatPay = new WechatPay(1, 1); - - $generator = $this->container->get(IdGeneratorInterface::class); - // 系统退款编号 + $generator = $this->container->get(IdGeneratorInterface::class); $inquiry_refund_no = $generator->generate(); - $options = array(); - $options['transaction_id'] = $order_inquiry['escrow_trade_no']; - $options['out_refund_no'] = (string)$inquiry_refund_no; - $options['reason'] = $refund_reason; - $options['amount'] = [ - 'refund' => (int)($order_inquiry['payment_amount_total'] * 100), - 'total' => (int)($order_inquiry['payment_amount_total'] * 100), - 'currency' => "CNY", - ]; + // 检测订单金额 + if ($order_inquiry['payment_amount_total'] > 0){ + // 发起退款 + $WechatPay = new WechatPay(1, 1); - $result = $WechatPay->refund($options); + $options = array(); + $options['transaction_id'] = $order_inquiry['escrow_trade_no']; + $options['out_refund_no'] = (string)$inquiry_refund_no; + $options['reason'] = $refund_reason; + $options['amount'] = [ + 'refund' => (int)($order_inquiry['payment_amount_total'] * 100), + 'total' => (int)($order_inquiry['payment_amount_total'] * 100), + 'currency' => "CNY", + ]; - // 处理订单退款状态 - // 问诊订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭) - if ($result['status'] == "SUCCESS") { - // 退款成功 + $result = $WechatPay->refund($options); + + // 处理订单退款状态 + // 问诊订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭) + if ($result['status'] == "SUCCESS") { + // 退款成功 + $inquiry_refund_status = 3; + } elseif ($result['status'] == "CLOSED") { + // 退款关闭 + $inquiry_refund_status = 5; + } elseif ($result['status'] == "PROCESSING") { + // 退款处理中 + $inquiry_refund_status = 2; + } elseif ($result['status'] == "ABNORMAL") { + // 退款异常,此情况不处理,进行短信通知 + throw new BusinessException("订单退款状态异常"); + } else { + throw new BusinessException("订单退款状态错误"); + } + + $refund_id = $result['refund_id']; + $success_time = $result['success_time']; + }else{ + // 模拟退款 $inquiry_refund_status = 3; - } elseif ($result['status'] == "CLOSED") { - // 退款关闭 - $inquiry_refund_status = 5; - } elseif ($result['status'] == "PROCESSING") { - // 退款处理中 - $inquiry_refund_status = 2; - } elseif ($result['status'] == "ABNORMAL") { - // 退款异常,此情况不处理,进行短信通知 - throw new BusinessException("订单退款状态异常"); - } else { - throw new BusinessException("订单退款状态错误"); + $refund_id = "模拟退款:" . $generator->generate(); + $success_time = date("Y-m-d H:i:s", time()); } // 新增退款表 @@ -929,13 +939,13 @@ class InquiryService extends BaseService $data['order_inquiry_id'] = $order_inquiry['order_inquiry_id']; $data['inquiry_no'] = $order_inquiry['inquiry_no']; $data['inquiry_refund_no'] = $inquiry_refund_no; - $data['refund_id'] = $result['refund_id']; + $data['refund_id'] = $refund_id; $data['inquiry_refund_status'] = $inquiry_refund_status; $data['refund_total'] = $order_inquiry['payment_amount_total']; $data['refund_reason'] = $refund_reason; - if ($inquiry_refund_status == 3 && !empty($result['success_time'])) { - $data['success_time'] = date("Y-m-d H:i:s", strtotime($result['success_time'])); // 退款成功时间 + if ($inquiry_refund_status == 3 && !empty($success_time)) { + $data['success_time'] = date("Y-m-d H:i:s", strtotime($success_time)); // 退款成功时间 } $order_inquiry_refund = OrderInquiryRefund::addOrderInquiryRefund($data); diff --git a/app/Services/MessagePush.php b/app/Services/MessagePush.php index 0b94108..02f023c 100644 --- a/app/Services/MessagePush.php +++ b/app/Services/MessagePush.php @@ -1137,6 +1137,8 @@ class MessagePush extends BaseService $link_params = array(); $link_params['order_inquiry_id'] = $this->order_inquiry['order_inquiry_id']; + $link_params['inquiry_type'] = $this->order_inquiry['inquiry_type']; + $link_params['patient_user_id'] = $this->order_inquiry['user_id']; $data['link_params'] = json_encode($link_params,JSON_UNESCAPED_UNICODE);// 跳转参数 $message = new SendStationMessageProducer($data);