stanley-king пре 3 година
родитељ
комит
068ccc095a

+ 5 - 0
helper/calc_helper.php

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

+ 1 - 0
helper/icalc.php

@@ -5,4 +5,5 @@ 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);
 }

+ 16 - 4
helper/refill/CalcMerchantPrice.php

@@ -13,6 +13,7 @@ use Log;
 class CalcMerchantPrice implements ICalc
 {
     private $mPrice;
+    private $mMaxInPrice;
 
     public function __construct($mchid,$spec,$card_type,$quality,$policy,$other = [])
     {
@@ -24,11 +25,12 @@ class CalcMerchantPrice implements ICalc
         }
 
         $price = $policy->price($mchid,$spec,$card_type,$quality,$pcode);
-        if($price === false) {
+        $max_inprice = $policy->max_inprice($mchid,$spec,$card_type,$quality,$pcode);
+        if ($price === false || $max_inprice === false) {
             throw new Exception("没有协商商品购买价格.");
-        }
-        else {
+        } else {
             $this->mPrice = $price;
+            $this->mMaxInPrice = $max_inprice;
         }
     }
 
@@ -36,6 +38,12 @@ 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'];
@@ -59,11 +67,15 @@ class ZeroMerchantPrice implements ICalc
     {
         return round(0,4);
     }
+
     public function calc_vorder_amount($order_info)
     {
         return round(0,4);
     }
-
+    public function max_inprice($order_info)
+    {
+        return round(0,4);
+    }
     public function calc_tips()
     {
         Log::record("没有实现该接口" . __FUNCTION__ ,Log::ERR);

+ 6 - 0
helper/refill/RefillBase.php

@@ -282,6 +282,8 @@ 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) {
@@ -308,6 +310,10 @@ 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);

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

@@ -12,6 +12,8 @@ interface IPolicy
     public function allow($mchid, $card_type, $amount, $quality): bool;
     public function notify($order_info, $refill_info): bool;
     public function price($mchid, $spec, $card_type, $quality, $pcode);
+    public function max_inprice($mchid, $spec, $card_type, $quality, $pcode);
+
     public function update_ratios($ratios);
     public function update_mchratios($all,$detail);
     public function update_chspeeds($speeds);

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

@@ -295,6 +295,11 @@ class policy extends ProviderManager implements IPolicy
         return $this->mPrices->price($mchid,$card_type,$spec,$quality,$pcode);
     }
 
+    public function max_inprice($mchid, $spec, $card_type, $quality, $pcode)
+    {
+        return $this->mPrices->max_inprice($mchid,$card_type,$spec,$quality,$pcode);
+    }
+
     public function channeles(int $mchid, int $spec, int $card_type, int $quality, $regin_no)
     {
         $providers = parent::get_providers($mchid, $spec, $card_type, $quality, $regin_no);

+ 25 - 2
helper/refill/policy/merchant_price.php

@@ -8,11 +8,13 @@ class merchant_price
 {
     private $mPrices;
     private $mExtraPrices;
+    private $mMaxInPrices;
 
     public function __construct()
     {
         $this->mPrices = [];
         $this->mExtraPrices = [];
+        $this->mMaxInPrices = [];
     }
 
     public function load($mchids)
@@ -40,6 +42,9 @@ class merchant_price
                 $card_types = $item['card_types'];
                 $price = ncPriceFormat($item['price']);
                 $extra_price = ncPriceFormat($item['extra_price']);
+                $max_inprice = ncPriceFormat($item['max_inprice']);
+
+                $max_inprice = $max_inprice <= 0.00001 ? $price : $max_inprice;
 
                 $spec = intval($item['spec']);
                 $quality = intval($item['quality']);
@@ -49,6 +54,7 @@ class merchant_price
                     $key = "{$mchid}-{$quality}-{$card_type}-{$spec}";
                     $this->mPrices[$key] = $price;
                     $this->mExtraPrices[$key] = $extra_price;
+                    $this->mMaxInPrices[$key] = $max_inprice;
                 }
             }
         }
@@ -57,7 +63,7 @@ class merchant_price
     public function price($mchid,$card_type,$spec,$quality,$pcode)
     {
         $card_type = intval($card_type);
-        if(in_array($card_type,[1,2,4,5,6])) //油,话费价格查找.
+        if (in_array($card_type, [1, 2, 4, 5, 6], true)) //油,话费价格查找.
         {
             $key = "{$mchid}-{$quality}-{$card_type}-{$spec}";
             if (array_key_exists($key, $this->mPrices)) {
@@ -92,7 +98,7 @@ class merchant_price
     public function extra_price($mchid,$card_type,$spec,$quality,$pcode)
     {
         $card_type = intval($card_type);
-        if(in_array($card_type,[1,2,4,5,6])) //油,话费价格查找.
+        if (in_array($card_type, [1, 2, 4, 5, 6], true)) //油,话费价格查找.
         {
             $key = "{$mchid}-{$quality}-{$card_type}-{$spec}";
             if (array_key_exists($key, $this->mExtraPrices)) {
@@ -105,4 +111,21 @@ class merchant_price
             return false;
         }
     }
+
+    public function max_inprice($mchid,$card_type,$spec,$quality,$pcode)
+    {
+        $card_type = intval($card_type);
+        if (in_array($card_type, [1, 2, 4, 5, 6], true)) //油,话费价格查找.
+        {
+            $key = "{$mchid}-{$quality}-{$card_type}-{$spec}";
+            if (array_key_exists($key, $this->mMaxInPrices)) {
+                return $this->mMaxInPrices[$key];
+            } else {
+                return false;
+            }
+        }
+        else {
+            return false;
+        }
+    }
 }

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

@@ -297,12 +297,13 @@ class policy extends ProviderManager implements IPolicy
         $extra_price = $this->mPrices->extra_price($mchid,$card_type,$spec,$fQuality,$pcode);
         $extra_price = $extra_price == false ? 0.00 : $extra_price;
 
+
         global $config;
         $auto_find = $config['auto_find_channels'];
 
         $mobile_types = [mtopcard\ChinaMobileCard, mtopcard\ChinaUnicomCard, mtopcard\ChinaTelecomCard];
         $qualities = [Quality::Normal];
-        if ($auto_find && in_array($card_type, $mobile_types) && in_array($cur_quality, $qualities)) {
+        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);
             Log::record("policy::find_providers ChannelControl auto_match quality={$cur_quality} spec={$spec} card_type={$card_type} result=" . implode(',', $names), Log::DEBUG);
         } else {
@@ -332,6 +333,11 @@ class policy extends ProviderManager implements IPolicy
         return $this->mPrices->price($mchid,$card_type,$spec,$quality,$pcode);
     }
 
+    public function max_inprice($mchid, $spec, $card_type, $quality, $pcode)
+    {
+        return $this->mPrices->max_inprice($mchid,$card_type,$spec,$quality,$pcode);
+    }
+
     public function channeles(int $mchid, int $spec, int $card_type, int $quality, $regin_no)
     {
         $providers = parent::get_providers($mchid, $spec, $card_type, $quality, $regin_no);