Просмотр исходного кода

Merge branch 'master' into dev

shish 2 месяцев назад
Родитель
Сommit
0b0d82e49d
2 измененных файлов с 16 добавлено и 8 удалено
  1. 14 6
      biz-ghs/custom/classes/CustomRechargeClass.php
  2. 2 2
      common/components/payUtil.php

+ 14 - 6
biz-ghs/custom/classes/CustomRechargeClass.php

@@ -30,6 +30,14 @@ class CustomRechargeClass extends BaseClass
         return $data;
     }
 
+    /**
+     * 客户向供货商线上充值:支付渠道回调入账。
+     *
+     * 职责:校验订单与金额、加锁入账、写余额变动与 FIFO 销账。
+     * 入参:payWay 支付方式;customRechargeSn 充值单号;totalFee 回调金额;attach/transactionId 渠道附加信息。
+     * 返回:true 表示已处理或重复回调幂等成功;异常单仍 util::fail。
+     * 关键边界:已 payStatus=1 的重复通知只记日志并 return,避免 util::fail 导致渠道收不到 SUCCESS 而反复重试。
+     */
     public static function thirdPay($payWay, $customRechargeSn, $totalFee, $attach, $transactionId)
     {
         $customRecharge = self::getByCondition(['orderSn' => $customRechargeSn], true);
@@ -45,15 +53,14 @@ class CustomRechargeClass extends BaseClass
             Yii::info($msg);
             util::fail($msg);
         }
-        if ($customRecharge->payStatus == 1) {
-            noticeUtil::push("充值订单,支付回调错误,已经充值过了 orderSn:{$customRechargeSn}", '15280215347');
-            $msg = "充值订单,支付回调错误,已经充值过了 orderSn:{$customRechargeSn}";
-            Yii::info($msg);
-            util::fail($msg);
-        }
         $amount = $totalFee;
         $id = $customRecharge->id;
         $customRecharge = self::getLockById($id);
+        // 加锁后再判已付:防并发双入账,重复回调静默成功以便 NoticeController 回 SUCCESS
+        if ((int)$customRecharge->payStatus === 1) {
+            Yii::info("充值订单重复支付回调,已处理过,幂等跳过 orderSn:{$customRechargeSn}");
+            return true;
+        }
         $payDate = date("Y-m-d H:i:s");
         $customRecharge->payTime = $payDate;
         $customRecharge->payWay = $payWay;
@@ -179,6 +186,7 @@ class CustomRechargeClass extends BaseClass
             );
         }
 
+        return true;
     }
 
     /**

+ 2 - 2
common/components/payUtil.php

@@ -19,14 +19,14 @@ class payUtil
 
     public static function thirdPay($payWay, $capitalType, $orderSn, $totalFee, $attach, $transactionId = '')
     {
-        //4秒内不允许第三方重复通知
+        // 同一 orderSn 短时重复通知直接跳过(NoticeController 仍会回 SUCCESS,避免渠道反复重试)
         $cacheKey = 'third_pay_' . $orderSn;
         $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
         if (!empty($has)) {
             Yii::info("支付回调短时间内出现重复通知,流水类型:{$capitalType} orderSn:{$orderSn}");
             return false;
         }
-        Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 4, 'has']);
+        Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 10, 'has']);
 
         //流水类型列表
         switch ($capitalType) {