From 8cc3cb32170cd84c1866f53348b18ae5f6052a83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E5=8D=8E=E6=B8=85?= <18691022700@163.com> Date: Sat, 17 Jan 2026 20:50:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=A1=E9=AA=8C=E6=95=B0=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/api/model/UserWallet.php | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/application/api/model/UserWallet.php b/application/api/model/UserWallet.php index e351f835..738cf2fe 100644 --- a/application/api/model/UserWallet.php +++ b/application/api/model/UserWallet.php @@ -4,6 +4,7 @@ namespace app\api\model; use think\Cache; use think\Db; +use think\Log; use think\Model; use Yzh\YunPay; @@ -318,6 +319,8 @@ class UserWallet extends Model $user_earnings = $user_wallet['earnings']; $original_coin = $user_earnings; // 保存原始值用于日志 + $money = $this ->formatScientificNumber($money); +// Log::record("计算收益:".$money,"info"); if(in_array($change_type,$in_types)){ $update_coin = bcadd($user_earnings , $money,4); }elseif(in_array($change_type,$out_types)){ @@ -352,4 +355,29 @@ class UserWallet extends Model return true; } + + function formatScientificNumber($num) { + // 1. 先将数值转为字符串,方便正则匹配 + $numStr = (string)$num; + + // 2. 正则匹配科学计数法格式(匹配 E/e 开头的科学计数法,包含正负指数) + $scientificPattern = '/^[+-]?\d+(\.\d+)?[Ee][+-]?\d+$/'; + + // 3. 判断是否是科学计数法 + if (preg_match($scientificPattern, $numStr)) { + // 是科学计数法,转换为浮点数后保留4位小数 + $floatNum = (float)$numStr; + // 保留4位小数,四舍五入,确保格式正确 + $result = number_format($floatNum, 4, '.', ''); +// echo "检测到科学计数法数值,处理后结果:{$result}\n"; + } else { + // 不是科学计数法,直接保留4位小数(兼容普通数值) + $floatNum = (float)$numStr; + $result = number_format($floatNum, 4, '.', ''); +// echo "非科学计数法数值,处理后结果:{$result}\n"; + } + + return $result; + } + } \ No newline at end of file