From 685edea7c09f5b580822e154959edfb78e9d9efc Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Mon, 17 Jun 2024 16:26:45 +0800 Subject: [PATCH 1/4] 1 --- .../controller/OutAppNftController.class.php | 62 +++++++++++++++++-- webapp/models/Nft.php | 14 +++++ 2 files changed, 70 insertions(+), 6 deletions(-) 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( From f3649e8e84122742bb3db833441b5dfb1a18ddbe Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Mon, 17 Jun 2024 17:23:41 +0800 Subject: [PATCH 2/4] 1 --- webapp/mt/Item.php | 1 + 1 file changed, 1 insertion(+) diff --git a/webapp/mt/Item.php b/webapp/mt/Item.php index b697d0d7..42bf5bb2 100644 --- a/webapp/mt/Item.php +++ b/webapp/mt/Item.php @@ -32,6 +32,7 @@ class Item { 26 晶体 29 外饰装扮 30 活动宝箱 + 31 金砖 */ /* From ca59bdccd1f5a1a01624c6eb4c119a8cb63fea8a Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Mon, 17 Jun 2024 17:25:43 +0800 Subject: [PATCH 3/4] 1 --- webapp/controller/BlockChainController.class.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/webapp/controller/BlockChainController.class.php b/webapp/controller/BlockChainController.class.php index 29031774..de4f6ea6 100644 --- a/webapp/controller/BlockChainController.class.php +++ b/webapp/controller/BlockChainController.class.php @@ -153,7 +153,11 @@ class BlockChainController extends BaseAuthedController { return; } } - $this->internalActivate721Nft($tokenId, Nft::HERO_TYPE, $heroDb['hero_uniid'], $heroDb['hero_id']); + $this->internalActivate721Nft($tokenId, + Nft::HERO_TYPE, + $heroDb['hero_uniid'], + $heroDb['hero_id'], + true); } break; default: @@ -188,7 +192,7 @@ class BlockChainController extends BaseAuthedController { } - private function internalActivate721Nft($tokenId, $tokenType, $itemUniId, $itemId) + private function internalActivate721Nft($tokenId, $tokenType, $itemUniId, $itemId, $isMint) { $params = array( 'c' => 'BcService', @@ -200,6 +204,7 @@ class BlockChainController extends BaseAuthedController { 'token_type' => $tokenType, 'item_uniid' => $itemUniId, 'item_id' => $itemId, + 'is_mint' => $isMint, 'net_id' => NET_ID ); { From f1a575e9f0b5f354090aaab681506bb1ba84f96c Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Mon, 17 Jun 2024 17:40:59 +0800 Subject: [PATCH 4/4] 1 --- .../controller/BlockChainController.class.php | 52 +++++++++---------- 1 file changed, 24 insertions(+), 28 deletions(-) diff --git a/webapp/controller/BlockChainController.class.php b/webapp/controller/BlockChainController.class.php index de4f6ea6..cc2998c9 100644 --- a/webapp/controller/BlockChainController.class.php +++ b/webapp/controller/BlockChainController.class.php @@ -124,40 +124,36 @@ class BlockChainController extends BaseAuthedController { myself()->_rspErr(1, 'hero not found'); return; } + $isMint = true; if ($heroDb['token_id'] && $heroDb['activate']) { - myself()->_rspErr(1, 'already activated'); - return; - } - /* - if ($heroDb['state'] == 1) { - myself()->_rspErr(1, 'cant mint'); - return; - }*/ - $tokenId = $heroDb['token_id']; - if (!$tokenId) { - $tokenId = BuyRecord::genOrderId - ( - GAME_ID, - phpcommon\BC_FUNC_CREATION, - myself()->_getNowTime(), - myself()->_getAddress() - ); - Hero::safeUpdateTokenId($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; + $isMint = false; + } else { + $tokenId = $heroDb['token_id']; + if (!$tokenId) { + $tokenId = BuyRecord::genOrderId + ( + GAME_ID, + phpcommon\BC_FUNC_CREATION, + myself()->_getNowTime(), + myself()->_getAddress() + ); + Hero::safeUpdateTokenId($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::HERO_TYPE, $heroDb['hero_uniid'], $heroDb['hero_id'], - true); + $isMint); } break; default: @@ -204,7 +200,7 @@ class BlockChainController extends BaseAuthedController { 'token_type' => $tokenType, 'item_uniid' => $itemUniId, 'item_id' => $itemId, - 'is_mint' => $isMint, + 'is_mint' => $isMint ? 1 : 0, 'net_id' => NET_ID ); {