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

+ 25 - 3
data/config/dev/refill.ini.php

@@ -1490,9 +1490,31 @@ $config['auto_find_channels'] = true;
 $config['cancel_retry_time'] = [10120 => ["9:00",'10:00','11:00']];
 $config['merchant_retry_times'] = [
     1092 => [
-        'qualities' => [1 => ['secs' => 300, 'times' => 5], 2 => ['secs' => 300, 'times' => 200]],
-        'lower_ratio' => ['ratio' => 0.9,'period' => 3600]
-    ]    
+        'qualities' => [1 => ['secs' => 420, 'times' => 100], 2 => ['secs' => 180, 'times' => 100]],
+        'lower_ratio' => ['ratio' => 0.9, 'period' => 3600], 'profit_ratio' => 0.005
+    ],
+//    10213 => [ //邀友-普充10分 ,昵称 二号
+//        'qualities' => [1 => ['secs' => 1100, 'times' => 100], 2 => ['secs' => 100, 'times' => 5]],
+//        'lower_ratio' => ['ratio' => 0.9,'period' => 3600]
+//    ],
+    10211 => [ //飘逸-混充20分
+        'qualities' => [1 => ['secs' => 1100, 'times' => 100], 2 => ['secs' => 100, 'times' => 5]],
+        'lower_ratio' => ['ratio' => 0.9, 'period' => 3600]
+    ],
+    10216 => [ //飘逸-10分
+        'qualities' => [1 => ['secs' => 530, 'times' => 100], 2 => ['secs' => 70, 'times' => 5]],
+        'lower_ratio' => ['ratio' => 0.4, 'period' => 3600], 'profit_ratio' => 0.005
+    ],
+    10217 => [ //天采-混充10m
+        'qualities' => [1 => ['secs' => 1100, 'times' => 100], 2 => ['secs' => 100, 'times' => 5]],
+        'lower_ratio' => ['ratio' => 0.9, 'period' => 3600]
+    ]
+];
+
+//// "status": 1 //状态 0:空号;1:实号;2:停机;3:库无;4:沉默号;5:风险号
+$config['merchant_intercept'] = [
+    1092 => ['card_states' => [2,4],'is_transfer' => false],
+    10213 => ['card_states' => [],'is_transfer' => true]
 ];
 
 //// "status": 1 //状态 0:空号;1:实号;2:停机;3:库无;4:沉默号;5:风险号

+ 1 - 1
data/config/xyz/refill.ini.php

@@ -2777,7 +2777,7 @@ $config['cancel_retry_time'] = [10120 => ["9:00",'10:00','11:00']];
 $config['merchant_retry_times'] = [
     1092 => [
         'qualities' => [1 => ['secs' => 420, 'times' => 100], 2 => ['secs' => 180, 'times' => 100]],
-        'lower_ratio' => ['ratio' => 0.9,'period' => 3600]
+        'lower_ratio' => ['ratio' => 0.9,'period' => 3600], 'profit' => 0.005
     ],
 //    10213 => [ //邀友-普充10分 ,昵称 二号
 //        'qualities' => [1 => ['secs' => 1100, 'times' => 100], 2 => ['secs' => 100, 'times' => 5]],

+ 2 - 2
helper/refill/RefillBase.php

@@ -738,8 +738,8 @@ class RefillBase
     {
         $this->mPolicy->update_ratios($ratios);
     }
-    public function UpdatMchRatios($ratios)
+    public function UpdatMchRatios($gross,$detail)
     {
-        $this->mPolicy->update_mchratios($ratios);
+        $this->mPolicy->update_mchratios($gross,$detail);
     }
 }

+ 1 - 1
helper/refill/policy/IPolicy.php

@@ -13,5 +13,5 @@ interface IPolicy
     public function notify($order_info, $refill_info): bool;
     public function price($mchid, $spec, $card_type, $quality, $pcode);
     public function update_ratios($ratios);
-    public function update_mchratios($ratios);
+    public function update_mchratios($all,$detail);
 }

+ 13 - 2
helper/refill/policy/PolicyUtil.php

@@ -4,9 +4,10 @@ namespace refill;
 
 class PolicyUtil
 {
+    private const MixedQuality = [Quality::DefSuccess, Quality::NormalQuick];
     public static function mixed_quality($quality) : bool
     {
-        if($quality == Quality::DefSuccess || $quality == Quality::NormalQuick) {
+        if(in_array($quality,PolicyUtil::MixedQuality)) {
             return true;
         } else {
             return false;
@@ -15,7 +16,17 @@ class PolicyUtil
 
     public static function mixed_qualities()
     {
-        $mixed = [Quality::DefSuccess, Quality::NormalQuick];
+        return PolicyUtil::MixedQuality;
+    }
+
+    public static function mixed_ratio()
+    {
+        $mixed = [Quality::DefSuccess];
         return $mixed;
     }
+
+    public static function isMixedQuality($org_quality)
+    {
+        return in_array($org_quality,[Quality::NormalQuick]);
+    }
 }

+ 2 - 2
helper/refill/policy/lingzh/policy.php

@@ -437,8 +437,8 @@ class policy extends ProviderManager implements IPolicy
         $this->mChannelControl->update_ratios($ratios);
     }
 
-    public function update_mchratios($ratios)
+    public function update_mchratios($all,$detail)
     {
-        $this->mQuality->update_mchratios($ratios);
+        $this->mQuality->update_mchratios($all,$detail);
     }
 }

+ 3 - 3
helper/refill/policy/mchctl.php

@@ -62,14 +62,14 @@ class mchctl
         }
     }
 
-    public function mechants_quality($mixed_quality)
+    public function mechants_quality()
     {
         $result = [];
         foreach ($this->mMchidMapCtls as $mchid => $item)
         {
             $quality = intval($item['quality']);
-            if($quality == $mixed_quality) {
-                $result[] = $mchid;
+            if(PolicyUtil::mixed_quality($quality)) {
+                $result[$mchid] = $quality;
             }
         }
         return $result;

+ 121 - 35
helper/refill/policy/mratio_control.php

@@ -1,18 +1,21 @@
 <?php
 
 namespace refill;
+
 use Log;
 
 class mratio_control
 {
     private $mTimesConfig; //对应refill.ini 配置文件数据
-    private $mCurRatios;
+    private $mGrossRatios;
+    private $mDetailRatios;
     private $mMixedPrices;
 
     public function __construct()
     {
         $this->mTimesConfig = [];
-        $this->mCurRatios = [];
+        $this->mGrossRatios = [];
+        $this->mDetailRatios = [];
         $this->mMixedPrices = [];
     }
 
@@ -22,18 +25,45 @@ class mratio_control
         $this->mTimesConfig = $config['merchant_retry_times'] ?? [];
     }
 
-    public function setMixedPrice($mchid,$mixed_quality,$card_type,$spec,$out_price,$qprices)
+    public function update($gross_ratios, $detail_ratios)
+    {
+        if (!empty($gross_ratios)) {
+            $this->mGrossRatios = $gross_ratios;
+        }
+        if (!empty($detail_ratios)) {
+            $this->mDetailRatios = $detail_ratios;
+        }
+    }
+
+    public function setMixedPrice($mchid, $mixed_quality, $card_type, $spec, $prices)
     {
         $key = "{$card_type}-{$spec}";
-        $this->mMixedPrices[$mchid][$mixed_quality][$key]['out_price'] = $out_price;
-        $this->mMixedPrices[$mchid][$mixed_quality][$key]['qprices'] = $qprices;
+        $this->mMixedPrices[$mchid][$mixed_quality][$key] = $prices;
     }
 
+    //获取售价和进价
+    private function getPrice($mchid, $mixed_quality, $card_type, $spec)
+    {
+        $key = "{$card_type}-{$spec}";
+        if (array_key_exists($mchid, $this->mMixedPrices))
+        {
+            $prices = $this->mMixedPrices[$mchid];
+            if (array_key_exists($mixed_quality, $prices))
+            {
+                $qprices = $prices[$mixed_quality];
+                if (array_key_exists($key, $qprices)) {
+                    $price = $qprices[$key];
+                    return $price;
+                }
+            }
+        }
+
+        return false;
+    }
 
     public function total($mchid)
     {
-        if(array_key_exists($mchid,$this->mTimesConfig))
-        {
+        if (array_key_exists($mchid, $this->mTimesConfig)) {
             $items = $this->mTimesConfig[$mchid]['qualities'];
 
             $times = 0;
@@ -42,18 +72,17 @@ class mratio_control
                 $times += $val['times'] ?? 1;
                 $secs += $val['secs'] ?? 180;
             }
-            return [true,$times,$secs];
+            return [true, $times, $secs];
         } else {
-            return [false,0,0];
+            return [false, 0, 0];
         }
     }
 
-    public function times($mchid,$quality)
+    public function times($mchid, $quality)
     {
-        if(array_key_exists($mchid,$this->mTimesConfig))
-        {
+        if (array_key_exists($mchid, $this->mTimesConfig)) {
             $items = $this->mTimesConfig[$mchid]['qualities'] ?? [];
-            if(array_key_exists($quality,$items)) {
+            if (array_key_exists($quality, $items)) {
                 return $items[$quality]['times'];
             }
         }
@@ -61,12 +90,11 @@ class mratio_control
         return false;
     }
 
-    public function seconds($mchid,$quality)
+    public function seconds($mchid, $quality)
     {
-        if(array_key_exists($mchid,$this->mTimesConfig))
-        {
+        if (array_key_exists($mchid, $this->mTimesConfig)) {
             $items = $this->mTimesConfig[$mchid]['qualities'] ?? [];
-            if(array_key_exists($quality,$items)) {
+            if (array_key_exists($quality, $items)) {
                 return $items[$quality]['secs'];
             }
         }
@@ -83,38 +111,96 @@ class mratio_control
         }
     }
 
-    public function update($ratios)
-    {
-        if(!empty($ratios)) {
-            $this->mCurRatios = $ratios;
-        }
-    }
-
     private function lower_ratio($mchid)
     {
         $lower_ratio = $this->mTimesConfig[$mchid]['lower_ratio'] ?? [];
-        return [$lower_ratio['ratio'],$lower_ratio['period']];
+        return [$lower_ratio['ratio'], $lower_ratio['period']];
     }
 
-    private function cur_ratio($mchid,$period)
+    private function profit_ratio($mchid) {
+        $profit_ratio = $this->mTimesConfig[$mchid]['profit_ratio'] ?? 0.0;
+        return $profit_ratio;
+    }
+
+    private function gross_ratio($mchid, $period)
     {
-        $mratios = $this->mCurRatios;
-        if(array_key_exists($mchid,$mratios)) {
+        $mratios = $this->mGrossRatios;
+        if (array_key_exists($mchid, $mratios)) {
             $mratios = $mratios[$mchid];
-            if(array_key_exists($period,$mratios)) {
+            if (array_key_exists($period, $mratios)) {
                 return $mratios[$period];
             }
         }
 
-        return 1.0;
+        return [0, 0, 1.0];
+    }
+    private function detail_ratio($mchid, $quality, $card_type, $spec, $period)
+    {
+        $key = "{$mchid}-{$quality}-{$card_type}-{$spec}";
+        if(array_key_exists($key,$this->mDetailRatios)) {
+            $ratios = $this->mDetailRatios[$key];
+            if(array_key_exists($period,$ratios)) {
+                return $ratios[$period];
+            }
+        }
+        return [0, 0, 1.0];
+    }
+
+    private function detail_ratios($mchid,$qualities,$card_type, $spec,$period)
+    {
+        $result = [];
+        foreach ($qualities as $quality) {
+            $ret = $this->detail_ratio($mchid,$quality,$card_type,$spec,$period);
+            $result[$quality] = $ret;
+        }
+
+        return $result;
     }
 
-    public function ratio_match($mchid)
+    public function ratio_match($mchid, $org_quality, $cur_quality, $card_type, $spec,$qualities)
     {
-        [$ratio,$period] = $this->lower_ratio($mchid);
-        $cur_ratio = $this->cur_ratio($mchid,$period);
-        Log::record("ratio_match mchid={$mchid} cur_ratio={$cur_ratio}",Log::DEBUG);
+        [$ratio, $period] = $this->lower_ratio($mchid);
+        [$_succ, $_fail, $gross_ratio] = $this->gross_ratio($mchid, $period);
+
+        if($gross_ratio >= $ratio) return true;
+        [$_succ, $_fail, $cur_ratio] = $this->detail_ratio($mchid, $cur_quality, $card_type, $spec, $period);
+        if($cur_ratio >= $ratio) return true;
+
+        if (!PolicyUtil::mixed_quality($org_quality)) {
+            return false;
+        }
+
+        $prices = $this->getPrice($mchid, $org_quality, $card_type, $spec);
+        if ($prices === false) {
+            return false;
+        }
+
+        $dratios = $this->detail_ratios($mchid, $qualities,$card_type, $spec, $period);
+        $profit_ratio = $this->profit_ratio($mchid);
+
+        $judger = function ($org_quality,$qualities,$prices,$dratios,$profit_ratio)
+        {
+            $sale = $prices[$org_quality];
+
+            $profit = 0;
+            $amount = 0;
+            foreach ($qualities as $quality)
+            {
+                $inprice = $prices[$quality] ?? false;
+                if($inprice === false) continue;
+
+                [$succ,$fail,$ratio] = $dratios[$quality];
+                $profit += $succ * ($sale - $inprice);
+                $amount += $succ * $inprice;
+            }
+
+            $cur_pratio = round(($profit + 0.00001) / ($amount + 0.00001),4);
+            $profit_ratio = round($profit_ratio,4);
+
+            return $cur_pratio > $profit_ratio;
+        };
 
-        return $cur_ratio >= $ratio;
+        $fMatch = $judger($org_quality,$qualities,$prices,$dratios,$profit_ratio);
+        return $fMatch;
     }
 }

+ 13 - 20
helper/refill/policy/quaility.php

@@ -43,6 +43,7 @@ class Quality
     protected $mSpeeds;
     protected $mQualities;
     protected $mTryAdjuster;
+
     protected $mRatioCtl;
 
     public function __construct()
@@ -50,7 +51,7 @@ class Quality
         $this->mMchPhonectl = new mchctl();
         $this->mMchoilctl = new mchoilctl();
         $this->mTryAdjuster = new try_judge();
-        $this->mRatioCtl = new mratio_control();
+        $this->mRatioCtl = null;
     }
 
     public function load()
@@ -73,8 +74,8 @@ class Quality
         }
     }
 
-    public function mechants_quality($mixed_quality) {
-        return $this->mMchPhonectl->mechants_quality($mixed_quality);
+    public function mechants_quality() {
+        return $this->mMchPhonectl->mechants_quality();
     }
 
     public function find_quality($mchid, $card_type, $spec, $org_quality, $cur_quality, $times, $used_time, $caller): array
@@ -161,21 +162,17 @@ class Quality
             {
                 if(array_key_exists($setting_quality,$this->mQualities)) {
                     $org_quality = $setting_quality;
-                    $qualities = $this->mQualities[$setting_quality];
                 }
                 else {
                     $org_quality = $setting_quality;
-                    $qualities = [$setting_quality];
                 }
             }
             else {
                 $org_quality = self::Normal; //如果没设置质量,默认为普通
-                $qualities = $this->mQualities[$org_quality];
                 $time_out = $this->mSpeeds[$org_quality]['retry_timeout'];
             }
         }
         elseif(array_key_exists($org_quality,$this->mQualities)) {
-            $qualities = $this->mQualities[$org_quality];
             [$success, $setting_quality, $time_out] = $this->mMchPhonectl->getCtls($mchid);
         }
         else {
@@ -187,20 +184,19 @@ class Quality
             $time_out = $this->mSpeeds[$org_quality]['retry_timeout'];
         }
 
+        $qualities = $this->qualities($org_quality);
         $max_times = $this->max_times($mchid,$org_quality);
-        if($this->mRatioCtl->exist($mchid))
-        {
-            $qualities = $this->ratio_phone_quality($qualities, $cur_quality, $times, $used_time, $mchid, $card_type, $spec);
-            return [$org_quality,$qualities];
-        }
-        else {
+        if ($this->mRatioCtl->exist($mchid)) {
+            $qualities = $this->ratio_phone_quality($org_quality, $qualities, $cur_quality, $times, $used_time, $mchid, $card_type, $spec);
+            return [$org_quality, $qualities];
+        } else {
             $fMixed = PolicyUtil::mixed_quality($org_quality);
-            $qualities = $this->calc_phone_quality($qualities,$fMixed,$cur_quality,$times,$used_time,$time_out,$max_times,$mchid);
-            return [$org_quality,$qualities];
+            $qualities = $this->calc_phone_quality($qualities, $fMixed, $cur_quality, $times, $used_time, $time_out, $max_times, $mchid);
+            return [$org_quality, $qualities];
         }
     }
 
-    private function ratio_phone_quality($qualities, $cur_quality, $times, $used_time, $mchid, $card_type, $spec)
+    private function ratio_phone_quality($org_quality,$qualities, $cur_quality, $times, $used_time, $mchid, $card_type, $spec)
     {
         [$succ,$max_times,$time_out] = $this->mRatioCtl->total($mchid);
 
@@ -209,7 +205,7 @@ class Quality
             return [];
         }
 
-        $match_ratio = $this->mRatioCtl->ratio_match($mchid);
+        $match_ratio = $this->mRatioCtl->ratio_match($mchid, $org_quality, $cur_quality, $card_type, $spec, $qualities);
 
         Log::record("ratio_phone_quality begin qualities= " . implode(',',$qualities),Log::DEBUG);
         $times_checker = function ($qualities, $times) use ($match_ratio, $cur_quality, $max_times, $mchid)
@@ -433,7 +429,4 @@ class Quality
 
         return $qualities;
     }
-    public function update_mchratios($ratios) {
-        $this->mRatioCtl->update($ratios);
-    }
 }

+ 15 - 14
helper/refill/policy/xyz/policy.php

@@ -16,7 +16,6 @@ class policy extends ProviderManager implements IPolicy
     protected $mAmountLockTurn;
     protected $mStorageLocker;
     protected $mGroupCtl;
-    protected $mAvgPrice;
     protected $mRatioCtl;
 
     public function __construct()
@@ -27,9 +26,8 @@ class policy extends ProviderManager implements IPolicy
         $this->mPrices = new merchant_price();
         $this->mStorageLocker = new rstorage();
         $this->mGroupCtl = new rgroup_ctl();
-        $this->mAvgPrice = new mavg_price();
-        $this->mRatioCtl = new mratio_control();
 
+        $this->mRatioCtl = new mratio_control();
         $this->mQuality->setRatioCtl($this->mRatioCtl);
     }
 
@@ -93,16 +91,14 @@ class policy extends ProviderManager implements IPolicy
         };
 
         $pQuality = $this->mQuality;
-        $mixed_quality = Quality::NormalQuick;
-        $mchids = $pQuality->mechants_quality($mixed_quality);
-        foreach ($mchids as $mchid)
+        $mchids = $pQuality->mechants_quality();
+        foreach ($mchids as $mchid => $mixed_quality)
         {
             $qualities = $pQuality->qualities($mixed_quality);
             $specs = [];
-            foreach ($qualities as $quality)
-            {
+            foreach ($qualities as $quality) {
                 $item = $this->mPrices->merchant_specs($mchid, $quality);
-                if(empty($item)) continue;
+                if (empty($item)) continue;
                 $specs[$quality] = $item;
             }
 
@@ -112,11 +108,16 @@ class policy extends ProviderManager implements IPolicy
                 [$card_type, $spec] = $item;
                 if (!in_array($card_type, [4, 5, 6])) continue;
 
+                $prices = [];
                 $sale_price = $this->mPrices->price($mchid,$card_type,$spec,$mixed_quality,'');
-                $low_price  = $this->calc_avgprice($mchid, $qualities[0], $card_type, $spec);
-                $high_price = $this->calc_avgprice($mchid, $qualities[1], $card_type, $spec);
+                $prices[$mixed_quality] = round($sale_price,4);
+
+                foreach ($qualities as $quality) {
+                    $inprice  = $this->calc_avgprice($mchid, $quality, $card_type, $spec);
+                    $prices[$quality] = round($inprice,4);
+                }
 
-                $this->mRatioCtl->setMixedPrice($mchid, $mixed_quality, $card_type, $spec, $sale_price, [$qualities[0] => $low_price, $qualities[1] => $high_price]);
+                $this->mRatioCtl->setMixedPrice($mchid, $mixed_quality, $card_type, $spec, $prices);
             }
         }
     }
@@ -535,8 +536,8 @@ class policy extends ProviderManager implements IPolicy
         $this->mChannelControl->update_ratios($ratios);
     }
 
-    public function update_mchratios($ratios)
+    public function update_mchratios($gross,$detail)
     {
-        $this->mQuality->update_mchratios($ratios);
+        $this->mRatioCtl->update($gross,$detail);
     }
 }

+ 3 - 4
plot/MchDataCenter.py

@@ -643,16 +643,15 @@ class MchDataCenter(object):
                 all_paths = self.paths(time_stamp)
                 mchid_paths = self.merchant_rmobile_path(all_paths)
 
-                all = {}
+                gross = {}
                 for mchid, paths in mchid_paths.items():
                     counts = self.mch_count(paths, presecs, time_stamp)
-                    all[mchid] = counts
+                    gross[mchid] = counts
 
                 paths = self.rmobile_path(all_paths)
                 detail = self.mch_detail_count(paths, presecs, time_stamp)
 
-                result = {'all': all, 'detail': detail}
-
+                result = {'gross': gross, 'detail': detail}
                 if len(result) != 0:
                     r.set(f"nc_merchant_refill_counts", json.dumps(result))
                     r.publish('refill',json.dumps({'type':'mch_counts','value':0}))

+ 8 - 5
rdispatcher/codispatcher.php

@@ -91,15 +91,18 @@ function subscribe_message(&$quit, &$redis, $channels)
 
                         refill\RefillFactory::instance()->UpdateRatio($ratios);
                     }
-                    elseif($type == 'mch_ratio') {
+                    elseif($type == 'mch_counts') {
                         $ins = Cache::getInstance('cacheredis');
-                        $val = $ins->get_org('merchant_ratios');
+                        $val = $ins->get_org('merchant_refill_counts');
 
                         if(empty($val)) continue;
-                        $mch_ratios = json_decode($val,true);
-                        if(empty($mch_ratios)) continue;
+                        $counts = json_decode($content,true);
+                        if(empty($counts)) continue;
 
-                        refill\RefillFactory::instance()->UpdatMchRatios($mch_ratios);
+                        $gross = $counts['gross'];
+                        $detail = $counts['detail'];
+
+                        refill\RefillFactory::instance()->UpdatMchRatios($gross,$detail);
                     }
                     else {
                         Log::record("subscribe_message dont not handle mgs:{$sub_type}-{$channel}-{$type}",Log::DEBUG);

Разлика између датотеке није приказан због своје велике величине
+ 5 - 1
test/TestBigData.php