From 0b68216cb09f36e2e0a78f3405a4f9d5c7b9008f Mon Sep 17 00:00:00 2001 From: liangyuyan <1103300295@qq.com> Date: Wed, 26 Aug 2020 20:18:05 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=A2=E5=8D=95=E9=80=80=E6=AC=BE--=E4=BF=AE?= =?UTF-8?q?=E6=94=B95-=E5=BE=AE=E4=BF=A1=E9=80=80=E6=AC=BE=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Service/OrderService.php | 1 - app/Service/WxRefundService.php | 57 ++++++++++++++++++++------------- 2 files changed, 34 insertions(+), 24 deletions(-) diff --git a/app/Service/OrderService.php b/app/Service/OrderService.php index 3b0e76a..7c40f85 100644 --- a/app/Service/OrderService.php +++ b/app/Service/OrderService.php @@ -797,7 +797,6 @@ class OrderService implements OrderServiceInterface // 微信支付 微信退款 $refundRes = $this->wxRefundService->wxPayRefund($orderMain->global_order_id); - var_dump($refundRes); if( empty($refundRes) || !$refundRes diff --git a/app/Service/WxRefundService.php b/app/Service/WxRefundService.php index 7fe5362..6c7545e 100644 --- a/app/Service/WxRefundService.php +++ b/app/Service/WxRefundService.php @@ -9,6 +9,8 @@ use App\Commons\Log; use App\Constants\LogLabel; use Hyperf\Di\Annotation\Inject; use Hyperf\Guzzle\CoroutineHandler; +use Hyperf\Database\Exception\QueryException; +use App\Exception\BusinessException; class WxRefundService implements WxRefundServiceInterface { @@ -23,33 +25,42 @@ class WxRefundService implements WxRefundServiceInterface */ public function wxPayRefund($global_order_id) { - $config = config('wxpay'); - $app = Factory::payment($config); - $app['guzzle_handler'] = CoroutineHandler::class; - - // 查询订单 - $orderMain = OrderMain::query() - ->select('id','global_order_id','order_num','money','state') + try{ + $config = config('wxpay'); + $app = Factory::payment($config); + $app['guzzle_handler'] = CoroutineHandler::class; + + // 查询订单 + $orderMain = OrderMain::query() + ->select(['id','global_order_id','order_num','money','state']) ->where('global_order_id',$global_order_id) ->where('pay_type',OrderMain::ORDER_PAY_WX) - ->where(Db::raw('refund_time is null')) - ->first()->toArray(); + ->whereRaw('refund_time is null') + ->first(); - if(empty($orderMain)){ - return false; - }; + if(empty($orderMain)){ + return false; + }; - $options = [ - 'refund_desc' => '线上订单退款', - // 'notify_url' => config('site_host') . '/wechat/notify/wxpayrefund' - ]; - $result = $app->refund->byOutTradeNumber( - $orderMain->global_order_id, - $orderMain->global_order_id, - $orderMain->money * 100, - $orderMain->money * 100, - $options - ); + $options = [ + 'refund_desc' => '线上订单退款', + // 'notify_url' => config('site_host') . '/wechat/notify/wxpayrefund' + ]; + $result = $app->refund->byOutTradeNumber( + $orderMain->global_order_id, + $orderMain->global_order_id, + $orderMain->money * 100, + $orderMain->money * 100, + $options + ); + } catch (QueryException $e) { + $this->log->event(LogLabel::WX_PAY_REFUND,$e->getMessage()); + return false; + } catch (BusinessException $e){ + $this->log->event(LogLabel::WX_PAY_REFUND,$e->getMessage()); + return false; + } + $this->log->event(LogLabel::WX_PAY_REFUND,$result); return $result; }