diff --git a/webapp/controller/GunController.class.php b/webapp/controller/GunController.class.php index f6f12285..071d87b2 100644 --- a/webapp/controller/GunController.class.php +++ b/webapp/controller/GunController.class.php @@ -92,16 +92,9 @@ class GunController extends BaseAuthedController { public function gunList() { $gunList = array(); - SqlHelper::ormSelect( - $this->_getSelfMysql(), - 't_gun', - array( - 'account_id' => $this->_getAccountId() - ), - function ($row) use(&$gunList) { - array_push($gunList, Gun::toDto($row)); - } - ); + Gun::getGunList(function ($row) use(&$gunList) { + array_push($gunList, Gun::toDto($row)); + }); $this->_rspData(array( 'gun_list' => $gunList )); diff --git a/webapp/models/Gun.php b/webapp/models/Gun.php index 6df56f75..28bfa273 100644 --- a/webapp/models/Gun.php +++ b/webapp/models/Gun.php @@ -5,6 +5,7 @@ namespace models; require_once('mt/GunLevel.php'); require_once('mt/GunQuality.php'); require_once('models/GunSkin.php'); +require_once('services/NftService.php'); use mt; use phpcommon\SqlHelper; @@ -24,31 +25,55 @@ class Gun extends BaseModel { myself()->_getSelfMysql(), 't_gun', array( - 'account_id' => myself()->_getAccountId(), 'idx' => $gunUniId, ) ); if ($row) { $row['gun_uniid'] = $row['idx']; + if ($row['account_id'] != myself()->_getAccountId()) { + if (!services\NftService::isEquipOwner($row['token_id'])) { + $row = null; + } + } } return $row; } public static function getValidGun($gunId) { - $row = SqlHelper::ormSelectOne( - myself()->_getSelfMysql(), + $gunList = array(); + self::getGunList(function ($row) use($gunId, &$gunList) { + if ($row['gun_id'] == $gunId && $row['state'] == self::GETED_STATE) { + array_push($gunList, self::toDto($row)); + } + }); + return !empty($gunList) ? $gunList[0] : null; + } + + public static function getGunList($cb) + { + SqlHelper::ormSelect( + $this->_getSelfMysql(), 't_gun', array( - 'account_id' => myself()->_getAccountId(), - 'gun_id' => $gunId, - 'state' => self::GETED_STATE, - ) + 'account_id' => $this->_getAccountId() + ), + function ($row) use($cb) { + $cb($row); + } ); - if ($row) { - $row['gun_uniid'] = $row['idx']; + foreach (services\NftService::getEquips() as $nftDb) { + $row = SqlHelper::ormSelectOne( + myself()->_getSelfMysql(), + 't_gun', + array( + 'token_id' => $nftDb['token_id'], + ) + ); + if ($row) { + $cb($row); + } } - return $row; } public static function toDto($row) @@ -145,15 +170,16 @@ class Gun extends BaseModel { public static function update($gunUniId, $fieldsKv) { - SqlHelper::update - (myself()->_getSelfMysql(), - 't_gun', - array( - 'account_id' => myself()->_getAccountId(), - 'idx' => $gunUniId, - ), - $fieldsKv - ); + if (self::find($gunUniId)) { + SqlHelper::update + (myself()->_getSelfMysql(), + 't_gun', + array( + 'idx' => $gunUniId, + ), + $fieldsKv + ); + } } } diff --git a/webapp/models/Hero.php b/webapp/models/Hero.php index 49620651..888c550f 100644 --- a/webapp/models/Hero.php +++ b/webapp/models/Hero.php @@ -60,7 +60,7 @@ class Hero extends BaseModel { array( 'account_id' => $this->_getAccountId() ), - function ($row) { + function ($row) use($cb) { $cb($row); } ); diff --git a/webapp/services/NftService.php b/webapp/services/NftService.php index 82ff1cb6..001b476b 100644 --- a/webapp/services/NftService.php +++ b/webapp/services/NftService.php @@ -12,9 +12,29 @@ class NftService extends BaseService { { } + public static function isEquipOwner($tokenId) + { + + } + + public static function isChipOwner($tokenId) + { + + } + public static function getHeros() { } + public static function getEquips() + { + + } + + public static function getChips() + { + + } + }