stanley 2 年 前
コミット
168a712826

+ 1 - 0
data/config/dev/refill.ini.php

@@ -6581,3 +6581,4 @@ $config['cancel_retry_time'] = [10120 => ["9:00",'10:00','11:00']];
 $third_jumps = [
     10120 => ['x1' => 'x2','x2' => 'x3']
 ];
+$config['third_jumps'] = $third_jumps;

+ 20 - 8
helper/refill/RefillBase.php

@@ -51,9 +51,9 @@ class RefillBase
         return $this->mPolicy->find_quality($order,$skip);
     }
 
-    private function third_can_retry(order $order) : bool
+    private function third_can_retry(order $order) : array
     {
-
+        return $this->mPolicy->third_retry($order);
     }
 
     public function notify($chname, $input)
@@ -207,10 +207,17 @@ class RefillBase
                 $mod_refill->partition(util::part_refill($order_time))->edit($order_id, ['is_retrying' => 1,'notify_time' => time()]);
                 $tran->commit();
 
-                [$can_retry,$params] = $this->retry($refill_info, $order_info);
+                $order = order::from_db($refill_info,$order_info);
+                [$can_retry,$params] = $this->retry($order);
                 if ($can_retry)
                 {
-                    if(util::push_add($params)) {
+                    if($order->is_third())
+                    {
+                        if(util::push_addthird($params)) {
+                            return true;
+                        }
+                    }
+                    elseif(util::push_add($params)) {
                         return true;
                     }
                 }
@@ -237,14 +244,19 @@ class RefillBase
         }
     }
 
-    private function retry(array $refill_info, array $order_info)
+    private function retry(order $order)
     {
         $trace = new scope_trace(__METHOD__);
-        $order = order::from_db($refill_info,$order_info);
         if($order->is_third())
         {
-            if($this->third_can_retry($order))
-            return [false,null];
+            [$can_retry,$next_pcode] = $this->third_can_retry($order);
+            if($can_retry) {
+                $params = $order->third_requeue_params($next_pcode);
+                return [$can_retry,$params];
+            }
+            else {
+                return [false,null];
+            }
         }
 
         [$org_quality,$quality] = $this->find_quality($order);

+ 1 - 0
helper/refill/XYZRefillFactory.php

@@ -37,6 +37,7 @@ require_once(BASE_HELPER_PATH . '/refill/policy/overload_assigner.php');
 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/functional.php');
 require_once(BASE_HELPER_PATH . '/refill/chprice_helper.php');

+ 36 - 0
helper/refill/order.php

@@ -388,4 +388,40 @@ class order
 
         return $params;
     }
+
+    public function third_requeue_params($pcode)
+    {
+        $params = ['mchid' => $this->mMchid,
+            'buyer_id' => $this->mBuyerId,
+            'amount' => $this->mAmount,
+            'card_no' => $this->mCardNo,
+            'org_quality' => $this->mOriginQuality,
+            'quality' => $this->mCurQuality,
+            'mch_order' => $this->mMchOrder,
+            'notify_url' => $this->mNotifyUrl,
+            'idcard' => $this->mIdCard,
+            'card_name' => $this->mCardName,
+            'order_time' => $this->mOrderTime,
+            'commit_times' => $this->mCommitTimes,
+            'order_id' => $this->mLastOrderID,
+
+            'card_type' => $this->mCardType,
+            'third_product_type' => $this->mThirdPorductType,
+            'third_card_type' => $this->mThirdCardType
+        ];
+
+        $params['product_code'] = $pcode;
+        if ($this->mThirdPorductType == mtopcard\ThirdElectricProduct) {
+            $params['company_type'] = $this->mThirdExtes['company_type'];
+            $params['use_type'] = $this->mThirdExtes['use_type'];
+            $params['province'] = $this->mThirdExtes['province'];
+            $params['city'] = $this->mThirdExtes['city'];
+            $params['card_id'] = $this->mThirdExtes['card_id'];
+        }
+        elseif ($this->mThirdPorductType == mtopcard\ThirdSinopecECouponPoroduct) {
+            $params['province'] = $this->mThirdExtes['province'];
+        }
+
+        return $params;
+    }
 }

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

@@ -16,6 +16,8 @@ interface IPolicy
     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 third_retry(order $order): array;
+
     public function update_mchratios($all,$detail,$types);
     public function update_chctl($speeds);
     public function update_maxspeeds($speeds);

+ 4 - 0
helper/refill/policy/lingzh/policy.php

@@ -487,4 +487,8 @@ class policy extends ProviderManager implements IPolicy
     {
         $this->mRatioCtl->update($gross,$detail);
     }
+    public function third_retry(order $order): array
+    {
+        return [false,''];
+    }
 }

+ 44 - 0
helper/refill/policy/third_helper.php

@@ -0,0 +1,44 @@
+<?php
+
+namespace refill;
+
+class third_helper
+{
+    private $mThirdJumps;
+    public function __construct()
+    {
+        $this->mThirdJumps = [];
+    }
+
+    public function load()
+    {
+        global $config;
+        $this->mThirdJumps = $config['third_jumps'] ?? [];
+    }
+
+    public function third_retry(order $order): array
+    {
+        $next_pcoder = function ($mchid,$pcode)
+        {
+            if(array_key_exists($mchid,$this->mThirdJumps))
+            {
+                $jumps = $this->mThirdJumps[$mchid];
+                if(array_key_exists($pcode,$jumps)) {
+                    $next_pcode = $jumps[$pcode];
+                    return [true,$next_pcode];
+                }
+            }
+
+            return [false,''];
+        };
+
+        if($order->is_third())
+        {
+            $mchid = $order->mchid();
+            $cur_pcode = $order->pcode();
+            return $next_pcoder($mchid,$cur_pcode);
+        } else {
+            return [false,''];
+        }
+    }
+}

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

@@ -20,6 +20,7 @@ class policy extends ProviderManager implements IPolicy
     protected $mRatioCtl;
     protected $mGlobalInterceptor;
     protected $mMChannels;
+    protected $mThirdHelper;
 
     public function __construct()
     {
@@ -34,6 +35,7 @@ class policy extends ProviderManager implements IPolicy
         $this->mQuality->setRatioCtl($this->mRatioCtl);
         $this->mGlobalInterceptor = new interceptor();
         $this->mMChannels = new mchannel();
+        $this->mThirdHelper = new third_helper();
     }
 
     public function load()
@@ -59,6 +61,7 @@ class policy extends ProviderManager implements IPolicy
         $this->mRatioCtl->load();
         $this->mGlobalInterceptor->load();
         $this->mMChannels->load();
+        $this->mThirdHelper->load();
 
         $this->init_mavg_price();
     }
@@ -634,4 +637,8 @@ class policy extends ProviderManager implements IPolicy
     {
         $this->mChannelControl->update_maxspeeds($speeds);
     }
+    public function third_retry(order $order): array
+    {
+        return $this->mThirdHelper->third_retry($order);
+    }
 }

+ 26 - 1
test/TestRefillPolicy.php

@@ -15,8 +15,12 @@ require_once(BASE_HELPER_PATH . '/queue/iqueue.php');
 require_once(BASE_HELPER_PATH . '/queue/monitor.php');
 require_once(BASE_HELPER_PATH . '/refill/util.php');
 
+
+
 class TestRefillPolicy extends TestCase
 {
+    private $mThirdJumps;
+
     public static function setUpBeforeClass(): void
     {
         Base::run_util();
@@ -44,7 +48,28 @@ class TestRefillPolicy extends TestCase
 
     public function testThirdRetryPath()
     {
-        $x = 10;
+        refill\RefillFactory::instance();
+        global $config;
+        $this->mThirdJumps = $config['third_jumps'] ?? [];
+
+        $next_pcoder = function ($mchid,$pcode)
+        {
+            if(array_key_exists($mchid,$this->mThirdJumps))
+            {
+                $jumps = $this->mThirdJumps[$mchid];
+                if(array_key_exists($pcode,$jumps)) {
+                    $next_pcode = $jumps[$pcode];
+                    return [true,$next_pcode];
+                }
+            }
+
+            return [false,''];
+        };
+
+        [$can_try,$next_pcode] = $next_pcoder(10120,'x1');
+        [$can_try,$next_pcode] = $next_pcoder(10120,'x2');
+        [$can_try,$next_pcode] = $next_pcoder(10120,'x3');
+
     }
 
 }