_isValidAddress()) { die(json_encode(array( 'errcode' => 501, 'errmsg' => 'you are not a wallet user' ))); return; } } public function active721Nft() { myself()->_verifySwitch('heroMint'); $type = getReqVal('type', 0); $uniid = getReqVal('uniid', 0); $accountAddress = strtolower(getReqVal('account_address', '')); if ($accountAddress != myself()->_getAddress()) { myself()->_rspErr(1, 'account address error'); return; } switch ($type) { case 1: { //myself()->_rspErr(1, 'server internal error'); //return; $heroDb = Hero::find($uniid); if (!$heroDb) { myself()->_rspErr(1, 'hero not found'); return; } if (!$heroDb['seal_type']) { myself()->_rspErr(1, 'hero no seal'); return; } if ($heroDb['quality'] <= 1) { myself()->_rspErr(1, 'hero is N quality'); return; } $isMint = true; $tokenId = $heroDb['token_id']; if ($heroDb['token_id'] && $heroDb['activate']) { $isMint = false; } else if (empty($tokenId) ){ $tokenId = BuyRecord::genOrderId ( GAME_ID, phpcommon\BC_FUNC_CREATION, myself()->_getNowTime(), myself()->_getAddress() ); Hero::safeUpdateTokenId(myself()->_getAccountId(), $heroDb['hero_uniid'], $tokenId); $heroDb = Hero::find($uniid); if (!$heroDb) { myself()->_rspErr(1, 'hero not found'); return; } if ($heroDb['token_id'] != $tokenId) { myself()->_rspErr(500, 'server internal error'); return; } } $this->internalActivate721Nft($tokenId, Nft::GCARD_HERO_TYPE, $heroDb['hero_uniid'], $heroDb['hero_id'], $isMint, null); } break; default: { myself()->_rspErr(1, 'type param error'); return; } break; } } public function mintGoldBullion() { myself()->_verifySwitch('goldSyn'); $type = getReqVal('type', 0); $accountAddress = strtolower(getReqVal('account_address', '')); if ($accountAddress != myself()->_getAddress()) { myself()->_rspErr(1, 'account address error'); return; } $itemId = 0; $goldNum = 0; switch ($type) { case 1: { $itemId = V_ITEM_GOLD_BULLION_1W; $goldNum = 1000; } break; case 2: { $itemId = V_ITEM_GOLD_BULLION_10W; $goldNum = 10000 * 1; } break; default: { return; } } if (empty($itemId) || empty($goldNum)) { return; } $costItems = array( array( 'item_id' => V_ITEM_GOLD, 'item_num' => $goldNum ), ); $lackItem = null; if (!$this->_hasEnoughItems($costItems, $lackItem)) { $this->_rspErr(3, 'gold not enough'); return; } $tokenId = BuyRecord::genOrderId ( GAME_ID, phpcommon\BC_FUNC_CREATION, myself()->_getNowTime(), myself()->_getAddress() ); $okCb = function () use($tokenId, $itemId, $costItems, $lackItem, $goldNum) { $lackItem = null; if (!myself()->_hasEnoughItems($costItems, $lackItem)) { myself()->_rspErr(3, 'gold not enough'); return false; } $goldBullionDb = SqlHelper::ormSelectOne (myself()->_getSelfMysql(), 't_gold_bullion', array( 'token_id' => $tokenId ) ); if (!empty($goldBullionDb)) { $this->_rspErr(500, 'server internal error'); return false; } myself()->_decItems($costItems); SqlHelper::insert (myself()->_getSelfMysql(), 't_gold_bullion', array( 'src_account_id' => myself()->_getAccountId(), 'src_address' => myself()->_getAddress(), 'token_id' => $tokenId, 'net_id' => NET_ID, 'item_id' => $itemId, 'gold' => $goldNum, 'createtime' => myself()->_getNowTime(), 'modifytime' => myself()->_getNowTime(), ) ); return true; }; $this->internalActivate721Nft( $tokenId, Nft::GOLD_BULLION_TYPE, 0, $itemId, true, $okCb); } private function internalActivate721Nft($tokenId, $tokenType, $itemUniId, $itemId, $isMint, $okCb) { $params = array( 'c' => 'BcService', 'a' => 'activate721Nft', 'account_id' => myself()->_getAccountId(), 'session_id' => myself()->_getSessionId(), 'account' => myself()->_getAddress(), 'token_id' => $tokenId, 'token_type' => $tokenType, 'item_uniid' => $itemUniId, 'item_id' => $itemId, 'is_mint' => $isMint ? 1 : 0, 'net_id' => NET_ID ); { $url = self::getWeb3ServiceUrl(); $response = ''; if (!phpcommon\HttpClient::get ($url, $params, $response)) { myself()->_rspErr(500, 'server internal error'); die(); return; } $rspObj = json_decode($response, true); if ($rspObj['errcode'] == 0) { $transId = $rspObj['trans_id']; Transaction::add( $transId, Transaction::MINT_721_ACTION_TYPE, $tokenId, $tokenType, $itemUniId, $itemId, 1, 1 ); if (!empty($okCb) && !$okCb()) { return; } myself()->_rspData(array( 'trans_id' => $transId, 'trans_req' => $rspObj['trans_req'] )); } else { myself()->_rspErr(500, 'server internal error'); return; } } } private static function getWeb3ServiceUrl() { $web3ServiceCluster = require_once('../config/web3service.cluster.php'); return $web3ServiceCluster[rand() % count($web3ServiceCluster)]; } }