From 9780c16ff8a1b8a02b60a89088039980bbb2d089 Mon Sep 17 00:00:00 2001 From: hujiabin <519660157@qq.com> Date: Fri, 20 Sep 2024 18:22:46 +0800 Subject: [PATCH] 1 --- sql/gamedb.sql | 22 +++++++ sql/gamedb2006_migrate_240920_01.sql | 19 ++++++ webapp/controller/CircuitController.class.php | 14 +++++ .../OutAppCircuitController.class.php | 63 +++++++++++++++++++ webapp/models/Circuit.php | 2 +- webapp/models/CircuitReward.php | 50 +++++++++++++++ webapp/mt/CircuitTime.php | 10 +++ 7 files changed, 179 insertions(+), 1 deletion(-) create mode 100644 sql/gamedb2006_migrate_240920_01.sql create mode 100644 webapp/controller/OutAppCircuitController.class.php create mode 100644 webapp/models/CircuitReward.php diff --git a/sql/gamedb.sql b/sql/gamedb.sql index 56d51b0d..8a331dbc 100644 --- a/sql/gamedb.sql +++ b/sql/gamedb.sql @@ -2056,4 +2056,26 @@ CREATE TABLE `t_circuit_battle` ( PRIMARY KEY (`idx`), KEY `idx_account_season` (`account_id`, `season`) ) 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` +-- + +DROP TABLE IF EXISTS `t_circuit_reward`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `t_circuit_reward` ( + `idx` bigint NOT NULL AUTO_INCREMENT COMMENT '自增id', + `account_id` varchar(60) NOT NULL DEFAULT '' COMMENT '账号id(channel + "_" + gameid + "_" + openid)', + `address` varchar(60) CHARACTER SET utf8 COMMENT 'address', + `season` int(11) NOT NULL DEFAULT '0' COMMENT '赛季', + `stage` int(11) NOT NULL DEFAULT '0' COMMENT '阶段', + `ranking` int(11) NOT NULL DEFAULT '0' COMMENT '排名', + `reward_num` 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 `account_season_stage` (`account_id`, `season`, `stage`) +) ENGINE=InnoDB AUTO_INCREMENT=10000 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; /*!40101 SET character_set_client = @saved_cs_client */; \ No newline at end of file diff --git a/sql/gamedb2006_migrate_240920_01.sql b/sql/gamedb2006_migrate_240920_01.sql new file mode 100644 index 00000000..9e72542a --- /dev/null +++ b/sql/gamedb2006_migrate_240920_01.sql @@ -0,0 +1,19 @@ +begin; + +CREATE TABLE `t_circuit_reward` ( + `idx` bigint NOT NULL AUTO_INCREMENT COMMENT '自增id', + `account_id` varchar(60) NOT NULL DEFAULT '' COMMENT '账号id(channel + "_" + gameid + "_" + openid)', + `address` varchar(60) CHARACTER SET utf8 COMMENT 'address', + `season` int(11) NOT NULL DEFAULT '0' COMMENT '赛季', + `stage` int(11) NOT NULL DEFAULT '0' COMMENT '阶段', + `ranking` int(11) NOT NULL DEFAULT '0' COMMENT '排名', + `reward_num` 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 `account_season_stage` (`account_id`, `season`, `stage`) +) ENGINE=InnoDB AUTO_INCREMENT=10000 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; + +insert into version (version) values(2024091501); + +commit; diff --git a/webapp/controller/CircuitController.class.php b/webapp/controller/CircuitController.class.php index 32a14ca0..41c8778f 100644 --- a/webapp/controller/CircuitController.class.php +++ b/webapp/controller/CircuitController.class.php @@ -17,6 +17,20 @@ use phpcommon\SqlHelper; class CircuitController extends BaseAuthedController { private $redis_key_circuit_ranking = 'circuit_ranking'; + public function _handlePre() + { + parent::_handlePre(); + if (!myself()->_switchIsOpen('circuitMatch')) { + $this->_rspErr(1, 'current stage Have not yet started'); + return; + } + if (!(count(CIRCUIT_MATCH_SERVER_LIST) <= 0 && + in_array(myself()->_getZid(), CIRCUIT_MATCH_SERVER_LIST))) { + $this->_rspErr(1, 'current stage Have not yet started'); + return; + } + } + public function getCurrentStage(){ $circuitStageMeta = mt\CircuitTime::getCurrentStage(); if (!$circuitStageMeta){ diff --git a/webapp/controller/OutAppCircuitController.class.php b/webapp/controller/OutAppCircuitController.class.php new file mode 100644 index 00000000..26b6f5b6 --- /dev/null +++ b/webapp/controller/OutAppCircuitController.class.php @@ -0,0 +1,63 @@ + 0){ + $totalWeight = 0; + $rate = \mt\Parameter::getVal('circuit_reward_rate',''); + $count = floor(count($rows) * $rate) ; + foreach ($rows as $k=>$value){ + $ranking = $k+1; + $rewardWeight = \mt\CircuitReward::getRewardWeight($ranking); + if ($ranking <= $count){ + $totalWeight += $rewardWeight; + } + } + $cecPool = $prevStageMeta['cec_pool']; + foreach ($rows as $k=>$value){ + $cec = 0; + $ranking = $k+1; + $rewardWeight = \mt\CircuitReward::getRewardWeight($ranking); + if ($ranking <= $count){ + $cec = ($rewardWeight / $totalWeight) * $cecPool; + } + $user = User::find($value['account_id']); + CircuitReward::add( + $user['account_id'], + $user['address'], + $prevStageMeta['circuit_season'], + $prevStageMeta['circuit_phase'], + $ranking, + $cec + ); + } + } + $this->_rspOk(); + return; + } + $this->_rspErr(1,'未满足结算条件'); + } + +} diff --git a/webapp/models/Circuit.php b/webapp/models/Circuit.php index 12991941..af28141d 100644 --- a/webapp/models/Circuit.php +++ b/webapp/models/Circuit.php @@ -47,7 +47,7 @@ class Circuit extends BaseModel $whereKv = array( "season" => $season, ); - $rows = myself()->_getSelfMysql()->execQuery($sql,$whereKv); + $rows = myself()->_getMysql('')->execQuery($sql,$whereKv); if (!$rows){ $rows = array(); } diff --git a/webapp/models/CircuitReward.php b/webapp/models/CircuitReward.php new file mode 100644 index 00000000..26367933 --- /dev/null +++ b/webapp/models/CircuitReward.php @@ -0,0 +1,50 @@ +_getMysql(''), + 't_circuit_reward', + array( + 'season' => $season, + 'stage' => $stage + ) + ); + if ($row){ + return true; + } + return false; + } + + public static function add($account,$address,$season,$stage,$ranking,$rewardNum){ + SqlHelper::upsert( + myself()->_getMysql(''), + 't_circuit_reward', + array( + 'account_id' => $account, + 'season' => $season, + 'stage' => $stage + ), + array( + + ), + array( + 'account_id' => $account, + 'address' => $address, + 'season' => $season, + 'stage' => $stage, + 'ranking' => $ranking, + 'reward_num' => $rewardNum, + 'createtime' => myself()->_getNowTime(), + 'modifytime' => myself()->_getNowTime(), + ) + ); + } +} + diff --git a/webapp/mt/CircuitTime.php b/webapp/mt/CircuitTime.php index 66c79e7b..1eb61c36 100644 --- a/webapp/mt/CircuitTime.php +++ b/webapp/mt/CircuitTime.php @@ -18,6 +18,16 @@ class CircuitTime { return null; } + public static function getPrevStage(){ + $prev = array(); + foreach (self::getCircuitAll(self::STAGE_SEASON_TYPE) as $meta){ + if (myself()->_getNowTime() > strtotime($meta['end_time'])){ + $prev = $meta; + } + } + return $prev; + } + public static function getCurrentStage(){ foreach (self::getCircuitAll(self::STAGE_SEASON_TYPE) as $meta){ if (myself()->_getNowTime() >= strtotime($meta['start_time']) &&