This commit is contained in:
aozhiwei 2022-03-31 08:51:34 +08:00
parent f8cafa49fd
commit f49f3ef9f9
2 changed files with 78 additions and 7 deletions

View File

@ -7,6 +7,10 @@ use phpcommon\SqlHelper;
class Nft extends BaseModel {
const HERO_TYPE = 0;
const EQUIP_TYPE = 1;
const CHIP_TYPE = 2;
public function getNftList($account)
{
$nftList = array();
@ -23,6 +27,23 @@ class Nft extends BaseModel {
return $nftList;
}
public function getNftListByType($account, $type)
{
$nftList = array();
SqlHelper::ormSelect(
myself()->_getMarketMysql(),
't_nft',
array(
'owner_address' => $account,
'token_type' => $type,
),
function ($row) use(&$nftList) {
array_push($nftList, $row);
}
);
return $nftList;
}
public function getNft($tokenId)
{
$row = SqlHelper::ormSelectOne(

View File

@ -2,39 +2,89 @@
namespace services;
require_once('models/Nft.php');
use models\Nft;
class NftService extends BaseService {
private static $heros = null;
private static $equips = null;
private static $chips = null;
private static $heroList = null;
private static $heroHash = null;
private static $equipList = null;
private static $equipHash = null;
private static $chipList = null;
private static $chipHash = null;
public static function isHeroOwner($tokenId)
{
self::mustBeHeros();
$nftDB = getXVal(self::heroHash, $tokenId);
return $nftDb && $nftDB['owner_address'] == myself()->_getOpenId();
}
public static function isEquipOwner($tokenId)
{
self::mustBeEquips();
$nftDb = getXVal(self::equipHash, $tokenId);
return $nftDb && $nftDB['owner_address'] == myself()->_getOpenId();
}
public static function isChipOwner($tokenId)
{
self::mustBeChips();
$nftDb = getXVal(self::chipHash, $tokenId);
return $nftDb && $nftDB['owner_address'] == myself()->_getOpenId();
}
public static function getHeros()
{
self::mustBeHeros();
return self::heroList;
}
public static function getEquips()
{
self::mustBeEquips();
return self::equipList;
}
public static function getChips()
{
self::mustBeChips();
return self::chipList;
}
private static function mustBeHeros()
{
if (is_null(self::heroList)) {
self::heroList = Nft::GetNftListByType(myself()->_getOpenId(), Nft::HERO_TYPE);
self::heroHash = array();
foreach (self::heroList as $nftDb) {
self::heroHash[$nftDb['token_id']] = $nftDb;
}
}
}
private static function mustBeEquips()
{
if (is_null(self::equipList)) {
self::equipList = Nft::GetNftListByType(myself()->_getOpenId(), Nft::EQUIP_TYPE);
self::equipHash = array();
foreach (self::equipList as $nftDb) {
self::equipHash[$nftDb['token_id']] = $nftDb;
}
}
}
private static function mustBeChips()
{
if (is_null(self::chipList)) {
self::chipList = Nft::GetNftListByType(myself()->_getOpenId(), Nft::CHIP_TYPE);
self::chipHash = array();
foreach (self::chipList as $nftDb) {
self::chipHash[$nftDb['token_id']] = $nftDb;
}
}
}
}