game2006api/webapp/services/ServerSwitch.php
aozhiwei 17c7b693ca 1
2024-08-14 11:23:36 +08:00

73 lines
1.9 KiB
PHP

<?php
use phpcommon\SqlHelper;
class ServerSwitch {
const SERVER_SWITCH_KEY = 'server_switch_redis_key:';
public function getConfig(){
return $this->getGameSwitch();
}
public function heroChainIsOpen(){
if ($this->getConfig()['heroChain'] > 0){
return true;
}
return false;
}
public function heroUpIsOpen(){
if ($this->getConfig()['heroUp'] > 0){
return true;
}
return false;
}
public function goldSynIsOpen(){
if ($this->getConfig()['goldSyn'] > 0){
return true;
}
return false;
}
public function heroPieceSynIsOpen(){
if ($this->getConfig()['heroPieceSyn'] > 0){
return true;
}
return false;
}
public function chipPieceSynIsOpen(){
if ($this->getConfig()['chipPieceSyn'] > 0){
return true;
}
return false;
}
// private $switchConfig = null;
//
// 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'];
}
}
return $data;
}
}