Quellcode durchsuchen

add interval control

stanley-king vor 4 Jahren
Ursprung
Commit
ebdbe1d4cf
4 geänderte Dateien mit 48 neuen und 14 gelöschten Zeilen
  1. 10 13
      helper/mtopcard/mtopcard.php
  2. 23 0
      helper/refill/util.php
  3. 7 1
      mobile/control/refill.php
  4. 8 0
      test/TestRedis.php

+ 10 - 13
helper/mtopcard/mtopcard.php

@@ -131,22 +131,19 @@ function topcard_format($card_list)
 
 function simple_card_type($cardno)
 {
-    if(preg_match( '/^1[0-9]{18}$/',$cardno,$matches)) {
+    if (preg_match('/^1[0-9]{18}$/', $cardno, $matches)) {
         return SinopecCard;
-    }
-    elseif(preg_match( '/^9[0-9]{15}$/',$cardno,$matches)) {
+    } elseif (preg_match('/^9[0-9]{15}$/', $cardno, $matches)) {
         return PetroChinaCard;
-    }
-    elseif(preg_match('/^1\d{10}$/',$cardno,$matches)) {
+    } elseif (preg_match('/^134[0-8]\d{7}$|^(?:13[5-9]|147|15[0-27-9]|17[28]|18[2-478]|19[578])\d{8}$/', $cardno, $matches)) {
+        return ChinaMobileCard;
+    } elseif (preg_match('/^(?:13[0-2]|145|15[56]|166|17[156]|18[56]|196)\d{8}$/', $cardno, $matches)) {
+        return ChinaUnicomCard;
+    } elseif (preg_match('/^(?:133|149|153|177|173|18[019]|19[0139])\d{8}$/', $cardno, $matches)) {
+        return ChinaTelecomCard;
+    } elseif (preg_match('/^1\d{10}$/', $cardno, $matches)) {
         return PhoneCard;
-
-    }elseif(preg_match( '/^1[0-9]{18}$/',$cardno,$matches)) {
-        return SinopecCard;
-    }
-    elseif(preg_match( '/^9[0-9]{15}$/',$cardno,$matches)) {
-        return PetroChinaCard;
-    }
-    else {
+    } else {
         return UnknownCard;
     }
 }

+ 23 - 0
helper/refill/util.php

@@ -11,6 +11,7 @@ use Log;
 use Exception;
 use Cache;
 use QueueClient;
+use function PHPUnit\Framework\returnArgument;
 
 class util
 {
@@ -26,6 +27,28 @@ class util
         return $no;
     }
 
+    public static function can_refill($card_no,$card_type)
+    {
+        if($card_type == mtopcard\SinopecCard || $card_type == mtopcard\PetroChinaCard)
+        {
+            $result = rcache('card_expired','',"{$card_no}");
+            if(empty($result)) {
+                wcache("card_expired",[$card_no => time()],'');
+                return [true,0];
+            }
+            else {
+                $latest = current($result);
+                $cur = time();
+                $success = ($cur - $latest) > 600;
+
+                return [$success, $latest +  600 - $cur];
+            }
+        }
+        else {
+            return [true,0];
+        }
+    }
+
     static function read_card($card_no,$card_type = 0)
     {
         if(empty($card_no)) return false;

+ 7 - 1
mobile/control/refill.php

@@ -73,9 +73,15 @@ class refillControl extends merchantControl
             return self::outerr(205,"客户订单号重复或者为空.");
         }
 
-        $card_type = mtopcard\card_type($card_no);
+        $card_type = mtopcard\simple_card_type($card_no);
         if($card_type === mtopcard\SinopecCard || $card_type === mtopcard\PetroChinaCard)
         {
+            [$can_refill,$period] = refill\util::can_refill($card_no,$card_type);
+            if($can_refill === false) {
+                Log::record("");
+                return self::outerr(208,"请{$card_no}至少在{$period}秒后再试.");
+            }
+
             if(!$this->can_refill($card_no)) {
                 return self::outerr(206,"平台不支持该卡充值.");
             }

+ 8 - 0
test/TestRedis.php

@@ -134,6 +134,14 @@ class TestRedis extends TestCase
         $z = !isset($y) || (is_object($y) == false);
     }
 
+    public function testWRcache()
+    {
+        $t = current(['1000119000003695610' => time()]);
+        wcache("card_expired",['1000119000003695610' => time()],'');
+        $x = rcache('card_expired','','1000119000003695610');
+
+    }
+
 
     public static function tearDownAfterClass() : void
     {