Przeglądaj źródła

add channel ch notify cannot commit times and goods timds

stanley-king 1 rok temu
rodzic
commit
25c961b925

+ 2 - 2
admin/templates/default/provider.edit.php

@@ -48,14 +48,14 @@
                 <td class="vatop tips"></td>
             </tr>
             <tr class="noborder">
-                <td colspan="2"><label for="end_period">提单失败次数(同一单,多次提交后,渠道直接返回失败的次数):</label></td>
+                <td colspan="2"><label for="end_period">提单限制次数(同一单,多次提交后,渠道回调返回限制提交的次数,-1表示无限制):</label></td>
             </tr>
             <tr class="noborder">
                 <td class="vatop rowform"><input type="text" value="<?php echo $output['provider']['fail_times']?>" name="fail_times" id="fail_times" class="txt"></td>
                 <td class="vatop tips"></td>
             </tr>
             <tr class="noborder">
-                <td colspan="2"><label for="end_period">提单最大次数(同一单,多次提交的理想次数。因此系统有可能提单次数超过这个值.):</label></td>
+                <td colspan="2"><label for="end_period">理想提单次数(同一单,多次提交的理想次数。因此系统有可能提单次数超过这个值,-1表示无限制.):</label></td>
             </tr>
             <tr class="noborder">
                 <td class="vatop rowform"><input type="text" value="<?php echo $output['provider']['enough_times']?>" name="enough_times" id="enough_times" class="txt"></td>

+ 2 - 1
helper/refill/RefillBase.php

@@ -447,10 +447,11 @@ class RefillBase
         $mch_order = $order->mch_order();
 
         [$providers, $overload] = $this->mPolicy->find_providers($order);
+        $ch_times = $this->mPolicy->get_times();
 
         $chfilters = $order->filter();
         $cur_quality = $order->cur_quality();
-        $providers = $chfilters->getProviders($cur_quality,$providers);
+        $providers = $chfilters->getProviders($cur_quality, $providers, $ch_times);
 
         if (empty($providers)) {
             Log::record("canot find any providers", Log::DEBUG);

+ 1 - 1
helper/refill/XYZRefillFactory.php

@@ -8,7 +8,6 @@ require_once(BASE_HELPER_PATH . '/refill/ProviderManager.php');
 require_once(BASE_HELPER_PATH . '/refill/order.php');
 require_once(BASE_HELPER_PATH . '/refill/divert_account.php');
 require_once(BASE_HELPER_PATH . '/refill/store_member.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');
@@ -38,6 +37,7 @@ require_once(BASE_HELPER_PATH . '/refill/policy/interceptor.php');
 require_once(BASE_HELPER_PATH . '/refill/policy/transfer.php');
 require_once(BASE_HELPER_PATH . '/refill/policy/mchannel.php');
 require_once(BASE_HELPER_PATH . '/refill/policy/third_helper.php');
+require_once(BASE_HELPER_PATH . '/refill/policy/ch_times.php');
 require_once(BASE_HELPER_PATH . '/refill/functional.php');
 require_once(BASE_HELPER_PATH . '/refill/chprice_helper.php');
 require_once(BASE_HELPER_PATH . '/refill/EventManager.php');

+ 2 - 0
helper/refill/policy/IPolicy.php

@@ -22,4 +22,6 @@ interface IPolicy
     public function update_mchratios($all,$detail,$types);
     public function update_chctl($speeds);
     public function update_maxspeeds($speeds);
+
+    public function get_times();
 }

+ 8 - 3
helper/refill/policy/ch_times.php

@@ -41,7 +41,12 @@ class ch_times
         $this->mChTimes = $cfgs;
     }
 
-    public function 
-
-
+    public function get_times($ch_name)
+    {
+        if (array_key_exists($ch_name, $this->mChTimes)) {
+            return $this->mChTimes[$ch_name];
+        } else {
+            return [65536, 65536];
+        }
+    }
 }

+ 59 - 5
helper/refill/policy/channel_filter.php

@@ -169,7 +169,7 @@ class channel_filter
         }
     }
 
-    public function getProviders($cur_quality,$inProviders)
+    public function getProviders($cur_quality, $inProviders, $ch_times)
     {
         $this->mQuality = $cur_quality;
         if ($this->mCardType == mtopcard\SinopecCard || $this->mCardType == mtopcard\PetroChinaCard) {
@@ -177,16 +177,70 @@ class channel_filter
         } elseif ($this->mCardType == mtopcard\ThirdRefillCard) {
             return $inProviders;
         } elseif ($this->mQuality == Quality::Normal) {
-            return $this->asc($inProviders,1,10);
+            return $this->ascex($inProviders, $ch_times);
         } elseif ($this->mQuality == Quality::Quick) {
-            return $this->asc($inProviders,1,10);
+            return $this->ascex($inProviders, $ch_times);
         } elseif ($this->mQuality == Quality::CardKey) {
-            return $this->asc($inProviders,1,1);
+            return $this->ascex($inProviders, $ch_times);
         } else {
-            return $this->asc($inProviders,1,1);
+            return $this->ascex($inProviders,$ch_times);
         }
     }
 
+    private function ascex($inProviders, $ch_times)
+    {
+        if(array_key_exists($this->mQuality,$this->mDatas)) {
+            $ch_infos = $this->mDatas[$this->mQuality];
+        } else {
+            $ch_infos = [];
+        }
+
+        $filter = function ($ch_infos) use ($ch_times)
+        {
+            $fail = [];
+            $good = [];
+            $enough = [];
+
+            foreach ($ch_infos as $name => $item)
+            {
+                [$fails, $succs] = $ch_times->get_times($name);
+                if($item['fail'] >= 0 or $item['succ'] >= $fails) {
+                    $fail[] = $name;
+                }
+                elseif($item['succ'] >= $succs) {
+                    $enough[] = $name;
+                }
+                else {
+                    $good[] = $name;
+                }
+            }
+
+            return [$good,$enough,$fail];
+        };
+
+        [$good,$enough,$fail] = $filter($ch_infos);
+
+        $fail_providers = [];
+        $enough_providers = [];
+        $good_providers = [];
+
+        foreach ($inProviders as $provider)
+        {
+            $name = $provider->name();
+            if(in_array($name,$fail)) {
+                $fail_providers[] = $provider;
+            }
+            elseif(in_array($name,$enough)) {
+                $enough_providers[] = $provider;
+            }
+            else {
+                $good_providers[] = $provider;
+            }
+        }
+        $result = array_merge($good_providers,$enough_providers);
+        return $result;
+    }
+
     private function asc($inProviders,$fails,$succs)
     {
         if(array_key_exists($this->mQuality,$this->mDatas)) {

+ 8 - 0
helper/refill/policy/xyz/policy.php

@@ -21,6 +21,7 @@ class policy extends ProviderManager implements IPolicy
     protected $mGlobalInterceptor;
     protected $mMChannels;
     protected $mThirdHelper;
+    protected $mChTimes;
 
     public function __construct()
     {
@@ -36,6 +37,7 @@ class policy extends ProviderManager implements IPolicy
         $this->mGlobalInterceptor = new interceptor();
         $this->mMChannels = new mchannel();
         $this->mThirdHelper = new third_helper();
+        $this->mChTimes = new ch_times();
     }
 
     public function load()
@@ -64,6 +66,12 @@ class policy extends ProviderManager implements IPolicy
         $this->mThirdHelper->load();
 
         $this->init_mavg_price();
+        $this->mChTimes->load();
+    }
+
+    public function get_times()
+    {
+        return $this->mChTimes;
     }
 
     private function init_mavg_price()

+ 7 - 0
test/TestRefillUtil.php

@@ -52,6 +52,13 @@ class TestRefillUtil extends TestCase
         $all = refill\util::read_ches_submit_times();
     }
 
+    public function testChTimes()
+    {
+        $ch_times  = new refill\ch_times();
+        [$fail,$enough] = $ch_times->get_times('test');
+        [$fail,$enough] = $ch_times->get_times('xxxx');
+    }
+
     public function testSingleCrash()
     {
         $card_no =  13911129867;