diff --git a/webapp/services/BlockChainService.php b/webapp/services/BlockChainService.php index b0cb21bb..3876823d 100644 --- a/webapp/services/BlockChainService.php +++ b/webapp/services/BlockChainService.php @@ -166,6 +166,67 @@ class BlockChainService { } } + public static function beNftMallTransBuyPlanet($address, $itemNum, $currency, $price) + { + if (!($actionType > Transaction::BUY_BEGIN_ACTION_TYPE && + $actionType < Transaction::BUY_END_ACTION_TYPE)) { + error_log('beNftMallTransBuyPlanet action_type error:' . $actionType); + myself()->_rspErr(500, 'server internal error 1'); + die(); + return; + } + $account = $address; + if (empty($account)) { + error_log('beNftMallTransBuyPlanet address is emtpy:'); + myself()->_rspErr(500, 'server internal error 2'); + die(); + return; + } + $params = array( + 'c' => 'BeNftMallTrans', + 'a' => 'buyPlanet', + 'account' => $account, + 'currency_name' => $currency, + 'price' => $price, + 'net_id' => NET_ID + ); + { + $url = self::getWeb3ServiceUrl(); + $response = ''; + if (!phpcommon\HttpClient::get + ($url, + $params, + $response)) { + myself()->_rspErr(500, 'server internal error 3, url:' . $url); + die(); + return; + } + error_log("beNftMallTransBuyPlanet:" . $response . "url:" . $url); + $rspObj = json_decode($response, true); + if ($rspObj['errcode'] == 0) { + $transId = $rspObj['trans_id']; + Transaction::add( + $transId, + $actionType, + '', //$tokenId, + '', //$tokenType, + 0, //$itemUniId, + $itemId, //$itemId, + $itemNum, + 1 + ); + return array( + 'trans_id' => $transId, + 'params' => $rspObj['params'] + ); + } else { + myself()->_rspErr(500, 'server internal error 4'); + die(); + return; + } + } + } + /* $price 是一个小数精确到小数点后5位 */