diff --git a/webapp/controller/HeroController.class.php b/webapp/controller/HeroController.class.php index 3967d8ea..9c1f8691 100644 --- a/webapp/controller/HeroController.class.php +++ b/webapp/controller/HeroController.class.php @@ -37,14 +37,8 @@ class HeroController extends BaseAuthedController { public function heroList() { $heroList = array(); - $userDb = myself()->_getOrmUserInfo(); - Hero::getHeroList(function ($row) use(&$heroList,$userDb) { - $row['hero_uniid'] = $row['idx']; - $row['is_select'] = 0; - if ($row['idx'] == $userDb['hero_id']){ - $row['is_select'] = 1; - } - array_push($heroList, $row); + Hero::getHeroList(function ($row) use(&$heroList) { + array_push($heroList, Hero::listDto($row)); }); $this->_rspData(array( 'hero_list' => $heroList diff --git a/webapp/models/Hero.php b/webapp/models/Hero.php index 9eb86439..ea7d4b32 100644 --- a/webapp/models/Hero.php +++ b/webapp/models/Hero.php @@ -210,6 +210,42 @@ class Hero extends BaseModel { self::updateByTokenId($row['token_id'],$fieldsKv); } + public static function listDto($row){ + $attr = emptyReplace(json_decode($row['rand_attr'], true), array()); + $userDb = myself()->_getOrmUserInfo(); + $isSelect = 0; + if ($row['idx'] == $userDb['hero_id']){ + $isSelect = 1; + } + $heroMeta = \mt\Item::get($row['hero_id']); + $heroAtteMeta = \mt\EconomyAttribute::findByGrade($heroMeta['relationship'],$row['quality']); + $unsealTime = $row['unseal_time'] ? $row['unseal_time'] : $row['activate_time']; + $validTime = $unsealTime + 86400 * $heroAtteMeta['validTime'] ; + return array( + 'idx' => $row['idx'], + 'token_id' => $row['token_id'], + 'hero_uniid' => $row['idx'], + 'hero_id' => $row['hero_id'], + 'hero_lv' => $row['hero_lv'], + 'hero_tili' => $row['hero_tili'], + 'state' => $row['state'], + 'quality' => $row['quality'], + 'skill_lv1' => $row['skill_lv1'], + 'skill_lv2' => $row['skill_lv2'], + 'rand_attr' => $attr, + 'is_select' => $isSelect, + 'lucky' => self::getHeroLucky($row), + 'wealth' => self::getHeroWealth($row), + 'seal_type' => $row['seal_type'], + 'unseal_time' => $row['unseal_time'], + 'valid_lefttime' => max(0, + $validTime - myself()->_getNowTime()), + 'valid_time' => max(0, + 86400 * $heroAtteMeta['validTime']), + ); + + } + public static function toDto($row) { $attr = emptyReplace(json_decode($row['rand_attr'], true), array());