Sfoglia il codice sorgente

add priority and speed control to xyz

stanley-king 4 anni fa
parent
commit
50b35e87b2

+ 3 - 2
helper/refill/LZRefillFactory.php

@@ -4,10 +4,11 @@ namespace refill;
 
 require_once(BASE_HELPER_PATH . '/refill/RefillBase.php');
 require_once(BASE_HELPER_PATH . '/refill/ProviderManager.php');
+
 require_once(BASE_HELPER_PATH . '/refill/policy/IPolicy.php');
 require_once(BASE_HELPER_PATH . '/refill/policy/lingzh/policy.php');
-require_once(BASE_HELPER_PATH . '/refill/policy/lingzh/chctl.php');
-require_once(BASE_HELPER_PATH . '/refill/policy/lingzh/ctl_item.php');
+require_once(BASE_HELPER_PATH . '/refill/policy/chctl.php');
+require_once(BASE_HELPER_PATH . '/refill/policy/ctl_item.php');
 
 use Log;
 use StatesHelper;

+ 3 - 0
helper/refill/XYZRefillFactory.php

@@ -6,8 +6,11 @@ namespace refill;
 require_once(BASE_HELPER_PATH . '/refill/RefillBase.php');
 require_once(BASE_HELPER_PATH . '/refill/ProviderManager.php');
 require_once(BASE_HELPER_PATH . '/rbridge/RBridgeFactory.php');
+
 require_once(BASE_HELPER_PATH . '/refill/policy/IPolicy.php');
 require_once(BASE_HELPER_PATH . '/refill/policy/xyz/policy.php');
+require_once(BASE_HELPER_PATH . '/refill/policy/chctl.php');
+require_once(BASE_HELPER_PATH . '/refill/policy/ctl_item.php');
 
 use Log;
 use StatesHelper;

helper/refill/policy/lingzh/chctl.php → helper/refill/policy/chctl.php


helper/refill/policy/lingzh/ctl_item.php → helper/refill/policy/ctl_item.php


+ 47 - 4
helper/refill/policy/xyz/policy.php

@@ -9,16 +9,59 @@ use StatesHelper;
 
 class policy extends ProviderManager implements IPolicy
 {
-    const normal_times = 15;
+    const normal_times = 30;
     const normle_time_out = 900;
 
     const high_times = 5;
     const high_time_out = 60;
 
+    protected $mChannelControl;
+    public function __construct()
+    {
+        parent::__construct();
+        $this->mChannelControl = new chctl();
+    }
+
+    public function load()
+    {
+        parent::load();
+        $this->mChannelControl->load();
+    }
+
     public function find_providers(int $spec, int $card_type,int $quality): array
     {
         $providers = parent::find_providers($spec,$card_type,$quality);
 
+        if(empty($providers)) {
+            return [$providers,false];
+        }
+
+        $names = [];
+        foreach ($providers as $provider) {
+            $names[] = $provider->name();
+        }
+
+        [$names,$overload] = $this->mChannelControl->match($names,$spec,$card_type,$quality);
+
+        $result = [];
+        foreach ($names as $name)
+        {
+            foreach ($providers as $provider)
+            {
+                if($name == $provider->name()) {
+                    $result[] = $provider;
+                }
+            }
+        }
+
+        return [$result,$overload];
+//        $this->sort_price($providers,$spec,$card_type,$quality);
+//        return [$providers,false];
+    }
+
+    //按价格从低到高排序
+    private function sort_price($providers,int $spec, int $card_type,int $quality)
+    {
         $ascending = function ($l, $r) use ($quality,$spec,$card_type) {
             [$glid, $lprice] = $l->goods($quality,$spec,$card_type);
             [$rgid, $rprice] = $r->goods($quality,$spec,$card_type);
@@ -35,7 +78,7 @@ class policy extends ProviderManager implements IPolicy
         };
         usort($providers, $ascending);
 
-        return [$providers,false];
+        return $providers;
     }
 
     public function can_retry(array $refill_info, array $order_info) : bool
@@ -49,12 +92,12 @@ class policy extends ProviderManager implements IPolicy
             }
 
             $times = intval($refill['commit_times']);
-            if ($times > 15) {
+            if ($times > policy::normal_times) {
                 return false;
             }
 
             $period = time() - $refill['order_time'];
-            if ($period >= 15 * 60) {
+            if ($period >= policy::normle_time_out) {
                 Log::record("retry false:time > 15m", Log::DEBUG);
                 return false;
             }