502 lines
20 KiB
PHP
502 lines
20 KiB
PHP
<?php
|
|
|
|
require_once 'metatable/shopGoods.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' => DBNAME_PREFIX . $mysql_conf['instance_id']
|
|
));
|
|
return $conn;
|
|
}
|
|
|
|
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 getSeason($season_id)
|
|
{
|
|
$season_meta_table = require('../res/season@season.php');
|
|
$season_meta = getSeasonConfig($season_meta_table, $season_id);
|
|
$season = array(
|
|
'number' => $season_meta['season_number'],
|
|
'open_time' => $season_meta['time1'],
|
|
'end_time' => $season_meta['time2'],
|
|
'reward' => $season_meta['season_reward'],
|
|
'weekreward' => $season_meta['week_reward'],
|
|
);
|
|
return $season;
|
|
}
|
|
|
|
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' => time(),
|
|
));
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
|
|
$quest_list = array();
|
|
if (!$conn) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
|
|
return;
|
|
}
|
|
//任务
|
|
$rowCount = $conn->execQueryRowCount('SELECT * FROM quest WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id,
|
|
));
|
|
if ($rowCount != 0) {
|
|
$rows = $conn->execQuery('SELECT * FROM quest WHERE accountid=:accountid AND quest_type=:quest_type;',
|
|
array(
|
|
':accountid' => $account_id,
|
|
':quest_type' => 1
|
|
));
|
|
if ($rows) {
|
|
foreach ($rows as $row) {
|
|
array_push($quest_list, array(
|
|
'type' => $row['quest_type'],
|
|
'quest_id' => $row['quest_id'],
|
|
'quest_num' => $row['quest_num'],
|
|
'quest_state' => $row['quest_state']
|
|
));
|
|
}
|
|
}
|
|
}
|
|
//赛季
|
|
//判断当前赛季
|
|
$number = 0;
|
|
$open_time = 0;
|
|
$end_time = 0;
|
|
$sea_reward = array();
|
|
$passport_reward = array();
|
|
$rank_status = 0;
|
|
$season_meta_table = require('../res/season@season.php');
|
|
for ($i = 1; $i <= count($season_meta_table); $i++) {
|
|
$season = $this->getSeason($i);
|
|
if (time() >= strtotime($season['open_time']) && time() <= strtotime($season['end_time'])) {
|
|
$open_time = strtotime($season['open_time']);
|
|
$end_time = strtotime($season['end_time']);
|
|
$number = $i;
|
|
$item_multiply = $this->getExplode($season['reward']);
|
|
$passportaward = array();
|
|
for($ii = 1; $ii <= count($item_multiply); $ii++) {
|
|
$rowpass = $conn->execQueryOne('SELECT active_status, honor_status, season_passport ' .
|
|
' FROM passinfo WHERE accountid=:accountid AND passid=:passid;',
|
|
array(
|
|
':accountid' => $account_id,
|
|
':passid' => $ii,
|
|
));
|
|
$rank_status = 0;
|
|
if (!$rowpass) {
|
|
$ret = $conn->execScript('INSERT INTO passinfo(accountid, passid, active_status, honor_status, season_passport, create_time, modify_time) ' .
|
|
' VALUES(:accountid, :passid, 0, 0, :season_passport, :create_time, :modify_time) ' .
|
|
' ON DUPLICATE KEY UPDATE accountid=:accountid, passid=:passid, active_status=0, honor_status=0, modify_time=:modify_time;',
|
|
array(
|
|
':accountid' => $account_id,
|
|
':passid' => $ii,
|
|
':season_passport' => '',
|
|
':create_time' => time(),
|
|
':modify_time' => time()
|
|
));
|
|
if (!$ret) {
|
|
die();
|
|
return;
|
|
}
|
|
$rank_status = 0;
|
|
} else {
|
|
$rank_status = $rowpass['active_status'];
|
|
if (!is_null($rowpass['season_passport']) && !empty($rowpass['season_passport'])) {
|
|
$passportawardinfo = json_decode($rowpass['season_passport'], true);
|
|
foreach($passportawardinfo as $key => $status) {
|
|
if (!array_key_exists($key, $passportaward)) {
|
|
$passportaward[$key] = $this->getExplode($season_meta_table[$i][$key]);
|
|
$passport_reward[$key] = array();
|
|
}
|
|
|
|
$passport_reward[$key][] = array(
|
|
'item_id' => $passportaward[$key][$ii - 1][0],
|
|
'item_num' => $passportaward[$key][$ii - 1][1],
|
|
'time' => $passportaward[$key][$ii - 1][2],
|
|
'status' => $status,
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
$key = $ii - 1;
|
|
array_push($sea_reward, array(
|
|
'item_id' => $item_multiply[$key][0],
|
|
'item_num' => $item_multiply[$key][1],
|
|
'time' => $item_multiply[$key][2],
|
|
'status' => $rank_status
|
|
));
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
if ($number == 0) {
|
|
phpcommon\sendError(ERR_USER_BASE + 2, '赛季未开启');
|
|
return;
|
|
}
|
|
//当前段位及积分
|
|
$rank = 0;
|
|
$rank_score = 0;
|
|
$max_rank_score = 0;
|
|
$min_rank_score = 0;
|
|
$reward = array();
|
|
$week_reward = array();
|
|
$row = $conn->execQueryOne('SELECT integral, pass_status, score FROM user WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id,
|
|
));
|
|
if (!$row) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
|
|
return;
|
|
}
|
|
$pass_status = $row['pass_status'];
|
|
$rank_status = 0;
|
|
$seaPoint_meta_table = require('../res/seasomPoint@seasomPoint.php');
|
|
for ($ii = 1; $ii <= count($seaPoint_meta_table); $ii++) {
|
|
$seaPoint = $this->getSeasonPoint($ii);
|
|
if ($row['integral'] >= $seaPoint['min'] && $row['integral'] <= $seaPoint['max']
|
|
|| $row['integral'] >= $seaPoint['min'] && $seaPoint['max'] == -1)
|
|
{
|
|
$delim1 = '|';
|
|
$drop_multiply = explode($delim1, $season['weekreward']);
|
|
|
|
$delim2 = ';';
|
|
$mul = explode($delim2, $drop_multiply[$ii - 1]);
|
|
|
|
$delim = ':';
|
|
$week_array = array();
|
|
for ($i2 = 0; $i2 < count($mul); $i2++) {
|
|
$mul1 = explode($delim, $mul[$i2]);
|
|
array_push($week_array, $mul1);
|
|
}
|
|
|
|
for($s = 0; $s < count($week_array); $s++) {
|
|
array_push($week_reward, array(
|
|
'item_id' => $week_array[$s][0],
|
|
'item_num' => $week_array[$s][1],
|
|
'time' => $week_array[$s][2],
|
|
'status' => $row['pass_status']
|
|
));
|
|
}
|
|
$rank = $ii;
|
|
$min_rank_score = $seaPoint['min'];
|
|
$max_rank_score = $seaPoint['max'] + 1 - $seaPoint['min'];
|
|
$rank_score = $row['integral'] - $seaPoint['min'] + 1;
|
|
if ($seaPoint['max'] == -1) {
|
|
$max_rank_score = $seaPoint['min'];
|
|
$rank_score = $row['integral'];
|
|
}
|
|
}
|
|
}
|
|
//背包
|
|
$bag_list = array();
|
|
$rows = $conn->execQuery('SELECT * FROM bag WHERE accountid=:account_id;',
|
|
array(
|
|
':account_id' => $account_id
|
|
));
|
|
if ($rows) {
|
|
foreach ($rows as $row){
|
|
$active_time = 0;
|
|
$color_id = 0;
|
|
$status = $row['status'];
|
|
if (time() >= $row['active_time'] && $row['active_time'] != 0) {
|
|
$ret = $conn->execScript('UPDATE bag SET active_time=0, color_id=0, status=2, modify_time=:modify_time ' .
|
|
' WHERE accountid=:account_id AND id=:id;',
|
|
array(
|
|
':account_id' => $account_id,
|
|
':id' => $row['id'],
|
|
':modify_time' => time()
|
|
));
|
|
if (!$ret) {
|
|
die();
|
|
return;
|
|
}
|
|
$active_time = 0;
|
|
$color_id = 0;
|
|
$status = 2;
|
|
} else {
|
|
if ($row['active_time'] != 0) {
|
|
$active_time = $row['active_time'];
|
|
}
|
|
$color_id = $row['color_id'];
|
|
$status = $row['status'];
|
|
}
|
|
array_push($bag_list, array(
|
|
'id' => $row['id'],
|
|
'active_time' => $active_time,
|
|
'status' => $status,
|
|
'color_id' => $color_id,
|
|
'num' => $row['num'],
|
|
));
|
|
}
|
|
}
|
|
//吃鸡
|
|
$row = $conn->execQueryOne('SELECT daily_order1, daily_order2, daily_order3 FROM user WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id
|
|
));
|
|
if (!$row) {
|
|
phpcommon\sendError(ERR_USER_BASE + 2, '没有这个玩家');
|
|
return;
|
|
}
|
|
$item_list = array();
|
|
$daily_order1 = $row['daily_order1'];
|
|
$daily_order2 = $row['daily_order2'];
|
|
$daily_order3 = $row['daily_order3'];
|
|
$p1 = $this->getParameter(LOGINBOX_TIME1);
|
|
$p2 = $this->getParameter(LOGINBOX_TIME2);
|
|
$p3 = $this->getParameter(LOGINBOX_TIME3);
|
|
$p = $this->getParameter(LOGINBOX_TIME);
|
|
$pt1 = $p1['value'];
|
|
$pt2 = $p2['value'];
|
|
$pt3 = $p3['value'];
|
|
$pt = $p['value'];
|
|
$nowTime = floor((time() - phpcommon\getdayseconds(time())) / 3600);
|
|
if ($nowTime < $pt1) {
|
|
$daily_order1 = 0;
|
|
$daily_order2 = 0;
|
|
$daily_order3 = 0;
|
|
} else if ($nowTime >= $pt1 && $nowTime < $pt1 + $pt) {
|
|
if ($daily_order1 == 0) {
|
|
$daily_order1 = 1;
|
|
} else {
|
|
$daily_order1 = $row['daily_order1'];
|
|
}
|
|
$daily_order2 = 0;
|
|
$daily_order3 = 0;
|
|
} else if ($nowTime >= $pt1 + $pt && $nowTime < $pt2) {
|
|
if ($daily_order1 <= 1) {
|
|
$daily_order1 = 3;
|
|
} else {
|
|
$daily_order1 = $row['daily_order1'];
|
|
}
|
|
$daily_order2 = 0;
|
|
$daily_order3 = 0;
|
|
} else if ($nowTime >= $pt2 && $nowTime < $pt2 + $pt) {
|
|
if ($daily_order1 <= 1) {
|
|
$daily_order1 = 3;
|
|
} else {
|
|
$daily_order1 = $row['daily_order1'];
|
|
}
|
|
if ($daily_order2 == 0) {
|
|
$daily_order2 = 1;
|
|
} else {
|
|
$daily_order2 = $row['daily_order2'];
|
|
} $daily_order3 = 0;
|
|
} else if ($nowTime >= $pt2 + $pt && $nowTime < $pt3) {
|
|
if ($daily_order1 <= 1) {
|
|
$daily_order1 = 3;
|
|
} else {
|
|
$daily_order1 = $row['daily_order1'];
|
|
}
|
|
if ($daily_order2 <= 1) {
|
|
$daily_order2 = 3;
|
|
} else {
|
|
$daily_order2 = $row['daily_order2'];
|
|
}
|
|
$daily_order3 = 0;
|
|
} else if ($nowTime >= $pt3 && $nowTime < $pt3 + $pt) {
|
|
if ($daily_order1 <= 1) {
|
|
$daily_order1 = 3;
|
|
} else {
|
|
$daily_order1 = $row['daily_order1'];
|
|
}
|
|
if ($daily_order2 <= 1) {
|
|
$daily_order2 = 3;
|
|
} else {
|
|
$daily_order2 = $row['daily_order2'];
|
|
}
|
|
if ($daily_order3 == 0) {
|
|
$daily_order3 = 1;
|
|
} else {
|
|
$daily_order3 = $row['daily_order3'];
|
|
}
|
|
} else if ($nowTime >= $pt3 + $pt) {
|
|
if ($daily_order1 <= 1) {
|
|
$daily_order1 = 3;
|
|
} else {
|
|
$daily_order1 = $row['daily_order1'];
|
|
}
|
|
if ($daily_order2 <= 1) {
|
|
$daily_order2 = 3;
|
|
} else {
|
|
$daily_order2 = $row['daily_order2'];
|
|
}
|
|
if ($daily_order3 <= 1) {
|
|
$daily_order3 = 3;
|
|
} else {
|
|
$daily_order3 = $row['daily_order3'];
|
|
}
|
|
}
|
|
$stauts = 0;
|
|
for ($i = 0; $i < 3; $i++) {
|
|
if ($i == 0) {
|
|
$status = $daily_order1;
|
|
} else if ($i == 1) {
|
|
$status = $daily_order2;
|
|
} else if ($i == 2) {
|
|
$status = $daily_order3;
|
|
}
|
|
array_push($item_list, array(
|
|
'status' => $status
|
|
));
|
|
}
|
|
$ret = $conn->execScript('UPDATE user SET daily_order1=:daily_order1, daily_order2=:daily_order2, daily_order3=:daily_order3 ' .
|
|
' WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id,
|
|
':daily_order1' => $daily_order1,
|
|
':daily_order2' => $daily_order2,
|
|
':daily_order3' => $daily_order3
|
|
));
|
|
if (!$ret) {
|
|
die();
|
|
return;
|
|
}
|
|
//登录信息
|
|
$rowuser = $conn->execQueryOne('SELECT daily_first_login, first_login, game_times FROM user WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id
|
|
));
|
|
if (!$rowuser) {
|
|
phpcommon\sendError(ERR_USER_BASE + 2, '没有这个玩家');
|
|
return;
|
|
}
|
|
$ret = $conn->execScript('UPDATE user SET daily_first_login=:daily_first_login, first_login=:first_login ' .
|
|
'WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id,
|
|
':first_login' => $rowuser['first_login'] + 1,
|
|
':daily_first_login' => $rowuser['daily_first_login'] + 1,
|
|
));
|
|
if (!$ret) {
|
|
die();
|
|
return;
|
|
}
|
|
|
|
$shopgoods = metatable\getShopGoodsConf();
|
|
foreach($shopgoods as $key => $goodsitem) {
|
|
if ($goodsitem['type'] != 9) {
|
|
continue;
|
|
}
|
|
|
|
$keyname = 'shop_'.$key;
|
|
if (array_key_exists($keyname, $passport_reward)) {
|
|
continue;
|
|
}
|
|
|
|
$passport_reward[$keyname] = array();
|
|
$passportawardinfo = $this->getExplode($season_meta_table[$number][$keyname]);
|
|
foreach($passportawardinfo as $awarditem) {
|
|
$passport_reward[$keyname][] = array(
|
|
'item_id' => $awarditem[0],
|
|
'item_num' => $awarditem[1],
|
|
'time' => $awarditem[2],
|
|
'status' => -1,
|
|
);
|
|
}
|
|
}
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg' => '',
|
|
'quest_list' => $quest_list,
|
|
'pass_status' => $pass_status,
|
|
'season' => $number,
|
|
'open_time' => $open_time,
|
|
'end_time' => $end_time,
|
|
'rank' => $rank,
|
|
'rank_score' => $rank_score,
|
|
'max_rank_score' => $max_rank_score,
|
|
'reward' => $reward,
|
|
'week' => $week_reward,
|
|
'seareward' => $sea_reward,
|
|
'bag_list' => $bag_list,
|
|
'item_list' => $item_list,
|
|
'first_login' => $rowuser['first_login'] + 1,
|
|
'daily_first_login' => $rowuser['daily_first_login'] + 1,
|
|
'game_times' => $rowuser['game_times'],
|
|
'min_rank_score' => $min_rank_score,
|
|
'passport_reward' => $passport_reward,
|
|
));
|
|
}
|
|
}
|
|
?>
|