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);