From 20d979b1ece14651b6f95aa5d9fb58d8bafbc4f0 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Tue, 16 Jul 2024 14:07:07 +0800 Subject: [PATCH 1/5] 1 --- webapp/models/Nft.php | 1 + 1 file changed, 1 insertion(+) diff --git a/webapp/models/Nft.php b/webapp/models/Nft.php index 98aa21d3..f75ff077 100644 --- a/webapp/models/Nft.php +++ b/webapp/models/Nft.php @@ -28,6 +28,7 @@ class Nft extends BaseModel const EXPLORER_TYPE = 9; //Explorer const CANDY_TYPE = 10; //CANDY const GOLD_BULLION_TYPE = 11; //金砖 + const GCARD_HERO_TYPE = 12; //游戏内合成的nft英雄 const RING_TYPE = 19; //戒指 const AVATAR_TYPE = 30; //装饰 From 546dd97bd591304bdfc20c560369eff2ff15215c Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Tue, 16 Jul 2024 19:09:35 +0800 Subject: [PATCH 2/5] 1 --- .../controller/OutAppNftController.class.php | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/webapp/controller/OutAppNftController.class.php b/webapp/controller/OutAppNftController.class.php index 72ef94cc..51e3e2cf 100644 --- a/webapp/controller/OutAppNftController.class.php +++ b/webapp/controller/OutAppNftController.class.php @@ -442,4 +442,65 @@ class OutAppNftController extends BaseController { return $quality; } + public function getHeroList() + { + $accountId = getReqVal('account_id', ''); + $rows = SqlHelper::ormSelect( + myself()->_getMarketMysql(), + 't_hero', + array( + 'account_id' => $accountId, + ) + ); + $rspData = array( + 'rows' => array() + ); + foreach ($rows as $row) { + $info = array( + 'uniid' => '', + 'net_id' => 0, + 'contract_address' => '', + 'token_id' => '', + 'owner_address' => '', + 'meta_url' => '', + 'name' => '', + 'item_id' => 0, + 'type' => 0, + 'image' => '', + 'on_sale' => 0, + 'detail' => array() + ); + $heroDb = $row; + $info['uniid'] = $heroDb['idx']; + $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/' . $nftDb['net_id'] . '/' . $nftDb['token_id']; + $info['name'] = $heroMeta['name']; + $info['item_id'] = $heroMeta['id']; + $info['type'] = Nft::HERO_TYPE; + $info['image'] = 'https://res2.counterfire.games/nft/meta/' . $heroMeta['id'] . '_' . $this->getRealHeroQuality($heroDb) . '.gif'; + $info['detail']['quality'] = $this->getRealHeroQuality($heroDb); + $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']; + } + array_push($rspData['rows'], $info); + } + myself()->_rspData($rspData); + } + } From 54e4a116953e484fd1d6ba09d22f33bb1029ba13 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Wed, 17 Jul 2024 14:26:47 +0800 Subject: [PATCH 3/5] 1 --- webapp/controller/OutAppNftController.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webapp/controller/OutAppNftController.class.php b/webapp/controller/OutAppNftController.class.php index 51e3e2cf..4f1b1297 100644 --- a/webapp/controller/OutAppNftController.class.php +++ b/webapp/controller/OutAppNftController.class.php @@ -446,7 +446,7 @@ class OutAppNftController extends BaseController { { $accountId = getReqVal('account_id', ''); $rows = SqlHelper::ormSelect( - myself()->_getMarketMysql(), + myself()->_getMysql($accountId), 't_hero', array( 'account_id' => $accountId, From fb3873c960f1acb0a098ebebb2b2996d7653b5a7 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Wed, 17 Jul 2024 16:59:18 +0800 Subject: [PATCH 4/5] 1 --- .../controller/BlockChainController.class.php | 4 +- .../controller/OutAppMintController.class.php | 110 ++++++++++++++++++ webapp/models/Hero.php | 37 ++++-- 3 files changed, 139 insertions(+), 12 deletions(-) create mode 100644 webapp/controller/OutAppMintController.class.php diff --git a/webapp/controller/BlockChainController.class.php b/webapp/controller/BlockChainController.class.php index 69439337..df13620d 100644 --- a/webapp/controller/BlockChainController.class.php +++ b/webapp/controller/BlockChainController.class.php @@ -124,6 +124,8 @@ class BlockChainController extends BaseAuthedController { switch ($type) { case 1: { + myself()->_rspErr(1, 'server internal error'); + return; $heroDb = Hero::find($uniid); if (!$heroDb) { myself()->_rspErr(1, 'hero not found'); @@ -145,7 +147,7 @@ class BlockChainController extends BaseAuthedController { myself()->_getNowTime(), myself()->_getAddress() ); - Hero::safeUpdateTokenId($heroDb['hero_uniid'], $tokenId); + Hero::safeUpdateTokenId(myself()->_getAccountId(), $heroDb['hero_uniid'], $tokenId); $heroDb = Hero::find($uniid); if (!$heroDb) { myself()->_rspErr(1, 'hero not found'); diff --git a/webapp/controller/OutAppMintController.class.php b/webapp/controller/OutAppMintController.class.php new file mode 100644 index 00000000..5c76ebb8 --- /dev/null +++ b/webapp/controller/OutAppMintController.class.php @@ -0,0 +1,110 @@ + $accountId, + 'uuid' => $uniid + ))); + $heroDb = Hero::findByAccountIdEx($accountId, $uniid); + if (!$heroDb) { + myself()->_rspErr(1, 'hero not found'); + 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 + ); + error_log(json_encode($params)); + { + $url = self::getWeb3ServiceUrl(); + $response = ''; + if (!phpcommon\HttpClient::get + ($url, + $params, + $response)) { + myself()->_rspErr(500, 'server internal error'); + die(); + return; + } + error_log($response); + $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)]; + } + +} diff --git a/webapp/models/Hero.php b/webapp/models/Hero.php index cdb3932f..7430d483 100644 --- a/webapp/models/Hero.php +++ b/webapp/models/Hero.php @@ -72,6 +72,22 @@ class Hero extends BaseModel { return self::internalFind($accountId, User::findUserAddress($accountId), $heroUniId); } + public static function findByAccountIdEx($accountId, $heroUniId) + { + $row = SqlHelper::ormSelectOne( + myself()->_getMysql($accountId), + 't_hero', + array( + 'idx' => $heroUniId, + 'account_id' => $accountId, + ) + ); + if ($row) { + $row['hero_uniid'] = $row['idx']; + } + return $row; + } + public static function findByTokenId($tokenId) { $row = SqlHelper::ormSelectOne( @@ -671,18 +687,17 @@ class Hero extends BaseModel { } } - public static function safeUpdateTokenId($heroUniId, $tokenId) + public static function safeUpdateTokenId($accountId, $heroUniId, $tokenId) { - if (self::find($heroUniId)) { - myself()->_getSelfMysql()->execScript( - 'UPDATE t_hero SET token_id=:token_id ' . - 'WHERE idx=:idx AND token_id IS NULL;', - array( - ':idx' => $heroUniId, - ':token_id' => $tokenId, - ) - ); - } + myself()->_getMysql($accountId)->execScript( + 'UPDATE t_hero SET token_id=:token_id ' . + 'WHERE idx=:idx AND account_id=:account_id AND token_id IS NULL;', + array( + ':idx' => $heroUniId, + ':account_id' => $accountId, + ':token_id' => $tokenId, + ) + ); } public static function updateByTokenId($tokenId, $fieldsKv) From 203b393c8927debf20344c68742f537cd7dc80a5 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Wed, 17 Jul 2024 23:52:43 +0800 Subject: [PATCH 5/5] 1 --- webapp/controller/BaseAuthedController.class.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/webapp/controller/BaseAuthedController.class.php b/webapp/controller/BaseAuthedController.class.php index e515ca5d..2f38a71c 100644 --- a/webapp/controller/BaseAuthedController.class.php +++ b/webapp/controller/BaseAuthedController.class.php @@ -88,8 +88,9 @@ class BaseAuthedController extends BaseController { // } // } if (SERVER_ENV == _ONLINE) { - //phpcommon\sendError(1001, 'session expiration'); - //die(); + phpcommon\sendError(1001, 'session expiration'); + die(); + return; } $this->accountId = getReqVal('account_id', ''); $this->sessionId = getReqVal('session_id', '');