Browse Source

增加通道最高价限制

stanley-king 3 năm trước cách đây
mục cha
commit
b8ca1d7ab9

+ 2 - 3
admin/control/provider_ctl.php

@@ -49,8 +49,7 @@ class provider_ctlControl extends SystemControl
                 $index = "{$data['type']}-{$data['amount']}";
                 $result[$index][] = $data;
             }
-//            var_dump($result);die;
-//            Log::record("provider amount data:".json_encode($result),Log::DEBUG);
+
             wcache($rkey, ['data' => serialize($result)], 'provider-');
             showMessage('编辑成功');
         } else {
@@ -93,7 +92,7 @@ class provider_ctlControl extends SystemControl
                 }
             }
 
-            $ProviderManager = new \refill\ProviderManager();
+            $ProviderManager = new refill\ProviderManager();
             $ProviderManager->load();
             $QPTA = $ProviderManager->getQPTA();
             $QPTA = $QPTA[$quality[$form]];

+ 0 - 5
helper/calc_helper.php

@@ -400,9 +400,4 @@ class CalcPrice implements ICalc
 
         return true;
     }
-
-    public function max_inprice($order_info)
-    {
-        return false;
-    }
 }

+ 0 - 1
helper/icalc.php

@@ -5,5 +5,4 @@ interface ICalc
     public function calc_vgoods_price($goods_info);
     public function calc_vorder_amount($order_info);
     public function calc_tips();
-    public function max_inprice($order_info);
 }

+ 2 - 14
helper/refill/CalcMerchantPrice.php

@@ -13,8 +13,6 @@ use Log;
 class CalcMerchantPrice implements ICalc
 {
     private $mPrice;
-    private $mMaxInPrice;
-
     public function __construct($mchid,$spec,$card_type,$quality,$policy,$other = [])
     {
         if(empty($other) || empty($other['product_code'])) {
@@ -25,12 +23,10 @@ class CalcMerchantPrice implements ICalc
         }
 
         $price = $policy->price($mchid,$spec,$card_type,$quality,$pcode);
-        $max_inprice = $policy->max_inprice($mchid,$spec,$card_type,$quality,$pcode);
-        if ($price === false || $max_inprice === false) {
+        if ($price === false) {
             throw new Exception("没有协商商品购买价格.");
         } else {
             $this->mPrice = $price;
-            $this->mMaxInPrice = $max_inprice;
         }
     }
 
@@ -39,11 +35,6 @@ class CalcMerchantPrice implements ICalc
         return round($this->mPrice,4);
     }
 
-    public function max_inprice($order_info)
-    {
-        return round($this->mMaxInPrice,4);
-    }
-
     public function calc_vorder_amount($order_info)
     {
         $num = $order_info['quantity'];
@@ -72,10 +63,7 @@ class ZeroMerchantPrice implements ICalc
     {
         return round(0,4);
     }
-    public function max_inprice($order_info)
-    {
-        return round(0,4);
-    }
+
     public function calc_tips()
     {
         Log::record("没有实现该接口" . __FUNCTION__ ,Log::ERR);

+ 0 - 6
helper/refill/RefillBase.php

@@ -282,8 +282,6 @@ class RefillBase
                 $calc = new CalcMerchantPrice($mchid, $order->spec(), $order->card_type(),$order->cur_quality(),$this->mPolicy,$order->thrid_params());
             }
             $mch_price = $calc->calc_vgoods_price([]);
-            $max_inprice = $calc->max_inprice([]);
-
             $mch_amount = $mch_price * $order->quantity();
         }
         catch (Exception $ex) {
@@ -310,10 +308,6 @@ class RefillBase
                 continue;
             }
 
-            if($price > $max_inprice) {
-                continue;
-            }
-
             $mod_refill = Model('refill_order');
             $channel_amount = $price * $order->quantity();
             [$order_success, $order_id, $order_sn] = $this->create_order($order, $goods_id, $minfo, $calc, $channel_name, $channel_amount, $mch_amount);

+ 39 - 17
helper/refill/policy/chctl.php

@@ -22,10 +22,10 @@ class chctl
         ['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'], //24 hour
-        ['quality'=> 6,'name' => 'channel-ctl-phone-slow6-limit'],//6 hour
+        ['quality'=> 5,'name' => 'channel-ctl-phone-slow-limit'],  //24 hour
+        ['quality'=> 6,'name' => 'channel-ctl-phone-slow6-limit'], //6 hour
         ['quality'=> 7,'name' => 'channel-ctl-phone-slow2-limit'], //2 hour
-        ['quality'=> 8,'name' => 'channel-ctl-phone-slow48-limit'], //48 hour
+        ['quality'=> 8,'name' => 'channel-ctl-phone-slow48-limit'],//48 hour
         ['quality'=> 9,'name' => 'channel-ctl-phone-slow72-limit'] //72 hour
     ];
 
@@ -112,23 +112,38 @@ class chctl
         }
     }
 
-    public function match($names,int $spec, int $card_type,int $quality)
+    public function match($names, int $spec, int $card_type, int $quality, $max_inprice)
     {
         $trace = new scope_trace(__METHOD__);
         if ($card_type == mtopcard\ThirdRefillCard) {
             return $names;
         }
 
-        $ctl_items = [];
-        foreach ($names as $name)
+        $pThis = $this;
+        $price_filter = function ($names,$spec,$card_type,$quality) use($pThis,$max_inprice)
         {
-            $key = $this->prefix($name,$spec,$card_type,$quality);
-            if(array_key_exists($key,$this->mSpeedtable)) {
-                $ctl_items[] = $this->mSpeedtable[$key];
-            } else {
-                Log::record("unavaliable key={$key}",Log::DEBUG);
+            $ctls = [];
+            foreach ($names as $name)
+            {
+                $key = $pThis->prefix($name,$spec,$card_type,$quality);
+                if(array_key_exists($key,$pThis->mSpeedtable))
+                {
+                    $item = $pThis->mSpeedtable[$key];
+
+                    $inPrice = $item->price();
+                    if ($max_inprice !== false && $inPrice > $max_inprice) {
+                        continue;
+                    } else {
+                        $ctls[] = $item;
+                    }
+                }
+                else {
+                    Log::record("auto_match speed table key={$key} is empty.",Log::DEBUG);
+                }
             }
-        }
+            return $ctls;
+        };
+        $ctl_items = $price_filter($names,$spec,$card_type,$quality);
 
         $chooser = function ($ctl_items)
         {
@@ -355,7 +370,7 @@ class chctl
         return [$feeds,$profits];
     }
 
-    public function auto_match($names, int $spec, int $card_type, int $quality, $out_price, $left_time) : array
+    public function auto_match($names, int $spec, int $card_type, int $quality, $out_price, $max_inprice, $left_time): array
     {
         $formater = function ($val) {
             return number_format($val,10,'.','');
@@ -462,16 +477,23 @@ class chctl
 
 
         $pThis = $this;
-        $speed_locker = function ($names,$spec,$card_type,$quality) use($pThis)
+        $price_filter = function ($names,$spec,$card_type,$quality) use($pThis,$max_inprice)
         {
             $ctls = [];
             foreach ($names as $name)
             {
                 $key = $pThis->prefix($name,$spec,$card_type,$quality);
-                if(array_key_exists($key,$pThis->mSpeedtable)) {
+                if(array_key_exists($key,$pThis->mSpeedtable))
+                {
                     $item = $pThis->mSpeedtable[$key];
                     $item->calc_speed();
-                    $ctls[] = $item;
+
+                    $inPrice = $item->price();
+                    if ($max_inprice !== false && $inPrice > $max_inprice) {
+                        continue;
+                    } else {
+                        $ctls[] = $item;
+                    }
                 }
                 else {
                     Log::record("auto_match speed table key={$key} is empty.",Log::DEBUG);
@@ -492,7 +514,7 @@ class chctl
         Log::record("auto_match outprice= {$out_price} names=" . implode(',', $names), Log::DEBUG);
 
         $can_feed = true;
-        $ctls = $speed_locker($names,$spec,$card_type,$quality);
+        $ctls = $price_filter($names,$spec,$card_type,$quality);
         [$sleeps,$wakeups] = $this->knockout($ctls,$out_price);
 
         $logger($sleeps,'sleeps');

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

@@ -44,17 +44,22 @@ class merchant_price
                 $extra_price = ncPriceFormat($item['extra_price']);
                 $max_inprice = ncPriceFormat($item['max_inprice']);
 
-                $max_inprice = $max_inprice <= 0.00001 ? $price : $max_inprice;
+                //false 表示不曾设置价格限制
+                $max_inprice = $max_inprice <= 0.00001 ? false : $max_inprice;
 
                 $spec = intval($item['spec']);
                 $quality = intval($item['quality']);
 
                 $types = explode(',',$card_types);
-                foreach ($types as $card_type) {
+                foreach ($types as $card_type)
+                {
                     $key = "{$mchid}-{$quality}-{$card_type}-{$spec}";
+
                     $this->mPrices[$key] = $price;
                     $this->mExtraPrices[$key] = $extra_price;
-                    $this->mMaxInPrices[$key] = $max_inprice;
+                    if ($max_inprice !== false) {
+                        $this->mMaxInPrices[$key] = $max_inprice;
+                    }
                 }
             }
         }

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

@@ -284,19 +284,22 @@ class policy extends ProviderManager implements IPolicy
         Log::record("GroupControl second result=" . implode(',',$names),Log::DEBUG);
 
         if(PolicyUtil::mixed_quality($org_quality)) {
-            $fQuality = $org_quality;
+            $mixedQuality = $org_quality;
         }
         else {
-            $fQuality = $cur_quality;
+            $mixedQuality = $cur_quality;
         }
 
-        $price = $this->mPrices->price($mchid,$card_type,$spec,$fQuality,$pcode);
+        $price = $this->mPrices->price($mchid,$card_type,$spec,$mixedQuality,$pcode);
         if($price === false) {
             return [[],false];
         }
-        $extra_price = $this->mPrices->extra_price($mchid,$card_type,$spec,$fQuality,$pcode);
+
+        $extra_price = $this->mPrices->extra_price($mchid,$card_type,$spec,$mixedQuality,$pcode);
         $extra_price = $extra_price == false ? 0.00 : $extra_price;
 
+        //以当前通道质量为准
+        $max_inprice = $this->mPrices->max_inprice($mchid,$card_type,$spec,$cur_quality,$pcode);
 
         global $config;
         $auto_find = $config['auto_find_channels'];
@@ -304,10 +307,10 @@ class policy extends ProviderManager implements IPolicy
         $mobile_types = [mtopcard\ChinaMobileCard, mtopcard\ChinaUnicomCard, mtopcard\ChinaTelecomCard];
         $qualities = [Quality::Normal];
         if ($auto_find && in_array($card_type, $mobile_types, true) && in_array($cur_quality, $qualities, true)) {
-            $names = $this->mChannelControl->auto_match($names, $spec, $card_type, $cur_quality, $price - $extra_price, time() - $order_time);
+            $names = $this->mChannelControl->auto_match($names, $spec, $card_type, $cur_quality, $price - $extra_price, $max_inprice, time() - $order_time);
             Log::record("policy::find_providers ChannelControl auto_match quality={$cur_quality} spec={$spec} card_type={$card_type} result=" . implode(',', $names), Log::DEBUG);
         } else {
-            $names = $this->mChannelControl->match($names, $spec, $card_type, $cur_quality);
+            $names = $this->mChannelControl->match($names, $spec, $card_type, $cur_quality, $max_inprice);
             Log::record("policy::find_providers ChannelControl match quality={$cur_quality} spec={$spec} card_type={$card_type} result=" . implode(',', $names), Log::DEBUG);
         }
 
@@ -393,12 +396,13 @@ class policy extends ProviderManager implements IPolicy
                 Log::record("{$mchid} 没有协商 quality = {$quality} 价格",Log::DEBUG);
                 continue;
             }
+            $max_inprice = $this->mPrices->max_inprice($mchid,$card_type,$spec,$cur_quality,$pcode);
 
             $providers = parent::get_providers($mchid, $spec, $card_type, $quality, $regin_no);
             if(empty($providers)) continue;
 
             $names = $namer($providers);
-            $names = $this->mChannelControl->match($names, $spec, $card_type, $quality);
+            $names = $this->mChannelControl->match($names, $spec, $card_type, $quality, $max_inprice);
             if (!empty($names)) {
                 return [$org_quality, $quality];
             } else {