78 lines
2.2 KiB
PHP
78 lines
2.2 KiB
PHP
<?php
|
|
|
|
use phpcommon\SqlHelper;
|
|
|
|
class ServerSwitch {
|
|
const SERVER_SWITCH_KEY = 'server_switch_redis_key:';
|
|
const SERVER_AUDITING_KEY = 'server_auditing_redis_key:';
|
|
|
|
public function getConfig(){
|
|
return $this->getGameSwitch()['normal'];
|
|
}
|
|
|
|
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(
|
|
'normal' => array(),
|
|
'auditing' => array(),
|
|
);
|
|
if (count($rows) > 0){
|
|
foreach ($rows as $row){
|
|
$data['normal'][$row['switch_name']] = $row['is_open'];
|
|
$data['auditing'][$row['switch_name']] = $row['audit_is_open'];
|
|
}
|
|
}
|
|
return $data;
|
|
}
|
|
|
|
}
|