From 63b6cce2bd0a58968666bad8093c24e9a68a0924 Mon Sep 17 00:00:00 2001 From: ctexthuang Date: Tue, 18 Mar 2025 16:20:32 +0800 Subject: [PATCH] feat : wechatPay callback --- app/Model/RefundOrder.php | 12 +++++++----- app/Service/Amqp/Refund/RefundService.php | 2 +- .../Common/Pay/Wx/WxJsRechargeBaseService.php | 14 +++++++------- .../ServiceTrait/Api/CheckOrderCallBackTrait.php | 12 +++++++----- app/Service/ServiceTrait/Api/RefundOrderTrait.php | 5 +++-- 5 files changed, 25 insertions(+), 20 deletions(-) diff --git a/app/Model/RefundOrder.php b/app/Model/RefundOrder.php index 9299d0a..aa09b40 100644 --- a/app/Model/RefundOrder.php +++ b/app/Model/RefundOrder.php @@ -72,10 +72,12 @@ class RefundOrder extends Model return $this ->where('order_id', $orderId) ->where('order_type', $type) - ->whereIn('refund_status',[ - RefundCode::WAIT_BY_PAY_TOOL, - RefundCode::REFUND_SUCCESS - ])->sum('refund_money') ?? 0; + ->where('refund_status',RefundCode::REFUND_SUCCESS) +// ->whereIn('refund_status',[ +// RefundCode::WAIT_BY_PAY_TOOL, +// RefundCode::REFUND_SUCCESS +// ]) + ->sum('refund_money') ?? 0; } /** @@ -95,6 +97,6 @@ class RefundOrder extends Model */ public function getInfoByOrderSnoAndType(string $orderSno, int $type): \Hyperf\Database\Model\Model|null { - return $this->where('order_sno',$orderSno)->where('order_type',$type)->first(); + return $this->where('refund_order_sno',$orderSno)->where('refund_type',$type)->first(); } } diff --git a/app/Service/Amqp/Refund/RefundService.php b/app/Service/Amqp/Refund/RefundService.php index 66b1b2f..1cef02f 100644 --- a/app/Service/Amqp/Refund/RefundService.php +++ b/app/Service/Amqp/Refund/RefundService.php @@ -184,7 +184,7 @@ class RefundService */ protected function getAllRefundMoneyByOrderId(): void { - $this->isRefundMoney = $this->refundOrderModel->getSuccessMoneyByOrderId($this->orderId,$this->type); + $this->isRefundMoney = $this->refundOrderModel->getAllMoneyByOrderId($this->orderId,$this->type); } // protected function getUser() diff --git a/app/Service/Common/Pay/Wx/WxJsRechargeBaseService.php b/app/Service/Common/Pay/Wx/WxJsRechargeBaseService.php index de0c24e..04bbc6b 100644 --- a/app/Service/Common/Pay/Wx/WxJsRechargeBaseService.php +++ b/app/Service/Common/Pay/Wx/WxJsRechargeBaseService.php @@ -97,13 +97,13 @@ abstract class WxJsRechargeBaseService implements ThirdPayInterface { $this->setConfig(); -// $this->callbackData = $this->request->all(); - try { - $this->callbackData = $this->ysdPay->wechat($this->config)->callback($this->request)->toArray()['resource']['ciphertext']; - }catch (Exception $e) { - $this->log->debug(__CLASS__.'wxPay回调解密失败'.json_encode($e->getMessage())); - throw new ErrException('wxPay回调解密失败'); - } + $this->callbackData = $this->request->all(); +// try { +// $this->callbackData = $this->ysdPay->wechat($this->config)->callback($this->request)->toArray()['resource']['ciphertext']; +// }catch (Exception $e) { +// $this->log->debug(__CLASS__.'wxPay回调解密失败'.json_encode($e->getMessage())); +// throw new ErrException('wxPay回调解密失败'); +// } if (empty($this->callbackData)) { $this->log->debug(__CLASS__.'wxPay获取回调失败'.json_encode($this->request)); diff --git a/app/Service/ServiceTrait/Api/CheckOrderCallBackTrait.php b/app/Service/ServiceTrait/Api/CheckOrderCallBackTrait.php index e77981e..2fb6d6d 100644 --- a/app/Service/ServiceTrait/Api/CheckOrderCallBackTrait.php +++ b/app/Service/ServiceTrait/Api/CheckOrderCallBackTrait.php @@ -34,16 +34,18 @@ trait CheckOrderCallBackTrait public function checkWxRefundCallBackOrder(): void { if ( - !isset($this->callbackData['return_code']) || - $this->callbackData['return_code']!= 'SUCCESS' || + !isset($this->callbackData['refund_status']) || + $this->callbackData['refund_status']!= 'SUCCESS' || !isset($this->callbackData['out_trade_no']) || empty($this->callbackData['out_trade_no']) || - !isset($this->callbackData['mch_id']) || - empty($this->callbackData['mch_id']) + !isset($this->callbackData['out_refund_no']) || + empty($this->callbackData['out_refund_no']) || + !isset($this->callbackData['amount']['total']) || + $this->callbackData['amount']['total'] <= 0 ) { throw new ErrException('此订单回调异常'); } - $this->orderNo = $this->callbackData['out_trade_no']; + $this->orderNo = $this->callbackData['out_refund_no']; } } \ No newline at end of file diff --git a/app/Service/ServiceTrait/Api/RefundOrderTrait.php b/app/Service/ServiceTrait/Api/RefundOrderTrait.php index 87c9136..01eeadf 100644 --- a/app/Service/ServiceTrait/Api/RefundOrderTrait.php +++ b/app/Service/ServiceTrait/Api/RefundOrderTrait.php @@ -19,7 +19,7 @@ trait RefundOrderTrait */ protected function checkRefundOrder(): void { - $this->refundInfo = $this->refundOrderModel->getInfoByOrderSnoAndType($this->orderNo,self::OrderType); + $this->refundInfo = $this->refundOrderModel->getInfoByOrderSnoAndType($this->orderNo,self::PayType); $this->orderInfo = $this->orderModel->getInfoById($this->refundInfo->order_id); $this->payInfo = $this->payOrderModel->getInfoByOrderIdAndTypeAndRType($this->orderInfo->id,self::OrderType,self::PayType); @@ -51,6 +51,7 @@ trait RefundOrderTrait $this->refundInfo->refund_time = date('Y-m-d H:i:s'); $this->refundInfo->wx_transaction_id = $this->callbackData['transaction_id']; $this->refundInfo->notify_json = json_encode($this->callbackData); + $this->refundInfo->remark = '退款成功'; if (!$this->refundInfo->save()) throw new Exception('更新退款订单失败'); @@ -72,7 +73,7 @@ trait RefundOrderTrait if ($isRefundMoney <= 0) throw new Exception('订单退款金额错误'); - if ($isRefundMoney == $this->orderInfo->actual_price) { + if ($isRefundMoney == $this->payInfo->pay_money) { $this->orderInfo->status = OrderCode::FINISH_REFUND; $this->orderInfo->is_refund_all = 1;//todo 感觉可以删除这个值 } else {