Bladeren bron

限购处理缓存存在不严谨问题

shizhongqi 4 maanden geleden
bovenliggende
commit
00f224f82e
2 gewijzigde bestanden met toevoegingen van 9 en 6 verwijderingen
  1. 4 2
      biz-ghs/product/classes/ProductClass.php
  2. 5 4
      biz-hd/product/classes/ProductClass.php

+ 4 - 2
biz-ghs/product/classes/ProductClass.php

@@ -2820,27 +2820,29 @@ class ProductClass extends BaseClass
         $has = Yii::$app->redis->executeCommand('HEXISTS', [$limitKey, $customId]);
         if (!empty($has)) {
             $hasNum = Yii::$app->redis->executeCommand('HGET', [$limitKey, $customId]);
+            self::recordLimitBuyRollbackSnapshot($productId, $customId, true, $hasNum);
             $lastNum = bcadd($hasNum, $num);
             if ($lastNum > $limitBuy) {
                 // 如果有特价,则超过的数量按原价卖;否则中断
                 if ($product['hjDiscountPrice'] > 0 && $product['discountPrice'] > 0 && $product['skDiscountPrice'] > 0) {
+                    Yii::$app->redis->executeCommand('HSET', [$limitKey, $customId, $limitBuy]);
                     return;
                 }
 
                 util::error(-1, '累计已超出限购数', ['productId'=>$productId, 'limitBuy'=>$limitBuy, 'exceed'=>$lastNum - $limitBuy]);
             }
-            self::recordLimitBuyRollbackSnapshot($productId, $customId, true, $hasNum);
             Yii::$app->redis->executeCommand('HSET', [$limitKey, $customId, $lastNum]);
         } else {
+            self::recordLimitBuyRollbackSnapshot($productId, $customId, false, 0);
             if ($num > $limitBuy) {
                 // 如果有特价,则超过的数量按原价卖;否则中断
                 if ($product['hjDiscountPrice'] > 0 && $product['discountPrice'] > 0 && $product['skDiscountPrice'] > 0) {
+                    Yii::$app->redis->executeCommand('HSET', [$limitKey, $customId, $limitBuy]);
                     return;
                 }
 
                 util::error(-1, '超出限购数', ['productId'=>$productId, 'limitBuy'=>$limitBuy, 'exceed'=>$num - $limitBuy]);
             }
-            self::recordLimitBuyRollbackSnapshot($productId, $customId, false, 0);
             Yii::$app->redis->executeCommand('HSET', [$limitKey, $customId, $num]);
         }
     }

+ 5 - 4
biz-hd/product/classes/ProductClass.php

@@ -447,27 +447,28 @@ class ProductClass extends BaseClass
         $has = Yii::$app->redis->executeCommand('HEXISTS', [$limitKey, $customId]);
         if (!empty($has)) {
             $hasNum = Yii::$app->redis->executeCommand('HGET', [$limitKey, $customId]);
-            $lastNum = bcadd($hasNum, $num);
+            self::recordLimitBuyRollbackSnapshot($productId, $customId, true, $hasNum);
+            $lastNum = bcadd($hasNum, $num, 2);
             if ($lastNum > $limitBuy) {
                 // 如果有特价,则超过的数量按原价卖;否则中断
                 if ($product['hjDiscountPrice'] > 0 && $product['discountPrice'] > 0 && $product['skDiscountPrice'] > 0) {
+                    Yii::$app->redis->executeCommand('HSET', [$limitKey, $customId, $limitBuy]);
                     return;
                 }
 
                 util::error(-1, '累计已超出限购数', ['productId'=>$productId, 'limitBuy'=>$limitBuy, 'exceed'=>$lastNum - $limitBuy]);
             }
-            self::recordLimitBuyRollbackSnapshot($productId, $customId, true, $hasNum);
             Yii::$app->redis->executeCommand('HSET', [$limitKey, $customId, $lastNum]);
         } else {
+            self::recordLimitBuyRollbackSnapshot($productId, $customId, false, 0);
             if ($num > $limitBuy) {
                 // 如果有特价,则超过的数量按原价卖;否则中断
                 if ($product['hjDiscountPrice'] > 0 && $product['discountPrice'] > 0 && $product['skDiscountPrice'] > 0) {
+                    Yii::$app->redis->executeCommand('HSET', [$limitKey, $customId, $limitBuy]);
                     return;
                 }
-
                 util::error(-1, '超出限购数', ['productId'=>$productId, 'limitBuy'=>$limitBuy, 'exceed'=>$num - $limitBuy]);
             }
-            self::recordLimitBuyRollbackSnapshot($productId, $customId, false, 0);
             Yii::$app->redis->executeCommand('HSET', [$limitKey, $customId, $num]);
         }
     }