_rspData(array( 'data' => $list, )); } public function presetHero(){ $skillId = getReqVal('skill_id',0); $skillMeta = \mt\Skill::get($skillId); if (! $skillMeta){ $this->_rspErr(1,'skill_id parameter error'); return ; } $heroList = array(); Hero::getHeroList(function ($row) use(&$heroList) { array_push($heroList, $row); }); $list = array_unique(array_column($heroList,'hero_id')); $data = array(); if (count($list) > 0){ foreach ($list as $value){ $data[$value] = array( 'item_id' => $value, 'state' => 0 ); } } $rows = SqlHelper::ormSelect( $this->_getSelfMysql(), 't_hero_skill', array( 'account_id' => $this->_getAccountId(), 'skill_id' => $skillId, ) ); if ($rows){ foreach ($rows as $row){ $heroDb = Hero::find($row['hero_uid']); $data[$heroDb['hero_id']]['state'] = 1; } } $this->_rspData(array( 'data' => $data, )); } public function applyHero(){ $skillId = getReqVal('skill_id',0); $heroIds = getReqVal('hero_ids',''); $heroIdArr = explode('|',$heroIds); if (!$skillId || count($heroIdArr)<0){ $this->_rspErr(1,' parameter error'); return ; } $skillMeta = \mt\Skill::get($skillId); if (! $skillMeta){ $this->_rspErr(1,'skill_id parameter error'); return ; } foreach ($heroIdArr as $heroId){ $heroMeta = \mt\Hero::get($heroId); if (! $heroMeta){ $this->_rspErr(1,'hero_id parameter error'); return ; } } foreach ($heroIdArr as $heroId){ $heroList = Hero::getHeroByItemId($heroId); if ($heroList){ foreach ($heroList as $hero){ SqlHelper::upsert ($this->_getSelfMysql(), 't_hero_skill', array( 'account_id' => $this->_getAccountId(), 'hero_uid' => $hero['idx'], ), array( 'skill_id' => $skillId, 'modifytime' => $this->_getNowTime(), ), array( 'account_id' => $this->_getAccountId(), 'hero_uid' => $hero['idx'], 'skill_id' => $skillId, 'createtime' => $this->_getNowTime(), 'modifytime' => $this->_getNowTime(), ) ); } } } $this->_rspOk(); } }