From 43c933caea5a0f57ce9f48e8025fc69fc70cb31a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=9D=99?= Date: Sat, 18 Dec 2021 17:41:37 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=BE=AE=E4=BF=A1=E6=94=AF?= =?UTF-8?q?=E4=BB=98=E5=9B=9E=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Http/Controllers/WeChatPayController.php | 43 +++++++++++-------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/app/Endpoint/Callback/Http/Controllers/WeChatPayController.php b/app/Endpoint/Callback/Http/Controllers/WeChatPayController.php index bc2e7325..9e39addd 100644 --- a/app/Endpoint/Callback/Http/Controllers/WeChatPayController.php +++ b/app/Endpoint/Callback/Http/Controllers/WeChatPayController.php @@ -32,36 +32,41 @@ class WeChatPayController extends Controller return true; } - $attach = json_decode(data_get($message, 'attach'), true); + $attach = json_decode($message['attach'], true); if (! isset($attach['pay_target'])) { return true; } switch ($attach['pay_target']) { - // 支付订单 case 'order': - try { - DB::beginTransaction(); - - (new OrderService())->paySuccess($message['out_trade_no'], [ - 'pay_sn' => $message['transaction_id'], - 'pay_way' => Order::PAY_WAY_WXPAY, - 'pay_at' => Carbon::parse($message['time_end']), - ]); - - DB::commit(); - } catch (BizException|ModelNotFoundException $e) { - DB::rollBack(); - } catch (Throwable $e) { - DB::rollBack(); - - throw $e; - } + $this->handlePaidNotifyForOrder($message); break; } return true; }); } + + /** + * 处理订单支付结果通知 + * + * @param array $message + * @return void + */ + protected function handlePaidNotifyForOrder(array $message): void + { + try { + DB::transaction(function () use ($message) { + (new OrderService())->paySuccess($message['out_trade_no'], [ + 'pay_sn' => $message['transaction_id'], + 'pay_way' => Order::PAY_WAY_WXPAY, + 'pay_at' => Carbon::parse($message['time_end']), + ]); + }); + } catch (ModelNotFoundException|BizException $e) { + } catch (Throwable $e) { + throw $e; + } + } }