diff --git a/sql/gamedb.sql b/sql/gamedb.sql index b90aae3..b4b05f4 100644 --- a/sql/gamedb.sql +++ b/sql/gamedb.sql @@ -38,9 +38,22 @@ DROP TABLE IF EXISTS `user`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `user` ( `idx` int(11) NOT NULL AUTO_INCREMENT COMMENT '自增id', - `accountid` varchar(60) DEFAULT '' COMMENT '账号id(channel + "_" + gameid + "_" + openid)', - `user_name` varchar(50) DEFAULT '' COMMENT '用户名字', + `accountid` varchar(60) DEFAULT '' COMMENT '账号id(channel + "_" + gameid + "_" + openid)', + `user_name` varchar(50) DEFAULT '' COMMENT '用户名字', `avatar_url` varchar(256) NOT NULL DEFAULT '' COMMENT '用户头像', + `rank` int(11) NOT NULL COMMENT '用户排名(世界排名)', + `game_times` int(11) NOT NULL COMMENT '游戏场次', + `win_times` int(11) NOT NULL COMMENT '胜场', + `kills` int(11) NOT NULL COMMENT '所有击杀', + `harm` int(11) NOT NULL COMMENT '所有伤害', + `add_HP` int(11) NOT NULL COMMENT '所有治疗量', + `alive_time` int(11) NOT NULL COMMENT '所有生存时间', + `coin_num` int(11) NOT NULL COMMENT '角色金币', + `integral` int(11) NOT NULL COMMENT '角色积分', + `kill_his` int(11) NOT NULL COMMENT '最高击杀', + `alive_time_his` int(11) NOT NULL COMMENT '最长生存时间', + `harm_his` int(11) NOT NULL COMMENT '最高伤害', + `add_HP_his` int(11) NOT NULL COMMENT '最多治疗量', PRIMARY KEY (`idx`), UNIQUE KEY `accountid` (`accountid`) ) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; @@ -171,6 +184,29 @@ CREATE TABLE `active` ( PRIMARY KEY (`idx`), KEY `accountid` (`accountid`) ) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; + + +-- +-- Table structrure for table `history_record` +-- + +DROP TABLE IF EXISTS `history_record`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `history_record`( + `idx` int(11) NOT NULL AUTO_INCREMENT COMMENT '自增id', + `accountid` varchar(60) DEFAULT '' COMMENT '账号id(channel + "_" + gameid + "_" + openid)', + `map_name` varchar(50) DEFAULT '' COMMENT '地图名字', + `game_time` int(11) NOT NULL COMMENT '游戏完成时间', + `rank` int(11) NOT NULL COMMENT '游戏排名', + `kills` int(11) NOT NULL COMMENT '游戏击杀', + `harms` int(11) NOT NULL COMMENT '游戏伤害', + `hurts` int(11) NOT NULL COMMENT '承受伤害', + `alive_time` int(11) NOT NULL COMMENT '游戏生存时间', + PRIMARY KEY (`idx`), + UNIQUE KEY `accountid` (`accountid`) +) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; + /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; diff --git a/webapp/controller/RoleController.class.php b/webapp/controller/RoleController.class.php new file mode 100644 index 0000000..781c996 --- /dev/null +++ b/webapp/controller/RoleController.class.php @@ -0,0 +1,189 @@ + $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 = 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,);', + 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 + )); + } + +} + + + + +?>