584 lines
22 KiB
PHP
584 lines
22 KiB
PHP
<?php
|
|
|
|
require 'classes/Quest.php';
|
|
require 'classes/AddReward.php';
|
|
require_once 'metatable/parameter.php';
|
|
require_once 'metatable/season.php';
|
|
require_once 'metatable/seasoncard.php';
|
|
|
|
require_once('mt/Season.php');
|
|
require_once('mt/SeasonPoint.php');
|
|
|
|
class PassController extends BaseAuthedController {
|
|
|
|
public function getPassInfo()
|
|
{
|
|
$season = mt\Season::getNowSeason();
|
|
$number = mt\Season::getNowSeasonNum();
|
|
if ($number == 0) {
|
|
$this->rspErr(ERR_USER_BASE + 2, '赛季未开启');
|
|
return;
|
|
}
|
|
//判断当前赛季
|
|
$number = 0;
|
|
$sea_reward = array();
|
|
$sea_reward2 = array();
|
|
$rank_status = 0;
|
|
$item_multiply = $this->getExplode($season['season_reward']);
|
|
$item_multiply2 = $this->getExplode($season['season_reward2']);
|
|
for($ii = 1; $ii <= count($item_multiply); $ii++) {
|
|
$rank_status = 0;
|
|
$rank_status2 = 0;
|
|
phpcommon\SqlHelper::upsert
|
|
($this->getSelfMysql(),
|
|
'passinfo',
|
|
array(
|
|
'accountid' => $this->getAccountId(),
|
|
'passid' => $ii,
|
|
),
|
|
array(
|
|
),
|
|
array(
|
|
'accountid' => $this->getAccountId(),
|
|
'passid' => $ii,
|
|
'active_status' => 0,
|
|
'honor_status' => 0,
|
|
'create_time' => $this->getNowTime(),
|
|
'modify_time' => $this->getNowTime()
|
|
)
|
|
);
|
|
$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,
|
|
'type' => 0,
|
|
));
|
|
|
|
array_push($sea_reward2, array(
|
|
'item_id' => $item_multiply2[$key][0],
|
|
'item_num' => $item_multiply2[$key][1],
|
|
'time' => $item_multiply2[$key][2],
|
|
'status' => $rank_status2,
|
|
'type' => 1,
|
|
));
|
|
}
|
|
|
|
//当前段位及积分
|
|
$rank = 0;
|
|
$rank_score = 0;
|
|
$max_rank_score = 0;
|
|
$min_rank_score = 0;
|
|
$reward = array();
|
|
$week_reward = array();
|
|
$max_rank = 0;
|
|
$row = $conn->execQueryOne('SELECT integral, pass_status, score, max_integral FROM user WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id,
|
|
));
|
|
if (!$row) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
|
|
return;
|
|
}
|
|
$rank_status = 0;
|
|
$seaPoint_meta_table = require('../res/seasomPoint@seasomPoint.php');
|
|
for ($ii = 1; $ii <= count($seaPoint_meta_table); $ii++) {
|
|
$seaPoint = mt\SeasonPoint::getOldSeasonPoint($ii);
|
|
if ($row['integral'] >= $seaPoint['min'] && $row['integral'] <= $seaPoint['max']
|
|
|| $row['integral'] >= $seaPoint['min'] && $seaPoint['max'] == -1)
|
|
{
|
|
|
|
$rank = $ii;
|
|
$max_rank_score = $seaPoint['max'] + 1 - $seaPoint['min'];
|
|
$min_rank_score = $seaPoint['min'];
|
|
$rank_score = $row['integral'] - $seaPoint['min'] + 1;
|
|
if ($seaPoint['max'] == -1) {
|
|
$max_rank_score = $seaPoint['min'];
|
|
$rank_score = $row['integral'];
|
|
}
|
|
}
|
|
|
|
if ($row['max_integral'] >= $seaPoint['min'] && $row['max_integral'] <= $seaPoint['max']
|
|
|| $row['max_integral'] >= $seaPoint['min'] && $seaPoint['max'] == -1)
|
|
{
|
|
|
|
$max_rank = $ii;
|
|
}
|
|
}
|
|
|
|
if ($rank == 0) {
|
|
phpcommon\sendError(ERR_USER_BASE + 3, '未达到段位要求');
|
|
return;
|
|
}
|
|
//等级积分
|
|
$pass_array = metatable\getNowSeasoncard($row['score']);
|
|
$pass_lv = metatable\getNowSeasoncardInfo($row['score']);
|
|
$delim1 = '|';
|
|
$drop_multiply = explode($delim1, $season['week_reward']);
|
|
|
|
$delim2 = ';';
|
|
$mul = explode($delim2, $drop_multiply[$pass_lv - 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']
|
|
));
|
|
}
|
|
|
|
$cost = metatable\getParameterByName('season_card_cost');
|
|
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg'=> '',
|
|
'pass_status' => $row['pass_status'],
|
|
'season' => $number,
|
|
'open_time' => strtotime($season['time1']),
|
|
'end_time' => strtotime($season['time2']),
|
|
'rank' => $rank,
|
|
'rank_score' => $rank_score,
|
|
'max_rank_score' => $max_rank_score,
|
|
'reward' => $reward,
|
|
'week' => $week_reward,
|
|
'seareward' => $sea_reward,
|
|
'min_rank_score' => $min_rank_score,
|
|
'seareward2' => $sea_reward2,
|
|
'cost' => $cost,
|
|
'pass_array' => $pass_array,
|
|
'max_rank' => $max_rank,
|
|
));
|
|
}
|
|
|
|
public function getPassReward()
|
|
{
|
|
$account_id = $_REQUEST['account_id'];
|
|
$conn = $this->getMysql($account_id);
|
|
$passid = $_REQUEST['id'];
|
|
$type = $_REQUEST['type'];
|
|
$status = 0;
|
|
$rowPass = $conn->execQueryOne('SELECT active_status, honor_status ' .
|
|
' FROM passinfo WHERE accountid=:accountid AND passid=:passid;',
|
|
array(
|
|
':accountid' => $account_id,
|
|
':passid' => $passid
|
|
));
|
|
if ($rowPass) {
|
|
$status = $rowPass['active_status'];
|
|
if ($type == 1) {
|
|
$status = $rowPass['honor_status'];
|
|
}
|
|
if ($status == 1) {
|
|
phpcommon\sendError(ERR_USER_BASE + 2, '该奖励已领取');
|
|
return;
|
|
}
|
|
}
|
|
$row = $conn->execQueryOne('SELECT integral, passcard FROM user WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id,
|
|
));
|
|
if (!$row) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
|
|
return;
|
|
}
|
|
if ($type == 1 && $row['passcard'] == 0) {
|
|
phpcommon\sendError(ERR_USER_BASE + 3, '赛季手册未解锁');
|
|
return;
|
|
}
|
|
|
|
|
|
$this->updateStatus($account_id, $passid, $type);
|
|
//增加奖励
|
|
$season = array();
|
|
$season_meta_table = require('../res/season@season.php');
|
|
for ($i = 1; $i <= count($season_meta_table); $i++) {
|
|
$season = mt\Season::getOldSeason($i);
|
|
if (phpcommon\getNowTime() >= strtotime($season['open_time']) && phpcommon\getNowTime() <= strtotime($season['end_time'])) {
|
|
break;
|
|
}
|
|
}
|
|
$item_multiply = $this->getExplode($season['reward']);
|
|
if ($type == 1) {
|
|
$item_multiply = $this->getExplode($season['reward2']);
|
|
}
|
|
$items = $item_multiply[$passid - 1];
|
|
$reward = array();
|
|
array_push($reward, array(
|
|
'item_id' => $items[0],
|
|
'item_num' => $items[1],
|
|
'time' => $items[2],
|
|
));
|
|
$addreward = new classes\AddReward();
|
|
$all_item_list = $addreward->addReward($items[0], $items[1], $account_id, $items[2],0);
|
|
|
|
$coin_num = $addreward->getCoinNum($account_id);
|
|
$rmb_num = $addreward->getRmbNum($account_id);
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg'=> '',
|
|
'status' => 1,
|
|
'item_list' => $reward,
|
|
'coin_nums' => $coin_num,
|
|
'rmb_nums' => $rmb_num,
|
|
'all_item_list' => $all_item_list
|
|
));
|
|
}
|
|
|
|
protected function updateStatus($accountid, $passid, $type)
|
|
{
|
|
$conn = $this->getMysql($accountid);
|
|
if ($type == 1) {
|
|
$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' => phpcommon\getNowTime()
|
|
));
|
|
} else {
|
|
$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' => phpcommon\getNowTime()
|
|
));
|
|
}
|
|
if (!$ret) {
|
|
die();
|
|
return;
|
|
}
|
|
}
|
|
|
|
public function getWeekReward()
|
|
{
|
|
$account_id = $_REQUEST['account_id'];
|
|
$conn = $this->getMysql($account_id);
|
|
$row = $conn->execQueryOne('SELECT pass_status, integral FROM user WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id,
|
|
));
|
|
if (!$row) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
|
|
return;
|
|
}
|
|
|
|
if ($row['pass_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 = mt\SeasonPoint::getOldSeasonPoint($ii);
|
|
if ($row['integral'] >= $seaPoint['min'] && $row['integral'] <= $seaPoint['max']
|
|
|| $row['integral'] >= $seaPoint['min'] && $seaPoint['max'] == -1)
|
|
{
|
|
$season = array();
|
|
$season_meta_table = require('../res/season@season.php');
|
|
for ($i = 1; $i <= count($season_meta_table); $i++) {
|
|
$season = mt\Season::getOldSeason($i);
|
|
if (phpcommon\getNowTime() >= strtotime($season['open_time']) && phpcommon\getNowTime() <= strtotime($season['end_time'])) {
|
|
break;
|
|
}
|
|
}
|
|
$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($reward, array(
|
|
'item_id' => $week_array[$s][0],
|
|
'item_num' => $week_array[$s][1],
|
|
'time' => $week_array[$s][2],
|
|
));
|
|
}
|
|
$level = $ii;
|
|
}
|
|
}
|
|
$addreward = new classes\AddReward();
|
|
$all_item_list = array();
|
|
foreach ($reward as $r) {
|
|
$items = $addreward->addReward($r['item_id'], $r['item_num'], $account_id, $r['time'], 0);
|
|
foreach($items as $i) {
|
|
array_push($all_item_list, array(
|
|
'item_id' => $i['item_id'],
|
|
'item_num' => $i['item_num'],
|
|
'time' => $i['time'],
|
|
));
|
|
}
|
|
}
|
|
$ret = $conn->execScript('UPDATE user SET pass_status=1, modify_time=:modify_time ' .
|
|
' WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id,
|
|
':modify_time' => phpcommon\getNowTime()
|
|
));
|
|
if (!$ret) {
|
|
die();
|
|
return;
|
|
}
|
|
$coin_num = $addreward->getCoinNum($account_id);
|
|
$rmb_num = $addreward->getRmbNum($account_id);
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg'=> '',
|
|
'item_list' => $reward,
|
|
'level' => $level,
|
|
'coin_nums' => $coin_num,
|
|
'rmb_nums' => $rmb_num,
|
|
'all_item_list' => $all_item_list
|
|
));
|
|
}
|
|
|
|
public function getSeaReward()
|
|
{
|
|
$account_id = $_REQUEST['account_id'];
|
|
$conn = $this->getMysql($account_id);
|
|
$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 = mt\SeasonPoint::getOldSeasonPoint($ii);
|
|
if ($row['season_end_score'] >= $seaPoint['min'] && $row['season_end_score'] <= $seaPoint['max']
|
|
|| $row['season_end_score'] >= $seaPoint['min'] && $seaPoint['max'] == -1)
|
|
{
|
|
$level = $ii;
|
|
break;
|
|
}
|
|
}
|
|
//奖励结算
|
|
$season_meta_table = require('../res/season@season.php');
|
|
$id = 0;
|
|
for ($i = 1; $i <= count($season_meta_table); $i++) {
|
|
$season = mt\Season::getOldSeason($i);
|
|
if (phpcommon\getNowTime() >= strtotime($season['open_time']) && phpcommon\getNowTime() <= strtotime($season['end_time'])) {
|
|
$open_time = strtotime($season['open_time']);
|
|
$end_time = strtotime($season['end_time']);
|
|
$id = $i - 1;
|
|
break;
|
|
}
|
|
}
|
|
$s = mt\Season::getOldSeason($id);
|
|
if ($s) {
|
|
|
|
$delim1 = '|';
|
|
$item_multiply = explode($delim1, $s['season_overreward']);
|
|
|
|
$delim2 = ';';
|
|
$mul = explode($delim2, $item_multiply[$level - 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($reward, array(
|
|
'item_id' => $week_array[$s][0],
|
|
'item_num' => $week_array[$s][1],
|
|
'time' => $week_array[$s][2],
|
|
));
|
|
}
|
|
}
|
|
$all_item_list = array();
|
|
$addreward = new classes\AddReward();
|
|
foreach ($reward as $r) {
|
|
$items = $addreward->addReward($r['item_id'], $r['item_num'], $account_id, $r['time'], 0);
|
|
foreach($items as $j) {
|
|
array_push($all_item_list, array(
|
|
'item_id' => $j['item_id'],
|
|
'item_num' => $j['item_num'],
|
|
'time' => $j['time'],
|
|
));
|
|
}
|
|
}
|
|
$ret = $conn->execScript('UPDATE user SET season_status=1, modify_time=:modify_time ' .
|
|
' WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id,
|
|
':modify_time' => phpcommon\getNowTime()
|
|
));
|
|
if (!$ret) {
|
|
die();
|
|
return;
|
|
}
|
|
$rmb_num = $addreward->getRmbNum($account_id);
|
|
$coin_num = $addreward->getCoinNum($account_id);
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg'=> '',
|
|
'item_list' => $reward,
|
|
'level' => $level,
|
|
'all_item_list' => $all_item_list,
|
|
'rmb_nums' => $rmb_num,
|
|
'coin_nums' => $coin_num
|
|
));
|
|
}
|
|
|
|
public function buyExp()
|
|
{
|
|
$account_id = $_REQUEST['account_id'];
|
|
$conn = $this->getMysql($account_id);
|
|
$row = $conn->execQueryOne('SELECT score, rmb_num FROM user WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id,
|
|
));
|
|
if (!$row) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
|
|
return;
|
|
}
|
|
$score = metatable\getNowSeasoncardMaxExp($row['score']) + 1;
|
|
$cost = metatable\getNowSeasoncardCost($row['score']);
|
|
if ($row['rmb_num'] < $cost) {
|
|
phpcommon\sendError(ERR_USER_BASE + 2, '点券不足');
|
|
return;
|
|
}
|
|
$ret = $conn->execScript('UPDATE user SET score=:score, rmb_num=:rmb_num, modify_time=:modify_time ' .
|
|
' WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id,
|
|
':score' => $score,
|
|
':modify_time' => phpcommon\getNowTime(),
|
|
':rmb_num' => $row['rmb_num'] - $cost,
|
|
));
|
|
if (!$ret) {
|
|
die();
|
|
return;
|
|
}
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg'=> '',
|
|
'rmb_nums' => $row['rmb_num'] - $cost
|
|
));
|
|
}
|
|
|
|
public function getAllPassReward()
|
|
{
|
|
$account_id = $_REQUEST['account_id'];
|
|
$conn = $this->getMysql($account_id);
|
|
$row = $conn->execQueryOne('SELECT score, passcard FROM user WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id,
|
|
));
|
|
if (!$row) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
|
|
return;
|
|
}
|
|
$passid = metatable\getNowSeasoncardInfo($row['score']);
|
|
|
|
$rowPass = $conn->execQuery('SELECT passid, active_status, honor_status ' .
|
|
' FROM passinfo WHERE accountid=:accountid AND passid<=:passid;',
|
|
array(
|
|
':accountid' => $account_id,
|
|
':passid' => $passid
|
|
));
|
|
if (!$rowPass) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
|
|
return;
|
|
}
|
|
$item_list = array();
|
|
$all_item_list = array();
|
|
foreach($rowPass as $rp) {
|
|
$passid = $rp['passid'];
|
|
if ($rp['active_status'] == 0) {
|
|
$this->updateStatus($account_id, $passid, 0);
|
|
$item_list = $this->getpassrewardinfo($passid, 0, $item_list);
|
|
if ($row['passcard'] == 1 && $rp['honor_status'] == 0) {
|
|
$this->updateStatus($account_id, $passid, 1);
|
|
$item_list = $this->getpassrewardinfo($passid, 1, $item_list);
|
|
}
|
|
} else {
|
|
if ($row['passcard'] == 1 && $rp['honor_status'] == 0) {
|
|
$this->updateStatus($account_id, $passid, 1);
|
|
$item_list = $this->getpassrewardinfo($passid, 1, $item_list);
|
|
}
|
|
}
|
|
}
|
|
$addreward = new classes\AddReward();
|
|
foreach ($item_list as $r) {
|
|
$items = $addreward->addReward($r['item_id'], $r['item_num'], $account_id, $r['time'], 0);
|
|
foreach($items as $i) {
|
|
array_push($all_item_list, array(
|
|
'item_id' => $i['item_id'],
|
|
'item_num' => $i['item_num'],
|
|
'time' => $i['time'],
|
|
));
|
|
}
|
|
}
|
|
$coin_num = $addreward->getCoinNum($account_id);
|
|
$rmb_num = $addreward->getRmbNum($account_id);
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg'=> '',
|
|
'item_list' => $item_list,
|
|
'coin_nums' => $coin_num,
|
|
'rmb_nums' => $rmb_num,
|
|
'all_item_list' => $all_item_list
|
|
));
|
|
|
|
}
|
|
|
|
protected function getpassrewardinfo($pass_id, $type, $item_list)
|
|
{
|
|
//增加奖励
|
|
$season = array();
|
|
$season_meta_table = require('../res/season@season.php');
|
|
for ($i = 1; $i <= count($season_meta_table); $i++) {
|
|
$season = mt\Season::getOldSeason($i);
|
|
if (phpcommon\getNowTime() >= strtotime($season['open_time']) && phpcommon\getNowTime() <= strtotime($season['end_time'])) {
|
|
break;
|
|
}
|
|
}
|
|
$item_multiply = $this->getExplode($season['reward']);
|
|
if ($type == 1) {
|
|
$item_multiply = $this->getExplode($season['reward2']);
|
|
}
|
|
$items = $item_multiply[$pass_id - 1];
|
|
if ($items[0] != 0) {
|
|
array_push($item_list, array(
|
|
'item_id' => $items[0],
|
|
'item_num' => $items[1],
|
|
'time' => $items[2],
|
|
));
|
|
}
|
|
return $item_list;
|
|
}
|
|
}
|