From 2869661d78385d87a0a8e3ed105502637796f4bf Mon Sep 17 00:00:00 2001 From: wangwei01 Date: Thu, 25 Apr 2019 10:48:37 +0800 Subject: [PATCH] 1 --- webapp/controller/RankController.class.php | 155 +++++++++++++++++++++ webapp/controller/TeamController.class.php | 3 +- 2 files changed, 157 insertions(+), 1 deletion(-) create mode 100644 webapp/controller/RankController.class.php diff --git a/webapp/controller/RankController.class.php b/webapp/controller/RankController.class.php new file mode 100644 index 0000000..1f534b9 --- /dev/null +++ b/webapp/controller/RankController.class.php @@ -0,0 +1,155 @@ + $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 RankInfo() + { + $account_id = $_REQUEST['account_id']; + $conn = $this->getMysql($account_id); + if (!$conn) { + phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); + return; + } + $kill_list = array(); + $kill_rank = 0; + $alive_list = array(); + $alive_rank = 0; + $harm_list = array(); + $harm_rank = 0; + $rate_list = array(); + $rate_rank = 0; + $win_list = array(); + $win_rank = 0; + + //击杀榜 + $rows = $conn->execQuery('SELECT * FROM user ORDER BY kills / game_times DESC;'); + $i = 1; + if ($rows) { + foreach ($rows as $row) { + if ($row['accountid'] == $account_id) { + $kill_rank = $i; + } + array_push($kill_list, array( + 'account_id' => $row['accountid'], + 'kill' => $row['kills'] / $row['game_times'], + 'alive'=> $row['alive_time'] / $row['game_times'], + 'harm' => $row['harm'] / $row['game_times'], + 'win_rate' => $row['win_times'] / $row['game_times'], + 'win_game' => $row['win_times'] + )); + $i++; + } + } + + //生存榜 + $rows = $conn->execQuery('SELECT * FROM user ORDER BY alive_time / game_times DESC;'); + $i = 1; + if ($rows) { + foreach ($rows as $row) { + if ($row['accountid'] == $account_id) { + $alive_rank = $i; + } + array_push($alive_list, array( + 'account_id' => $row['accountid'], + 'kill' => $row['kills'] / $row['game_times'], + 'alive'=> $row['alive_time'] / $row['game_times'], + 'harm' => $row['harm'] / $row['game_times'], + 'win_rate' => $row['win_times'] / $row['game_times'], + 'win_game' => $row['win_times'] + )); + $i++; + } + } + + //伤害榜 + $rows = $conn->execQuery('SELECT * FROM user ORDER BY harm / game_times DESC;'); + $i = 1; + if ($rows) { + foreach ($rows as $row) { + if ($row['accountid'] == $account_id) { + $harm_rank = $i; + } + array_push($harm_list, array( + 'account_id' => $row['accountid'], + 'kill' => $row['kills'] / $row['game_times'], + 'alive'=> $row['alive_time'] / $row['game_times'], + 'harm' => $row['harm'] / $row['game_times'], + 'win_rate' => $row['win_times'] / $row['game_times'], + 'win_game' => $row['win_times'] + )); + $i++; + } + } + + //胜率榜 + $rows = $conn->execQuery('SELECT * FROM user ORDER BY win_times / game_times DESC;'); + $i = 1; + if ($rows) { + foreach ($rows as $row) { + if ($row['accountid'] == $account_id) { + $rate_rank = $i; + } + array_push($rate_list, array( + 'account_id' => $row['accountid'], + 'kill' => $row['kills'] / $row['game_times'], + 'alive'=> $row['alive_time'] / $row['game_times'], + 'harm' => $row['harm'] / $row['game_times'], + 'win_rate' => $row['win_times'] / $row['game_times'], + 'win_game' => $row['win_times'] + )); + $i++; + } + } + + //胜场榜 + $rows = $conn->execQuery('SELECT * FROM user ORDER BY win_times DESC;'); + $i = 1; + if ($rows) { + foreach ($rows as $row) { + if ($row['accountid'] == $account_id) { + $win_rank = $i; + } + array_push($win_list, array( + 'account_id' => $row['accountid'], + 'kill' => $row['kills'] / $row['game_times'], + 'alive'=> $row['alive_time'] / $row['game_times'], + 'harm' => $row['harm'] / $row['game_times'], + 'win_rate' => $row['win_times'] / $row['game_times'], + 'win_game' => $row['win_times'] + )); + + $i++; + } + } + echo json_encode(array( + 'errcode' => 0, + 'errmsg' => "", + 'kill_rank' => $kill_rank, + 'kill_list' => $kill_list, + 'alive_rank' => $alive_rank, + 'alive_list' => $alive_list, + 'harm_rank' => $harm_rank, + 'harm_list' => $harm_list, + 'rate_rank' => $rate_rank, + 'rate_list' => $rate_list, + 'win_rank' => $win_rank, + 'win_list' => $win_list + )); + } +} + + +?> diff --git a/webapp/controller/TeamController.class.php b/webapp/controller/TeamController.class.php index af5237e..13aa429 100644 --- a/webapp/controller/TeamController.class.php +++ b/webapp/controller/TeamController.class.php @@ -148,7 +148,7 @@ class teamController{ phpcommon\sendError(ERR_USER_BASE + 1,'session失效2'); return; } - + $flag = 0; foreach ($user_db['member_list'] as $member) { if ($member['account_id'] == $_REQUEST['account_id']){ if($member['idx'] != 1){ @@ -201,6 +201,7 @@ class teamController{ phpcommon\sendError(ERR_USER_BASE + 1,'session失效2'); return; } + $flag = 0; foreach ($user_db['member_list'] as $member) { if ($member['account_id'] == $_REQUEST['account_id']){ $flag = $member['idx'] - 1;