115 lines
3.5 KiB
PHP
115 lines
3.5 KiB
PHP
<?php
|
|
require_once('mt/Skill.php');
|
|
require_once('mt/Hero.php');
|
|
|
|
require_once('models/Hero.php');
|
|
|
|
|
|
use models\Hero;
|
|
use phpcommon\SqlHelper;
|
|
|
|
class HeroSkillController extends BaseAuthedController
|
|
{
|
|
public function getSkillList(){
|
|
// $skillList = \mt\Skill::getPresetSkill();
|
|
// $list = array();
|
|
// foreach ($skillList as $skill){
|
|
// $list[] = $skill['skill_id'];
|
|
// }
|
|
$list = array(10101,10201,10301,10401,10501);
|
|
$this->_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();
|
|
}
|
|
} |