This commit is contained in:
aozhiwei 2022-03-30 21:40:52 +08:00
parent a037de92f4
commit 4871084992
4 changed files with 69 additions and 30 deletions

View File

@ -92,16 +92,9 @@ class GunController extends BaseAuthedController {
public function gunList() public function gunList()
{ {
$gunList = array(); $gunList = array();
SqlHelper::ormSelect( Gun::getGunList(function ($row) use(&$gunList) {
$this->_getSelfMysql(), array_push($gunList, Gun::toDto($row));
't_gun', });
array(
'account_id' => $this->_getAccountId()
),
function ($row) use(&$gunList) {
array_push($gunList, Gun::toDto($row));
}
);
$this->_rspData(array( $this->_rspData(array(
'gun_list' => $gunList 'gun_list' => $gunList
)); ));

View File

@ -5,6 +5,7 @@ namespace models;
require_once('mt/GunLevel.php'); require_once('mt/GunLevel.php');
require_once('mt/GunQuality.php'); require_once('mt/GunQuality.php');
require_once('models/GunSkin.php'); require_once('models/GunSkin.php');
require_once('services/NftService.php');
use mt; use mt;
use phpcommon\SqlHelper; use phpcommon\SqlHelper;
@ -24,31 +25,55 @@ class Gun extends BaseModel {
myself()->_getSelfMysql(), myself()->_getSelfMysql(),
't_gun', 't_gun',
array( array(
'account_id' => myself()->_getAccountId(),
'idx' => $gunUniId, 'idx' => $gunUniId,
) )
); );
if ($row) { if ($row) {
$row['gun_uniid'] = $row['idx']; $row['gun_uniid'] = $row['idx'];
if ($row['account_id'] != myself()->_getAccountId()) {
if (!services\NftService::isEquipOwner($row['token_id'])) {
$row = null;
}
}
} }
return $row; return $row;
} }
public static function getValidGun($gunId) public static function getValidGun($gunId)
{ {
$row = SqlHelper::ormSelectOne( $gunList = array();
myself()->_getSelfMysql(), 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', 't_gun',
array( array(
'account_id' => myself()->_getAccountId(), 'account_id' => $this->_getAccountId()
'gun_id' => $gunId, ),
'state' => self::GETED_STATE, function ($row) use($cb) {
) $cb($row);
}
); );
if ($row) { foreach (services\NftService::getEquips() as $nftDb) {
$row['gun_uniid'] = $row['idx']; $row = SqlHelper::ormSelectOne(
myself()->_getSelfMysql(),
't_gun',
array(
'token_id' => $nftDb['token_id'],
)
);
if ($row) {
$cb($row);
}
} }
return $row;
} }
public static function toDto($row) public static function toDto($row)
@ -145,15 +170,16 @@ class Gun extends BaseModel {
public static function update($gunUniId, $fieldsKv) public static function update($gunUniId, $fieldsKv)
{ {
SqlHelper::update if (self::find($gunUniId)) {
(myself()->_getSelfMysql(), SqlHelper::update
't_gun', (myself()->_getSelfMysql(),
array( 't_gun',
'account_id' => myself()->_getAccountId(), array(
'idx' => $gunUniId, 'idx' => $gunUniId,
), ),
$fieldsKv $fieldsKv
); );
}
} }
} }

View File

@ -60,7 +60,7 @@ class Hero extends BaseModel {
array( array(
'account_id' => $this->_getAccountId() 'account_id' => $this->_getAccountId()
), ),
function ($row) { function ($row) use($cb) {
$cb($row); $cb($row);
} }
); );

View File

@ -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 getHeros()
{ {
} }
public static function getEquips()
{
}
public static function getChips()
{
}
} }