82 lines
2.5 KiB
PHP
82 lines
2.5 KiB
PHP
<?php
|
|
|
|
require_once('models/Hero.php');
|
|
require_once('services/BattleDataService.php');
|
|
|
|
use phpcommon\SqlHelper;
|
|
use models\Hero;
|
|
|
|
class BattleController extends BaseAuthedController {
|
|
|
|
public function preBattleCheck()
|
|
{
|
|
$this->_rspData(array(
|
|
'pre_battle_payload' => ''
|
|
));
|
|
}
|
|
|
|
public function battleReport()
|
|
{
|
|
$userInfo = $this->_getOrmUserInfo();
|
|
if (!$userInfo) {
|
|
$this->_rspErr(1, 'Without this player1');
|
|
return;
|
|
}
|
|
$battleDataService = new services\BattleDataService();
|
|
$battleDataService->updateBattleData();
|
|
SqlHelper::insert(
|
|
$this->_getSelfMysql(),
|
|
't_battle_record',
|
|
array(
|
|
'account_id' => $this->_getAccountId(),
|
|
'request' => json_encode($_REQUEST),
|
|
'createtime' => $this->_getNowTime(),
|
|
'modifytime' => $this->_getNowTime(),
|
|
)
|
|
);
|
|
$this->_rspOk();
|
|
}
|
|
|
|
public function getBattleData()
|
|
{
|
|
$mode = getReqVal('mode', '');
|
|
$members = json_decode(getReqVal('members', ''), true);
|
|
|
|
$data = array(
|
|
'members' => array()
|
|
);
|
|
error_log(json_encode($members));
|
|
foreach ($members as $member) {
|
|
$info = array(
|
|
'account_id' => $member['account_id'],
|
|
'session_id' => $member['session_id'],
|
|
'hero_uniid' => $member['hero_uniid'],
|
|
'battle_uuid' => $member['battle_uuid'],
|
|
'hero_dto' => '',
|
|
|
|
'is_valid_battle' => 0,
|
|
'payload' => json_encode($member['cmjoin']),
|
|
'errcode' => 0,
|
|
'errmsg' => '',
|
|
);
|
|
if (!phpcommon\isValidSessionId($member['account_id'], $member['session_id'])) {
|
|
$info['errcode'] = 50;
|
|
$info['errmsg'] = 'invalid session_id';
|
|
} else {
|
|
$heroDb = Hero::findByAccountId($member['account_id'], $member['hero_uniid']);
|
|
if ($heroDb) {
|
|
$info['is_valid_battle'] = 1;
|
|
$info['hero_dto'] = json_encode($Hero::toDto($heroDb));
|
|
} else {
|
|
$info['errcode'] = 51;
|
|
$info['errmsg'] = 'paramater error';
|
|
}
|
|
}
|
|
array_push($data['members'], $info);
|
|
}
|
|
error_log(json_encode($data));
|
|
myself()->_rspData($data);
|
|
}
|
|
|
|
}
|