hero ok
This commit is contained in:
parent
1a44f98abc
commit
a037de92f4
@ -25,16 +25,9 @@ class HeroController extends BaseAuthedController {
|
|||||||
public function heroList()
|
public function heroList()
|
||||||
{
|
{
|
||||||
$heroList = array();
|
$heroList = array();
|
||||||
SqlHelper::ormSelect(
|
Hero::getHeroList(function ($row) use(&$heroList) {
|
||||||
$this->_getSelfMysql(),
|
array_push($heroList, Hero::toDto($row));
|
||||||
't_hero',
|
});
|
||||||
array(
|
|
||||||
'account_id' => $this->_getAccountId()
|
|
||||||
),
|
|
||||||
function ($row) use(&$heroList) {
|
|
||||||
array_push($heroList, Hero::toDto($row));
|
|
||||||
}
|
|
||||||
);
|
|
||||||
$this->_rspData(array(
|
$this->_rspData(array(
|
||||||
'hero_list' => $heroList
|
'hero_list' => $heroList
|
||||||
));
|
));
|
||||||
|
@ -7,6 +7,7 @@ require_once('mt/HeroLevel.php');
|
|||||||
require_once('mt/HeroQuality.php');
|
require_once('mt/HeroQuality.php');
|
||||||
require_once('mt/AttrHelper.php');
|
require_once('mt/AttrHelper.php');
|
||||||
require_once('models/HeroSkin.php');
|
require_once('models/HeroSkin.php');
|
||||||
|
require_once('services/NftService.php');
|
||||||
|
|
||||||
use mt;
|
use mt;
|
||||||
use phpcommon\SqlHelper;
|
use phpcommon\SqlHelper;
|
||||||
@ -26,31 +27,55 @@ class Hero extends BaseModel {
|
|||||||
myself()->_getSelfMysql(),
|
myself()->_getSelfMysql(),
|
||||||
't_hero',
|
't_hero',
|
||||||
array(
|
array(
|
||||||
'account_id' => myself()->_getAccountId(),
|
|
||||||
'idx' => $heroUniId,
|
'idx' => $heroUniId,
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
if ($row) {
|
if ($row) {
|
||||||
$row['hero_uniid'] = $row['idx'];
|
$row['hero_uniid'] = $row['idx'];
|
||||||
|
if ($row['account_id'] != myself()->_getAccountId()) {
|
||||||
|
if (!services\NftService::isHeroOwner($row['token_id'])) {
|
||||||
|
$row = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return $row;
|
return $row;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getValidHero($heroId)
|
public static function getValidHero($heroId)
|
||||||
{
|
{
|
||||||
$row = SqlHelper::ormSelectOne(
|
$heroList = array();
|
||||||
myself()->_getSelfMysql(),
|
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',
|
't_hero',
|
||||||
array(
|
array(
|
||||||
'account_id' => myself()->_getAccountId(),
|
'account_id' => $this->_getAccountId()
|
||||||
'hero_id' => $heroId,
|
),
|
||||||
'state' => self::GETED_STATE,
|
function ($row) {
|
||||||
)
|
$cb($row);
|
||||||
|
}
|
||||||
);
|
);
|
||||||
if ($row) {
|
foreach (services\NftService::getHeros() as $nftDb) {
|
||||||
$row['hero_uniid'] = $row['idx'];
|
$row = SqlHelper::ormSelectOne(
|
||||||
|
myself()->_getSelfMysql(),
|
||||||
|
't_hero',
|
||||||
|
array(
|
||||||
|
'token_id' => $nftDb['token_id'],
|
||||||
|
)
|
||||||
|
);
|
||||||
|
if ($row) {
|
||||||
|
$cb($row);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return $row;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function toDto($row)
|
public static function toDto($row)
|
||||||
@ -68,6 +93,7 @@ class Hero extends BaseModel {
|
|||||||
mt\AttrHelper::mergeAttr($attr, $baseAttr);
|
mt\AttrHelper::mergeAttr($attr, $baseAttr);
|
||||||
}
|
}
|
||||||
$dto = array(
|
$dto = array(
|
||||||
|
'token_id' => $row['token_id'],
|
||||||
'hero_uniid' => $row['idx'],
|
'hero_uniid' => $row['idx'],
|
||||||
'hero_id' => $row['hero_id'],
|
'hero_id' => $row['hero_id'],
|
||||||
'hero_lv' => $row['hero_lv'],
|
'hero_lv' => $row['hero_lv'],
|
||||||
@ -181,37 +207,34 @@ class Hero extends BaseModel {
|
|||||||
|
|
||||||
public static function update($heroUniId, $fieldsKv)
|
public static function update($heroUniId, $fieldsKv)
|
||||||
{
|
{
|
||||||
SqlHelper::update
|
if (self::find($heroUniId)) {
|
||||||
(myself()->_getSelfMysql(),
|
SqlHelper::update
|
||||||
't_hero',
|
(myself()->_getSelfMysql(),
|
||||||
array(
|
't_hero',
|
||||||
'account_id' => myself()->_getAccountId(),
|
array(
|
||||||
'idx' => $heroUniId,
|
'idx' => $heroUniId,
|
||||||
),
|
),
|
||||||
$fieldsKv
|
$fieldsKv
|
||||||
);
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function randHero(&$heroUniId, &$heroId)
|
public static function randHero(&$heroUniId, &$heroId)
|
||||||
{
|
{
|
||||||
$heroUniId = 0;
|
$heroUniId = 0;
|
||||||
$heroId = 0;
|
$heroId = 0;
|
||||||
$rows = SqlHelper::select(
|
|
||||||
myself()->_getSelfMysql(),
|
$heroList = array();
|
||||||
't_hero',
|
Hero::getHeroList(function ($row) use($heroId, &$heroList) {
|
||||||
array(
|
if ($row['state'] == self::GETED_STATE) {
|
||||||
'idx',
|
array_push($heroList, Hero::toDto($row));
|
||||||
'hero_id'
|
}
|
||||||
),
|
});
|
||||||
array(
|
|
||||||
'account_id' => myself()->_getAccountId(),
|
$key = array_rand($heroList, 1);
|
||||||
'state' => self::GETED_STATE
|
|
||||||
)
|
|
||||||
);
|
|
||||||
$key = array_rand($rows, 1);
|
|
||||||
if (!is_null($key)) {
|
if (!is_null($key)) {
|
||||||
$heroUniId = $rows[$key]['idx'];
|
$heroUniId = $heroList[$key]['idx'];
|
||||||
$heroId = $rows[$key]['hero_id'];
|
$heroId = $heroList[$key]['hero_id'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
20
webapp/services/NftService.php
Normal file
20
webapp/services/NftService.php
Normal 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()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user