game2006api/webapp/controller/NftController.class.php
aozhiwei 675580afb8 1
2023-11-10 18:01:43 +08:00

149 lines
4.9 KiB
PHP

<?php
require_once('models/Nft.php');
require_once('models/Hero.php');
require_once('models/Gun.php');
require_once('models/Chip.php');
use phpcommon\SqlHelper;
use models\Nft;
use models\Hero;
use models\Gun;
use models\Chip;
class NftController extends BaseAuthedController
{
public function getNftList(){
$nftList = Nft::getNftList($this->_getAddress());
$listInfo = array();
if ($nftList){
foreach ($nftList as $nft){
$info = array(
"idx" => $nft['idx'],
"item_id" => $nft['item_id'],
"token_id" => $nft['token_id'],
"token_type" => $nft['token_type'],
"contract_address" => $nft['contract_address'],
"createtime" => $nft['createtime'],
"details" => array(),
);
switch ($nft['token_type']){
case Nft::HERO_TYPE : {
$heroDb = Hero::findByTokenId($nft['token_id']);
if ($heroDb){
$info['details'] = Hero::toDto($heroDb);
}
array_push($listInfo,$info);
}
break;
case Nft::EQUIP_TYPE : {
$gunDb = Gun::findByTokenId($nft['token_id']);
if ($gunDb){
$info['details'] = Gun::toDto($gunDb);
}
array_push($listInfo,$info);
}
break;
case Nft::CHIP_TYPE : {
$chipDb = Chip::findByTokenId($nft['token_id']);
if ($chipDb){
$info['details'] = Chip::toDto($chipDb);
}
array_push($listInfo,$info);
}
break;
case Nft::HONOR1_TYPE : {
array_push($listInfo,$info);
}
break;
case Nft::GENESIS_TYPE : {
array_push($listInfo,$info);
}
break;
case Nft::PLANET_TYPE : {
array_push($listInfo,$info);
}
break;
case Nft::EXPLORER_TYPE : {
array_push($listInfo,$info);
}
break;
}
}
}
$this->_rspData(array(
'nfts' => $listInfo,
));
}
public function getNftListByType(){
$tokenType= trim(getReqVal('token_type', 0));
$nftList = Nft::getNftList($this->_getAddress());
$data = array();
if ($nftList){
foreach ($nftList as $nft){
$info = array(
"idx" => $nft['idx'],
"item_id" => $nft['item_id'],
"token_id" => $nft['token_id'],
"token_type" => $nft['token_type'],
"createtime" => $nft['createtime'],
);
if ($tokenType == $nft['token_type']){
array_push($data,$info);
}
}
}
$this->_rspData(array(
'nfts' => $data,
));
}
public function NftDetail(){
$netId = trim(getReqVal('net_id', 0));
$tokenId = trim(getReqVal('token_id', 0));
if (! $tokenId){
$this->_rspErr(1, 'Please enter parameter token_id');
return ;
}
$nftDb = Nft::getNft($tokenId);
if (! $nftDb){
$this->_rspErr(1, 'parameter error');
return ;
}
$info = array(
"idx" => $nftDb['idx'],
"item_id" => $nftDb['item_id'],
"token_id" => $nftDb['token_id'],
"token_type" => $nftDb['token_type'],
"createtime" => $nftDb['createtime'],
"details" => array(),
);
switch ($nftDb['token_type']){
case Nft::HERO_TYPE : {
$heroDb = Hero::findByTokenId2($nftDb['token_id']);
if ($heroDb){
$info['details'] = Hero::toDto($heroDb);
}
}
break;
case Nft::EQUIP_TYPE : {
$gunDb = Gun::findByTokenId2($nftDb['token_id']);
if ($gunDb){
$info['details'] = Gun::toDto($gunDb);
}
}
break;
case Nft::CHIP_TYPE : {
$chipDb = Chip::findByTokenId2($nftDb['token_id']);
if ($chipDb){
$info['details'] = Chip::toDto($chipDb);
}
}
}
$this->_rspData(array(
'info' => $info,
));
}
}