diff --git a/webapp/controller/OutAppNftController.class.php b/webapp/controller/OutAppNftController.class.php index 172d1305..f34b6a24 100644 --- a/webapp/controller/OutAppNftController.class.php +++ b/webapp/controller/OutAppNftController.class.php @@ -202,6 +202,7 @@ class OutAppNftController extends BaseController { public function nftDetail() { $nftType = getReqVal('nft_type', ''); + $contractAddress = getReqVal('contract_address', ''); $netId = getReqVal('net_id', ''); $tokenId = getReqVal('token_id', ''); $info = array( @@ -216,17 +217,66 @@ class OutAppNftController extends BaseController { 'image' => '', 'detail' => array() ); - switch ($nftType) { - case 'hero': - { - $this->getHeroDetail($netId, $tokenId, $info); - } - break; + if (empty($contractAddress)) { + switch ($nftType) { + case 'hero': + { + $this->getHeroDetail($netId, $tokenId, $info); + } + break; + } + } else { + $this->internalGetNftDetail($netId, $contractAddress, $tokenId, $info); } error_log(json_encode($info)); myself()->_rspData($info); } + private function internalGetNftDetail($netId, $contractAddress, $tokenId, &$info) { + $nftDb = Nft::getNftByNetIdTokenTypeTokenId($netId, Nft::HERO_TYPE, $tokenId); + if (empty($nftDb)) { + return; + } + switch ($nftDb['token_type']) { + case Nft::HERO_TYPE: + { + $info['contract_address'] = $nftDb['contract_address']; + $info['token_id'] = $nftDb['token_id']; + $info['owner_address'] = $nftDb['owner_address']; + $heroDb = Hero::findByTokenId2($tokenId); + if ($heroDb) { + $heroAttrs = emptyReplace(json_decode($heroDb['wealth_attr'], true), array()); + $heroResult = \mt\EconomyAttribute::getAttrValue($heroAttrs); + $wealth = $heroResult['wealth']; + $wealth_rate = $heroResult['wealth_rate']; + $lucky = $heroResult['lucky']; + $lucky_rate = $heroResult['lucky_rate']; + $heroAbility = Hero::abilityInfo($heroDb); + $heroMeta = \mt\Hero::get($heroDb['hero_id']); + if ($heroMeta) { + $itemMeta = \mt\Item::get($heroDb['hero_id']); + $heroAtteMeta = \mt\EconomyAttribute::findByGrade($itemMeta['relationship'],$heroDb['quality']); + $info['meta_url'] = NFT_META_URL . '/hero/meta/' . $netId . '/' . $tokenId; + $info['name'] = $heroMeta['name']; + $info['item_id'] = $heroMeta['id']; + $info['type'] = $nftDb['token_type']; + $info['image'] = 'https://www.cebg.games/res/avatars/' . $heroMeta['id'] . '.png'; + $info['detail']['quality'] = $heroDb['quality']; + $info['detail']['max_mining_days'] = $heroAtteMeta['validTime']; + $info['detail']['wealth'] = floor($wealth * (1+$wealth_rate)); + $info['detail']['lucky'] = floor($lucky * (1+$lucky_rate)); + $info['detail']['hp'] = $heroAbility['hp']; + $info['detail']['atk'] = $heroAbility['attack']; + $info['detail']['def'] = $heroAbility['defence']; + $info['detail']['block'] = $heroAbility['block']; + $info['detail']['crit'] = $heroAbility['critical']; + } + } + } + break; + } + } + private function getHeroDetail($netId, $tokenId, &$info) { $nftDb = Nft::getNftByNetIdTokenTypeTokenId($netId, Nft::HERO_TYPE, $tokenId); diff --git a/webapp/models/Nft.php b/webapp/models/Nft.php index 796a5d57..f70e1d72 100644 --- a/webapp/models/Nft.php +++ b/webapp/models/Nft.php @@ -187,6 +187,20 @@ class Nft extends BaseModel return $row; } + public static function getNftByNetIdContractAddressTokenId($netId, $contractAddress, $tokenId) + { + $row = SqlHelper::ormSelectOne( + myself()->_getMarketMysql(), + 't_nft', + array( + 'net_id' => $netId, + 'contract_address' => $contractAddress, + 'token_id' => $tokenId, + ) + ); + return $row; + } + public static function getNftByNetCont($tokenId, $netId, $contractAddress) { $row = SqlHelper::ormSelectOne(