fix(partner): 修复 PHP 8 下微小浮点数科学计数法导致 bcmul 参数格式错误的 500 异常
这个提交包含在:
@@ -41,11 +41,22 @@ class RateService
|
||||
public function calcRate($n = null)
|
||||
{
|
||||
$n = $n === null ? $this->countN() : intval($n);
|
||||
$base = (float) PartnerConfig::get('partner_madow_base_rate', 0.00000075);
|
||||
$rawBase = PartnerConfig::get('partner_madow_base_rate', '0.00000075');
|
||||
$base = is_numeric($rawBase) ? (float) $rawBase : 0.00000075;
|
||||
// 关键防坑:PHP 8.0+ 下小于 0.0001 的浮点数转为 string 时会自动变成科学计数法 (如 "7.5E-7")
|
||||
// 传给 bcmul() 会直接抛出 Fatal error: Argument #1 ($num1) is not well-formed
|
||||
// 必须使用 number_format 格式化为无科学计数法的高精度十进制字符串
|
||||
$baseStr = number_format($base, 10, '.', '');
|
||||
|
||||
$step = intval(PartnerConfig::get('partner_madow_step_orders', 1));
|
||||
$step = $step > 0 ? $step : 1;
|
||||
$multiple = max(1, floor($n / $step));
|
||||
return function_exists('bcmul') ? (float) bcmul((string) $base, (string) $multiple, 10) : (float) ($base * $multiple);
|
||||
$multipleStr = number_format($multiple, 0, '.', '');
|
||||
|
||||
if (function_exists('bcmul')) {
|
||||
return (float) bcmul($baseStr, $multipleStr, 10);
|
||||
}
|
||||
return (float) ($base * $multiple);
|
||||
}
|
||||
|
||||
public function countN()
|
||||
|
||||
@@ -235,7 +235,7 @@ class Dashboard extends Common
|
||||
foreach ($allAgents as $ag) {
|
||||
if ($filterCallback($ag)) {
|
||||
$uCount++;
|
||||
$madowTotal = (float) bcadd((string)$madowTotal, (string)($ag->madow ?? 0), 8);
|
||||
$madowTotal = round($madowTotal + (float) ($ag->madow ?? 0), 8);
|
||||
$uid = (int) $ag->user_id;
|
||||
|
||||
// 收益按角色类型精准归集
|
||||
|
||||
在新工单中引用
屏蔽一个用户