From da07c61b1ed60de50a2c6ae0227c59fb823057cd Mon Sep 17 00:00:00 2001 From: hujiabin <519660157@qq.com> Date: Fri, 18 Oct 2024 15:23:11 +0800 Subject: [PATCH] 1 --- doc/Circuit.py | 13 +++++ sql/gamedb.sql | 21 ++++++++ sql/gamedb2006_migrate_241001_01.sql | 11 ++++ webapp/controller/CircuitController.class.php | 27 ++++++++++ webapp/models/Circuit.php | 52 ++++++++++++++++++- webapp/services/RoomBattleDataService.php | 6 ++- 6 files changed, 128 insertions(+), 2 deletions(-) diff --git a/doc/Circuit.py b/doc/Circuit.py index 9b32a34c..6d86b0a7 100644 --- a/doc/Circuit.py +++ b/doc/Circuit.py @@ -31,6 +31,19 @@ class Circuit(object): ['!rank_list', [rankingInfo()], '榜信息'], ['my_rank', rankingInfo(), '个人榜信息'], ] + },{ + 'name': 'getCircuitPhaseRanking', + 'desc': '巡回赛阶段排行', + 'group': 'Circuit', + 'url': 'webapp/index.php?c=Circuit&a=getCircuitPhaseRanking', + 'params': [ + _common.ReqHead(), + ], + 'response': [ + _common.RspHead(), + ['!rank_list', [rankingInfo()], '榜信息'], + ['my_rank', rankingInfo(), '个人榜信息'], + ] },{ 'name': 'CircuitTaskList', 'desc': '巡回赛任务', diff --git a/sql/gamedb.sql b/sql/gamedb.sql index f4c92c2f..8cddf5fa 100644 --- a/sql/gamedb.sql +++ b/sql/gamedb.sql @@ -2060,6 +2060,27 @@ CREATE TABLE `t_circuit_battle` ( ) ENGINE=InnoDB AUTO_INCREMENT=10000 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; /*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `t_circuit_battle_phase` +-- + +DROP TABLE IF EXISTS `t_circuit_battle_phase`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `t_circuit_battle_phase` ( + `idx` bigint NOT NULL AUTO_INCREMENT COMMENT '自增id', + `account_id` varchar(60) NOT NULL DEFAULT '' COMMENT '账号id(channel + "_" + gameid + "_" + openid)', + `season` int(11) NOT NULL DEFAULT '0' COMMENT '赛季', + `phase` int(11) NOT NULL DEFAULT '0' COMMENT '阶段', + `cumulative_score` int(11) NOT NULL DEFAULT '0' COMMENT '积分', + `createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间', + `modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间', + PRIMARY KEY (`idx`), + KEY `idx_account_season_phase` (`account_id`, `season`, `phase`) +) ENGINE=InnoDB AUTO_INCREMENT=10000 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; +/*!40101 SET character_set_client = @saved_cs_client */; + -- -- Table structure for table `t_circuit_reward` -- diff --git a/sql/gamedb2006_migrate_241001_01.sql b/sql/gamedb2006_migrate_241001_01.sql index dc51239b..7e575eaa 100644 --- a/sql/gamedb2006_migrate_241001_01.sql +++ b/sql/gamedb2006_migrate_241001_01.sql @@ -95,6 +95,17 @@ CREATE TABLE `t_lucky_symbol_record` ( UNIQUE KEY `uk_room_uuid_account_id` (`room_uuid`, `account_id`) ) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; +CREATE TABLE `t_circuit_battle_phase` ( + `idx` bigint NOT NULL AUTO_INCREMENT COMMENT '自增id', + `account_id` varchar(60) NOT NULL DEFAULT '' COMMENT '账号id(channel + "_" + gameid + "_" + openid)', + `season` int(11) NOT NULL DEFAULT '0' COMMENT '赛季', + `phase` int(11) NOT NULL DEFAULT '0' COMMENT '阶段', + `cumulative_score` int(11) NOT NULL DEFAULT '0' COMMENT '积分', + `createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间', + `modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间', + PRIMARY KEY (`idx`), + KEY `idx_account_season_phase` (`account_id`, `season`, `phase`) +) ENGINE=InnoDB AUTO_INCREMENT=10000 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; insert into version (version) values(2024092401); diff --git a/webapp/controller/CircuitController.class.php b/webapp/controller/CircuitController.class.php index da4b8dd7..66915ca2 100644 --- a/webapp/controller/CircuitController.class.php +++ b/webapp/controller/CircuitController.class.php @@ -19,6 +19,7 @@ use models\CircuitTask; use phpcommon\SqlHelper; class CircuitController extends BaseAuthedController { private $redis_key_circuit_ranking = 'circuit_ranking'; + private $redis_key_circuit_phase_ranking = 'circuit_phase_ranking'; public function _handlePre() { @@ -94,6 +95,32 @@ class CircuitController extends BaseAuthedController { 'my_rank' => $myRankedInfo, )); } + public function getCircuitPhaseRanking(){ + $currentCircuitMeta = mt\CircuitTime::getCurrentCircuit(); + if (!$currentCircuitMeta){ + $this->_rspErr(1, 'current stage Have not yet started'); + return ; + } + $currentStageMeta = mt\CircuitTime::getCurrentStage(); + if (!$currentStageMeta){ + $currentStageMeta = mt\CircuitTime::getPrevStage(); + } + $redis = $this->_getRedis($this->redis_key_circuit_phase_ranking); + if (! $redis->exists(CIRCUIT_RANKING_KEY.$this->redis_key_circuit_phase_ranking)){ + $rows = Circuit::getPhaseRankingList($currentStageMeta['circuit_season'],$currentStageMeta['circuit_phase']); + $list = $this->_extractRankingInfo($rows); + $redis->set(CIRCUIT_RANKING_KEY.$this->redis_key_circuit_phase_ranking , json_encode($list)); + $redis->pexpire(CIRCUIT_RANKING_KEY.$this->redis_key_circuit_phase_ranking , 10*60*1000); + }else{ + $listStr = $redis->get(CIRCUIT_RANKING_KEY.$this->redis_key_circuit_phase_ranking); + $list = emptyReplace(json_decode($listStr, true), array()); + } + $myRankedInfo = $this->_celMyRankingInfo($list); + $this->_rspData(array( + 'rank_list' => $list, + 'my_rank' => $myRankedInfo, + )); + } private function _extractRankingInfo($data){ $rankingList = array(); diff --git a/webapp/models/Circuit.php b/webapp/models/Circuit.php index af28141d..49224eae 100644 --- a/webapp/models/Circuit.php +++ b/webapp/models/Circuit.php @@ -29,6 +29,30 @@ class Circuit extends BaseModel ); } + public static function updatePhaseScore($season,$phase,$score){ + SqlHelper::upsert( + myself()->_getSelfMysql(), + 't_circuit_battle_phase', + array( + 'account_id' => myself()->_getAccountId(), + 'season' => $season, + 'phase' => $phase, + ), + array( + 'cumulative_score' => $score, + 'modifytime' => myself()->_getNowTime() + ), + array( + 'account_id' => myself()->_getAccountId(), + 'season' => $season, + 'phase' => $phase, + 'cumulative_score' => $score, + 'createtime' => myself()->_getNowTime(), + 'modifytime' => myself()->_getNowTime() + ) + ); + } + public static function getMyScore($season){ $row = SqlHelper::ormSelectOne( myself()->_getSelfMysql(), @@ -41,11 +65,37 @@ class Circuit extends BaseModel return $row ? $row['cumulative_score'] : 0; } + public static function getMyPhaseScore($season,$phase){ + $row = SqlHelper::ormSelectOne( + myself()->_getSelfMysql(), + 't_circuit_battle_phase', + array( + 'account_id' => myself()->_getAccountId(), + 'season' => $season, + 'phase' => $phase, + ) + ); + return $row ? $row['cumulative_score'] : 0; + } + public static function getRankingList($season){ $sql = "select * from t_circuit_battle where season=:season order by cumulative_score desc,modifytime asc"; $whereKv = array( - "season" => $season, + ":season" => $season, + ); + $rows = myself()->_getMysql('')->execQuery($sql,$whereKv); + if (!$rows){ + $rows = array(); + } + return $rows; + } + + public static function getPhaseRankingList($season,$phase){ + $sql = "select * from t_circuit_battle_phase where season=:season and phase=:phase order by cumulative_score desc,modifytime asc"; + $whereKv = array( + ":season" => $season, + ":phase" => $phase, ); $rows = myself()->_getMysql('')->execQuery($sql,$whereKv); if (!$rows){ diff --git a/webapp/services/RoomBattleDataService.php b/webapp/services/RoomBattleDataService.php index ad6cf272..18492221 100644 --- a/webapp/services/RoomBattleDataService.php +++ b/webapp/services/RoomBattleDataService.php @@ -133,14 +133,18 @@ class RoomBattleDataService extends BaseService { //巡回模式排位分计算 if ($this->mapMode == mt\MapMode::CIRCUIT_MODE){ $circuitMeta = mt\CircuitTime::getCurrentCircuit(); - if ($circuitMeta ){ + $circuitStageMeta = mt\CircuitTime::getCurrentStage(); + if ($circuitMeta && $circuitStageMeta){ $minScore = mt\Parameter::getVal('circuit_rank_score_min',0); $multConstant = mt\Parameter::getVal('circuit_score_mult_constant',1); $shiftConstant = mt\Parameter::getVal('circuit_score_shift_constant',1); $circuitScore = $battleScore * $multConstant + $shiftConstant; $myScore = Circuit::getMyScore($circuitMeta['circuit_season']); + $myPhaseScore = Circuit::getMyPhaseScore($circuitStageMeta['circuit_season'],$circuitStageMeta['circuit_phase']); $finalScore = max($minScore, $myScore+$circuitScore); + $finalPhaseScore = max($minScore, $myPhaseScore+$circuitScore); Circuit::updateScore($circuitMeta['circuit_season'],$finalScore); + Circuit::updatePhaseScore($circuitStageMeta['circuit_season'],$circuitStageMeta['circuit_phase'],$finalPhaseScore); $member['new_circuit_score'] = $finalScore; } }