game2001api/webapp/controller/RoleController.class.php
wangwei01 362cea871b 1
2019-04-19 14:56:04 +08:00

190 lines
7.3 KiB
PHP

<?php
class RoleController{
protected function getMysql($account_id)
{
$mysql_conf = getMysqlConfig(crc32($account_id));
$conn = new phpcommon\Mysql(array(
'host' => $mysql_conf['host'],
'port' => $mysql_conf['port'],
'user' => $mysql_conf['user'],
'passwd' => $mysql_conf['passwd'],
'dbname' => 'gamedb2001_' . $mysql_conf['instance_id']
));
return $conn;
}
public function RoleInfo()
{
$account_id = $_REQUEST['account_id'];
$conn = $this->getMysql($account_id);
if (!$conn) {
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
return;
}
$row = $conn->execQueryOne('SELECT * FROM user WHERE accountid=:accountid;',
array(
':accountid' => $account_id
));
if (!$row) {
$ret = $conn->execScript('INSERT INTO user(accountid, rank, game_times, win_times, kills, harm, add_HP, alive_time, coin_num, integral, kill_his, alive_time_his, harm_his, add_HP_his) ' .
' VALUES(:accountid, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);',
array(
':accountid' => $account_id
));
if (!$ret) {
die();
return;
}
echo json_encode(array(
'errcode' => 0,
'errmsg' => '',
'game_times' => 0,
'win_times' => 0,
'high_kill' => 0,
'kills' => 0,
'high_harm' => 0,
'harm' => 0,
'add_HP' => 0,
'alive_time' => 0,
));
} else {
echo json_encode(array(
'errcode' => 0,
'errmsg' => '',
'game_times' => $row['game_times'],
'win_times' => $row['win_times'],
'high_kill' => $row['kill_his'],
'kills' => $row['kills'],
'high_harm' => $row['harm_his'],
'harm' => $row['harm'],
'add_HP' => $row['add_HP'],
'alive_time' => $row['alive_time'],
));
}
}
public function battleReport()
{
$account_id = $_REQUEST['account_id'];
$map_name = $_REQUEST['map_name'];
$game_time = $_REQUEST['game_time'];
$hurt = $_REQUEST['hurt'];
$rank = $_REQUEST['rank'];
$kills = $_REQUEST['kills'];
$harm = $_REQUEST['harm'];
$add_HP = $_REQUEST['add_HP'];
$alive_time = $_REQUEST['alive_time'];
$conn = $this->getMysql($account_id);
$kill_his = $kills;
$harm_his = $harm;
$alive_time_his = $alive_time;
$add_HP_his = $add_HP;
if (!$conn) {
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
return;
}
$row = $conn->execQueryOne('SELECT * FROM user WHERE accountid=:accountid;',
array(
':accountid' => $account_id
));
if (!$row) {
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
return;
}
if ($kills < $row['kill_his']) {
$high_kill = $row['kill_his'];
}
if ($harm < $row['harm_his']) {
$high_harm = $row['harm_his'];
}
if ($rank == 1) {
$row['win_times']++;
}
if ($alive_time_his < $row['alive_time_his']) {
$alive_time_his = $row['alive_time_his'];
}
if ($add_HP_his < $row['add_HP_his']) {
$add_HP_his = $row['add_HP_his'];
}
$ret = $conn->execScript('UPDATE user SET game_times=:game_times, win_times=:win_times, kills=:kills, harm=:harm, add_HP=:add_HP, alive_time=:alive_time, kill_his=:kill_his, alive_time_his=:alive_time_his, harm_his=:harm_his, add_HP_his=:add_HP_his ' .
' WHERE accountid=:accountid;',
array(
':game_times' => $row['game_times']++,
':win_times' => $row['win_times'],
':kill_his' => $kill_his,
':kills' => $row['kills'] + $kills,
':harm_his' => $harm_his,
':harm' => $row['harm'] + $harm,
':add_HP' => $row['add_HP'] + $add_HP,
':alive_time' => $row['alive_time'] + $alive_time,
':alive_time_his' => $alive_time_his,
':add_HP_his' => $add_HP_his,
':accountid' => $account_id
));
if (!$ret) {
die();
return;
}
$ret = $conn->execScript('INSERT INTO history_record(accountid, map_name, game_time, rank, kills, harm, hurt, alive_time) ' .
' VALUES(:accountid, :map_name, :game_time, :rank, :kills, :harm, :hurt, :alive_time);',
array(
':accountid' => $account_id,
':game_time' => $game_time,
':rank' => $rank,
':kills' => $kills,
':harm' => $harm,
':hurt' => $hurt,
':alive_time' => $alive_time
));
if (!$ret) {
die();
return;
}
}
public function HistoryRecord()
{
$account_id = $_REQUEST['account_id'];
$conn = $this->getMysql($account_id);
$record_list = array();
if (!$conn) {
phpcommon\sendError(ERR_BASE_USER + 1, '没有这个玩家');
return;
}
$rowCount = $conn->execQueryRowCount('SELECT * FROM history_record WHERE accountid=:accountid;',
array(
':accountid' => $account_id
));
if ($rowCount != 0) {
$rows = $conn->execQuery('SELECT * FROM history_record WHERE accountid=:account_id;',
array(
':account_id' => $account_id
));
foreach ($rows as $row) {
array_push($record_list, array(
'map_name' => $row['map_name'],
'game_time' => $row['game_time'],
'rank' => $row['rank'],
'kills' => $row['kills'],
'harms' => $row['harms'],
'hurts' => $row['hurts'],
'alive_time' => $row['alive_time']
));
}
}
echo json_encode(array(
'errcode' => 0,
'errmsg' => '',
'record_list' => $record_list
));
}
}
?>