1
This commit is contained in:
parent
f8cafa49fd
commit
f49f3ef9f9
@ -7,6 +7,10 @@ use phpcommon\SqlHelper;
|
|||||||
|
|
||||||
class Nft extends BaseModel {
|
class Nft extends BaseModel {
|
||||||
|
|
||||||
|
const HERO_TYPE = 0;
|
||||||
|
const EQUIP_TYPE = 1;
|
||||||
|
const CHIP_TYPE = 2;
|
||||||
|
|
||||||
public function getNftList($account)
|
public function getNftList($account)
|
||||||
{
|
{
|
||||||
$nftList = array();
|
$nftList = array();
|
||||||
@ -23,6 +27,23 @@ class Nft extends BaseModel {
|
|||||||
return $nftList;
|
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)
|
public function getNft($tokenId)
|
||||||
{
|
{
|
||||||
$row = SqlHelper::ormSelectOne(
|
$row = SqlHelper::ormSelectOne(
|
||||||
|
@ -2,39 +2,89 @@
|
|||||||
|
|
||||||
namespace services;
|
namespace services;
|
||||||
|
|
||||||
|
require_once('models/Nft.php');
|
||||||
|
|
||||||
|
use models\Nft;
|
||||||
|
|
||||||
class NftService extends BaseService {
|
class NftService extends BaseService {
|
||||||
|
|
||||||
private static $heros = null;
|
private static $heroList = null;
|
||||||
private static $equips = null;
|
private static $heroHash = null;
|
||||||
private static $chips = null;
|
private static $equipList = null;
|
||||||
|
private static $equipHash = null;
|
||||||
|
private static $chipList = null;
|
||||||
|
private static $chipHash = null;
|
||||||
|
|
||||||
public static function isHeroOwner($tokenId)
|
public static function isHeroOwner($tokenId)
|
||||||
{
|
{
|
||||||
|
self::mustBeHeros();
|
||||||
|
$nftDB = getXVal(self::heroHash, $tokenId);
|
||||||
|
return $nftDb && $nftDB['owner_address'] == myself()->_getOpenId();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function isEquipOwner($tokenId)
|
public static function isEquipOwner($tokenId)
|
||||||
{
|
{
|
||||||
|
self::mustBeEquips();
|
||||||
|
$nftDb = getXVal(self::equipHash, $tokenId);
|
||||||
|
return $nftDb && $nftDB['owner_address'] == myself()->_getOpenId();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function isChipOwner($tokenId)
|
public static function isChipOwner($tokenId)
|
||||||
{
|
{
|
||||||
|
self::mustBeChips();
|
||||||
|
$nftDb = getXVal(self::chipHash, $tokenId);
|
||||||
|
return $nftDb && $nftDB['owner_address'] == myself()->_getOpenId();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getHeros()
|
public static function getHeros()
|
||||||
{
|
{
|
||||||
|
self::mustBeHeros();
|
||||||
|
return self::heroList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getEquips()
|
public static function getEquips()
|
||||||
{
|
{
|
||||||
|
self::mustBeEquips();
|
||||||
|
return self::equipList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getChips()
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user