From b0ad92e1494426bc273f38dd946703a06bd5a201 Mon Sep 17 00:00:00 2001 From: hujiabin <519660157@qq.com> Date: Sun, 18 Aug 2024 11:07:44 +0800 Subject: [PATCH] 1 --- webapp/controller/AnncController.class.php | 28 ++++++++++++---- webapp/controller/OtherController.class.php | 5 ++- ...rverSwitch.php => ServerSwitchService.php} | 32 +++++++++---------- 3 files changed, 40 insertions(+), 25 deletions(-) rename webapp/services/{ServerSwitch.php => ServerSwitchService.php} (64%) diff --git a/webapp/controller/AnncController.class.php b/webapp/controller/AnncController.class.php index 486513ad..3979f5cc 100644 --- a/webapp/controller/AnncController.class.php +++ b/webapp/controller/AnncController.class.php @@ -3,8 +3,23 @@ use phpcommon\SqlHelper; class AnncController extends BaseController { + const ANNC_REDIS_KEY = 'annc_redis_key:'; + public function getAnnc() { + $redis = myself()->_getRedis(self::ANNC_REDIS_KEY); + if ($redis->exists(self::ANNC_REDIS_KEY)){ + $data = json_decode($redis->get(self::ANNC_REDIS_KEY),true); + }else{ + $data = $this->_findAnnc(); + $redis->set(self::ANNC_REDIS_KEY,json_encode($data)); + $redis->pexpire(self::ANNC_REDIS_KEY , max(0, min(15, myself()->_getNowTime() - $data['end_time'])) * 1000); + } + + myself()->_rspData($data); + } + + private function _findAnnc(){ $seconds = myself()->_getNowTime() - myself()->_getNowDaySeconds(); $data = array(); $row = myself()->_getConfDbMysql()->execQueryOne( @@ -15,13 +30,14 @@ class AnncController extends BaseController { ) ); if ($row){ - $data = array( - 'id' => $row['uniid'], - 'title' => $row['title'], - 'content' => $row['content'] - ); + $data = array( + 'id' => $row['uniid'], + 'title' => $row['title'], + 'content' => $row['content'], + 'end_time' => $row['end_time'] + ); } - myself()->_rspData($data); + return $data; } } diff --git a/webapp/controller/OtherController.class.php b/webapp/controller/OtherController.class.php index 7911f3f6..ec958949 100644 --- a/webapp/controller/OtherController.class.php +++ b/webapp/controller/OtherController.class.php @@ -1,7 +1,7 @@ $packageId )); $examining = !empty($row) && $row['version'] == $version && $row['is_auditing'] ? 1 : 0; - $switchObj = new ServerSwitch(); - $con = $switchObj->getGameSwitch(); + $con = ServerSwitchService::getGameSwitch(); $this->_rspData(array( 'data' => $examining ? $con['auditing'] : $con['normal'] )); diff --git a/webapp/services/ServerSwitch.php b/webapp/services/ServerSwitchService.php similarity index 64% rename from webapp/services/ServerSwitch.php rename to webapp/services/ServerSwitchService.php index 7c176473..812f6a3e 100644 --- a/webapp/services/ServerSwitch.php +++ b/webapp/services/ServerSwitchService.php @@ -2,40 +2,40 @@ use phpcommon\SqlHelper; -class ServerSwitch { +class ServerSwitchService { const SERVER_SWITCH_KEY = 'server_switch_redis_key:'; const SERVER_AUDITING_KEY = 'server_auditing_redis_key:'; - public function getConfig(){ - return $this->getGameSwitch()['normal']; + public static function getConfig(){ + return self::getGameSwitch()['normal']; } - public function heroChainIsOpen(){ - if ($this->getConfig()['heroChain'] > 0){ + public static function heroChainIsOpen(){ + if (self::getConfig()['heroChain'] > 0){ return true; } return false; } - public function heroUpIsOpen(){ - if ($this->getConfig()['heroUp'] > 0){ + public static function heroUpIsOpen(){ + if (self::getConfig()['heroUp'] > 0){ return true; } return false; } - public function goldSynIsOpen(){ - if ($this->getConfig()['goldSyn'] > 0){ + public static function goldSynIsOpen(){ + if (self::getConfig()['goldSyn'] > 0){ return true; } return false; } - public function heroPieceSynIsOpen(){ - if ($this->getConfig()['heroPieceSyn'] > 0){ + public static function heroPieceSynIsOpen(){ + if (self::getConfig()['heroPieceSyn'] > 0){ return true; } return false; } - public function chipPieceSynIsOpen(){ - if ($this->getConfig()['chipPieceSyn'] > 0){ + public static function chipPieceSynIsOpen(){ + if (self::getConfig()['chipPieceSyn'] > 0){ return true; } return false; @@ -47,19 +47,19 @@ class ServerSwitch { // $this->switchConfig = getServerSwitchConfig(); // } - public function getGameSwitch(){ + public static function getGameSwitch(){ $redis = myself()->_getRedis(self::SERVER_SWITCH_KEY); if ($redis->exists(self::SERVER_SWITCH_KEY)){ $data = json_decode($redis->get(self::SERVER_SWITCH_KEY),true); }else{ - $data = $this->selectSwitchTable(); + $data = self::selectSwitchTable(); $redis->set(self::SERVER_SWITCH_KEY,json_encode($data)); $redis->pexpire(self::SERVER_SWITCH_KEY , 10*1000); } return $data; } - private function selectSwitchTable(){ + private static function selectSwitchTable(){ $rows = SqlHelper::ormSelect(myself()->_getConfDbMysql(), 't_game_switch', array()); $data = array( 'normal' => array(),