game2005api/webapp/controller/HangController.class.php
aozhiwei b8bb70a77f 1
2021-06-18 22:23:50 +08:00

287 lines
11 KiB
PHP

<?php
require_once 'metatable/parameter.php';
require_once 'metatable/season.php';
require_once 'metatable/seasoncard.php';
require_once 'metatable/drop.php';
require 'classes/AddReward.php';
class HangController extends BaseAuthedController {
protected function getExplode($string)
{
$delim = "|";
$drop_multiply = explode($delim, $string);
$delim1 = ":";
$arr = array();
for ($i = 0; $i < count($drop_multiply); $i++) {
$mul = explode($delim1, $drop_multiply[$i]);
array_push($arr, $mul);
}
return $arr;
}
protected function getParameter($para_id)
{
$parameter_meta_cluster = require('../res/parameter@parameter.php');
$parameter_meta = getParameterConfig($parameter_meta_cluster, $para_id);
$p = array(
'id' => $parameter_meta['id'],
'name' => $parameter_meta['param_name'],
'value' => $parameter_meta['param_value'],
);
return $p;
}
protected function getSeasonPoint($seaPoint_id)
{
$seaPoint_meta_table = require('../res/seasomPoint@seasomPoint.php');
$seaPoint_meta = getSeasonPointConfig($seaPoint_meta_table, $seaPoint_id);
$seaPoint = array(
'id' => $seaPoint_meta['id'],
'min' => $seaPoint_meta['min_point'],
'max' => $seaPoint_meta['max_point'],
'des' => $seaPoint_meta['des'],
//'reward' => $seaPoint_meta['season_reward'],
//'weekreward' => $seaPoint_meta['week_reward'],
);
return $seaPoint;
}
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;
}
echo json_encode(array(
'errcode' => 0,
'errmsg' => '',
'time' => phpcommon\getNowTime(),
));
}
public function getRedInfo()
{
$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;
}
echo json_encode(array(
'errcode' => 0
));
}
public function getOnlineReward()
{
$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;
$item_list = array();
$all_item_list = array();
$rowuser = $conn->execQueryOne('SELECT game_times FROM user WHERE accountid=:accountid;',
array(
':accountid' => $account_id
));
if (!$rowuser || $rowuser['game_times'] < metatable\getParameterByName('function_open_coin')) {
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
return;
}
$isnew = 0;
if (isset($_REQUEST['isnew']) && $_REQUEST['isnew'] == 1) {
$isnew = 1;
}
$row = $conn->execQueryOne('SELECT * FROM hang WHERE accountid=:accountid;',
array(
':accountid' => $account_id
));
$addreward = new classes\AddReward();
if (!$row) {
$ret = $conn->execScript('INSERT INTO hang(accountid, hang_time, reward_id, reward_num, create_time, modify_time) ' .
' VALUES(:accountid, :hang_time, 0, 0, :create_time, :modify_time) ' .
' ON DUPLICATE KEY UPDATE accountid=:accountid, hang_time=:hang_time, reward_id=0, reward_num=0, modify_time=:modify_time;',
array(
':accountid' => $account_id,
':hang_time' => phpcommon\getNowTime(),
':create_time' => phpcommon\getNowTime(),
':modify_time' => phpcommon\getNowTime()
));
if (!$ret) {
die();
return;
}
$num = 0;
} else {
$p_num = $this->getParameter(OFFLINE_REWARD_NUMBER);
$p_time_limit = $this->getParameter(OFFLINE_TIME_LIMIT);
$p_val = $this->getParameter(OFFLINE_TIME_UNIT);
$val = $addreward->getVipVal($account_id, 8);
$max_time = $p_time_limit['value'] + $val;
$num = floor((phpcommon\getNowTime() - $row['hang_time']) / $p_val['value'] * $p_num['value']);
if ((phpcommon\getNowTime() - $row['hang_time']) >= $max_time ||
$isnew == 1) {
$num = floor($max_time / $p_val['value'] * $p_num['value']);
}
$val2 = $addreward->getVipVal($account_id, 6);
$num = floor($num + $num * $val2 / 100);
$item_id = 10001;
$ret = $conn->execScript('UPDATE hang SET hang_time=:hang_time, reward_num=:reward_num, modify_time=:modify_time ' .
' WHERE accountid=:accountid;',
array(
':accountid' => $account_id,
':hang_time' => phpcommon\getNowTime(),
':modify_time' => phpcommon\getNowTime(),
//':reward_id' => $item_id,
':reward_num' => $num,
));
if (!$ret) {
die();
return;
}
//额外奖励
$val3 = $addreward->getVipVal($account_id, 7);
$jilv = metatable\getParameterByName('offline_time_pro') + $val3;
$rowu = $conn->execQueryOne('SELECT daily_offline FROM user WHERE accountid=:accountid;',
array(
':accountid' => $account_id
));
$rand = Rand(0, 100);
if ($rowu['daily_offline'] < metatable\getParameterByName('offline_time_boxtimes') &&
$jilv >= $rand) {
$dropid = metatable\getParameterByName('offline_time_box');
$item_list = metatable\getDropListById($dropid);
$ret = $conn->execScript('UPDATE user SET daily_offline=:daily_offline, modify_time=:modify_time ' .
' WHERE accountid=:accountid;',
array(
':accountid' => $account_id,
':modify_time' => phpcommon\getNowTime(),
':daily_offline' => $rowu['daily_offline'] + 1,
));
$ret = $conn->execScript('UPDATE hang SET hang_time=:hang_time, reward_id=:reward_id, modify_time=:modify_time ' .
' WHERE accountid=:accountid;',
array(
':accountid' => $account_id,
':hang_time' => phpcommon\getNowTime(),
':modify_time' => phpcommon\getNowTime(),
':reward_id' => $item_list[0]['item_id'],
));
if (!$ret) {
die();
return;
}
}
array_push($item_list, array(
'item_id' => $item_id,
'item_num' => $num,
'time' => 0,
));
foreach ($item_list as $i) {
$items = $addreward->addReward($i['item_id'], $i['item_num'], $account_id, $i['time'], 0);
foreach($items as $s) {
array_push($all_item_list, array(
'item_id' => $s['item_id'],
'item_num' => $s['item_num'],
'time' => $s['time'],
));
}
}
}
$coin_num = $addreward->getCoinNum($account_id);
echo json_encode(array(
'errcode' => 0,
'errmsg' => '',
'time' => phpcommon\getNowTime(),
'item_list' => $item_list,
'all_item_list' => $all_item_list,
'coin_nums' => $coin_num,
));
}
public function getHangDoubleReward()
{
$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;
if (!$conn) {
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
return;
}
$row = $conn->execQueryOne('SELECT * FROM hang WHERE accountid=:accountid;',
array(
':accountid' => $account_id
));
if (!$row) {
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
return;
}
$item_list = array();
array_push($item_list, array(
'item_id' => $row['reward_id'],
'item_num' => 1,
'time' => 0,
));
array_push($item_list, array(
'item_id' => 10001,
'item_num' => $row['reward_num'],
'time' => 0,
));
$addreward = new classes\AddReward();
$all_item_list = array();
foreach ($item_list as $i) {
$items = $addreward->addReward($i['item_id'], $i['item_num'], $account_id, $i['time'], 0);
foreach($items as $s) {
array_push($all_item_list, array(
'item_id' => $s['item_id'],
'item_num' => $s['item_num'],
'time' => $s['time'],
));
}
}
$coin_num = $addreward->getCoinNum($account_id);
echo json_encode(array(
'errcode' => 0,
'errmsg' => '',
'item_list' => $item_list,
'all_item_list' => $all_item_list,
'coin_nums' => $coin_num,
));
}
}
?>