This commit is contained in:
aozhiwei 2022-03-30 17:10:41 +08:00
parent 1a44f98abc
commit a037de92f4
3 changed files with 80 additions and 44 deletions

View File

@ -25,16 +25,9 @@ class HeroController extends BaseAuthedController {
public function heroList()
{
$heroList = array();
SqlHelper::ormSelect(
$this->_getSelfMysql(),
't_hero',
array(
'account_id' => $this->_getAccountId()
),
function ($row) use(&$heroList) {
array_push($heroList, Hero::toDto($row));
}
);
Hero::getHeroList(function ($row) use(&$heroList) {
array_push($heroList, Hero::toDto($row));
});
$this->_rspData(array(
'hero_list' => $heroList
));

View File

@ -7,6 +7,7 @@ require_once('mt/HeroLevel.php');
require_once('mt/HeroQuality.php');
require_once('mt/AttrHelper.php');
require_once('models/HeroSkin.php');
require_once('services/NftService.php');
use mt;
use phpcommon\SqlHelper;
@ -26,31 +27,55 @@ class Hero extends BaseModel {
myself()->_getSelfMysql(),
't_hero',
array(
'account_id' => myself()->_getAccountId(),
'idx' => $heroUniId,
)
);
if ($row) {
$row['hero_uniid'] = $row['idx'];
if ($row['account_id'] != myself()->_getAccountId()) {
if (!services\NftService::isHeroOwner($row['token_id'])) {
$row = null;
}
}
}
return $row;
}
public static function getValidHero($heroId)
{
$row = SqlHelper::ormSelectOne(
myself()->_getSelfMysql(),
$heroList = array();
Hero::getHeroList(function ($row) use($heroId, &$heroList) {
if ($row['hero_id'] == $heroId && $row['state'] == self::GETED_STATE) {
array_push($heroList, Hero::toDto($row));
}
});
return !empty($heroList) ? $heroList[0] : null;
}
public static function getHeroList($cb)
{
SqlHelper::ormSelect(
$this->_getSelfMysql(),
't_hero',
array(
'account_id' => myself()->_getAccountId(),
'hero_id' => $heroId,
'state' => self::GETED_STATE,
)
'account_id' => $this->_getAccountId()
),
function ($row) {
$cb($row);
}
);
if ($row) {
$row['hero_uniid'] = $row['idx'];
foreach (services\NftService::getHeros() as $nftDb) {
$row = SqlHelper::ormSelectOne(
myself()->_getSelfMysql(),
't_hero',
array(
'token_id' => $nftDb['token_id'],
)
);
if ($row) {
$cb($row);
}
}
return $row;
}
public static function toDto($row)
@ -68,6 +93,7 @@ class Hero extends BaseModel {
mt\AttrHelper::mergeAttr($attr, $baseAttr);
}
$dto = array(
'token_id' => $row['token_id'],
'hero_uniid' => $row['idx'],
'hero_id' => $row['hero_id'],
'hero_lv' => $row['hero_lv'],
@ -181,37 +207,34 @@ class Hero extends BaseModel {
public static function update($heroUniId, $fieldsKv)
{
SqlHelper::update
(myself()->_getSelfMysql(),
't_hero',
array(
'account_id' => myself()->_getAccountId(),
'idx' => $heroUniId,
),
$fieldsKv
);
if (self::find($heroUniId)) {
SqlHelper::update
(myself()->_getSelfMysql(),
't_hero',
array(
'idx' => $heroUniId,
),
$fieldsKv
);
}
}
public static function randHero(&$heroUniId, &$heroId)
{
$heroUniId = 0;
$heroId = 0;
$rows = SqlHelper::select(
myself()->_getSelfMysql(),
't_hero',
array(
'idx',
'hero_id'
),
array(
'account_id' => myself()->_getAccountId(),
'state' => self::GETED_STATE
)
);
$key = array_rand($rows, 1);
$heroList = array();
Hero::getHeroList(function ($row) use($heroId, &$heroList) {
if ($row['state'] == self::GETED_STATE) {
array_push($heroList, Hero::toDto($row));
}
});
$key = array_rand($heroList, 1);
if (!is_null($key)) {
$heroUniId = $rows[$key]['idx'];
$heroId = $rows[$key]['hero_id'];
$heroUniId = $heroList[$key]['idx'];
$heroId = $heroList[$key]['hero_id'];
}
}

View File

@ -0,0 +1,20 @@
<?php
namespace services;
class NftService extends BaseService {
private static $heros = null;
private static $equips = null;
private static $chips = null;
public static function isHeroOwner($tokenId)
{
}
public static function getHeros()
{
}
}