From e5f072223c2e07bd513ab77f6716a6bc5e00bad2 Mon Sep 17 00:00:00 2001 From: hujiabin <519660157@qq.com> Date: Tue, 27 Jun 2023 15:58:17 +0800 Subject: [PATCH] 1 --- webapp/controller/PassController.class.php | 4 ++-- webapp/services/BlockChainService.php | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/webapp/controller/PassController.class.php b/webapp/controller/PassController.class.php index 2cc5d27e..132e390d 100644 --- a/webapp/controller/PassController.class.php +++ b/webapp/controller/PassController.class.php @@ -207,7 +207,7 @@ class PassController extends BaseAuthedController return; } $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); BcOrder::upsert($response['trans_id'], array( @@ -237,7 +237,7 @@ class PassController extends BaseAuthedController return; } $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); BcOrder::upsert($response['trans_id'], array( 'item_id' => V_ITEM_EXP, diff --git a/webapp/services/BlockChainService.php b/webapp/services/BlockChainService.php index accf008e..062a4d39 100644 --- a/webapp/services/BlockChainService.php +++ b/webapp/services/BlockChainService.php @@ -3,6 +3,7 @@ namespace services; require_once('models/Transaction.php'); +require_once('phpcommon/bignumber.php'); use models\Transaction; 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() { if (SERVER_ENV == _TEST) {