Przeglądaj źródła

Merge branch 'master' into custom_manager

yb 6 miesięcy temu
rodzic
commit
06e40088ee

+ 8 - 4
app/admin/controller/notify/OrderPayController.php

@@ -10,26 +10,30 @@ class OrderPayController
 {
     public function wxpay(Request $request)
     {
-        Log::channel('pay')->info("WXPAY_NOTIFY", $request->all());
+        Log::channel('pay')->info("WXPAY_NOTIFY_REPLY", $request->all());
         try {
             $config = config('payment.wxpay');
             $config['notify_url'] = getenv('NOTIFY_DOMAIN_ADMIN').'/notify/orderPay/wxpay';
             Pay::wechat($config)->success()->send();
+
+            exit('<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>');
         }catch (\Exception $e){
-            Log::channel('pay')->info("WXPAY_NOTIFY_FAIL", ['msg'=>"回复失败"]);
+            Log::channel('pay')->info("WXPAY_NOTIFY_REPLY_FAIL", ['msg'=>"回复失败"]);
         }
 
     }
 
     public function alipay(Request $request)
     {
-        Log::channel('pay')->info("ALIPAY_NOTIFY", $request->all());
+        Log::channel('pay')->info("ALIPAY_NOTIFY_REPLY", $request->all());
         try {
             $config = config('payment.alipay');
             $config['notify_url'] = getenv('NOTIFY_DOMAIN_ADMIN').'/notify/orderPay/alipay';
             Pay::alipay($config)->success()->send();
+            header('Content-type: application/json');
+            exit(json_encode(['code' => '200', 'msg' => 'success']));
         }catch (\Exception $e){
-            Log::channel('pay')->info("ALIPAY_NOTIFY_FAIL", ['msg'=>"回复失败"]);
+            Log::channel('pay')->info("ALIPAY_NOTIFY_REPLY_FAIL", ['msg'=>"回复失败"]);
         }
     }
 }

Plik diff jest za duży
+ 262 - 243
app/admin/controller/order/WholeController.php


+ 13 - 6
app/admin/service/order/OrderService.php

@@ -13,6 +13,7 @@ use support\Db;
 use support\exception\BusinessException;
 use support\Log as SupportLog;
 use support\Redis;
+use Yansongda\Pay\Exceptions\GatewayException;
 use Yansongda\Pay\Log;
 use Yansongda\Pay\Pay;
 
@@ -221,9 +222,11 @@ class OrderService
             ];
             try {
                 $config = config('payment.wxpay');
-                $config['notify_url'] = getenv('NOTIFY_DOMAIN_ADMIN').'/notify/orderPay/wxpay';
+                $config['notify_url'] = getenv('NOTIFY_DOMAIN_ADMIN') . '/notify/orderPay/wxpay';
                 Pay::wechat($config)->pos($payData);
                 $result = self::findWxpay($params['orderGroupId'], 0);
+            }catch (GatewayException $g){
+                $result = self::findWxpay($params['orderGroupId'], 0);
             } catch (\Exception $e) {
                 $log->error("WXPAY", ['msg' => $e->getMessage()]);
                 throw new BusinessException("支付失败");
@@ -245,6 +248,8 @@ class OrderService
                 $config['notify_url'] = getenv('NOTIFY_DOMAIN_ADMIN').'/notify/orderPay/alipay';
                 Pay::alipay($config)->pos($payData);
                 $result = self::findAlipay($params['orderGroupId'], 0);
+            } catch (GatewayException $g){
+                $result = self::findAlipay($params['orderGroupId'], 0);
             } catch (\Exception $e) {
                 $log->error("ALIPAY", ['msg' => $e->getMessage()]);
                 throw new BusinessException("支付失败");
@@ -273,20 +278,21 @@ class OrderService
     public static function findWxpay($orderId, $nbr = 0)
     {
         if ($nbr >= 6) {
+            SupportLog::channel('pay')->error("FIND_WXPAY", ['msg' => '订单查询失败','order_id'=>$orderId]);
             throw new BusinessException("订单查询失败");
         }
         try {
             $result = Pay::wechat(config('payment.wxpay'))->find($orderId, 'pos');
             $result = json_decode(json_encode($result), true);
         } catch (\Exception $e) {
-            SupportLog::channel('pay')->error("WXPAY", ['msg' => $e->getMessage()]);
-            throw new BusinessException("订单查询失败");
+            SupportLog::channel('pay')->error("FIND_WXPAY", ['msg' => $e->getMessage()]);
         }
 
-        if (!empty($result['return_code']) && $result['return_code'] == 'SUCCESS' && !empty($result['result_code']) && $result['result_code'] == 'SUCCESS') {
+        if (!empty($result['return_code']) && $result['return_code'] == 'SUCCESS' && !empty($result['result_code']) && $result['result_code'] == 'SUCCESS' && !empty($result['trade_state']) && $result['trade_state'] == 'SUCCESS') {
             return $result;
         } else {
             sleep(5);
+            SupportLog::channel('pay')->error("FIND_WXPAY", ['nbr' => $nbr,'order_id'=>$orderId]);
             self::findWxpay($orderId, $nbr + 1);
         }
     }
@@ -304,20 +310,21 @@ class OrderService
     public static function findAlipay($orderId, $nbr = 0)
     {
         if ($nbr >= 6) {
+            SupportLog::channel('pay')->error("FIND_ALIPAY", ['msg' => '订单查询失败','order_id'=>$orderId]);
             throw new BusinessException("订单查询失败");
         }
         try {
             $result = Pay::alipay(config('payment.alipay'))->find($orderId);
             $result = json_decode(json_encode($result), true);
         } catch (\Exception $e) {
-            SupportLog::channel('pay')->error("ALIPAY", ['msg' => $e->getMessage()]);
-            throw new BusinessException("订单查询失败");
+            SupportLog::channel('pay')->error("FIND_ALIPAY", ['msg' => $e->getMessage()]);
         }
 
         if (!empty($result['code']) && $result['code'] == '10000' && !empty($result['trade_status']) && $result['trade_status'] == 'TRADE_SUCCESS') {
             return $result;
         } else {
             sleep(5);
+            SupportLog::channel('pay')->error("FIND_ALIPAY", ['nbr' => $nbr,'order_id'=>$orderId]);
             self::findAlipay($orderId, $nbr + 1);
         }
     }

Niektóre pliki nie zostały wyświetlone z powodu dużej ilości zmienionych plików