game2001api/webapp/controller/HangController.class.php
aozhiwei e073dabedf 1
2020-09-25 16:14:23 +08:00

359 lines
14 KiB
PHP

<?php
require 'classes/AddReward.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;
}
protected function getItem($item_id)
{
$g_conf_item_cluster = require('../res/item@item.php');
$item_conf = getItemConfig($g_conf_item_cluster, $item_id);
$it = array(
'id' => $item_conf['id'],
'price' => $item_conf['price'],
'dprice' => $item_conf['dprice'],
'type' => $item_conf['fuction'],
'index' => $item_conf['fuctionindex']
);
return $it;
}
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;
$times = 3;
$num = $num * $times;
}
$row = $conn->execQueryOne('SELECT * FROM user WHERE accountid=:accountid;',
array(
':accountid' => $account_id
));
$num = $num + $row['coin_num'];
$ret = $conn->execScript('UPDATE user SET coin_num=:coin_num, modify_time=:modify_time ' .
' WHERE accountid=:accountid;',
array(
':accountid' => $account_id,
':coin_num' => $num,
':modify_time' => time()
));
if (!$ret) {
die();
return;
}
}
echo json_encode(array(
'errcode' => 0,
'errmsg' => '',
'coin_nums' => $num,
'time' => time()
));
}
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 duihuanCoin()
{
$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;
}
$id = $_REQUEST['id'];
$it = $this->getItem($id);
$row = $conn->execQueryOne('SELECT coin_num, daily_skin_times, diamond_num, daily_diamond_times FROM user WHERE accountid=:accountid;',
array(
':accountid' => $account_id
));
if (!$row) {
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
return;
}
$p1 = $this->getParameter(COINREWARD);
$p2 = $this->getParameter(SUIPIANREWARD);
$p3 = $this->getParameter(SUIPIANTIME);
$p4 = $this->getParameter(ZIJIE_DIAMONDREWARD_TIMES);
$p5 = $this->getParameter(ZIJIE_DIAMONDREWARD);
$skin_times = $row['daily_skin_times'];
$diamond_times = $row['daily_diamond_times'];
$addreward = new classes\AddReward();
if ($it['type'] == 1) {
$num = $p1['param_value'];
$addreward->addReward($id, $num, $account_id);
}
if ($it['type'] == 2) {
if ($row['daily_diamond_times'] >= $p4['param_value']) {
phpcommon\sendError(ERR_USER_BASE + 2, '今日兑换次数已用完');
return;
}
$num = $p5['param_value'];
$addreward->addReward($id, $num, $account_id);
$diamond_times = $row['daily_diamond_times'] + 1;
$ret = $conn->execScript('UPDATE user SET daily_diamond_times=:daily_diamond_times, modify_time=:modify_time ' .
' WHERE accountid=:accountid;',
array(
':accountid' => $account_id,
':daily_diamond_times' => $diamond_times,
':modify_time' => time()
));
if (!$ret) {
die();
return;
}
}
if ($it['type'] == 4) {
if ($row['daily_skin_times'] >= $p3['param_value']) {
phpcommon\sendError(ERR_USER_BASE + 2, '今日兑换次数已用完');
return;
}
$addreward = new classes\AddReward();
$addreward->addReward($id - 1000, $p2['param_value'], $account_id);
$skin_times = $row['daily_skin_times'] + 1;
$ret = $conn->execScript('UPDATE user SET daily_skin_times=:daily_skin_times, modify_time=:modify_time ' .
' WHERE accountid=:accountid;',
array(
':accountid' => $account_id,
':daily_skin_times' => $skin_times,
':modify_time' => time()
));
if (!$ret) {
die();
return;
}
}
$coin_num = $addreward->getCoinNum($account_id);
$diamond_num = $addreward->getDiamondNum($account_id);
echo json_encode(array(
'errcode' => 0,
'errmsg' => '',
'coin_nums' => $coin_num,
'diamond_nums' => $diamond_num,
'times' => $skin_times,
'daily_diamond_times' => $diamond_times,
));
}
public function getNewHandReward()
{
$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;
}
$row = $conn->execQueryOne('SELECT newhand FROM user WHERE accountid=:account_id;',
array(
':account_id' => $account_id
));
$type = 1;
if (!$row || $row['newhand'] != 1) {
phpcommon\sendError(ERR_USER_BASE + 2, '未达到领取条件');
return;
}
$ret = $conn->execScript('UPDATE user SET newhand=2, modify_time=:modify_time ' .
' WHERE accountid=:accountid;',
array(
':modify_time' => time(),
':accountid' => $account_id
));
if (!$ret) {
die();
return;
}
$p_num = $this->getParameter(ZIJIE_ACTIVITY_REWARD);
$item_list = array();
array_push($item_list, array(
'item_id' => $p_num['param_value'],
'item_num' => 1,
));
$addreward = new classes\AddReward();
$item_list = $addreward->addReward($p_num['param_value'], 1, $account_id);
$coin_num = $addreward->getCoinNum($account_id);
$num = $addreward->getDiamondNum($account_id);
echo json_encode(array(
'errcode' => 0,
'errmsg'=> '',
'item_list' => $item_list,
'coin_num' => $coin_num,
'diamond_nums' => $num,
));
}
public function getMidAutReward()
{
$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;
}
$row = $conn->execQueryOne('SELECT mid_aut_status FROM user WHERE accountid=:account_id;',
array(
':account_id' => $account_id
));
if (!$row || $row['mid_aut_status'] != 1) {
phpcommon\sendError(ERR_USER_BASE + 2, '未达到领取条件');
return;
}
$ret = $conn->execScript('UPDATE user SET mid_aut_status=2, modify_time=:modify_time ' .
' WHERE accountid=:accountid;',
array(
':modify_time' => time(),
':accountid' => $account_id
));
if (!$ret) {
die();
return;
}
$p_num = $this->getParameter(ZIJIE_ACTIVITY2_REWARD);
$item_list = array();
array_push($item_list, array(
'item_id' => $p_num['param_value'],
'item_num' => 1,
));
$addreward = new classes\AddReward();
$item_list = $addreward->addReward($p_num['param_value'], 1, $account_id);
$coin_num = $addreward->getCoinNum($account_id);
$num = $addreward->getDiamondNum($account_id);
echo json_encode(array(
'errcode' => 0,
'errmsg'=> '',
'item_list' => $item_list,
'coin_num' => $coin_num,
'diamond_nums' => $num,
));
}
}
?>