瀏覽代碼

add card segment intercept

stanley-king 2 年之前
父節點
當前提交
8f939cf45c

+ 2 - 2
helper/refill/RefillBase.php

@@ -792,9 +792,9 @@ class RefillBase
         }
     }
 
-    public function need_intercept($mchid,$card_type,$card_state,$is_transfer)
+    public function need_intercept($mchid,$card_type,$card_state,$is_transfer,$card_no)
     {
-        return $this->mPolicy->need_intercept($mchid,$card_type,$card_state,$is_transfer);
+        return $this->mPolicy->need_intercept($mchid,$card_type,$card_state,$is_transfer,$card_no);
     }
     public function region_intercept($quality,$card_type,$region_no)
     {

+ 1 - 1
helper/refill/policy/IPolicy.php

@@ -13,7 +13,7 @@ interface IPolicy
     public function notify($order_info, $refill_info): bool;
     public function price($mchid, $spec, $card_type, $quality, $pcode);
     public function max_inprice($mchid, $spec, $card_type, $quality, $pcode);
-    public function need_intercept($mchid,$card_type,$card_state,$is_transfer) : bool;
+    public function need_intercept($mchid,$card_type,$card_state,$is_transfer,$card_no) : bool;
     public function region_intercept($quality,$card_type,$region_no) : bool;
 
     public function update_ratios($ratios);

+ 2 - 2
helper/refill/policy/lingzh/policy.php

@@ -466,9 +466,9 @@ class policy extends ProviderManager implements IPolicy
         return [$params, $sign];
     }
 
-    public function need_intercept($mchid,$card_type,$card_state,$is_transfer) : bool
+    public function need_intercept($mchid,$card_type,$card_state,$is_transfer,$card_no) : bool
     {
-        return $this->mRatioCtl->need_intercept($mchid,$card_type,$card_state,$is_transfer);
+        return $this->mRatioCtl->need_intercept($mchid,$card_type,$card_state,$is_transfer,$card_no);
     }
 
     public function region_intercept($quality,$card_type,$region_no) : bool

+ 34 - 1
helper/refill/policy/mratio_control.php

@@ -99,6 +99,25 @@ class mratio_control
                     $cfg = unserialize($item['intercept_cfg']);
                     if(empty($cfg)) continue;
 
+                    if(!empty($cfg['segment']))
+                    {
+                        $segment = $cfg['segment'];
+                        $sitems = explode(',',$segment);
+
+                        $tmp = [];
+                        foreach ($sitems as $sitem)
+                        {
+                            $sitem = trim($sitem);
+                            if(!empty($sitem)) {
+                                $tmp[] = $sitem;
+                            }
+                        }
+
+                        if(!empty($tmp)) {
+                            $cfg['segment'] = implode('|',$tmp);
+                        }
+                    }
+
                     $result[$mchid] = $cfg;
                 }
             }
@@ -515,8 +534,18 @@ class mratio_control
         return !$can_next;
     }
 
-    public function need_intercept($mchid,$card_type,$card_state,$is_transfer) : bool
+    public function need_intercept($mchid,$card_type,$card_state,$is_transfer,$card_no) : bool
     {
+        $start_with = function ($card_no,$segment)
+        {
+            $reg = "/^(?:{$segment})\d*$/";
+            if(preg_match($reg, $card_no, $matches)) {
+                return true;
+            } else {
+                return false;
+            }
+        };
+
         $mintercepts = $this->mInterceptConfig;
         if(array_key_exists($mchid,$mintercepts))
         {
@@ -532,6 +561,10 @@ class mratio_control
             if($mintercepts['is_transfer'] && $is_transfer) {
                 return true;
             }
+
+            if (!empty($mintercepts['segment']) && $start_with($card_no,$mintercepts['segment'])) {
+                return true;
+            }
         }
 
         return false;

+ 2 - 2
helper/refill/policy/xyz/policy.php

@@ -584,9 +584,9 @@ class policy extends ProviderManager implements IPolicy
         return $checker($url, "http://") || $checker($url, "https://");
     }
 
-    public function need_intercept($mchid,$card_type,$card_state,$is_transfer) : bool
+    public function need_intercept($mchid,$card_type,$card_state,$is_transfer,$card_no) : bool
     {
-        return $this->mRatioCtl->need_intercept($mchid,$card_type,$card_state,$is_transfer);
+        return $this->mRatioCtl->need_intercept($mchid,$card_type,$card_state,$is_transfer,$card_no);
     }
     public function region_intercept($quality,$card_type,$region_no) : bool
     {

+ 2 - 1
rdispatcher/proxy.php

@@ -192,8 +192,9 @@ class proxy
         $card_state = $order->card_state();
         $is_transfer = $order->is_transfer();
         $card_type = $order->card_type();
+        $card_no = $order->card_no();
 
-        return refill\RefillFactory::instance()->need_intercept($mchid,$card_type,$card_state,$is_transfer);
+        return refill\RefillFactory::instance()->need_intercept($mchid,$card_type,$card_state,$is_transfer,$card_no);
     }
 
     private function region_intercept(refill\order $order)

+ 38 - 0
test/TestRefillBalance.php

@@ -32,4 +32,42 @@ class TestRefillBalance extends TestCase
         $refill_balance = new statistics\refill_balance();
         $refill_balance->stat_all(0, strtotime('2022-01-15'));
     }
+
+    public function testSomething()
+    {
+        $checker = function ($cfg)
+        {
+            if(!empty($cfg['segment']))
+            {
+                $segment = $cfg['segment'];
+                $sitems = explode(',',$segment);
+
+                $tmp = [];
+                foreach ($sitems as $sitem)
+                {
+                    $sitem = trim($sitem);
+                    if(!empty($sitem)) {
+                        $tmp[] = $sitem;
+                    }
+                }
+
+                if(!empty($tmp)) {
+                    $cfg['segment'] = implode('|',$tmp);
+                }
+            }
+
+            return $cfg;
+        };
+
+        $cfg['segment'] = '133,139,147,,';
+
+        $acfg = $checker($cfg);
+
+        $reg = "/^(?:{$acfg['segment']})\d*$/";
+
+//        $x = preg_match('/^(?:139)\d{8}$/', 13911129866, $matches);
+        $x = preg_match($reg, 13911129866, $matches);
+
+
+    }
 }