Kaynağa Gözat

add to local

stanley-king 4 yıl önce
ebeveyn
işleme
24f8bf719a

+ 7 - 1
helper/mtopcard/mtopcard.php

@@ -140,7 +140,13 @@ function simple_card_type($cardno)
     elseif(preg_match('/^1\d{10}$/',$cardno,$matches)) {
         return PhoneCard;
 
-    } else {
+    }elseif(preg_match( '/^1[0-9]{18}$/',$cardno,$matches)) {
+        return SinopecCard;
+    }
+    elseif(preg_match( '/^9[0-9]{15}$/',$cardno,$matches)) {
+        return PetroChinaCard;
+    }
+    else {
         return UnknownCard;
     }
 }

+ 1 - 1
helper/refill/LZRefillFactory.php

@@ -10,7 +10,7 @@ require_once(BASE_HELPER_PATH . '/refill/policy/lingzh/policy.php');
 require_once(BASE_HELPER_PATH . '/refill/policy/chctl.php');
 require_once(BASE_HELPER_PATH . '/refill/policy/ctl_item.php');
 require_once(BASE_HELPER_PATH . '/refill/policy/mchctl.php');
-
+require_once(BASE_HELPER_PATH . '/refill/policy/quaility.php');
 
 use Log;
 use StatesHelper;

+ 3 - 0
helper/refill/ProviderManager.php

@@ -17,6 +17,9 @@ use Exception;
 
 class ProviderManager
 {
+    const LowestQuality  = 1;
+    const HighestQuality = 5;
+
     protected $mProviderNames;
     protected $mAllQMapPTS;
     protected $mProviders;

+ 22 - 16
helper/refill/RefillBase.php

@@ -44,8 +44,8 @@ class RefillBase
         $this->mPolicy->load();
     }
 
-    public function first_quality($mchid) {
-        return $this->mPolicy->first_quality($mchid);
+    public function find_quality($mchid,$spec,$card_type,$org_quality,$times,$period): array {
+        return $this->mPolicy->first_quality($mchid,$spec,$card_type,$org_quality,$times,$period);
     }
 
     public function notify($chname, $input)
@@ -131,14 +131,22 @@ class RefillBase
 
     private function retry(array $refill_info, array $order_info)
     {
-        [$cantry,$quality] = $this->mPolicy->can_retry($refill_info,$order_info);
-        if(!$cantry) return false;
+        $mchid = intval($refill_info['mchid']);
+        $spec  = intval($refill_info['refill_amount']);
+        $card_type = intval($refill_info['card_type']);
+        $org_quality = intval($refill_info['org_quality']);
+        $used_time = time() - intval($refill_info['order_time']);
+        $commit_times = intval($refill_info['commit_times']);
+
+        [$org_quality,$quality] = $this->mPolicy->find_quality($mchid,$spec,$card_type,$org_quality,$commit_times,$used_time);
+        if($quality <= 0) return false;
 
         $params = [ 'mchid' => $refill_info['mchid'],
             'buyer_id' => $order_info['buyer_id'],
             'amount' => $refill_info['refill_amount'],
             'card_no' => $refill_info['card_no'],
-            'quality' => $quality,
+            'card_type' => $refill_info['card_type'],
+            'org_quality' => $org_quality,
             'mch_order' =>  $refill_info['mch_order'],
             'notify_url' => $refill_info['notify_url'],
             'idcard' => $refill_info['idcard'] ?? '',
@@ -152,7 +160,7 @@ class RefillBase
     }
 
     public function zero_order($mchid, $buyer_id, $amount, $card_no,
-                        $mch_order, $idcard, $card_name, $notify_url,$quality,
+                        $mch_order, $idcard, $card_name, $notify_url,$quality,$org_quality,
                         $order_time = 0, $commit_times = 0,$errmsg='')
     {
         $card_type = mtopcard\card_type($card_no);
@@ -193,7 +201,8 @@ class RefillBase
                 'mch_amount' => $mch_amount, 'channel_amount' => 0,
                 'order_time' => $order_time, 'commit_times' => $commit_times,
                 'commit_time' => time(),'notify_state' => 1,'notify_time' => time(),
-                'card_type' => $card_type, 'card_no' => $card_no,'quality' => $quality,'err_msg' => $errmsg];
+                'card_type' => $card_type, 'card_no' => $card_no, 'quality' => $quality, 'org_quality' => $org_quality,
+                'err_msg' => $errmsg];
             $mod_refill->add_refill($orderext);
             return $order_id;
         }
@@ -202,20 +211,17 @@ class RefillBase
         }
     }
 
-    public function can_nettry($mchid,$quality,$order_time,$commit_times) : bool
-    {
-        return $this->mPolicy->can_nettry($mchid,$quality,$order_time,$commit_times);
-    }
-
     //$quality,质量
     //返回值:[ 错误码,错误信息,订单ID,是否是网络错误]
     //说明:错误码为true 表示成功
     //     其它情况,则需要判断订单ID
     public function add($mchid, $buyer_id, $amount, $card_no,
-                        $mch_order, $idcard, $card_name, $notify_url,$quality,
-                        $order_time, $commit_times,$last_orderid = 0)
+                        $mch_order, $idcard, $card_name, $notify_url,$quality,$org_quality,
+                        $order_time, $commit_times,$last_orderid = 0,$card_type = 0)
     {
-        $card_type = mtopcard\card_type($card_no);
+        if($card_type == 0) {
+            $card_type = mtopcard\card_type($card_no);
+        }
         [$providers,$overload] = $this->mPolicy->find_providers($amount,$card_type,$quality);
 
         if (empty($providers))
@@ -295,7 +301,7 @@ class RefillBase
                     'notify_url' => $notify_url, 'channel_name' => $channel_name,
                     'mch_amount' => $mch_amount, 'channel_amount' => $price,
                     'order_time' => $order_time, 'commit_times' => $commit_times,
-                    'card_type' => $card_type, 'card_no' => $card_no,'quality' => $quality];
+                    'card_type' => $card_type, 'card_no' => $card_no,'quality' => $quality,'org_quality'=> $org_quality];
                 $mod_refill->add_refill($orderext);
             } else {
                 Log::record("{$result['msg']}",Log::ERR);

+ 2 - 0
helper/refill/XYZRefillFactory.php

@@ -12,6 +12,8 @@ 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');
 require_once(BASE_HELPER_PATH . '/refill/policy/mchctl.php');
+require_once(BASE_HELPER_PATH . '/refill/policy/quaility.php');
+require_once(BASE_HELPER_PATH . '/refill/policy/xyz/quality_ploy.php');
 
 use Log;
 use StatesHelper;

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

@@ -6,10 +6,8 @@ namespace refill;
 
 interface IPolicy
 {
-    //[can_try,quality]
-    public function can_retry(array $refill_info, array $order_info) : array;
-    public function first_quality($mchid): int;
+    //[orgian_quality,current_quality]
+    public function find_quality($mchid,$spec,$card_type,$quality,$times,$used_time): array;
     public function allow($mchid,$card_type,$amount,$quality) : bool;
-    public function can_nettry($mchid,$quality,$order_time,$commit_times) : bool;
     public function notify($order_info, $refill_info) : bool;
 }

+ 5 - 1
helper/refill/policy/chctl.php

@@ -13,8 +13,12 @@ class chctl
     static $cache_names = [
         ['quality'=> 1,'name' => 'channel-ctl-oil-common-limit'],
         ['quality'=> 2,'name' => 'channel-ctl-oil-fast-limit'],
+
         ['quality'=> 1,'name' => 'channel-ctl-phone-common-limit'],
-        ['quality'=> 2,'name' => 'channel-ctl-phone-fast-limit']
+        ['quality'=> 2,'name' => 'channel-ctl-phone-fast-limit'],
+        ['quality'=> 3,'name' => 'channel-ctl-phone-card-limit'],
+        ['quality'=> 4,'name' => 'channel-ctl-phone-third-limit'],
+        ['quality'=> 5,'name' => 'channel-ctl-phone-slow-limit'],
     ];
 
     public function __construct()

+ 0 - 1
helper/refill/policy/ctl_item.php

@@ -13,7 +13,6 @@ class ctl_item
     private $mCardType;
     private $mAmount;
 
-
     private $mMaxSpeed;
     private $mPrefix;
     private $mLastReadTime;

+ 20 - 22
helper/refill/policy/lingzh/policy.php

@@ -7,31 +7,31 @@ use Log;
 
 class policy extends ProviderManager implements IPolicy
 {
-    const normal_times = 15;
-    const normle_time_out = 90;
-
-    const high_times = 5;
-    const high_time_out = 30;
-
     protected $mChannelControl;
     protected $mMchctl;
+    protected $mQuality;
+
     public function __construct()
     {
         parent::__construct();
         $this->mChannelControl = new chctl();
         $this->mMchctl = new mchctl();
+        $this->mQuality = new quality_ploy();
     }
 
     public function load()
     {
         parent::load();
+
         $this->mChannelControl->load();
         $this->mMchctl->load();
+        $this->mQuality->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];
         }
@@ -57,14 +57,22 @@ class policy extends ProviderManager implements IPolicy
         return [$result,$overload];
     }
 
-    public function first_quality($mchid): int
+    public function find_quality($mchid,$spec,$card_type,$org_quality,$times,$used_time): array
     {
-        return 1;
-    }
+        [$org_quality,$qualities] = $this->mQuality->find_quality($mchid,$org_quality,$times,$used_time);
+        foreach ($qualities as $quality)
+        {
+            $providers = parent::find_providers($spec,$card_type,$quality);
+            if(!empty($providers)) {
+                Log::record("Policy::find_quality:{$quality}-{$spec}-{$card_type} is ok",Log::DEBUG);
+                return [$org_quality,$quality];
+            }
+            else {
+                Log::record("Policy::find_quality:{$quality}-{$spec}-{$card_type} is fail",Log::DEBUG);
+            }
+        }
 
-    public function can_retry(array $refill_info, array $order_info): array
-    {
-        return [false,0];
+        return [$org_quality,0];
     }
 
     public function allow($mchid, $card_type, $amount, $quality): bool
@@ -72,16 +80,6 @@ class policy extends ProviderManager implements IPolicy
         return true;
     }
 
-    public function can_nettry($mchid,$quality,$order_time,$commit_times) : bool
-    {
-        if($quality == 1) {
-            return $commit_times < policy::normal_times && time() - $order_time < policy::normle_time_out;
-        }
-        else {
-            return $commit_times < policy::high_times && time() - $order_time < policy::high_time_out;
-        }
-    }
-
     public function notify($order_info, $refill_info) : bool
     {
         $order_state = $order_info['order_state'];

+ 33 - 0
helper/refill/policy/lingzh/quality_ploy.php

@@ -0,0 +1,33 @@
+<?php
+
+namespace refill;
+
+class quality_ploy extends Quality
+{
+    public function __construct()
+    {
+        parent::__construct();
+
+        $this->mSpeeds = [
+            self::Normal => ['retry_times' => 60,'retry_timeout' => 900,'per_secs' => 120],
+            self::Quick => ['retry_times' => 10,'retry_timeout' => 60,'per_secs' => 30],
+            self::CardKey => ['retry_times' => 60,'retry_timeout' => 900,'per_secs' => 60],
+            self::ThirdShop => ['retry_times' => 60,'retry_timeout' => 900,'per_secs' => 600],
+            self::Slow => ['retry_times' => 60,'retry_timeout' => 86400,'per_secs' => 3600],
+
+            self::DefNormal => ['retry_times' => 60,'retry_timeout' => 900,'per_secs' => 60],
+            self::DefSuccess => ['retry_times' => 60,'retry_timeout' => 900,'per_secs' => 60],
+        ];
+
+        $this->mQualities = [
+            self::Normal => [self::Normal],
+            self::Quick => [self::Quick],
+            self::CardKey => [self::CardKey],
+            self::ThirdShop => [self::ThirdShop],
+            self::Slow => [self::Slow],
+
+            self::DefNormal  => [self::ThirdShop,self::Normal],
+            self::DefSuccess => [self::ThirdShop,self::CardKey,self::Normal,self::Quick]
+        ];
+    }
+}

+ 100 - 0
helper/refill/policy/quaility.php

@@ -0,0 +1,100 @@
+<?php
+
+namespace refill;
+
+use Log;
+
+class Quality
+{
+    const Normal = 1;
+    const Quick = 2;
+    const CardKey = 3;
+    const ThirdShop = 4;
+    const Slow = 5;
+
+    const DefNormal  = 11; // 4 -> 1
+    const DefSuccess = 12; // 4 -> 3 -> 1 -> 2
+
+    protected $mMchctl;
+    protected $mSpeeds;
+    protected $mQualities;
+
+    public function __construct()
+    {
+        $this->mMchctl = new mchctl();
+    }
+
+    public function load()
+    {
+        $this->mMchctl->load();
+    }
+
+    public function find_quality($mchid,$quality,$times,$used_time): array
+    {
+        if($quality == 0)
+        {
+            [$sucdess,$setting_quality,$time_out] = $this->mMchctl->getCtls($mchid);
+            if($sucdess)
+            {
+                if(array_key_exists($setting_quality,$this->mQualities)) {
+                    $org = $setting_quality;
+                    $qualities = $this->mQualities[$setting_quality];
+                }
+                else {
+                    $org = $setting_quality;
+                    $qualities = [$setting_quality];
+                }
+            }
+            else {
+                $org = self::DefNormal;
+                $qualities = [self::ThirdShop,self::Normal];
+            }
+        }
+        elseif(array_key_exists($quality,$this->mQualities)) {
+            $org = $quality;
+            $qualities = $this->mQualities[$quality];
+        }
+        else {
+            Log::record("find_quality: cannot find any quality",Log::DEBUG);
+            return [0,[]];
+        }
+
+        if(empty($time_out)) {
+            $time_out = $this->mSpeeds[$org]['retry_timeout'];
+        }
+
+        $max_times = $this->mSpeeds[$org]['retry_times'];
+        $qualities = $this->calc_quality($qualities,$times,$used_time,$time_out,$max_times);
+
+        Log::record("find_quality: find org={$org} qualitys=" . implode(',',$qualities),Log::DEBUG);
+        return [$org,$qualities];
+    }
+
+    //通过每种类型通道耗时,倒推当前可用通道,并优先走推荐通道.
+    private function calc_quality($qualities, $times, $used_time, $time_out, $max_times)
+    {
+        $left_time = $time_out - $used_time;
+        if($left_time <= 0 || $max_times <= $times) return [];
+
+        $qualities = array_reverse($qualities);
+
+        $result = [];
+        foreach ($qualities as $quality)
+        {
+            $per_secs = $this->mSpeeds[$quality]['per_secs'];
+            $left_time -= $per_secs;
+            if($left_time > 0) {
+                $result[] = $quality;
+            } else {
+                break;
+            }
+        }
+
+        if(empty($result)) {
+            $result[] = $quality;
+        }
+
+        $result = array_reverse($result);
+        return $result;
+    }
+}

+ 37 - 91
helper/refill/policy/xyz/policy.php

@@ -9,27 +9,25 @@ use StatesHelper;
 
 class policy extends ProviderManager implements IPolicy
 {
-    const normal_times = 3;
-    const normal_time_out = 600;
-    const normal_req_secs = 60;
-
-    const high_times = 3;
-    const high_time_out = 60;
-
     protected $mChannelControl;
     protected $mMchctl;
+    protected $mQuality;
+
     public function __construct()
     {
         parent::__construct();
         $this->mChannelControl = new chctl();
         $this->mMchctl = new mchctl();
+        $this->mQuality = new quality_ploy();
     }
 
     public function load()
     {
         parent::load();
+
         $this->mChannelControl->load();
         $this->mMchctl->load();
+        $this->mQuality->load();
     }
 
     public function find_providers(int $spec, int $card_type,int $quality): array
@@ -61,97 +59,45 @@ class policy extends ProviderManager implements IPolicy
         return [$result,$overload];
     }
 
-    //按价格从低到高排序
-    private function sort_price($providers,int $spec, int $card_type,int $quality)
+//    //按价格从低到高排序
+//    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);
+//
+//            $lsort = $l->sort();
+//            $rsort = $r->sort();
+//
+//            if($lprice == $rprice) {
+//                return $lsort < $rsort ? -1 : 1;
+//            }
+//            else {
+//                return $lprice < $rprice ? -1 : 1;
+//            }
+//        };
+//        usort($providers, $ascending);
+//
+//        return $providers;
+//    }
+
+    //[orgian_quality,current_quality]
+    public function find_quality($mchid,$spec,$card_type,$org_quality,$times,$used_time): array
     {
-        $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);
-
-            $lsort = $l->sort();
-            $rsort = $r->sort();
-
-            if($lprice == $rprice) {
-                return $lsort < $rsort ? -1 : 1;
-            }
-            else {
-                return $lprice < $rprice ? -1 : 1;
-            }
-        };
-        usort($providers, $ascending);
-
-        return $providers;
-    }
-
-    public function can_retry(array $refill_info, array $order_info) : array
-    {
-        $checker = function ($refill, $order,$time_out,$quality)
+        [$org_quality,$qualities] = $this->mQuality->find_quality($mchid,$org_quality,$times,$used_time);
+        foreach ($qualities as $quality)
         {
-            $state = intval($order['order_state']);
-            if ($state !== ORDER_STATE_SEND) {
-                Log::record("retry false:order_state != send", Log::DEBUG);
-                return [false,0];
-            }
-
-            $times = intval($refill['commit_times']);
-            if ($times > policy::normal_times) {
-                return [false,0];
-            }
-
-            $period = time() - $refill['order_time'];
-            if ($period >= $time_out) {
-                Log::record("retry false:time > 15m", Log::DEBUG);
-                return [false,0];
-            }
-            elseif($period + 60 > $time_out && $quality == 3) {
-                return [true,2];
+            $providers = parent::find_providers($spec,$card_type,$quality);
+            if(!empty($providers)) {
+                Log::record("Policy::find_quality:{$quality}-{$spec}-{$card_type} is ok",Log::DEBUG);
+                return [$org_quality,$quality];
             }
             else {
-                return [true,$quality];
+                Log::record("Policy::find_quality:{$quality}-{$spec}-{$card_type} is fail",Log::DEBUG);
             }
-        };
-
-        $mchid = $refill_info['mchid'];
-        [$sucdess,$quality,$time_out] = $this->mMchctl->getCtls($mchid);
-
-        if($sucdess) {
-            Log::record("mchid = {$mchid} timeout={$time_out}",Log::DEBUG);
-            return $checker($refill_info, $order_info,$time_out,$quality);
-        }
-        else {
-            return $checker($refill_info, $order_info,policy::normal_time_out,1);
-        }
-    }
-
-    public function can_nettry($mchid,$quality,$order_time,$commit_times) : bool
-    {
-        [$sucdess,$quality,$time_out] = $this->mMchctl->getCtls($mchid);
-
-        if($sucdess)
-        {
-            if($quality == 1) {
-                return $commit_times < policy::normal_times && time() - $order_time < $time_out;
-            }
-            else {
-                return $commit_times < policy::high_times && time() - $order_time < $time_out;
-            }
-        }
-        elseif($quality == 1) {
-            return $commit_times < policy::normal_times && time() - $order_time < policy::normal_time_out;
-        }
-        else {
-            return $commit_times < policy::high_times && time() - $order_time < policy::high_time_out;
         }
-    }
 
-    public function first_quality($mchid): int
-    {
-        [$sucdess,$quality,$time_out] = $this->mMchctl->getCtls($mchid);
-        if($sucdess) {
-            return $quality;
-        } else {
-            return 1;
-        }
+        return [$org_quality,0];
     }
 
     public function allow($mchid,$card_type,$amount,$quality) : bool

+ 33 - 0
helper/refill/policy/xyz/quality_ploy.php

@@ -0,0 +1,33 @@
+<?php
+
+namespace refill;
+
+class quality_ploy extends Quality
+{
+    public function __construct()
+    {
+        parent::__construct();
+
+        $this->mSpeeds = [
+            self::Normal => ['retry_times' => 2,'retry_timeout' => 180,'per_secs' => 120],
+            self::Quick => ['retry_times' => 2,'retry_timeout' => 60,'per_secs' => 30],
+            self::CardKey => ['retry_times' => 2,'retry_timeout' => 120,'per_secs' => 60],
+            self::ThirdShop => ['retry_times' => 2,'retry_timeout' => 600,'per_secs' => 600],
+            self::Slow => ['retry_times' => 2,'retry_timeout' => 86400,'per_secs' => 3600],
+
+            self::DefNormal => ['retry_times' => 2,'retry_timeout' => 180,'per_secs' => 120],
+            self::DefSuccess => ['retry_times' => 2,'retry_timeout' => 60,'per_secs' => 30],
+        ];
+
+        $this->mQualities = [
+            self::Normal => [self::Normal],
+            self::Quick => [self::Quick],
+            self::CardKey => [self::CardKey],
+            self::ThirdShop => [self::ThirdShop],
+            self::Slow => [self::Slow],
+
+            self::DefNormal  => [self::Normal],
+            self::DefSuccess => [self::Quick],
+        ];
+    }
+}

+ 19 - 16
mobile/control/refill.php

@@ -66,7 +66,8 @@ class refillControl extends merchantControl
         $amount = intval($_GET['amount']);
         $card_no = $_GET['cardno'];
         $notify_url = $_GET['notifyurl'];
-        $mch_order = $_GET['order_sn']; //对方的order编号
+        $mch_order = $_GET['order_sn'];   //对方的order编号
+        $quality = $_GET['quality'] ?? 0;
 
         if(!$this->check_mchorder($this->mchid(),$mch_order)) {
             return self::outerr(205,"客户订单号重复或者为空.");
@@ -76,27 +77,29 @@ class refillControl extends merchantControl
             return self::outerr(206,"平台不支持该卡充值.");
         }
 
-//        $card_type = mtopcard\card_type($card_no);
-//        if($card_type === mtopcard\SinopecCard || $card_type === mtopcard\PetroChinaCard)
-//        {
-//            $allow = refill\RefillFactory::instance()->allow($this->mchid(),$card_type,$amount,$quality);
-//            if(!$allow) {
-//                if ($card_type === mtopcard\SinopecCard) {
-//                    $text = "中石化";
-//                }
-//                else {
-//                    $text = "中石油";
-//                }
-//                return self::outerr(207,"今日贵司{$amount}{$text}充值库存已经用完.");
-//            }
-//        }
+        $card_type = mtopcard\card_type($card_no);
+        if($card_type === mtopcard\SinopecCard || $card_type === mtopcard\PetroChinaCard)
+        {
+            $allow = refill\RefillFactory::instance()->allow($this->mchid(),$card_type,$amount,$quality);
+            if(!$allow) {
+                if ($card_type === mtopcard\SinopecCard) {
+                    $text = "中石化";
+                }
+                else {
+                    $text = "中石油";
+                }
+                return self::outerr(207,"今日贵司{$amount}{$text}充值库存已经用完.");
+            }
+        }
 
         $params = [ 'mchid' => $this->mchid(),
             'buyer_id' => $this->adminid(),
             'amount' => $amount,
             'card_no' => $card_no,
             'mch_order' => $mch_order,
-            'notify_url' => $notify_url];
+            'notify_url' => $notify_url,
+            'org_quality' => $quality
+            ];
 
         $state = refill\util::push_add($params);
         if($state === true) {

+ 4 - 1
racc/control/lzrefill.php

@@ -74,6 +74,7 @@ class lzrefillControl extends lzbaseControl
         $card_no = $_GET['mob'];
         $notify_url = $_GET['notifyurl'];
         $mch_order = $_GET['ord']; //对方的order编号
+        $quality = $_GET['quality'] ?? 0;
 
         //此处判断是对的
         if($amount > $this->member_available) {
@@ -93,7 +94,9 @@ class lzrefillControl extends lzbaseControl
             'amount' => $amount,
             'card_no' => $card_no,
             'mch_order' => $mch_order,
-            'notify_url' => $notify_url];
+            'notify_url' => $notify_url,
+            'org_quality' => $quality
+        ];
 
         $ret = refill\util::push_add($params);
         if($ret) {

+ 9 - 8
racc/control/refill.php

@@ -65,8 +65,7 @@ class refillControl extends merchantControl
         $card_no = $_GET['cardno'];
         $notify_url = $_GET['notifyurl'];
         $mch_order = $_GET['order_sn']; //对方的order编号
-        $idcard = $_GET['idcard'] ?? '';
-        $card_name = $_GET['card_name'] ?? '';
+        $quality = $_GET['quality'] ?? 0;
 
         if(!$this->check_mchorder($this->mchid(),$mch_order)) {
             return self::outerr(205,"客户订单号重复或者为空.");
@@ -98,12 +97,14 @@ class refillControl extends merchantControl
             return self::outerr(203, "余额不足");
         }
 
-        $params = [ 'mchid' => $this->mchid(),
-                    'buyer_id' => $this->adminid(),
-                    'amount' => $amount,
-                    'card_no' => $card_no,
-                    'mch_order' => $mch_order,
-                    'notify_url' => $notify_url];
+        $params = ['mchid' => $this->mchid(),
+            'buyer_id' => $this->adminid(),
+            'amount' => $amount,
+            'card_no' => $card_no,
+            'mch_order' => $mch_order,
+            'notify_url' => $notify_url,
+            'org_quality' => $quality
+        ];
 
         refill\util::push_add($params);
         return self::outsuccess(['state' => true]);

+ 12 - 10
rdispatcher/proxy.php

@@ -2,6 +2,7 @@
 
 
 use refill\util;
+use refill;
 
 require_once (BASE_ROOT_PATH . '/helper/model_helper.php');
 
@@ -28,17 +29,17 @@ class proxy
         $commit_times = $params['commit_times'] ?? 0;
         $last_order_id = $params['order_id'] ?? 0;
 
-        $quality = intval($params['quality']);
+        $org_quality = intval($params['org_quality']) ?? 0;
+        $card_type   = intval($params['card_type']) ?? 0;
 
-        if($quality != 1 && $quality != 2) {
-            $quality =  refill\RefillFactory::instance()->first_quality($mchid);
-            Log::record("add first_quality quality = {$quality}",Log::DEBUG);
+        if($card_type == 0) {
+            $card_type = mtopcard\card_type($card_no);
         }
 
-
-        [$errcode, $errmsg,$order_id,$neterr] = refill\RefillFactory::instance()->add($mchid, $buyer_id, $amount, $card_no,
-            $mch_order, $idcard, $card_name, $notify_url,$quality, $order_time, $commit_times,$last_order_id);
-
+        [$org_quality,$quality] = refill\RefillFactory::instance()->find_quality($mchid,$amount,$card_type,$org_quality,$commit_times,time() - $order_time);
+        [$errcode, $errmsg, $order_id, $neterr] = refill\RefillFactory::instance()->add($mchid, $buyer_id, $amount, $card_no,
+            $mch_order, $idcard, $card_name, $notify_url, $quality,$org_quality,
+            $order_time, $commit_times, $last_order_id,$card_type);
         $params['commit_times'] += 1;
         $commit_times += 1;
 
@@ -47,7 +48,8 @@ class proxy
             $fNotify = true;
             if(($errcode === refill\errcode::MERCHANT_REFILL_ERROR && $neterr) || $errcode == refill\errcode::PROVIDER_OVERLOAD)
             {
-                if (refill\RefillFactory::instance()->can_nettry($mchid, $quality, $order_time, $commit_times)) {
+                [$org_quality,$quality] = refill\RefillFactory::instance()->find_quality($mchid,$amount,$card_type,$org_quality,$commit_times,time() - $order_time);
+                if ($quality > 0) {
                     $fNotify = false;
                     $params['order_id'] = $order_id;
                     refill\util::push_add($params);
@@ -64,7 +66,7 @@ class proxy
                     $order_info = $this->latest_order($refill_order, $mchid, $mch_order);
                     if (empty($order_info)) {
                         $order_id = refill\RefillFactory::instance()->zero_order($mchid, $buyer_id, $amount, $card_no,
-                            $mch_order, $idcard, $card_name, $notify_url, $quality, $order_time, $commit_times, $errmsg);
+                            $mch_order, $idcard, $card_name, $notify_url, $quality, $org_quality, $order_time, $commit_times, $errmsg);
                     } else {
                         $order_id = $order_info['order_id'];
                     }

+ 1 - 0
test/TestMemberCard.php

@@ -474,6 +474,7 @@ class TestMemberCard extends TestCase
     public function testPhoneZone()
     {
         $x = $this->carrier_type('13911129867');
+        $x = $this->carrier_type('13886396292');
     }
     public function testCheckMobileChannel(){
         $mobile = 17801048874;