_verifySwitch('heroMint'); $accountId = getReqVal('account_id', ''); //$accountAddress = User::findUserAddress($accountId); //$accountAddress = '0x0c6c7399f1b6b19e96950ef294685bfd0dc46434'; $accountAddress = getReqVal('account_address', ''); $toAddress = getReqVal('to_address', ''); $uniid = getReqVal('uniid', 0); $userDb = User::find($accountId); if (empty($userDb)) { myself()->_rspErr(1, 'user not found'); return; } if ($userDb['gold'] < 0) { myself()->_rspErr(1, 'is valid user'); return; } $heroDb = Hero::findByAccountIdEx($accountId, $uniid); if (!$heroDb) { myself()->_rspErr(1, 'hero not found'); return; } if (!$heroDb['seal_type']) { myself()->_rspErr(1, 'hero is no seal'); return; } if ($heroDb['quality'] <= 1) { myself()->_rspErr(1, 'hero is N quality'); return; } /* if (!$heroDb['seal_type']) { myself()->_rspErr(1, 'hero no seal'); return; }*/ $isMint = true; $tokenId = $heroDb['token_id']; if ($heroDb['token_id'] && $heroDb['activate']) { myself()->_rspErr(1, 'hero already on chain'); return; $isMint = false; } else if (empty($tokenId) ){ $tokenId = BuyRecord::genOrderId ( GAME_ID, phpcommon\BC_FUNC_CREATION, myself()->_getNowTime(), $accountAddress ); Hero::safeUpdateTokenId($accountId, $heroDb['idx'], $tokenId); $heroDb = Hero::findByAccountIdEx($accountId, $uniid); if (!$heroDb) { myself()->_rspErr(1, 'hero not found'); return; } if ($heroDb['token_id'] != $tokenId) { myself()->_rspErr(500, 'server internal error'); return; } } $params = array( 'c' => 'BcService', 'a' => 'mintHero', 'account_id' => $accountId, 'account_address' => $accountAddress, 'token_ids' => $tokenId, 'nft_address' => NORMAL_HERO_CONTRACT_ADDRESS, 'to_address' => $toAddress, '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) { myself()->_rspData(array( 'trans_id' => '', '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)]; } }