From 3c5463a0af70297d8d07d1a26693d087a6e2903d Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Wed, 23 Aug 2023 16:12:09 +0800 Subject: [PATCH] 1 --- webapp/services/BlockChainService.php | 3 ++- webapp/services/EventService.php | 10 ++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/webapp/services/BlockChainService.php b/webapp/services/BlockChainService.php index 858753bb..b3a36a33 100644 --- a/webapp/services/BlockChainService.php +++ b/webapp/services/BlockChainService.php @@ -203,12 +203,13 @@ class BlockChainService { } } - public static function parseCurrencyVal($currencyName, $val, &$intPart, &$floatPart) + public static function parseCurrencyVal($currencyName, $val, &$intPart, &$floatPart, &$maxFloatPart) { $decimals = self::getCurrencyDecimals($currencyName); if ($decimals === false) { return false; } + $maxFloatPart = pow(10, $decimals); $intPart = '0'; $floatPart = '0'; if (strlen($val) <= $decimals) { diff --git a/webapp/services/EventService.php b/webapp/services/EventService.php index ea14128c..833de2d3 100644 --- a/webapp/services/EventService.php +++ b/webapp/services/EventService.php @@ -14,11 +14,17 @@ class EventService { { $intPart = 0; $floatPart = 0; - if (BlockChainService::parseCurrencyVal($currencyName, $val, $intPart, $floatPart)) { + $maxFloatPart = 0; + if (BlockChainService::parseCurrencyVal($currencyName, $val, $intPart, $floatPart, $maxFloatPart)) { $oldIntPart = DynData::GetVEx($accountId, TN_TOTAL_CEG_CONSUME, 0); $oldFloatPart = DynData::GetVEx($accountId, TN_TOTAL_CEG_CONSUME, 1); $newIntPart = $oldIntPart + $intPart; - $newFloatPart = $oldFloatPart; + $newFloatPart = $oldFloatPart + $floatPart; + if ($newFloatPart > $maxFloatPart) { + ++$newIntPart; + $newFloatPart = min($maxFloatPart, $newFloatPart - $maxFloatPart); + $newFloatPart = max($newFloatPart, 0); + } DynData::setVEx($accountId, TN_TOTAL_CEG_CONSUME, 0, $newIntPart); DynData::setVEx($accountId, TN_TOTAL_CEG_CONSUME, 1, $newFloatPart);