This commit is contained in:
aozhiwei 2022-04-01 10:36:36 +08:00
parent 6ed02245ef
commit e2add856f0
5 changed files with 56 additions and 65 deletions

View File

@ -25,6 +25,11 @@ class Bag extends BaseModel {
); );
if ($row) { if ($row) {
$row['item_uniid'] = $row['idx']; $row['item_uniid'] = $row['idx'];
if ($row['account_id'] != myself()->_getAccountId()) {
if (!NftService::isEquipOwner(myself()->_getOpenId(), $row['token_id'])) {
$row = null;
}
}
} }
return $row; return $row;
} }
@ -98,7 +103,7 @@ class Bag extends BaseModel {
$cb($row); $cb($row);
} }
); );
foreach (NftService::getChips() as $nftDb) { foreach (NftService::getChips(myself()->_getOpenId()) as $nftDb) {
$row = SqlHelper::ormSelectOne( $row = SqlHelper::ormSelectOne(
myself()->_getSelfMysql(), myself()->_getSelfMysql(),
't_bag', 't_bag',

View File

@ -33,7 +33,7 @@ class Gun extends BaseModel {
if ($row) { if ($row) {
$row['gun_uniid'] = $row['idx']; $row['gun_uniid'] = $row['idx'];
if ($row['account_id'] != myself()->_getAccountId()) { if ($row['account_id'] != myself()->_getAccountId()) {
if (!NftService::isEquipOwner($row['token_id'])) { if (!NftService::isEquipOwner(myself()->_getOpenId(), $row['token_id'])) {
$row = null; $row = null;
} }
} }
@ -80,7 +80,7 @@ class Gun extends BaseModel {
$cb($row); $cb($row);
} }
); );
foreach (NftService::getEquips() as $nftDb) { foreach (NftService::getEquips(myself()->_getOpenId()) as $nftDb) {
$row = SqlHelper::ormSelectOne( $row = SqlHelper::ormSelectOne(
myself()->_getSelfMysql(), myself()->_getSelfMysql(),
't_gun', 't_gun',

View File

@ -35,7 +35,7 @@ class Hero extends BaseModel {
if ($row) { if ($row) {
$row['hero_uniid'] = $row['idx']; $row['hero_uniid'] = $row['idx'];
if ($row['account_id'] != myself()->_getAccountId()) { if ($row['account_id'] != myself()->_getAccountId()) {
if (!NftService::isHeroOwner($row['token_id'])) { if (!NftService::isHeroOwner(myself()->_getOpenId(), $row['token_id'])) {
$row = null; $row = null;
} }
} }
@ -66,7 +66,7 @@ class Hero extends BaseModel {
$cb($row); $cb($row);
} }
); );
foreach (NftService::getHeros() as $nftDb) { foreach (NftService::getHeros(myself()->_getOpenId()) as $nftDb) {
$row = SqlHelper::ormSelectOne( $row = SqlHelper::ormSelectOne(
myself()->_getSelfMysql(), myself()->_getSelfMysql(),
't_hero', 't_hero',

View File

@ -38,7 +38,7 @@ class Nft extends BaseModel {
return self::NONE_TYPE; return self::NONE_TYPE;
} }
public function getNftList($account) public static function getNftList($account)
{ {
$nftList = array(); $nftList = array();
SqlHelper::ormSelect( SqlHelper::ormSelect(
@ -54,7 +54,7 @@ class Nft extends BaseModel {
return $nftList; return $nftList;
} }
public function getNftListByType($account, $type) public static function getNftListByType($account, $type)
{ {
$nftList = array(); $nftList = array();
SqlHelper::ormSelect( SqlHelper::ormSelect(
@ -71,7 +71,7 @@ class Nft extends BaseModel {
return $nftList; return $nftList;
} }
public function getNft($tokenId) public static function getNft($tokenId)
{ {
$row = SqlHelper::ormSelectOne( $row = SqlHelper::ormSelectOne(
myself()->_getMarketMysql(), myself()->_getMarketMysql(),

View File

@ -8,85 +8,71 @@ use models\Nft;
class NftService extends BaseService { class NftService extends BaseService {
private static $heroList = null; private static $userData = array();
private static $heroHash = null; private static $nftCfg = array(
private static $equipList = null; 'hero' => Nft::HERO_TYPE,
private static $equipHash = null; 'equip' => Nft::EQUIP_TYPE,
private static $chipList = null; 'chip' => Nft::CHIP_TYPE,
private static $chipHash = null; );
public static function isHeroOwner($tokenId) public static function isHeroOwner($openId, $tokenId)
{ {
self::mustBeHeros(); return self::internalIsOwner($openId, 'hero', $tokenId);
$nftDB = getXVal(self::$heroHash, $tokenId);
return $nftDb && $nftDB['owner_address'] == myself()->_getOpenId();
} }
public static function isEquipOwner($tokenId) public static function isEquipOwner($openId, $tokenId)
{ {
self::mustBeEquips(); return self::internalIsOwner($openId, 'equip', $tokenId);
$nftDb = getXVal(self::$equipHash, $tokenId);
return $nftDb && $nftDB['owner_address'] == myself()->_getOpenId();
} }
public static function isChipOwner($tokenId) public static function isChipOwner($openId, $tokenId)
{ {
self::mustBeChips(); return self::internalIsOwner($openId, 'chip', $tokenId);
$nftDb = getXVal(self::$chipHash, $tokenId);
return $nftDb && $nftDB['owner_address'] == myself()->_getOpenId();
} }
public static function getHeros() public static function getHeros($openId)
{ {
self::mustBeHeros(); return self::internalGetList($openId, 'hero');
return self::$heroList;
} }
public static function getEquips() public static function getEquips($openId)
{ {
self::mustBeEquips(); return self::internalGetList($openId, 'equip');
return self::$equipList;
} }
public static function getChips() public static function getChips($openId)
{ {
self::mustBeChips(); return self::internalGetList($openId, 'chip');
return self::$chipList;
} }
private static function mustBeHeros() private static function internalGetList($openId, $name)
{ {
if (is_null(self::$heroList)) { self::loadNft($openId, $name);
self::$heroList = Nft::GetNftListByType(myself()->_getOpenId(), Nft::HERO_TYPE); return getXVal(self::$userData[$openid], $name . 'List');
self::$heroHash = array(); }
foreach (self::$heroList as $nftDb) {
self::$heroHash[$nftDb['token_id']] = $nftDb; private static function internalIsOwner($openId, $name, $tokenId)
} {
//error_log(json_encode(self::$heroList)); self::loadNft($openId, $name);
$nftHash = getXVal(self::$userData[$openid], $name . 'Hash', array());
$nftDB = getXVal($nftHash, $tokenId);
return $nftDb && $nftDB['owner_address'] == $openId;
}
private static function loadNft($openId, $name)
{
if (!in_array($openId, self::$userData)) {
self::$userData[$openId] = array();
} }
} if (!in_array($name . 'List', self::$userData[$openId])) {
$listName = $name . 'List';
private static function mustBeEquips() $hashName = $name . 'Hash';
{ $tokenType = self::$nftCfg[$name];
if (is_null(self::$equipList)) { self::$userData[$openId][$listName] = Nft::GetNftListByType($openId, $tokenType);
self::$equipList = Nft::GetNftListByType(myself()->_getOpenId(), Nft::EQUIP_TYPE); self::$userData[$openId][$hashName] = array();
self::$equipHash = array(); foreach (self::$userData[$openId][$listName] as $nftDb) {
foreach (self::$equipList as $nftDb) { self::$userData[$openId][$hashName][$nftDb['token_id']] = $nftDb;
self::$equipHash[$nftDb['token_id']] = $nftDb;
} }
//error_log(json_encode(self::$equipList));
}
}
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;
}
//error_log(json_encode(self::$chipList));
} }
} }