This commit is contained in:
aozhiwei 2023-08-23 16:12:09 +08:00
parent a25cdeccbc
commit 3c5463a0af
2 changed files with 10 additions and 3 deletions

View File

@ -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) {

View File

@ -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);