465 lines
18 KiB
PHP
465 lines
18 KiB
PHP
<?php
|
|
|
|
require 'classes/Quest.php';
|
|
require 'classes/AddReward.php';
|
|
|
|
class PassController{
|
|
|
|
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' => 'gamedb2004_' . $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 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'],
|
|
);
|
|
return $season;
|
|
}
|
|
|
|
protected function getSeasonReward($seaReward_id)
|
|
{
|
|
$seaReward_meta_table = require('../res/seasonReward@seasonReward.php');
|
|
$seaReward_meta = getSeasonRewardConfig($seaReward_meta_table, $seaReward_id);
|
|
$seaReward = array(
|
|
'id' => $seaReward_meta['id'],
|
|
'point' => $seaReward_meta['point'],
|
|
'active' => $seaReward_meta['reward1'],
|
|
'honor' => $seaReward_meta['reward2'],
|
|
'level' => $seaReward_meta['level']
|
|
);
|
|
return $seaReward;
|
|
}
|
|
|
|
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'],
|
|
);
|
|
return $seaPoint;
|
|
}
|
|
|
|
public function getPassInfo()
|
|
{
|
|
$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;
|
|
}
|
|
//判断当前赛季
|
|
$number = 0;
|
|
$open_time = 0;
|
|
$end_time = 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']);
|
|
$ret = $conn->execScript('UPDATE user SET season_time=:season_time, modify_time=:modify_time ' .
|
|
' WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id,
|
|
':season_time' => $end_time,
|
|
':modify_time' => time()
|
|
));
|
|
if (!$ret) {
|
|
die();
|
|
return;
|
|
}
|
|
$number = $i;
|
|
break;
|
|
}
|
|
}
|
|
if ($number == 0) {
|
|
phpcommon\sendError(ERR_USER_BASE + 2, '赛季未开启');
|
|
return;
|
|
}
|
|
//当前段位及积分
|
|
$rank = 0;
|
|
$rank_score = 0;
|
|
$max_rank_score = 0;
|
|
$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;
|
|
}
|
|
$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)
|
|
{
|
|
$delim = ':';
|
|
$drop_multiply = explode($delim, $seaPoint['reward']);
|
|
array_push($reward, array(
|
|
'item_id' => $drop_multiply[0],
|
|
'item_num' => $drop_multiply[1],
|
|
));
|
|
$rank = $ii;
|
|
$max_rank_score = $seaPoint['max'] + 1 - $seaPoint['min'];
|
|
$rank_score = $row['integral'] - $seaPoint['min'];
|
|
if ($seaPoint['max'] == -1) {
|
|
$max_rank_score = $seaPoint['min'];
|
|
} else if ($seaPoint['min'] == 0) {
|
|
$max_rank_score = $seaPoint['max'] + 1;
|
|
}
|
|
}
|
|
}
|
|
if ($rank == 0) {
|
|
phpcommon\sendError(ERR_USER_BASE + 3, '未达到段位要求');
|
|
return;
|
|
}
|
|
//奖励信息
|
|
$level = 0;
|
|
$sum_score = 0;
|
|
$pass_score = 0;
|
|
$max_pass_score = 0;
|
|
$sum_point = 0;
|
|
$item_list = array();
|
|
$seaReward_meta_table = require('../res/seasonReward@seasonReward.php');
|
|
for ($j = 1; $j <= count($seaReward_meta_table); $j++) {
|
|
$id = $j + 100;
|
|
$drop_multiply = array();
|
|
$status = 0;
|
|
$seaReward = $this->getSeasonReward($id - 1);
|
|
$sum_point = $sum_point + $seaReward['point'];
|
|
if ($row['score'] <= $sum_point) {
|
|
$level = $seaReward['level'];
|
|
$pass_score = $row['score'] - $sum_point + $seaReward['point'];
|
|
$max_pass_score = $seaReward['point'];
|
|
if ($row['score'] == $sum_point) {
|
|
$level = $level + 1;
|
|
$s = $this->getSeasonReward($id);
|
|
$max_pass_score = $s['point'];
|
|
} else {
|
|
if ($id - 1 == 100) {
|
|
$pass_score = $row['score'];
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
|
|
if ($seaReward['point'] == -1) {
|
|
$level = $seaReward['level'];
|
|
$pass_score = $row['score'];
|
|
$max_pass_score = $seaReward['point'];
|
|
break;
|
|
}
|
|
}
|
|
foreach ($seaReward_meta_table as $seaR) {
|
|
//如果是最大等级,则返回上一级的最大值
|
|
$status = 0;
|
|
if ($seaR['point'] == -1) {
|
|
$sea = $this->getSeasonReward($seaR['id'] - 1);
|
|
$sum_score = $sea['point'];
|
|
} else {
|
|
$sum_score = $seaR['point'];
|
|
}
|
|
$rowPass = $conn->execQueryOne('SELECT active_status, honor_status ' .
|
|
' FROM passinfo WHERE accountid=:accountid AND passid=:passid;',
|
|
array(
|
|
':accountid' => $account_id,
|
|
':passid' => $seaR['id']
|
|
));
|
|
$itemid = 0;
|
|
$itemnum = 0;
|
|
for ($t = 1; $t <= 2; $t++) {
|
|
$delim = ":";
|
|
if ($t == 1) {
|
|
if ($seaR['reward1'] != '') {
|
|
$drop_multiply = explode($delim, $seaR['reward1']);
|
|
$itemid = $drop_multiply[0];
|
|
$itemnum = $drop_multiply[1];
|
|
}
|
|
if ($rowPass) {
|
|
$status = $rowPass['active_status'];
|
|
}
|
|
}
|
|
if ($t == 2) {
|
|
if ($seaR['reward2'] != '') {
|
|
$drop_multiply = explode($delim, $seaR['reward2']);
|
|
$itemid = $drop_multiply[0];
|
|
$itemnum = $drop_multiply[1];
|
|
}
|
|
if ($rowPass) {
|
|
$status = $rowPass['honor_status'];
|
|
}
|
|
}
|
|
array_push($item_list, array(
|
|
'id' => $seaR['id'],
|
|
'type' => $t,
|
|
'point' => $seaR['point'],
|
|
'item_id' => $itemid,
|
|
'item_num' => $itemnum,
|
|
'status' => $status,
|
|
));
|
|
}
|
|
}
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg'=> '',
|
|
'pass_status' => $row['pass_status'],
|
|
'season' => $number,
|
|
'open_time' => $open_time,
|
|
'end_time' => $end_time,
|
|
'rank' => $rank,
|
|
'rank_score' => $rank_score,
|
|
'max_rank_score' => $max_rank_score,
|
|
'level' => $level,
|
|
'sum_score' => $sum_score,
|
|
'pass_score' => $pass_score,
|
|
'max_pass_score' => $max_pass_score,
|
|
'reward' => $reward,
|
|
'item_list' => $item_list
|
|
));
|
|
}
|
|
|
|
|
|
public function getPassReward()
|
|
{
|
|
$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;
|
|
}
|
|
$passid = $_REQUEST['id'];
|
|
$type = $_REQUEST['type'];
|
|
$status = 0;
|
|
$seaReward = $this->getSeasonReward($passid);
|
|
if (!$seaReward) {
|
|
phpcommon\sendError(ERR_USER_BASE + 3, '没有这个奖励');
|
|
return;
|
|
}
|
|
$rowPass = $conn->execQueryOne('SELECT active_status, honor_status ' .
|
|
' FROM passinfo WHERE accountid=:accountid AND passid=:passid;',
|
|
array(
|
|
':accountid' => $account_id,
|
|
':passid' => $passid
|
|
));
|
|
if ($rowPass) {
|
|
if ($type == 1) {
|
|
$status = $rowPass['active_status'];
|
|
}
|
|
if ($type == 2) {
|
|
$status = $rowPass['honor_status'];
|
|
}
|
|
if ($status == 1) {
|
|
phpcommon\sendError(ERR_USER_BASE + 2, '该奖励已领取');
|
|
return;
|
|
}
|
|
}
|
|
$row = $conn->execQueryOne('SELECT score, pass_status FROM user WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id,
|
|
));
|
|
if (!$row) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
|
|
return;
|
|
}
|
|
$seaR = $this->getSeasonReward($passid - 1);
|
|
if ($seaR['point'] > $row['score']) {
|
|
phpcommon\sendError(ERR_USER_BASE + 4, '没有达到通行证要求');
|
|
return;
|
|
}
|
|
|
|
if ($type == 2 && $row['pass_status'] == 0) {
|
|
phpcommon\sendError(ERR_USER_BASE + 4, '没有达到通行证要求');
|
|
return;
|
|
}
|
|
|
|
if (!$rowPass) {
|
|
$ret = $conn->execScript('INSERT INTO passinfo(accountid, passid, active_status, honor_status, create_time, modify_time) ' .
|
|
' VALUES(:accountid, :passid, 0, 0, :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' => $passid,
|
|
':create_time' => time(),
|
|
':modify_time' => time()
|
|
));
|
|
if (!$ret) {
|
|
die();
|
|
return;
|
|
}
|
|
}
|
|
$this->updateStatus($account_id, $passid, $type);
|
|
//增加奖励
|
|
$drop_multiply = array();
|
|
if ($type == 1) {
|
|
$delim = ':';
|
|
$drop_multiply = explode($delim, $seaReward['active']);
|
|
}
|
|
if ($type == 2) {
|
|
$delim = ':';
|
|
$drop_multiply = explode($delim, $seaReward['honor']);
|
|
}
|
|
$addreward = new classes\AddReward();
|
|
$addreward->addReward($drop_multiply[0], $drop_multiply[1], $account_id);
|
|
$coin_num = $addreward->getCoinNum($account_id);
|
|
$diamond_num = $addreward->getDiamondNum($account_id);
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg'=> '',
|
|
'status' => 1,
|
|
'coin_nums' => $coin_num,
|
|
'diamond_nums' => $diamond_num
|
|
));
|
|
}
|
|
|
|
protected function updateStatus($accountid, $passid, $type)
|
|
{
|
|
$conn = $this->getMysql($accountid);
|
|
if (!$conn) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
|
|
return;
|
|
}
|
|
if ($type == 1) {
|
|
$ret = $conn->execScript('UPDATE passinfo SET active_status=1, modify_time=:modify_time ' .
|
|
' WHERE accountid=:accountid AND passid=:passid;',
|
|
array(
|
|
':accountid' => $accountid,
|
|
':passid' => $passid,
|
|
':modify_time' => time()
|
|
));
|
|
if (!$ret) {
|
|
die();
|
|
return;
|
|
}
|
|
}
|
|
if ($type == 2) {
|
|
$ret = $conn->execScript('UPDATE passinfo SET honor_status=1, modify_time=:modify_time ' .
|
|
' WHERE accountid=:accountid AND passid=:passid;',
|
|
array(
|
|
':accountid' => $accountid,
|
|
':passid' => $passid,
|
|
':modify_time' => time()
|
|
));
|
|
if (!$ret) {
|
|
die();
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
public function getSeaReward()
|
|
{
|
|
$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 season_end_score, season_status FROM user WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id,
|
|
));
|
|
if (!$row) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
|
|
return;
|
|
}
|
|
|
|
if ($row['season_status'] == 1) {
|
|
phpcommon\sendError(ERR_USER_BASE + 2, '赛季未结束');
|
|
return;
|
|
}
|
|
$reward = array();
|
|
$level = 0;
|
|
$seaPoint_meta_table = require('../res/seasomPoint@seasomPoint.php');
|
|
for ($ii = 1; $ii <= count($seaPoint_meta_table); $ii++) {
|
|
$seaPoint = $this->getSeasonPoint($ii);
|
|
if ($row['season_end_score'] >= $seaPoint['min'] && $row['season_end_score'] <= $seaPoint['max']
|
|
|| $row['season_end_score'] >= $seaPoint['min'] && $seaPoint['max'] == -1)
|
|
{
|
|
$delim = ':';
|
|
$drop_multiply = explode($delim, $seaPoint['reward']);
|
|
array_push($reward, array(
|
|
'item_id' => $drop_multiply[0],
|
|
'item_num' => $drop_multiply[1],
|
|
));
|
|
$level = $ii;
|
|
}
|
|
}
|
|
$addreward = new classes\AddReward();
|
|
foreach ($reward as $r) {
|
|
$addreward->addReward($r['item_id'], $r['item_num'], $account_id);
|
|
}
|
|
$ret = $conn->execScript('UPDATE user SET season_end_score=0, season_status=1, modify_time=:modify_time ' .
|
|
' WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id,
|
|
':modify_time' => time()
|
|
));
|
|
if (!$ret) {
|
|
die();
|
|
return;
|
|
}
|
|
$diamond_num = $addreward->getDiamondNum($account_id);
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg'=> '',
|
|
'item_list' => $reward,
|
|
'level' => $level,
|
|
'diamond_nums' => $diamond_num
|
|
));
|
|
}
|
|
}
|
|
?>
|