Merge branch 'hjb' of git.kingsome.cn:server/game2006api into hjb

This commit is contained in:
hujiabin 2024-06-18 14:39:01 +08:00
commit 8ca927d436
4 changed files with 100 additions and 34 deletions

View File

@ -124,36 +124,36 @@ class BlockChainController extends BaseAuthedController {
myself()->_rspErr(1, 'hero not found'); myself()->_rspErr(1, 'hero not found');
return; return;
} }
$isMint = true;
if ($heroDb['token_id'] && $heroDb['activate']) { if ($heroDb['token_id'] && $heroDb['activate']) {
myself()->_rspErr(1, 'already activated'); $isMint = false;
return; } else {
} $tokenId = $heroDb['token_id'];
/* if (!$tokenId) {
if ($heroDb['state'] == 1) { $tokenId = BuyRecord::genOrderId
myself()->_rspErr(1, 'cant mint'); (
return; GAME_ID,
}*/ phpcommon\BC_FUNC_CREATION,
$tokenId = $heroDb['token_id']; myself()->_getNowTime(),
if (!$tokenId) { myself()->_getAddress()
$tokenId = BuyRecord::genOrderId );
( Hero::safeUpdateTokenId($heroDb['hero_uniid'], $tokenId);
GAME_ID, $heroDb = Hero::find($uniid);
phpcommon\BC_FUNC_CREATION, if (!$heroDb) {
myself()->_getNowTime(), myself()->_rspErr(1, 'hero not found');
myself()->_getAddress() return;
); }
Hero::safeUpdateTokenId($heroDb['hero_uniid'], $tokenId); if ($heroDb['token_id'] != $tokenId) {
$heroDb = Hero::find($uniid); myself()->_rspErr(500, 'server internal error');
if (!$heroDb) { return;
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']); $this->internalActivate721Nft($tokenId,
Nft::HERO_TYPE,
$heroDb['hero_uniid'],
$heroDb['hero_id'],
$isMint);
} }
break; break;
default: default:
@ -188,7 +188,7 @@ class BlockChainController extends BaseAuthedController {
} }
private function internalActivate721Nft($tokenId, $tokenType, $itemUniId, $itemId) private function internalActivate721Nft($tokenId, $tokenType, $itemUniId, $itemId, $isMint)
{ {
$params = array( $params = array(
'c' => 'BcService', 'c' => 'BcService',
@ -200,6 +200,7 @@ class BlockChainController extends BaseAuthedController {
'token_type' => $tokenType, 'token_type' => $tokenType,
'item_uniid' => $itemUniId, 'item_uniid' => $itemUniId,
'item_id' => $itemId, 'item_id' => $itemId,
'is_mint' => $isMint ? 1 : 0,
'net_id' => NET_ID 'net_id' => NET_ID
); );
{ {

View File

@ -202,6 +202,7 @@ class OutAppNftController extends BaseController {
public function nftDetail() public function nftDetail()
{ {
$nftType = getReqVal('nft_type', ''); $nftType = getReqVal('nft_type', '');
$contractAddress = getReqVal('contract_address', '');
$netId = getReqVal('net_id', ''); $netId = getReqVal('net_id', '');
$tokenId = getReqVal('token_id', ''); $tokenId = getReqVal('token_id', '');
$info = array( $info = array(
@ -216,17 +217,66 @@ class OutAppNftController extends BaseController {
'image' => '', 'image' => '',
'detail' => array() 'detail' => array()
); );
switch ($nftType) { if (empty($contractAddress)) {
case 'hero': switch ($nftType) {
{ case 'hero':
$this->getHeroDetail($netId, $tokenId, $info); {
} $this->getHeroDetail($netId, $tokenId, $info);
break; }
break;
}
} else {
$this->internalGetNftDetail($netId, $contractAddress, $tokenId, $info);
} }
error_log(json_encode($info)); error_log(json_encode($info));
myself()->_rspData($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) private function getHeroDetail($netId, $tokenId, &$info)
{ {
$nftDb = Nft::getNftByNetIdTokenTypeTokenId($netId, Nft::HERO_TYPE, $tokenId); $nftDb = Nft::getNftByNetIdTokenTypeTokenId($netId, Nft::HERO_TYPE, $tokenId);

View File

@ -187,6 +187,20 @@ class Nft extends BaseModel
return $row; 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) public static function getNftByNetCont($tokenId, $netId, $contractAddress)
{ {
$row = SqlHelper::ormSelectOne( $row = SqlHelper::ormSelectOne(

View File

@ -32,6 +32,7 @@ class Item {
26 晶体 26 晶体
29 外饰装扮 29 外饰装扮
30 活动宝箱 30 活动宝箱
31 金砖
*/ */
/* /*