|
@@ -219,6 +219,24 @@ class mratio_controlex
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ //{\"10202\":{\"ratio\":0.65,\"period\":86400,\"profit_ratio\":0.002,\"profit_formula\":\"all\"}
|
|
|
+ //to-do for test
|
|
|
+// private function lowest_ratio($mchid)
|
|
|
+// {
|
|
|
+// $lower_ratio = $this->mTimesConfig[$mchid]['lower_ratio'] ?? [];
|
|
|
+// if (empty($lower_ratio)) {
|
|
|
+// return [0.30, 86400];
|
|
|
+// } else {
|
|
|
+// return [$lower_ratio['ratio'], $lower_ratio['period']];
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// private function profit_ratio($mchid) {
|
|
|
+// $profit_ratio = $this->mTimesConfig[$mchid]['profit_ratio'] ?? 0.002;
|
|
|
+// return $profit_ratio;
|
|
|
+// }
|
|
|
+
|
|
|
+
|
|
|
private function lowest_ratio($mchid)
|
|
|
{
|
|
|
$lower_ratio = $this->mTimesConfig[$mchid]['lower_ratio'] ?? [];
|
|
@@ -287,11 +305,6 @@ class mratio_controlex
|
|
|
|
|
|
private function pre_checker($mchid, $card_type, $spec, $header, $lowest_ratio)
|
|
|
{
|
|
|
- $lowest_pratio = $this->profit_ratio($mchid);
|
|
|
-
|
|
|
- [$all_submit, $succ_count, $fail_count, $cur_ratio, $profit, $cur_pratio] = $this->detail_ratio($mchid, $card_type, $spec);
|
|
|
- Log::record("{$header} $cur_pratio={$cur_pratio},lower_pratio={$lowest_pratio}", Log::DEBUG);
|
|
|
-
|
|
|
$ts_ratios = function ($mchid,$type_specs,$all_submit)
|
|
|
{
|
|
|
$result = [];
|
|
@@ -311,34 +324,64 @@ class mratio_controlex
|
|
|
return $result;
|
|
|
};
|
|
|
|
|
|
- $factor_calc = function ($item)
|
|
|
+ $spec_extract = function ($item)
|
|
|
{
|
|
|
[$card_type, $spec, $submit_ratio, $cur_ratio, $cur_pratio] = $item;
|
|
|
- $factor = $submit_ratio * $cur_ratio * $cur_pratio / $spec;
|
|
|
- return $factor;
|
|
|
+ return $spec;
|
|
|
+ };
|
|
|
+
|
|
|
+ $ts_sorter_spec = function ($left,$right) use($spec_extract)
|
|
|
+ {
|
|
|
+ $l = $spec_extract($left);
|
|
|
+ $r = $spec_extract($right);
|
|
|
+
|
|
|
+ if($l > $r)
|
|
|
+ return 1;
|
|
|
+ elseif($l < $r)
|
|
|
+ return -1;
|
|
|
+ else
|
|
|
+ return 0;
|
|
|
};
|
|
|
|
|
|
- $ts_sorter = function ($left,$right) use($factor_calc)
|
|
|
+ $ts_filter = function ($ts_ratios, $ratio, $lowest_ratio)
|
|
|
{
|
|
|
- $l = $factor_calc($left);
|
|
|
- $r = $factor_calc($right);
|
|
|
+ $result = [];
|
|
|
+
|
|
|
+ $all = 0.00;
|
|
|
+ foreach ($ts_ratios as $item)
|
|
|
+ {
|
|
|
+ [$card_type, $spec, $submit_ratio, $cur_ratio, $cur_pratio] = $item;
|
|
|
+ $all += $submit_ratio * $cur_ratio;
|
|
|
|
|
|
- if($l > $r) return -1;
|
|
|
- elseif($l < $r) return 1;
|
|
|
- else return 0;
|
|
|
+ $r = $all / ($lowest_ratio + 0.00001);
|
|
|
+ if($r > $ratio)
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+
|
|
|
$type_specs = $this->mMchQTS[$mchid];
|
|
|
$ts_ratios = $ts_ratios($mchid, $type_specs, $all_submit);
|
|
|
- usort($ts_ratios, $ts_sorter);
|
|
|
-
|
|
|
- if ($cur_pratio >= $lowest_pratio)
|
|
|
- {
|
|
|
- if($cur_ratio >= $lowest_ratio) {
|
|
|
- return false;
|
|
|
- }
|
|
|
+ usort($ts_ratios, $ts_sorter_spec);
|
|
|
|
|
|
- return false;
|
|
|
+ $ratio = $gross_ratio / ($lowest_ratio + 0.00001);
|
|
|
+ if($ratio > 1.1) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ $meet = $ts_filter($ts_ratios,$ratio,$lowest_ratio);
|
|
|
+ $exist = array_key_exists("{$card_type}-{$spec}",$meet);
|
|
|
+ return !$exist;
|
|
|
}
|
|
|
}
|
|
|
|