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()
{
$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
));

View File

@ -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
);
}
}
}

View File

@ -60,7 +60,7 @@ class Hero extends BaseModel {
array(
'account_id' => $this->_getAccountId()
),
function ($row) {
function ($row) use($cb) {
$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 getEquips()
{
}
public static function getChips()
{
}
}