436 lines
16 KiB
PHP
436 lines
16 KiB
PHP
<?php
|
|
use phpcommon\SqlHelper;
|
|
require_once('models/Nft.php');
|
|
require_once('models/User.php');
|
|
require_once('models/Hero.php');
|
|
require_once('services/NftService.php');
|
|
require_once('mt/NftDesc.php');
|
|
require_once('mt/Hero.php');
|
|
require_once('mt/EconomyAttribute.php');
|
|
|
|
use models\Nft;
|
|
use models\User;
|
|
use models\Hero;
|
|
|
|
class OutAppNftController extends BaseController {
|
|
|
|
public function getNftList(){
|
|
$address = getReqVal('address', '');
|
|
$type = getReqVal('type', '');
|
|
if ($type){
|
|
$nftList = Nft::getNftListByType($address,$type);
|
|
}else{
|
|
$nftList = Nft::getNftList($address);
|
|
}
|
|
$listInfo = array();
|
|
if ($nftList){
|
|
foreach ($nftList as $nft) {
|
|
$image = 'https://www.cebg.games/res/avatars/' . $nft['item_id'] . '.png';
|
|
$full_image = 'https://www.cebg.games/res/avatars/full_' . $nft['item_id'] . '.png';
|
|
$info = array(
|
|
"idx" => $nft['idx'],
|
|
"owner_address" => $nft['owner_address'],
|
|
"item_id" => $nft['item_id'],
|
|
"token_id" => $nft['token_id'],
|
|
"token_type" => $nft['token_type'],
|
|
"contract_address" => $nft['contract_address'],
|
|
'image' => $image,
|
|
'full_image' => $full_image,
|
|
"details" => array(),
|
|
);
|
|
array_push($listInfo,$info);
|
|
}
|
|
}
|
|
|
|
$this->_rspData(array(
|
|
'nfts' => $listInfo,
|
|
));
|
|
|
|
}
|
|
|
|
public function getWebInfo(){
|
|
$channel = getReqVal('channel', '');
|
|
$openId = getReqVal('openId', '');
|
|
$accountId = BC_POLY_CHANNEL.'_'.$this->_getGameId().'_'.$channel.'_'.$openId;
|
|
// $userDb = User::find($accountId);
|
|
// if (!$userDb){
|
|
// $this->_rspErr(1, 'user not found');
|
|
// return;
|
|
// }
|
|
|
|
$info = array(
|
|
'loginVal' => 0,
|
|
'battleTimes' => 0,
|
|
'winTimes' => 0,
|
|
'kills' => 0,
|
|
'getGoldVal' => 0,
|
|
);
|
|
$accountBindDb = SqlHelper::ormSelectOne(
|
|
myself()->_getMysql($openId),
|
|
't_sub_user_bind',
|
|
array(
|
|
'org_account_id' => $accountId,
|
|
)
|
|
);
|
|
$accountId = $accountBindDb ? $accountBindDb['cur_account_id'] : $accountId ;
|
|
$redis = $this->_getRedis($accountId);
|
|
$lastActiveTime = $redis->get(LAST_ACTIVE_TIME . $accountId);
|
|
if (!empty($lastActiveTime) && $lastActiveTime > myself()->_getNowDaySeconds()){
|
|
$info['loginVal'] = 1;
|
|
}
|
|
// $loginDyn = SqlHelper::ormSelectOne(
|
|
// myself()->_getMysql($openId),
|
|
// 't_dyndata',
|
|
// array(
|
|
// 'account_id' => $accountId,
|
|
// 'x' => TN_DAILY_LOGINS,
|
|
// 'y' => 0,
|
|
// )
|
|
// );
|
|
// if ($loginDyn){
|
|
// $info['loginVal'] = $loginDyn['val'];
|
|
// if (myself()->_getDaySeconds($loginDyn['modifytime']) < myself()->_getNowDaySeconds()) {
|
|
// $info['loginVal'] = 0;
|
|
// }
|
|
// }
|
|
|
|
$battleDb = SqlHelper::ormSelectOne(
|
|
myself()->_getMysql($openId),
|
|
't_battle',
|
|
array(
|
|
'account_id' => $accountId,
|
|
)
|
|
);
|
|
if ($battleDb){
|
|
$hisBattleData = json_decode($battleDb['battle_data'], true);
|
|
$todayBattleData = getXVal($hisBattleData, 'today_data', array());
|
|
if (myself()->_getDaySeconds(getXVal($todayBattleData, 'modifytime', 0)) == myself()->_getNowDaySeconds()) {
|
|
$info['battleTimes'] = getXVal($todayBattleData, "total_battle_times", 0);
|
|
$info['winTimes'] = getXVal($todayBattleData, "total_special_win_times", 0);
|
|
$info['kills'] = getXVal($todayBattleData, "total_kills_times", 0);
|
|
}
|
|
}
|
|
$getGoldDyn = SqlHelper::ormSelectOne(
|
|
myself()->_getMysql($openId),
|
|
't_dyndata',
|
|
array(
|
|
'account_id' => $accountId,
|
|
'x' => TN_DAILY_GATHER_GOLD,
|
|
'y' => 0,
|
|
)
|
|
);
|
|
if ($getGoldDyn){
|
|
$info['getGoldVal'] = $getGoldDyn['val'];
|
|
if (myself()->_getDaySeconds($getGoldDyn['modifytime']) < myself()->_getNowDaySeconds()) {
|
|
$info['getGoldVal'] = 0;
|
|
}
|
|
}
|
|
$this->_rspData(array(
|
|
'info' => $info,
|
|
));
|
|
}
|
|
|
|
public function hasLockedNft()
|
|
{
|
|
$accountAddress = strtolower(getReqVal('account_address', ''));
|
|
}
|
|
|
|
public function nftMetaView()
|
|
{
|
|
$netId = getReqVal('net_id', '');
|
|
$tokenType = getReqVal('token_type', '');
|
|
$tokenId = getReqVal('token_id', '');
|
|
$info = array(
|
|
"token_id" => '',
|
|
"name" => "",
|
|
"description" => "",
|
|
"image" => "",
|
|
"attributes" => array(),
|
|
);
|
|
$nftDb = Nft::getNftByNetIdTokenTypeTokenId($netId, $tokenType, $tokenId);
|
|
switch ($tokenType) {
|
|
case Nft::HERO_TYPE:
|
|
{
|
|
$heroDb = Hero::findByTokenId2($tokenId);
|
|
if (!$heroDb){
|
|
echo json_encode($info);
|
|
die;
|
|
}
|
|
$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']);
|
|
$NftMeta = \mt\NftDesc::getByItemId($heroDb['hero_id']);
|
|
$itemMeta = \mt\Item::get($heroDb['hero_id']);
|
|
$heroAtteMeta = \mt\EconomyAttribute::findByGrade($itemMeta['relationship'],$heroDb['quality']);
|
|
$info['token_id'] = $tokenId;
|
|
$info['name'] = $heroMeta['name'];
|
|
$info['description'] = $NftMeta['desc'];
|
|
$info['image'] = "https://res2.counterfire.games/nft/meta/".
|
|
$heroDb['hero_id'].'_'.$this->getRealHeroQuality($heroDb).".gif";
|
|
array_push($info['attributes'],array(
|
|
"trait_type" => "quality",
|
|
"value" => intval($this->getRealHeroQuality($heroDb)),
|
|
));
|
|
array_push($info['attributes'],array(
|
|
"trait_type" => "max_mining_days",
|
|
"value" => $heroAtteMeta['validTime'],
|
|
));
|
|
array_push($info['attributes'],array(
|
|
"trait_type" => "wealth",
|
|
"value" => floor($wealth * (1+$wealth_rate)),
|
|
));
|
|
array_push($info['attributes'],array(
|
|
"trait_type" => "lucky",
|
|
"value" => floor($lucky * (1+$lucky_rate)),
|
|
));
|
|
if ($this->isCloseBox()) {
|
|
$this->fillBoxMeta($info);
|
|
}
|
|
}
|
|
break;
|
|
case Nft::GOLD_BULLION_TYPE:
|
|
{
|
|
$nftMeta = \mt\NftDesc::getByItemId($nftDb['item_id']);
|
|
$info['token_id'] = $tokenId;
|
|
$info['name'] = $nftMeta['name'];
|
|
$info['description'] = $nftMeta['desc'];
|
|
$info['image'] = "https://res2.counterfire.games/nft/meta/".$nftDb['item_id'].".png";
|
|
if ($this->isCloseBox()) {
|
|
$this->fillBoxMeta($info);
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
error_log(json_encode($info));
|
|
myself()->_rspData($info);
|
|
}
|
|
|
|
public function nftDetailList()
|
|
{
|
|
$rspObj = array(
|
|
'nfts' => array()
|
|
);
|
|
$data = file_get_contents('php://input');
|
|
$dataJson = json_decode($data, true);
|
|
if (count($dataJson['nfts']) > 20) {
|
|
myself()->_rspErr(1, 'nfts count error');
|
|
return;
|
|
}
|
|
foreach ($dataJson['nfts'] as $row) {
|
|
$netId = $row['net_id'];
|
|
$contractAddress = $row['contract_address'];
|
|
$tokenId = $row['token_id'];
|
|
$nftDb = Nft::getNftByNetIdContractAddressTokenId($netId, $contractAddress, $tokenId);
|
|
if (!empty($nftDb)) {
|
|
$info = array();
|
|
$this->internalNftDetail($netId, $nftDb, $info);
|
|
array_push($rspObj['nfts'], $info);
|
|
}
|
|
}
|
|
myself()->_rspData($rspObj);
|
|
}
|
|
|
|
public function nftDetailByContractAddress()
|
|
{
|
|
$contractAddress = getReqVal('contract_address', '');
|
|
$netId = getReqVal('net_id', '');
|
|
$tokenId = getReqVal('token_id', '');
|
|
$nftDb = Nft::getNftByNetIdContractAddressTokenId($netId, $contractAddress, $tokenId);
|
|
$info = array();
|
|
error_log(json_encode($_REQUEST));
|
|
$this->internalNftDetail($netId, $nftDb, $info);
|
|
error_log(json_encode($info));
|
|
myself()->_rspData($info);
|
|
}
|
|
|
|
public function nftDetailByTokenType()
|
|
{
|
|
$netId = getReqVal('net_id', '');
|
|
$tokenType = getReqVal('token_type', '');
|
|
$tokenId = getReqVal('token_id', '');
|
|
$nftDb = Nft::getNftByNetIdTokenTypeTokenId($netId, $tokenType, $tokenId);
|
|
$info = array();
|
|
error_log(json_encode($_REQUEST));
|
|
$this->internalNftDetail($netId, $nftDb, $info);
|
|
error_log(json_encode($info));
|
|
myself()->_rspData($info);
|
|
}
|
|
|
|
private function internalNftDetail($netId, &$nftDb, &$info)
|
|
{
|
|
$onSale = $this->nftIsOnSale($nftDb['net_id'], $nftDb['contract_address'], $nftDb['token_id']);
|
|
$info = array(
|
|
'net_id' => $netId,
|
|
'contract_address' => '',
|
|
'token_id' => '',
|
|
'owner_address' => '',
|
|
'meta_url' => '',
|
|
'name' => '',
|
|
'item_id' => 0,
|
|
'type' => 0,
|
|
'image' => '',
|
|
'on_sale' => $onSale,
|
|
'detail' => array()
|
|
);
|
|
if (!empty($nftDb)) {
|
|
$this->internalGetNftDetail($nftDb, $info);
|
|
}
|
|
}
|
|
|
|
private function internalGetNftDetail($nftDb, &$info) {
|
|
$info['contract_address'] = $nftDb['contract_address'];
|
|
$info['token_id'] = $nftDb['token_id'];
|
|
$info['owner_address'] = $nftDb['owner_address'];
|
|
switch ($nftDb['token_type']) {
|
|
case Nft::HERO_TYPE:
|
|
{
|
|
$heroDb = Hero::findByTokenId2($nftDb['token_id']);
|
|
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/' . $nftDb['net_id'] . '/' . $nftDb['token_id'];
|
|
$info['name'] = $heroMeta['name'];
|
|
$info['item_id'] = $heroMeta['id'];
|
|
$info['type'] = $nftDb['token_type'];
|
|
$info['image'] = 'https://res2.counterfire.games/nft/meta/' . $heroMeta['id'] . '_' . $heroDb['quality'] . '.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']['wealth'] = '';
|
|
$info['detail']['lucky'] = '';
|
|
$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'];
|
|
}
|
|
}
|
|
if ($this->isCloseBox()) {
|
|
$this->fillBoxDetail($info);
|
|
}
|
|
}
|
|
break;
|
|
case Nft::GOLD_BULLION_TYPE:
|
|
{
|
|
$nftMeta = \mt\NftDesc::getByItemId($nftDb['item_id']);
|
|
if ($nftMeta) {
|
|
$info['meta_url'] = NFT_META_URL . '/gold_bullion/meta/' . $nftDb['net_id'] . '/' . $nftDb['token_id'];
|
|
$info['name'] = $nftMeta['name'];
|
|
$info['item_id'] = $nftMeta['item_id'];
|
|
$info['type'] = $nftDb['token_type'];
|
|
$info['image'] = 'https://res2.counterfire.games/nft/meta/' . $nftMeta['item_id'] . '.png';
|
|
$info['detail']['gold_coins'] = $this->getGoldBullionGoldNum($nftDb['item_id']);
|
|
}
|
|
if ($this->isCloseBox()) {
|
|
$this->fillBoxDetail($info);
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
private function getGoldBullionGoldNum($itemId)
|
|
{
|
|
switch ($itemId) {
|
|
case V_ITEM_GOLD_BULLION_1W:
|
|
{
|
|
return 10000;
|
|
}
|
|
break;
|
|
case V_ITEM_GOLD_BULLION_10W:
|
|
{
|
|
return 10000 * 10;
|
|
}
|
|
break;
|
|
default:
|
|
{
|
|
return 0;
|
|
}
|
|
}
|
|
}
|
|
|
|
private function isCloseBox()
|
|
{
|
|
$tokenId = getReqVal('token_id', '');
|
|
if ($tokenId == '6240619010000001') {
|
|
return false;
|
|
}
|
|
$openTime = 1719828000 + 3600 * 24;
|
|
if (myself()->_getNowTime() < $openTime) {
|
|
if (SERVER_ENV == _ONLINE) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
private function fillBoxMeta(&$info)
|
|
{
|
|
$info['name'] = 'Genesis Hero';
|
|
$info['description'] = 'Genesis Hero';
|
|
$info['image'] = "https://res2.counterfire.games/nft/box/Gen2_raw.gif";
|
|
$info['attributes'] = array();
|
|
}
|
|
|
|
private function fillBoxDetail(&$info)
|
|
{
|
|
$info = array(
|
|
'net_id' => $info['net_id'],
|
|
'contract_address' => $info['contract_address'],
|
|
'token_id' => $info['token_id'],
|
|
'owner_address' => $info['owner_address'],
|
|
'meta_url' => $info['meta_url'],
|
|
'name' => 'Genesis Hero',
|
|
'item_id' => 0,
|
|
'type' => $info['type'],
|
|
'image' => "https://res2.counterfire.games/nft/box/Gen2_raw.gif",
|
|
'on_sale' => $info['on_sale'],
|
|
'detail' => array()
|
|
);
|
|
}
|
|
|
|
private function nftIsOnSale($netId, $contractAddress, $tokenId)
|
|
{
|
|
$row = SqlHelper::ormSelectOne(
|
|
myself()->_getMarketMysql(),
|
|
't_order',
|
|
array(
|
|
'net_id' => $netId,
|
|
'contract_address' => $contractAddress,
|
|
'token_id' => $tokenId,
|
|
'status' => 'ACTIVE',
|
|
)
|
|
);
|
|
return $row ? 1 : 0;
|
|
}
|
|
|
|
private function getRealHeroQuality($heroDb)
|
|
{
|
|
$quality = $heroDb['quality'];;
|
|
if ($heroDb['createtime'] <= 1719985966) {
|
|
} else {
|
|
$quality = $quality - 1;
|
|
if ($quality <= 0) {
|
|
$quality = 1;
|
|
}
|
|
}
|
|
return $quality;
|
|
}
|
|
|
|
}
|