From 403781da6949527a2d3aeba79ca0c653b1ed23ea Mon Sep 17 00:00:00 2001 From: hujiabin Date: Tue, 18 Oct 2022 11:18:41 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=89=E6=8B=A9=E5=85=8D=E8=B4=B9=E8=8B=B1?= =?UTF-8?q?=E9=9B=84=E6=9E=AA=E6=A2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/Ranking.py | 27 ++++ doc/User.py | 14 ++ sql/gamedb.sql | 1 + webapp/bootstrap/constant.php | 1 + webapp/controller/ChipController.class.php | 4 +- webapp/controller/RankingController.class.php | 55 ++++++++ webapp/controller/UserController.class.php | 130 ++++++++++++++++-- webapp/models/Season.php | 4 +- webapp/mt/RankSeason.php | 11 ++ webapp/services/SeasonService.php | 25 +++- 10 files changed, 256 insertions(+), 16 deletions(-) diff --git a/doc/Ranking.py b/doc/Ranking.py index 0ab8c510..20ba67c4 100644 --- a/doc/Ranking.py +++ b/doc/Ranking.py @@ -46,5 +46,32 @@ class Ranking(object): _common.RspHead(), ['ranking_list', _common.RankingListEx(), '排行榜数据'] ] + }, + { + 'name': 'getRankStatus', + 'desc': '获得排位的状态', + 'group': 'Ranking', + 'url': 'webapp/index.php?c=Ranking&a=getRankStatus', + 'params': [ + _common.ReqHead(), + ], + 'response': [ + _common.RspHead(), + ['status', 0, '0:常规状态 1:引导初始排位 2:赛季初,需结算上个赛季'], + ['is_rank', 0, '赛季是否空挡期 1:是 0:不是'] + ] + }, + { + 'name': 'resetRankGainAward', + 'desc': '重置段位获取赛季奖励', + 'group': 'Ranking', + 'url': 'webapp/index.php?c=Ranking&a=resetRankGainAward', + 'params': [ + _common.ReqHead(), + ], + 'response': [ + _common.RspHead(), + ['property_chg', _common.PropertyChg(), '属性变更'], + ] } ] diff --git a/doc/User.py b/doc/User.py index 9a67b656..a027d34c 100644 --- a/doc/User.py +++ b/doc/User.py @@ -134,5 +134,19 @@ class User(object): 'response': [ _common.RspHead(), ] + },{ + 'name': 'selectFreeItem', + 'desc': '选择免费英雄和武器', + 'group': 'User', + 'url': 'webapp/index.php?c=User&a=selectFreeItem', + 'params': [ + _common.ReqHead(), + ['hero_id', '', '英雄 item id'] + ['gun_id', '', '枪械 item id'] + ], + 'response': [ + _common.RspHead(), + ['property_chg', _common.PropertyChg(), '属性变更'], + ] }, ] diff --git a/sql/gamedb.sql b/sql/gamedb.sql index 3ef3a25d..fa0c47dd 100644 --- a/sql/gamedb.sql +++ b/sql/gamedb.sql @@ -59,6 +59,7 @@ CREATE TABLE `t_user` ( `best_rank_modifytime` int(11) NOT NULL DEFAULT '0' COMMENT 'bestrank修改时间', `createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间', `modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间', + `last_login_time` int(11) NOT NULL DEFAULT '0' COMMENT '上次登录时间', PRIMARY KEY (`idx`), UNIQUE KEY `account_id` (`account_id`), KEY `channel` (`channel`) diff --git a/webapp/bootstrap/constant.php b/webapp/bootstrap/constant.php index ae59a709..b3463592 100644 --- a/webapp/bootstrap/constant.php +++ b/webapp/bootstrap/constant.php @@ -22,6 +22,7 @@ define('TN_HERO_MAX_LEVEL', 8008); define('TN_GUN_MAX_LEVEL', 80008); define('TN_HERO_MAX_QUALITY', 8009); define('TN_GUN_MAX_QUALITY', 80009); +define('TN_RANK_STATUS', 99999); define('TN_END', 8007); define('TN_DAILY_BEGIN', 9001); diff --git a/webapp/controller/ChipController.class.php b/webapp/controller/ChipController.class.php index e1c59d25..a0a5a410 100644 --- a/webapp/controller/ChipController.class.php +++ b/webapp/controller/ChipController.class.php @@ -11,13 +11,14 @@ require_once('services/PropertyChgService.php'); require_once('services/LogService.php'); require_once('services/SeasonService.php'); - +require_once('models/Season.php'); use models\Chip; use models\Hero; use models\Gun; use models\User; use models\Nft; +use models\Season; use services\FormulaService; use services\LogService; use phpcommon\SqlHelper; @@ -576,7 +577,6 @@ class ChipController extends BaseAuthedController // $this->chipDetails(); // $arr = [30900=>2,31000=>6,31100=>4]; - } diff --git a/webapp/controller/RankingController.class.php b/webapp/controller/RankingController.class.php index 172fa1a5..5e743874 100644 --- a/webapp/controller/RankingController.class.php +++ b/webapp/controller/RankingController.class.php @@ -1,15 +1,37 @@ _getOrmUserInfo(); + $currSeasonMeta = mt\RankSeason::getCurrentSeason(); + if($currSeasonMeta){ + $this->_setV(TN_RANK_STATUS, 1, 1); + if ($currSeasonMeta['id'] != $userInfo['last_season_id']){ + $this->_setV(TN_RANK_STATUS, 0, 2); + } + }else{ + $this->_setV(TN_RANK_STATUS, 1, 0); + } + + $rank_status = $this->_getV(TN_RANK_STATUS, 0 ); + $is_rank = $this->_getV(TN_RANK_STATUS, 1 ); + $this->_rspData(array( + 'status' => $rank_status, // 0:常规状态 1:引导初始排位 2:赛季初,需结算上个赛季 + 'is_rank' => $is_rank //赛季是否空挡期 + )); + } + public function rankingList() { $userInfo = $this->_getOrmUserInfo(); @@ -89,6 +111,39 @@ class RankingController extends BaseAuthedController { ); } + public function resetRankGainAward(){ + $userInfo = $this->_getOrmUserInfo(); + $currSeasonMeta = mt\RankSeason::getCurrentSeason(); + if ($currSeasonMeta && $currSeasonMeta['id'] > $userInfo['last_season_id']) { + $rank = $userInfo['rank']; + for ($i=$userInfo['last_season_id'];$i<$currSeasonMeta['id'];$i++){ + $currRankMeta = mt\Rank::getRankById($rank); + $dropRankMeta = mt\Rank::getRankById($currRankMeta ? $currRankMeta['next_season'] : 1); + $rank= $dropRankMeta['id']; + $award = Season::seasonReward($currRankMeta); + } + //掉段 + if ($dropRankMeta) { + myself()->_updateUserInfo(array( + 'rank' => $dropRankMeta['id'], + 'score' => $dropRankMeta['rank_score'], + 'last_season_id' => $currSeasonMeta['id'], + )); + } + $awardService = new services\AwardService(); + $propertyChgService = new services\PropertyChgService(); + $propertyChgService->addUserChg(); + $propertyChgService->addBagChg(); + if ($award){ + $this->_addItems($award,$awardService,$propertyChgService); + } + $this->_setV(TN_RANK_STATUS, 0, 0); + $this->_rspData([ + 'property_chg' => $propertyChgService->toDto(), + ]); + } + } + private function internalGetActivityRankData($type) { $channel = 6516; diff --git a/webapp/controller/UserController.class.php b/webapp/controller/UserController.class.php index 62674ad6..c9bd6cb7 100644 --- a/webapp/controller/UserController.class.php +++ b/webapp/controller/UserController.class.php @@ -4,6 +4,7 @@ require_once('models/User.php'); require_once('models/Hero.php'); require_once('models/Season.php'); require_once('models/Nft.php'); +require_once('models/Gun.php'); require_once('mt/Parameter.php'); require_once('mt/Drop.php'); @@ -20,6 +21,7 @@ require_once('services/NameService.php'); use phpcommon\SqlHelper; use models\User; use models\Hero; +use models\Gun; use models\Season; use models\Nft; @@ -38,16 +40,33 @@ class UserController extends BaseAuthedController { $avatarUrl = '18003'; $userInfo = $this->_safeGetOrmUserInfo(); - if (!$userInfo) { - $this->createNewUser($userName, $avatarUrl); - - $this->addChip(); - - $userInfo = $this->_getOrmUserInfo(); - } - if (!$this->loginCheck($userInfo)) { + if (SERVER_ENV == _ONLINE) { + //测试服 + if (!$userInfo) { + $this->createNewUserV2($userName); + $this->addChip(); //测试需要,上线要删除 + $userInfo = $this->_getOrmUserInfo(); + $this->_setV(TN_RANK_STATUS, 0, 1); + } + //elo 衰减 + $this->checkElo($userInfo); $userInfo = $this->_getOrmUserInfo(); + //跟新登录时间 + $this->_updateUserInfo(array( + 'last_login_time'=>myself()->_getNowTime(), + )); + }else{ + if (!$userInfo) { + $this->createNewUser($userName, $avatarUrl); + $this->addChip(); //测试需要,上线要删除 + $userInfo = $this->_getOrmUserInfo(); + $this->_setV(TN_RANK_STATUS, 0, 1); + } + if (!$this->loginCheck($userInfo)) { + $userInfo = $this->_getOrmUserInfo(); + } } + $this->_rspData(array( 'info' => User::show($userInfo) )); @@ -225,6 +244,7 @@ class UserController extends BaseAuthedController { 'best_rank_modifytime' => $this->_getNowTime(), 'createtime' => $this->_getNowTime(), 'modifytime' => $this->_getNowTime(), + 'last_login_time' => $this->_getNowTime(), ) ); $awardService = new services\AwardService(); @@ -398,8 +418,8 @@ class UserController extends BaseAuthedController { $reqVal = getReqVal($key, ''); if (!empty($reqVal)) { if (isset($field['valid_func'])) { - if (!$field['valid_func']($reqVal, $errCode, $errMsg)) { - $this->_rspErr($errCode, $errMsg); + if (!$field['valid_func']($reqVal, $errCod, $errMsg)) { + $this->_rspErr($errCod, $errMsg); return; } $fieldsKv[$field['field_name']] = $field['val_func']($reqVal); @@ -571,7 +591,97 @@ class UserController extends BaseAuthedController { 'elo' => $initEloParameterMeta ? $initEloParameterMeta['param_value'] : 0, ); User::update($fields); + $this->_setV(TN_RANK_STATUS, 0, 0); $this->_rspOk(); } + public function selectFreeItem(){ + $hero_id = getReqVal('hero_id', ''); + $gun_id = getReqVal('gun_id', ''); + if (!$hero_id || !$gun_id){ + $this->_rspErr(1, 'param is error'); + return; + } + $heroMeta = mt\Item::get($hero_id); + if (! $heroMeta){ + $this->_rspErr(1, 'hero_id is error'); + return; + } + $gunMeta = mt\Item::get($gun_id); + if (! $gunMeta){ + $this->_rspErr(1, 'gun_id is error'); + return; + } + $temp = explode('|',$heroMeta['normal_gift']); + $headList = array(); + if ($heroMeta['normal_gift']){ + array_push($headList,$heroMeta['normal_gift']); + } + Hero::addHero($heroMeta); + Gun::addGun($gunMeta); + $fields = array( + 'hero_id' => $temp ? $temp[1] : 0, + 'head_id' => $temp ? $temp[0] : 0, + 'head_frame' => 60000, + 'head_list' => json_encode($headList), + 'head_frame_list' => json_encode(array(60000)), + ); + User::update($fields); + $propertyChgService = new services\PropertyChgService(); + $propertyChgService->addUserChg(); + $propertyChgService->addHeroChg(); + $propertyChgService->addGunChg(); + $this->_rspData([ + 'data'=>array( + 'hero_id' => $hero_id, + 'gun_id' => $gun_id, + ), + 'property_chg' => $propertyChgService->toDto(), + ]); + } + + private function checkElo($userInfo){ + $time_diff = myself()->_getNowTime()-$userInfo['last_login_time']; + if ($userInfo['elo'] > 1500 && floor($time_diff/86400) > 0){ + $newElo = min(round(pow(log10(floor($time_diff/86400)),1.5)*350),450); + $this->_updateUserInfo(array( + 'elo' => $userInfo['elo'] - $newElo + )); +// $userInfo = $this->_getOrmUserInfo(); + } + } + + private function createNewUserV2($userName){ + $currSeasonMeta = mt\RankSeason::getCurrentSeason(); + if (!$currSeasonMeta){ + $time = $this->_getNowTime() + (86400*10); + $currSeasonMeta = mt\RankSeason::getSeasonByTime($time); + } + SqlHelper::upsert + ($this->_getSelfMysql(), + 't_user', + array( + 'account_id' => $this->_getAccountId() + ), + array( + ), + array( + 'account_id' => $this->_getAccountId(), + 'channel' => $this->_getChannel(), + 'name' => $userName, + 'sex' => rand() % 2, + 'gold' => 0, + 'diamond' => 0, + 'level' => 1, + 'exp' => 0, + 'last_season_id' => $currSeasonMeta ? $currSeasonMeta['id'] : 0, + 'score_modifytime' => $this->_getNowTime(), + 'best_rank_modifytime' => $this->_getNowTime(), + 'createtime' => $this->_getNowTime(), + 'modifytime' => $this->_getNowTime(), + 'last_login_time' => $this->_getNowTime(), + ) + ); + } + } diff --git a/webapp/models/Season.php b/webapp/models/Season.php index 65ac2c4f..b646191f 100644 --- a/webapp/models/Season.php +++ b/webapp/models/Season.php @@ -38,8 +38,8 @@ class Season extends BaseModel { foreach ($rewards as $reward){ $temp = explode(',',$reward); array_push($rewardList,array( - 'reward_id' => $temp[0], - 'reward_num' => $temp[1], + 'item_id' => $temp[0], + 'item_num' => $temp[1], )); } return $rewardList; diff --git a/webapp/mt/RankSeason.php b/webapp/mt/RankSeason.php index 7c28b65b..fdabc74b 100644 --- a/webapp/mt/RankSeason.php +++ b/webapp/mt/RankSeason.php @@ -30,6 +30,17 @@ class RankSeason return null; } + public static function getSeasonByTime($time) + { + foreach (self::getMetaList() as $meta) { + if ($time >= strtotime($meta['start_time']) && + $time <= strtotime($meta['end_time'])) { + return $meta; + } + } + return null; + } + protected static $metaList; } \ No newline at end of file diff --git a/webapp/services/SeasonService.php b/webapp/services/SeasonService.php index 56b9d5a9..8ae1465d 100644 --- a/webapp/services/SeasonService.php +++ b/webapp/services/SeasonService.php @@ -5,9 +5,11 @@ namespace services; require_once('mt/Rank.php'); require_once('mt/Season.php'); require_once('models/User.php'); +require_once('models/Season.php'); use mt; use models\User; +use models\Season; class SeasonService extends BaseService { @@ -28,12 +30,31 @@ class SeasonService extends BaseService { } if ($initRankMeta && $userInfo['rank'] < $initRankMeta['rank']) { myself()->_updateUserInfo(array( - 'rank' => $initRankMeta['rank'], - 'score' => $initRankMeta['min_score'], + 'rank' => $initRankMeta['rank'], + 'score' => $initRankMeta['min_score'], )); return false; } return true; } + + //赛季结束后奖励及重置排位段位 + public function seasonAward($userInfo){ + $currRankMeta = mt\Rank::getRankById($userInfo['rank']); + $dropRankMeta = mt\Rank::getRankById($currRankMeta ? $currRankMeta['next_season'] : 1); + $award =array(); + if ($currRankMeta){ + $award = Season::seasonReward($currRankMeta); + if ($dropRankMeta) { + myself()->_updateUserInfo(array( + 'rank' => $dropRankMeta['id'], + 'score' => $dropRankMeta['rank_score'], + )); + } + } + return $award; + } + + }