diff --git a/webapp/services/ServerSwitch.php b/webapp/services/ServerSwitch.php index 7845193d..356ab934 100644 --- a/webapp/services/ServerSwitch.php +++ b/webapp/services/ServerSwitch.php @@ -1,12 +1,11 @@ switchConfig){ - $this->initConfig(); - } - return $this->switchConfig; + return $this->getGameSwitch(); } public function heroChainIsOpen(){ @@ -40,10 +39,35 @@ class ServerSwitch { return false; } - private $switchConfig = null; +// private $switchConfig = null; +// +// private function initConfig(){ +// $this->switchConfig = getServerSwitchConfig(); +// } - private function initConfig(){ - $this->switchConfig = getServerSwitchConfig(); + public 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(); + $redis->set(self::SERVER_SWITCH_KEY,json_encode($data)); + $redis->pexpire(self::SERVER_SWITCH_KEY , 10*1000); + } + return $data; + } + + private function selectSwitchTable(){ + $rows = SqlHelper::ormSelect(myself()->_getConfDbMysql(), 't_game_switch', array()); + $data = array(); + if (count($rows) > 0){ + foreach ($rows as $row){ + $data[$row['switch_name']] = $row['is_open']; + } + }else{ + $data = getServerSwitchConfig(); + } + return $data; } }