|
@@ -6,12 +6,11 @@ use Log;
|
|
|
|
|
|
class mratio_controlex
|
|
|
{
|
|
|
- const delta = 0.0000001;
|
|
|
-
|
|
|
private $mTimesConfig; //对应refill.ini 配置文件数据
|
|
|
private $mInterceptConfig;
|
|
|
|
|
|
private $mGrossRatios;
|
|
|
+ private $mTypeRatios;
|
|
|
private $mDetailRatios;
|
|
|
|
|
|
private $mMchQTS;
|
|
@@ -24,6 +23,7 @@ class mratio_controlex
|
|
|
$this->mInterceptConfig = [];
|
|
|
|
|
|
$this->mGrossRatios = [];
|
|
|
+ $this->mTypeRatios = [];
|
|
|
$this->mDetailRatios = [];
|
|
|
|
|
|
$this->mMixedPrices = [];
|
|
@@ -131,11 +131,14 @@ class mratio_controlex
|
|
|
$this->mInterceptConfig = $mch_configs();
|
|
|
}
|
|
|
|
|
|
- public function update($gross_ratios, $detail_ratios)
|
|
|
+ public function update($gross_ratios, $detail_ratios,$type_ratios)
|
|
|
{
|
|
|
if (!empty($gross_ratios)) {
|
|
|
$this->mGrossRatios = $gross_ratios;
|
|
|
}
|
|
|
+ if (!empty($type_ratios)) {
|
|
|
+ $this->mTypeRatios = $type_ratios;
|
|
|
+ }
|
|
|
if (!empty($detail_ratios)) {
|
|
|
$this->mDetailRatios = $detail_ratios;
|
|
|
}
|
|
@@ -215,11 +218,11 @@ class mratio_controlex
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private function profit_formula($mchid) {
|
|
|
+ public function profit_formula($mchid) {
|
|
|
return $this->mTimesConfig[$mchid]['profit_formula'] ?? 'qts';
|
|
|
}
|
|
|
|
|
|
- private function lowest_ratio($mchid)
|
|
|
+ public function lowest_ratio($mchid)
|
|
|
{
|
|
|
$lower_ratio = $this->mTimesConfig[$mchid]['lower_ratio'] ?? [];
|
|
|
if (empty($lower_ratio)) {
|
|
@@ -229,215 +232,50 @@ class mratio_controlex
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private function profit_ratio($mchid)
|
|
|
+ public function profit_ratio($mchid)
|
|
|
{
|
|
|
$profit_ratio = $this->mTimesConfig[$mchid]['profit_ratio'] ?? 0.0;
|
|
|
return $profit_ratio;
|
|
|
}
|
|
|
|
|
|
- //[submit_count, $succ_count, $fail_count, $succ_ratio, $profit, $profit_ratio]
|
|
|
- private function gross_ratio($mchid)
|
|
|
+ public function type_specs($mchid)
|
|
|
{
|
|
|
- $mratios = $this->mGrossRatios;
|
|
|
- if (array_key_exists($mchid, $mratios)) {
|
|
|
- return $mratios[$mchid];
|
|
|
+ if(array_key_exists($mchid,$this->mMchQTS)) {
|
|
|
+ return $this->mMchQTS[$mchid];
|
|
|
}
|
|
|
-
|
|
|
- return [0, 0, 0, 0, 0, 0];
|
|
|
- }
|
|
|
-
|
|
|
- //[submit_count, $succ_count, $fail_count, $succ_ratio, $profit, $profit_ratio]
|
|
|
- private function detail_ratio($mchid, $card_type, $spec)
|
|
|
- {
|
|
|
- $key = "{$mchid}-{$card_type}-{$spec}";
|
|
|
- if (array_key_exists($key, $this->mDetailRatios)) {
|
|
|
- return $this->mDetailRatios[$key];
|
|
|
+ else {
|
|
|
+ return [];
|
|
|
}
|
|
|
-
|
|
|
- return [0, 0, 0, 0, 0, 0];
|
|
|
}
|
|
|
|
|
|
//match: true 表示当前质量满足条件,可以不走溢价,false,表示可以走溢价
|
|
|
//can_last: true,能补充,false 表示不能走溢价
|
|
|
- public function ratio_matchex($mchid, $org_quality, $card_type, $spec, $qualities)
|
|
|
+ public function ratio_match($mchid, $org_quality, $card_type, $spec, $qualities)
|
|
|
{
|
|
|
if (count($qualities) <= 1) {
|
|
|
return [true, true];
|
|
|
}
|
|
|
|
|
|
- $lowest_ratio = $this->lowest_ratio($mchid);
|
|
|
- $lowest_pratio = $this->profit_ratio($mchid);
|
|
|
- $profit_formula = $this->profit_formula($mchid);
|
|
|
- $header = __METHOD__ . " mchid={$mchid} card_type={$card_type} spec={$spec}";
|
|
|
-
|
|
|
- Log::record("{$header} formula={$profit_formula}, lowest_ratio={$lowest_ratio} lowest_pratio={$lowest_pratio}", Log::DEBUG);
|
|
|
-
|
|
|
$formula = $this->profit_formula($mchid);
|
|
|
- Log::record("{$header} formula = {$formula}",Log::DEBUG);
|
|
|
+
|
|
|
+ $header = __METHOD__ . " mchid={$mchid} card_type={$card_type} spec={$spec}";
|
|
|
+ Log::record("{$header} formula={$formula}", Log::DEBUG);
|
|
|
|
|
|
if($formula === 'all')
|
|
|
{
|
|
|
- [$submit_count, $succ_count, $fail_count, $gross_ratio, $profit, $gross_pratio] = $this->gross_ratio($mchid);
|
|
|
- Log::record("{$header} gross_ratio={$gross_ratio}, gross_pratio={$gross_pratio}", Log::DEBUG);
|
|
|
-
|
|
|
- if ($gross_pratio > $lowest_pratio) {
|
|
|
- $can_last = true;
|
|
|
- } else {
|
|
|
- $can_last = false;
|
|
|
- }
|
|
|
-
|
|
|
- if (!PolicyUtil::mixed_quality($org_quality))
|
|
|
- {
|
|
|
- if ($gross_ratio >= $lowest_ratio) {
|
|
|
- return [true,true];
|
|
|
- } else {
|
|
|
- return [false,true];
|
|
|
- }
|
|
|
- }
|
|
|
- elseif ($gross_ratio >= $lowest_ratio) {
|
|
|
- $match = $this->pre_checker($mchid, $card_type, $spec, $header, $lowest_ratio);
|
|
|
- return [$match,$can_last];
|
|
|
- } else {
|
|
|
- $match = $this->all_checker($mchid, $card_type, $spec, $header, $lowest_ratio);
|
|
|
- return [$match,$can_last];
|
|
|
- }
|
|
|
+ $matcher = new whole_match($this,$this->mGrossRatios,$this->mTypeRatios,$this->mDetailRatios);
|
|
|
+ return $matcher->match($mchid, $org_quality, $card_type, $spec, $qualities);
|
|
|
}
|
|
|
elseif($formula === 'qt') {
|
|
|
- return $this->qts_checker($mchid, $org_quality,$cur_quality, $card_type, $spec, $qualities,$period,$header,$ratio);
|
|
|
- }
|
|
|
- else {
|
|
|
- return $this->qts_checker($mchid, $org_quality,$cur_quality, $card_type, $spec, $qualities,$period,$header,$ratio);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- [$submit_count, $succ_count, $fail_count, $gross_ratio, $profit, $gross_pratio] = $this->gross_ratio($mchid);
|
|
|
- Log::record("{$header} gross_ratio={$gross_ratio}, lower_ratio={$lowest_ratio}", Log::DEBUG);
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- private function pre_checker($mchid, $card_type, $spec, $header, $lowest_ratio)
|
|
|
- {
|
|
|
- //计算各个card_type,spec 提交订单的占比情况,及所有面额
|
|
|
- $spec_ratios = function ($mchid, $type_specs, $all_submit)
|
|
|
- {
|
|
|
- $specs = [];
|
|
|
- $spec_details = [];
|
|
|
- foreach ($type_specs as $item)
|
|
|
- {
|
|
|
- [$card_type, $spec] = $item;
|
|
|
- if(!in_array($spec,$spec_details)) {
|
|
|
- $spec_details[] = $spec;
|
|
|
- $specs[] = $spec;
|
|
|
- }
|
|
|
-
|
|
|
- [$submit_count, $succ_count, $fail_count, $cur_ratio, $profit, $cur_pratio] = $this->detail_ratio($mchid, $card_type, $spec);
|
|
|
- $spec_details[$spec][] = [$submit_count, $succ_count, $fail_count, $cur_ratio, $profit, $cur_pratio];
|
|
|
- }
|
|
|
-
|
|
|
- $ratios = [];
|
|
|
- foreach ($spec_details as $spec => $details)
|
|
|
- {
|
|
|
- [$submit_count, $succ_count, $fail_count] = [0, 0, 0];
|
|
|
- foreach ($details as $item) {
|
|
|
- [$_submit_count, $_succ_count, $_fail_count, $_cur_ratio, $_profit, $_cur_pratio] = $item;
|
|
|
- $submit_count += $_submit_count;
|
|
|
- $succ_count += $_succ_count;
|
|
|
- $fail_count += $_fail_count;
|
|
|
- }
|
|
|
- $submit_ratio = $submit_count / ($all_submit + self::delta);
|
|
|
- $cur_ratio = $succ_count / ($succ_count + $fail_count + self::delta);
|
|
|
-
|
|
|
- $ratios[$spec] = [$submit_count, $succ_count, $fail_count, $submit_ratio, $cur_ratio];
|
|
|
- }
|
|
|
-
|
|
|
- return [$specs, $ratios];
|
|
|
- };
|
|
|
-
|
|
|
- $split_array
|
|
|
-
|
|
|
- //找出最佳补充面额
|
|
|
- $ts_filter = function ($all_submit, $specs, $spec_details, $ratio, $lowest_ratio)
|
|
|
- {
|
|
|
- $count = count($specs);
|
|
|
- if ($count === 1) {
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- for ($i = 1; $i < $count; $i++)
|
|
|
- {
|
|
|
- end()
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- $mast_succs = intval($all_submit * $lowest_ratio);
|
|
|
- $result = [];
|
|
|
-
|
|
|
- $all = 0.00;
|
|
|
- foreach ($spec_details as $item)
|
|
|
- {
|
|
|
- [$card_type, $spec, $submit_ratio, $cur_ratio, $cur_pratio] = $item;
|
|
|
- $all += $submit_ratio * $cur_ratio;
|
|
|
-
|
|
|
- $r = $all / ($lowest_ratio + self::delta);
|
|
|
- if ($r > 1)
|
|
|
- break;
|
|
|
- else {
|
|
|
- $result[] = "{$card_type}-{$spec}";
|
|
|
- }
|
|
|
- }
|
|
|
- return $result;
|
|
|
- };
|
|
|
-
|
|
|
-
|
|
|
- $lowest_pratio = $this->profit_ratio($mchid);
|
|
|
- [$all_submit, $succ_count, $fail_count, $gross_ratio, $profit, $cur_pratio] = $this->gross_ratio($mchid);
|
|
|
-
|
|
|
- if ($cur_pratio <= $lowest_pratio) {
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
- $ratio = $gross_ratio / ($lowest_ratio + self::delta);
|
|
|
- if ($lowest_pratio >= 0.95) {
|
|
|
- $max_ratio = 1.0;
|
|
|
- }
|
|
|
- elseif($lowest_pratio >= 0.90) {
|
|
|
- $max_ratio = 1.02;
|
|
|
- }
|
|
|
- elseif ($lowest_pratio >= 0.5) {
|
|
|
- $max_ratio = 1.05;
|
|
|
+ $matcher = new type_match($this,$this->mGrossRatios,$this->mTypeRatios,$this->mDetailRatios);
|
|
|
+ return $matcher->match($mchid, $org_quality, $card_type, $spec, $qualities);
|
|
|
}
|
|
|
else {
|
|
|
- $max_ratio = 1.07;
|
|
|
- }
|
|
|
-
|
|
|
- if($ratio >= $max_ratio) {
|
|
|
- return true;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- $type_specs = $this->mMchQTS[$mchid];
|
|
|
- [$specs, $spec_ratios] = $spec_ratios($mchid, $type_specs, $all_submit);
|
|
|
- sort($specs);
|
|
|
-
|
|
|
- $meet = $ts_filter($all_submit, $spec_ratios, $ratio, $lowest_ratio);
|
|
|
- $exist = array_key_exists("{$card_type}-{$spec}", $meet);
|
|
|
- return !$exist;
|
|
|
+ $matcher = new type_spec_match($this,$this->mGrossRatios,$this->mTypeRatios,$this->mDetailRatios);
|
|
|
+ return $matcher->match($mchid, $org_quality, $card_type, $spec, $qualities);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private function all_checker($mchid, $card_type, $spec, $header, $lowest_ratio)
|
|
|
- {
|
|
|
- $lowest_pratio = $this->profit_ratio($mchid);
|
|
|
- [$submit_count, $succ_count, $fail_count, $gross_ratio, $profit, $gross_pratio] = $this->gross_ratio($mchid);
|
|
|
- //当前毛利润率小于最低利润率的时候,不可以补充了
|
|
|
- if ($gross_pratio <= $lowest_pratio) {
|
|
|
- return true;
|
|
|
- } else {
|
|
|
- return false;
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
//机构订单拦截
|
|
|
public function need_intercept($mchid, $card_type, $card_state, $is_transfer, $card_no): bool
|