This commit is contained in:
hujiabin 2023-06-27 15:58:17 +08:00
parent 164b3199e9
commit e5f072223c
2 changed files with 14 additions and 2 deletions

View File

@ -207,7 +207,7 @@ class PassController extends BaseAuthedController
return; return;
} }
$response = services\BlockChainService::gameItemMallBuy( $response = services\BlockChainService::gameItemMallBuy(
Transaction::BUY_PASS_ACTION_TYPE, $price * pow(10,18), V_ITEM_PASS, 1); Transaction::BUY_PASS_ACTION_TYPE, services\BlockChainService::formatCurrency($price), V_ITEM_PASS, 1);
$this->_setV(TN_DAILY_BUY_PASS_STATE, 0, 1); $this->_setV(TN_DAILY_BUY_PASS_STATE, 0, 1);
BcOrder::upsert($response['trans_id'], array( BcOrder::upsert($response['trans_id'], array(
@ -237,7 +237,7 @@ class PassController extends BaseAuthedController
return; return;
} }
$response = services\BlockChainService::gameItemMallBuy( $response = services\BlockChainService::gameItemMallBuy(
Transaction::BUY_EXP_ACTION_TYPE, $price * pow(10,18), V_ITEM_EXP, $passMeta['total_exp'] - $this->userInfo['exp']); Transaction::BUY_EXP_ACTION_TYPE, services\BlockChainService::formatCurrency($price), V_ITEM_EXP, $passMeta['total_exp'] - $this->userInfo['exp']);
$this->_setV(TN_DAILY_BUY_LEVEL_STATE, 0, 1); $this->_setV(TN_DAILY_BUY_LEVEL_STATE, 0, 1);
BcOrder::upsert($response['trans_id'], array( BcOrder::upsert($response['trans_id'], array(
'item_id' => V_ITEM_EXP, 'item_id' => V_ITEM_EXP,

View File

@ -3,6 +3,7 @@
namespace services; namespace services;
require_once('models/Transaction.php'); require_once('models/Transaction.php');
require_once('phpcommon/bignumber.php');
use models\Transaction; use models\Transaction;
use phpcommon; use phpcommon;
@ -82,6 +83,17 @@ class BlockChainService {
} }
} }
/*
$price 是一个小数精确到小数点后5位
*/
public static function formatCurrency($price)
{
$xiShu = 10000;
$intPrice = $price * $xiShu;
$formatedStr = phpcommon\bnDiv(phpcommon\bnMul_s($intPrice, phpcommon\bnPow_s(10, 18)), $xiShu);
return $formatedStr;
}
private static function getWeb3ServiceUrl() private static function getWeb3ServiceUrl()
{ {
if (SERVER_ENV == _TEST) { if (SERVER_ENV == _TEST) {