153 lines
5.8 KiB
PHP
153 lines
5.8 KiB
PHP
<?php
|
|
|
|
class HangController{
|
|
|
|
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' => 'gamedb2001_' . $mysql_conf['instance_id']
|
|
));
|
|
return $conn;
|
|
}
|
|
|
|
protected function getParameter($para_id)
|
|
{
|
|
$g_conf_para_cluster = require('../res/parameter@parameter.php');
|
|
$para_conf = getParameterConfig($g_conf_para_cluster, $para_id);
|
|
$p = array(
|
|
'id' => $para_conf['id'],
|
|
'param_name' => $para_conf['param_name'],
|
|
'param_value' => $para_conf['param_value'],
|
|
);
|
|
return $p;
|
|
}
|
|
|
|
public function getTime()
|
|
{
|
|
$account_id = $_REQUEST['account_id'];
|
|
//登录校验
|
|
$login = loginVerify($account_id, $_REQUEST['session_id']);
|
|
if (!$login) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, 'session无效');
|
|
return;
|
|
}
|
|
$conn = $this->getMysql($account_id);
|
|
if (!$conn) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
|
|
return;
|
|
}
|
|
$num = 0;
|
|
$row = $conn->execQueryOne('SELECT * FROM hang WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id
|
|
));
|
|
if (!$row) {
|
|
$ret = $conn->execScript('INSERT INTO hang(accountid, hang_time, create_time, modify_time) ' .
|
|
' VALUES(:accountid, :hang_time, :create_time, :modify_time) ' .
|
|
' ON DUPLICATE KEY UPDATE accountid=:accountid, hang_time=:hang_time, modify_time=:modify_time;',
|
|
array(
|
|
':accountid' => $account_id,
|
|
':hang_time' => time(),
|
|
':create_time' => time(),
|
|
':modify_time' => time()
|
|
));
|
|
if (!$ret) {
|
|
die();
|
|
return;
|
|
}
|
|
} else {
|
|
/*$p_num = $this->getParameter(GOLD);
|
|
$p_time_limit = $this->getParameter(TIME_LIMIT);
|
|
$num = floor((time() - $row['hang_time']) / 5 * $p_num['param_value']);
|
|
if ((time() - $row['hang_time']) >= $p_time_limit['param_value']) {
|
|
$num = floor($p_time_limit['param_value'] / 5 * $p_num['param_value']);
|
|
}*/
|
|
}
|
|
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg' => '',
|
|
'time' => time(),
|
|
'num' => $num
|
|
));
|
|
}
|
|
|
|
public function getHangReward()
|
|
{
|
|
$account_id = $_REQUEST['account_id'];
|
|
//登录校验
|
|
$login = loginVerify($account_id, $_REQUEST['session_id']);
|
|
if (!$login) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, 'session无效');
|
|
return;
|
|
}
|
|
$conn = $this->getMysql($account_id);
|
|
$item_id = 0;
|
|
$num = 0;
|
|
$weight = $_REQUEST['weight'];
|
|
if (!$conn) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
|
|
return;
|
|
}
|
|
$row = $conn->execQueryOne('SELECT * FROM hang WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id
|
|
));
|
|
if ($row) {
|
|
$ret = $conn->execScript('UPDATE hang SET hang_time=:hang_time, modify_time=:modify_time ' .
|
|
' WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id,
|
|
':hang_time' => time(),
|
|
':modify_time' => time()
|
|
));
|
|
if (!$ret) {
|
|
die();
|
|
return;
|
|
}
|
|
|
|
$item_id = 10001;
|
|
$p_num = $this->getParameter(GOLD);
|
|
$p_time_limit = $this->getParameter(TIME_LIMIT);
|
|
$num = floor((time() - $row['hang_time']) / 5 * $p_num['param_value']);
|
|
if ((time() - $row['hang_time']) >= $p_time_limit['param_value']) {
|
|
$num = floor($p_time_limit['param_value'] / 5 * $p_num['param_value']);
|
|
}
|
|
if ($weight != 0) {
|
|
$p = $this->getParameter(REWARD_TIMES);
|
|
$times = $p['param_value'] - 1;
|
|
$num = $num * $times;
|
|
}
|
|
$row = $conn->execQueryOne('SELECT * FROM user WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id
|
|
));
|
|
$ret = $conn->execScript('UPDATE user SET coin_num=:coin_num, modify_time=:modify_time ' .
|
|
' WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id,
|
|
':coin_num' => $num + $row['coin_num'],
|
|
':modify_time' => time()
|
|
));
|
|
if (!$ret) {
|
|
die();
|
|
return;
|
|
}
|
|
}
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg' => '',
|
|
'item_id' => $item_id,
|
|
'num' => $num,
|
|
'time' => time()
|
|
));
|
|
}
|
|
|
|
}
|
|
?>
|