game2006api/webapp/controller/TempToolsController.class.php
aozhiwei ae9893d4f7 1
2022-06-01 10:25:24 +08:00

59 lines
1.6 KiB
PHP

<?php
use phpcommon\SqlHelper;
class TempToolsController extends BaseController {
public function _handlePre()
{
parent::_handlePre();
}
public function getBattleData()
{
$targetId = getReqVal('target_id', '');
$time = getReqVal('time', '');
$conn = myself()->_getMysql($targetId);
$data = array();
$survivalTime = 0;
$sameTimes = 0;
{
$rows = SqlHelper::ormSelect(
$conn,
't_battle_record',
array(
'account_id' => $targetId
)
);
foreach ($rows as $row) {
$reqObj = json_decode($row['request'], true);
$reqObj['start_time'] = $reqObj['game_time'] -
$reqObj['alive_time']/1000;
$survivalTime += $reqObj['alive_time']/1000;
array_push($data, $reqObj);
}
}
usort($data, function ($a, $b) {
return $a['start_time'] < $b['start_time'] ? -1 : 1;
});
{
for ($i = 0; $i < count($data); ++$i){
if ($i + 1 >= count($data)) {
break;
}
if ($data[$i]['start_time'] + $time < $data[$i + 1]['start_time']) {
++$i;
++$sameTimes;
}
}
}
myself()->_rspData(array(
'battle_times' => count($data),
'same_times' => $sameTimes,
'survival_time' => $survivalTime,
'data' => $data
));
}
}