From 136d9e171445025c36d95d86fd5f842db2d90303 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Sat, 22 Jun 2024 19:27:53 +0800 Subject: [PATCH] =?UTF-8?q?feat(PayController):=20=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E6=94=AF=E4=BB=98=E6=8E=A7=E5=88=B6=E5=99=A8=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=EF=BC=8C=E4=BC=98=E5=8C=96=E4=BA=86=E5=B0=8F=E7=A8=8B=E5=BA=8F?= =?UTF-8?q?=E6=94=AF=E4=BB=98=E5=9B=9E=E8=B0=83=E3=80=81=E5=BE=AE=E4=BF=A1?= =?UTF-8?q?=E6=94=AF=E4=BB=98=E6=9F=A5=E8=AF=A2=E7=AD=89=E6=96=B9=E6=B3=95?= =?UTF-8?q?=EF=BC=8C=E5=B9=B6=E4=BF=AE=E5=A4=8D=E4=BA=86=E7=9B=B8=E5=85=B3?= =?UTF-8?q?bug=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/controller/PayController.php | 31 +++++++++++++++------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/app/api/controller/PayController.php b/app/api/controller/PayController.php index af0e6b091..e422175d5 100644 --- a/app/api/controller/PayController.php +++ b/app/api/controller/PayController.php @@ -19,7 +19,7 @@ use support\Log; class PayController extends BaseApiController { - public $notNeedLogin = ['notifyMnp', 'alipay_return', 'alipay_notify','wechatQuery']; + public $notNeedLogin = ['notifyMnp', 'alipay_return', 'alipay_notify', 'wechatQuery']; /** * @notes 小程序支付回调 @@ -44,19 +44,18 @@ class PayController extends BaseApiController break; } } - }else{ + } else { if ($result && $result->event_type == 'REFUND.SUCCESS') { $ciphertext = $result->resource['ciphertext']; if ($ciphertext['refund_status'] === 'SUCCESS') { //处理订单 -1判断是退的一单还是拆分的订单 - $out_trade_no = $ciphertext['out_trade_no'].'-1'; - $check = StoreOrder::where('order_id',$out_trade_no)->count(); - if($check){ - $ciphertext['out_trade_no'] =$out_trade_no; + $out_trade_no = $ciphertext['out_trade_no'] . '-1'; + $check = StoreOrder::where('order_id', $out_trade_no)->count(); + if ($check) { + $ciphertext['out_trade_no'] = $out_trade_no; } PayNotifyLogic::handle('refund', $ciphertext['out_trade_no'], $ciphertext); $app->wechat->success(); - } } } @@ -68,22 +67,26 @@ class PayController extends BaseApiController public function wechatQuery() { $order_no = $this->request->get('order_no'); - $recharge = $this->request->get('recharge',0); + $recharge = $this->request->get('recharge', 0); $order = [ 'out_trade_no' => $order_no, ]; $app = new PayService(0); - $res = $app->wechat->query($order); + try { + $res = $app->wechat->query($order); + } catch (\Exception $e) { + return $this->fail($e->extra['message']); + } if ($res['trade_state'] == 'SUCCESS' && $res['trade_state_desc'] == '支付成功') { - if($recharge==0){ + if ($recharge == 0) { PayNotifyLogic::handle('wechat_common', $res['out_trade_no'], $res); - }else{ + } else { PayNotifyLogic::handle('recharge', $res['out_trade_no'], $res); } return $this->success('支付成功'); } else { - return $this->fail('订单支付中或已失效'); + return $this->fail('订单支付中'); } } @@ -97,7 +100,7 @@ class PayController extends BaseApiController if ($result) { $data = $result->toArray(); if ($data['trade_status'] === 'TRADE_SUCCESS') { - $attach = $data['extend_params']['attach']??''; + $attach = $data['extend_params']['attach'] ?? ''; switch ($attach) { case 'alipay_cashier': PayNotifyLogic::handle('alipay_cashier', $data['out_trade_no'], $data); @@ -117,7 +120,7 @@ class PayController extends BaseApiController if ($result) { $data = $result->toArray(); if ($data['trade_status'] === 'TRADE_SUCCESS') { - $attach = $data['extend_params']['attach']??''; + $attach = $data['extend_params']['attach'] ?? ''; switch ($attach) { case 'alipay_cashier': PayNotifyLogic::handle('alipay_cashier', $data['out_trade_no'], $data);