Browse Source

支付日志优化

gorden 7 months ago
parent
commit
7ec5a97f1f
2 changed files with 29 additions and 4 deletions
  1. 13 4
      app/admin/service/order/OrderService.php
  2. 16 0
      config/log.php

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

@@ -11,6 +11,7 @@ use app\model\PayDetail;
 use app\model\SysDept;
 use support\Db;
 use support\exception\BusinessException;
+use support\Log as SupportLog;
 use support\Redis;
 use Yansongda\Pay\Log;
 use Yansongda\Pay\Pay;
@@ -195,9 +196,17 @@ class OrderService
      */
     public static function qrcodePay($params)
     {
+        $log = SupportLog::channel('pay');
+        $log->info("PAY_PARAMS",json_decode(json_encode($params),true));
         $params['order_amount_pay'] = floatval($params['order_amount_pay']);
         $qrcodeNbr = $params['qrcode_nbr'];
         $prefix = substr($qrcodeNbr,0,2);
+        // 模拟数据
+        // $result = [
+        //     'return_code'=>'SUCCESS',
+        //     'result_code' => 'SUCCESS'
+        // ];
+        // return $result;
         // 微信支付
         if(in_array($prefix,[10,11,12,13,14,15])){
             $payData = [
@@ -209,11 +218,11 @@ class OrderService
             try{
                 $result = Pay::wechat(config('payment.wxpay'))->pos($payData);
             }catch(\Exception $e){
-                Log::error("WXPAY",['msg'=>$e->getMessage()]);
+                $log->error("WXPAY",['msg'=>$e->getMessage()]);
                 throw new BusinessException("支付失败");
             }
 
-            Log::info("WXPAY_RETURN",json_decode(json_encode($result),true));
+            $log->info("WXPAY_RETURN",json_decode(json_encode($result),true));
 
         }else if(in_array($prefix,[25,26,27,28,29,30])){
             $payData = [
@@ -225,11 +234,11 @@ class OrderService
             try{
                 $result = Pay::alipay(config('payment.alipay'))->pos($payData);
             }catch(\Exception $e){
-                Log::error("ALIPAY",['msg'=>$e->getMessage()]);
+                $log->error("ALIPAY",['msg'=>$e->getMessage()]);
                 throw new BusinessException("支付失败");
             }
             
-            Log::info("ALIPAY_RETURN",json_decode(json_encode($result),true));
+            $log->info("ALIPAY_RETURN",json_decode(json_encode($result),true));
 
         }else{
             throw new BusinessException("二维码无效");

+ 16 - 0
config/log.php

@@ -29,4 +29,20 @@ return [
             ]
         ],
     ],
+    'pay' => [
+        'handlers' => [
+            [
+                'class' => Monolog\Handler\RotatingFileHandler::class,
+                'constructor' => [
+                    runtime_path() . '/logs/pay.log',
+                    7, //$maxFiles
+                    Monolog\Logger::DEBUG,
+                ],
+                'formatter' => [
+                    'class' => Monolog\Formatter\LineFormatter::class,
+                    'constructor' => [null, 'Y-m-d H:i:s', true],
+                ],
+            ]
+        ],
+    ],
 ];