99 lines
3.1 KiB
PHP
99 lines
3.1 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'],
|
|
"token_id" => $nft['token_id'],
|
|
"token_type" => $nft['token_type'],
|
|
"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);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
$this->_rspData(array(
|
|
'nfts' => $listInfo,
|
|
));
|
|
|
|
}
|
|
|
|
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 ;
|
|
}
|
|
$details = array();
|
|
switch ($nftDb['token_type']){
|
|
case Nft::HERO_TYPE : {
|
|
$heroDb = Hero::findByTokenId($nftDb['token_id']);
|
|
if ($heroDb){
|
|
$details = Hero::toDto($heroDb);
|
|
}
|
|
}
|
|
break;
|
|
case Nft::EQUIP_TYPE : {
|
|
$gunDb = Gun::findByTokenId($nftDb['token_id']);
|
|
if ($gunDb){
|
|
$details = Gun::toDto($gunDb);
|
|
}
|
|
}
|
|
break;
|
|
case Nft::CHIP_TYPE : {
|
|
$chipDb = Chip::findByTokenId($nftDb['token_id']);
|
|
if ($chipDb){
|
|
$details = Chip::toDto($chipDb);
|
|
}
|
|
}
|
|
}
|
|
$this->_rspData(array(
|
|
'info' => $details,
|
|
));
|
|
}
|
|
|
|
} |