game2004api/webapp/controller/ServerSwitchController.class.php

109 lines
3.8 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
class ServerSwitchController {
protected function getMysql($account_id)
{
$mysql_conf = getMysqlConfig(crc32($account_id));
$conn = new phpcommon\Mysql(array(
'host' => $mysql_conf['host'],
'port' => $mysql_conf['port'],
'user' => $mysql_conf['user'],
'passwd' => $mysql_conf['passwd'],
'dbname' => DBNAME_PREFIX . $mysql_conf['instance_id']
));
return $conn;
}
private function isForbidCity()
{
return false;
/*if (in_array(strtolower($_REQUEST['province']),
array(
strtolower('Shanghai'),
strtolower('Beijing'),
'上海',
'北京'
)) ||
in_array(strtolower($_REQUEST['city']),
array(
strtolower('Guangzhou'),
strtolower('Shenzhen'),
strtolower('Chengdu'),
'广州',
'深圳',
'成都'
))
) {
return true;
}
return false;*/
}
public function getSwitch()
{
/*if (SERVER_ENV != _ONLINE) {
echo json_encode(array(
'errcode' => 0,
'errmsg' => '',
'payable' => 1
));
die();
}*/
//error_log(json_encode($_REQUEST));
$payable = 0;
/*
1玩家进入第一天战斗7次开放充值除北上广深成
2玩家进入第二天战斗7次已充值玩家战斗2次除北上广深成
3玩家进入第三天战斗7次已充值玩家战斗2次。
*/
if (phpcommon\isValidSessionId($_REQUEST['account_id'],
$_REQUEST['session_id'])) {
$recharge_times = 0;
$conn = $this->getMysql($_REQUEST['account_id']);
$row = $conn->execQueryOne('SELECT recharge_times_total FROM user WHERE accountid=:accountid;',
array(
':accountid' => $_REQUEST['account_id']
));
if ($row) {
$recharge_times = $row['recharge_times_total'];
}
$register_time = phpcommon\extractRegisterTimeFromSessionId($_REQUEST['session_id']);
$nowtime = time();
$register_time = phpcommon\getdayseconds($register_time);
$nowtime = phpcommon\getdayseconds($nowtime);
if ($nowtime - $register_time > 3600 * 24 * 2) {
//第三天
if ($_REQUEST['battle_times'] >= 2) {
$payable = 1;
} else if ($recharge_times > 0 && $_REQUEST['battle_times'] >= 1) {
$payable = 1;
}
} else if ($nowtime - $register_time > 3600 * 24 * 1) {
//第二天
if ($this->isForbidCity()) {
} else {
if ($_REQUEST['battle_times'] >= 2) {
$payable = 1;
} else if ($recharge_times > 0 && $_REQUEST['battle_times'] >= 2) {
$payable = 1;
}
}
} else {
//第一天
if ($this->isForbidCity()) {
} else if ($_REQUEST['battle_times'] >= 3) {
$payable = 1;
}
}
}
echo json_encode(array(
'errcode' => 0,
'errmsg' => '',
'payable' => $payable
));
}
}