diff --git a/doc/Battle.py b/doc/Battle.py index 874732d..4997433 100644 --- a/doc/Battle.py +++ b/doc/Battle.py @@ -40,7 +40,7 @@ class Battle(object): ['weapons_slot', '', '武器信息 weapon_id:use_times|'], ['heros', '', '武器信息 hero_id:skill_lv:weapon_lv|'], - ['rank_score', 0, '排位积分'], + #['rank_score', 0, '排位积分'], ['pass_score', 0, '通行证积分'], ['items', 0, '道具|分割'], ], diff --git a/doc/_common.py b/doc/_common.py index 8707cee..3b35ada 100644 --- a/doc/_common.py +++ b/doc/_common.py @@ -45,6 +45,8 @@ class UserInfo(object): ['level', 0, '等级'], ['exp', 0, '经验'], ['max_exp', 0, '经验(上限)'], + ['rank', 0, '当前段位'], + ['history_best_rank', 0, '历史最高段位'], ['gold', 0, '金币'], ['diamond', 0, '钻石'], ['hero_id', 0, '当前使用的英雄ID'], diff --git a/sql/gamedb.sql b/sql/gamedb.sql index 3771cca..c5b5d90 100644 --- a/sql/gamedb.sql +++ b/sql/gamedb.sql @@ -36,6 +36,7 @@ CREATE TABLE `t_user` ( `level` int(11) NOT NULL DEFAULT '0' COMMENT '等级', `exp` int(11) NOT NULL DEFAULT '0' COMMENT '经验', `rank` int(11) NOT NULL DEFAULT '0' COMMENT '段位', + `history_best_rank` int(11) NOT NULL DEFAULT '0' COMMENT '历史最高段位', `score` int(11) NOT NULL DEFAULT '0' COMMENT '积分', `gold` int(11) NOT NULL DEFAULT '0' COMMENT '金币', `diamond` int(11) NOT NULL DEFAULT '0' COMMENT '钻石', @@ -272,8 +273,8 @@ CREATE TABLE `t_season` ( `season_id` int(11) NOT NULL DEFAULT '0' COMMENT '赛季id', `card_lv` int(11) NOT NULL DEFAULT '0' COMMENT '赛季手册等级', `card_exp` int(11) NOT NULL DEFAULT '0' COMMENT '赛季手册经验', - `total_score` int(11) NOT NULL DEFAULT '0' COMMENT '赛季积分', - `max_score` int(11) NOT NULL DEFAULT '0' COMMENT '赛季最高积分', + `rank` int(11) NOT NULL DEFAULT '0' COMMENT '段位', + `score` int(11) NOT NULL DEFAULT '0' COMMENT '积分', `gift_state1` int(11) NOT NULL DEFAULT '0' COMMENT '普通礼包购买状态 0:未购 1:已购', `gift_buytime1` int(11) NOT NULL DEFAULT '0' COMMENT '普通礼包购买时间', `gift_state2` int(11) NOT NULL DEFAULT '0' COMMENT '豪华礼包购买状态 0:未购 1:已购', diff --git a/webapp/controller/UserController.class.php b/webapp/controller/UserController.class.php index 4420fe1..817c5d4 100644 --- a/webapp/controller/UserController.class.php +++ b/webapp/controller/UserController.class.php @@ -2,6 +2,7 @@ require_once('models/User.php'); require_once('models/Hero.php'); +require_once('models/Season.php'); require_once('mt/Parameter.php'); require_once('mt/Drop.php'); @@ -17,6 +18,7 @@ require_once('services/NameService.php'); use phpcommon\SqlHelper; use models\User; use models\Hero; +use models\Season; class UserController extends BaseAuthedController { @@ -330,40 +332,53 @@ class UserController extends BaseAuthedController { public function detailInfo() { $targetId = getReqVal('target_id', ''); - $userDb = SqlHelper::ormSelectOne - ($this->_getMysql($targetId), - 't_user', - array( - 'account_id' => $targetId - ) - ); + $userDb = User::find($targetId); if (!$userDb) { $this->_rspErr(1, '账号不存在'); return; } $userDto = User::info($userDb); - $userDto['current_rank'] = 1; - $userDto['history_best_rank'] = 1; - $userDto['history_seasons'] = array( - array( - 'season_id' => 0, - 'total_kills' => 0, - 'game_times' => 0, - 'win_times' => 0, - 'win_rate' => 0, - 'max_kills' => 0, - 'avg_kills' => 0, - 'max_damage_out' => 0, - 'avg_damage_out' => 0, - 'star_kills' => 0, - 'star_damage' => 0, - 'star_alive' => 0, - 'star_recover' => 0, - 'star_win' => 0, - ) - ); + $userDto['current_rank'] = $userDb['rank']; + $userDto['history_seasons'] = array(); + $seasonDbs = Season::getHistorySeasons($targetId); + foreach ($seasonDbs as $seasonDb) { + $battleData = json_decode($seasonDb['battle_data'], true); + $seasonBattleData = isset($battleData) ? getXVal($battleData, 'season_data', array()) : array(); + $gameTimes = getXVal($seasonBattleData, 'total_battle_times', 0); + $winTimes = getXVal($seasonBattleData, 'total_win_times', 0); + $winRate = $gameTimes > 0 ? intval($winTimes / $gameTimes * 100) : 0; + $totalKills = getXVal($seasonBattleData, 'total_kills_times', 0); + $totalDamage = getXVal($seasonBattleData, 'total_damage_out', 0); + $totalAlive = getXVal($seasonBattleData, 'total_alive_time', 0); + $totalRecoverHp = getXVal($seasonBattleData, 'total_recover_hp', 0); + $avgDamage = $gameTimes > 0 ? intval($totalDamage / $gameTimes) : 0; + $avgKills = $gameTimes > 0 ? intval($totalKills / $gameTimes) : 0; + $starKills = $gameTimes > 0 ? intval($totalKills / $gameTimes / 10 *100) : 0; + $starDamage = $gameTimes > 0 ? intval($totalDamage / $gameTimes / 1500 * 100) : 0; + $starAlive = $gameTimes > 0 ? intval($totalAlive / $gameTimes / 300 * 0.1) : 0; + $starRecover = $gameTimes > 0 ? intval($totalRecoverHp / $gameTimes / 300 * 100) : 0; + $starWin = $gameTimes > 0 ? intval($winTimes / $gameTimes / 0.5 * 100) : 0; + array_push($userDto['history_seasons'], + array( + 'season_id' => $seasonDb['season_id'], + 'total_kills' => $totalKills, + 'game_times' => $gameTimes, + 'win_times' => $winTimes, + 'win_rate' => $winRate, + 'max_kills' => getXVal($seasonBattleData, 'max_kills_times', 0), + 'avg_kills' => $avgKills, + 'max_damage_out' => getXVal($seasonBattleData, 'max_damage_out', 0), + 'avg_damage_out' => $avgDamage, + 'star_kills' => min(100, $starKills), + 'star_damage' => min(100, $starDamage), + 'star_alive' => min(100, $starAlive), + 'star_recover' => min(100, $starRecover), + 'star_win' => min(100, $starWin), + )); + } $this->_rspData(array( 'info' => $userDto )); } + } diff --git a/webapp/models/Season.php b/webapp/models/Season.php index 133ad8e..a080aa2 100644 --- a/webapp/models/Season.php +++ b/webapp/models/Season.php @@ -51,6 +51,18 @@ class Season extends BaseModel { ); } + public static function getHistorySeasons($targetId) + { + $rows = SqlHelper::ormSelect( + myself()->_getMysql($targetId), + 't_season', + array( + 'account_id' => $targetId, + ) + ); + return $rows; + } + public static function updateGiftPackageState($seasonId, $packageId) { if (in_array($packageId, array( diff --git a/webapp/models/User.php b/webapp/models/User.php index 35097f4..f574923 100644 --- a/webapp/models/User.php +++ b/webapp/models/User.php @@ -9,6 +9,18 @@ use phpcommon\SqlHelper; class User extends BaseModel { + public function find($targetId) + { + $row = SqlHelper::ormSelectOne + ($this->_getMysql($targetId), + 't_user', + array( + 'account_id' => $targetId + ) + ); + return $row ? $row : null; + } + public static function show($row) { return array( @@ -22,6 +34,7 @@ class User extends BaseModel { 'exp' => $row['exp'], 'max_exp' => $row['exp'] + 1000, 'rank' => $row['rank'], + 'history_best_rank' => $row['history_best_rank'], 'score' => $row['score'], 'gold' => $row['gold'], 'diamond' => $row['diamond'], @@ -45,6 +58,7 @@ class User extends BaseModel { 'exp' => $row['exp'], 'max_exp' => $row['exp'] + 1000, 'rank' => $row['rank'], + 'history_best_rank' => $row['history_best_rank'], 'score' => $row['score'], 'gold' => $row['gold'], 'diamond' => $row['diamond'],