_getMysql($targetId); $data = array(); $survivalTime = 0; $sameTimes = 0; $sessionChgTimes = 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; }); $lastSessionId = ''; { 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; } if ($lastSessionId) { if ($lastSessionId != $data[$i]['session_id']) { ++$sessionChgTimes; $lastSessionId = $data[$i]['session_id']; } } else { $lastSessionId = $data[$i]['session_id']; } } } myself()->_rspData(array( 'battle_times' => count($data), 'same_times' => $sameTimes, 'session_chg_times' => $sessionChgTimes, 'survival_time' => $survivalTime, 'data' => $data )); } public function exportRankActivity() { $type = getReqVal('type', ''); $count = getReqVal('count', ''); $accounts = array(); $conn = myself()->_getMysql(''); { $rows = $conn->execQuery( 'SELECT * FROM t_rank_activity ' . 'WHERE type=:type AND channel=:channel AND value>=:value ' . 'ORDER BY value DESC, modifytime ASC ' . "LIMIT ${count}", array( ':type' => $type, ':channel' => 6516, ':value' => 600 ) ); $ranked = 1; foreach ($rows as $row) { array_push($accounts, array( 'account_id' => $row['account_id'], 'name' => '', 'ranked' => $ranked, 'score' => $row['value'] )); ++$ranked; } } { foreach ($accounts as &$account) { $row = SqlHelper::ormSelectone( $conn, 't_user', array( 'account_id' => $account['account_id'] ) ); $account['name'] = $row['name']; } } echo 'account_id,name,rank' . "\n"; foreach ($accounts as $account) { echo $account['account_id'] . ',' . $account['name'] . ',' . $account['ranked'] . "\n"; } } public function getRiskAccounts() { $accounts = array(); $conn = myself()->_getMysql(''); { $count = 1000; $rows = $conn->execQuery( 'SELECT * FROM t_rank_activity ' . 'WHERE type=:type AND channel=:channel AND value>=:value ' . 'ORDER BY value DESC, modifytime ASC ' . "LIMIT ${count}", array( ':type' => 1, ':channel' => 6516, ':value' => 600 ) ); $ranked = 1; foreach ($rows as $row) { array_push($accounts, array( 'account_id' => $row['account_id'], 'ranked' => $ranked )); ++$ranked; } } $riskAccountHash = array(); foreach ($accounts as $account) { $rows = SqlHelper::ormSelect( $conn, 't_battle_record', array( 'account_id' => $account['account_id'] ) ); $sessionChgTimes = 0; $lastSessionId = ''; foreach ($rows as $row) { $reqObj = json_decode($row['request'], true); if ($lastSessionId) { if ($lastSessionId != $reqObj['session_id']) { ++$sessionChgTimes; $lastSessionId = $reqObj['session_id']; } } else { $lastSessionId = $reqObj['session_id']; } } $account['session_changed_times'] = $sessionChgTimes; array_push($riskAccountHash, $account); } usort($riskAccountHash, function ($a, $b) { return $a['session_changed_times'] > $b['session_changed_times'] ? -1 : 1; }); echo 'account_id,rank,session_changed_times' . "\n"; foreach ($riskAccountHash as $account) { echo $account['account_id'] . ',' . $account['ranked'] . ',' . $account['session_changed_times'] . "\n"; } } public function exportData() { $type = getReqVal('type', ''); if ($type == 1) { $this->exportData1(); } else if($type == 2) { $this->exportData2(); } else if($type == 3) { $this->exportData3(); } } public function exportData1() { $type = getReqVal('type', ''); $accounts = array(); $conn = myself()->_getMysql(''); { $rows = $conn->execQuery( 'SELECT * FROM t_battle', array( ) ); echo 'account_id,first_battle_utc_time' . "\n"; foreach ($rows as $row) { $channel = phpcommon\extractChannel($row['account_id']); if ($channel == 6516) { echo phpcommon\extractOpenId($row['account_id']) . ',' . phpcommon\timestamp_to_datetime($row['createtime']) . "\n"; } } } } public function exportData2() { $type = getReqVal('type', ''); $accounts = array(); $conn = myself()->_getMysql(''); { $rows = $conn->execQuery( 'SELECT * FROM t_user', array( ) ); echo 'account_id' . "\n"; foreach ($rows as $row) { $channel = phpcommon\extractChannel($row['account_id']); if ($channel == 6516) { echo $row['account_id'] . "\n"; } } } } public function exportData3() { $type = getReqVal('type', ''); $accounts = array(); $conn = myself()->_getMysql(''); { $rows = $conn->execQuery( 'SELECT * FROM t_dyndata WHERE x=:x AND y=:y', array( ':x' => TN_ACTIVE, ':y' => 0, ) ); echo 'account_id' . ",name,active>=10,active>=30,active>=50,active_value\n"; foreach ($rows as $row) { $channel = phpcommon\extractChannel($row['account_id']); if ($channel == 6516) { $userDb = SqlHelper::ormSelectone( $conn, 't_user', array( 'account_id' => $row['account_id'] ) ); echo $row['account_id'] . ',' . ($userDb ? $userDb['name'] : '') . ',' . ($row['val'] >= 10 && $row['val'] < 30 ? 1 :0) . ',' . ($row['val'] >= 30 && $row['val'] < 50 ? 1 :0) . ',' . ($row['val'] >= 50 ? 1 :0) . ',' . $row['val'] . ',' . "\n"; } } } } }