812 lines
28 KiB
PHP
812 lines
28 KiB
PHP
<?php
|
|
|
|
require 'classes/AddReward.php';
|
|
require_once 'metatable/activity.php';
|
|
require_once 'metatable/activityplus.php';
|
|
require 'classes/Quest.php';
|
|
|
|
class FesActivityController{
|
|
|
|
protected function getRedis($act_uuid)
|
|
{
|
|
$redis_conf = getRedisConfig(crc32($act_uuid));
|
|
$r = new phpcommon\Redis(array(
|
|
'host' => $redis_conf['host'],
|
|
'port' => $redis_conf['port'],
|
|
'passwd' => $redis_conf['passwd']
|
|
|
|
));
|
|
return $r;
|
|
}
|
|
|
|
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 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 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 readFesActDB($account_id) {
|
|
$conn = $this->getMysql($account_id);
|
|
$row = $conn->execQueryOne('SELECT blobdata FROM festival_activity WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id
|
|
));
|
|
if (!empty($row)) {
|
|
$fes_db_str = $row['blobdata'];
|
|
$fes_db = json_decode($fes_db_str, true);
|
|
return $fes_db;
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
protected function saveFesActDB($account_id, $fes_db) {
|
|
$conn = $this->getMysql($account_id);
|
|
$row = $conn->execQueryOne('SELECT accountid FROM festival_activity WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id
|
|
));
|
|
$fes_db_str = "";
|
|
if (!empty($fes_db)) {
|
|
$fes_db_str = json_encode($fes_db);
|
|
}
|
|
if (!empty($row)) {
|
|
//update
|
|
$row = $conn->execScript('UPDATE festival_activity SET blobdata=:blobdata, modify_time=:modify_time WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id,
|
|
':blobdata' => $fes_db_str,
|
|
':modify_time' => time()
|
|
));
|
|
} else {
|
|
//insert
|
|
$row = $conn->execScript('INSERT INTO festival_activity(accountid, blobdata, create_time, modify_time) ' .
|
|
' VALUES(:account_id, :blobdata, :create_time, :modify_time) ' .
|
|
' ON DUPLICATE KEY UPDATE accountid=:account_id, blobdata=:blobdata, modify_time=:modify_time;',
|
|
array(
|
|
':account_id' => $account_id,
|
|
':blobdata' => $fes_db_str,
|
|
':create_time' => time(),
|
|
':modify_time' => time(),
|
|
));
|
|
}
|
|
}
|
|
|
|
//节日活动
|
|
public function acitivityInfo()
|
|
{
|
|
$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 + 2, '没有这个玩家');
|
|
return;
|
|
}
|
|
//节日活动信息
|
|
$this->getfesActInfo($account_id);
|
|
$user_db = $this->readFesActDB($account_id);
|
|
//metatable\getRewardInfo(1,1,1);
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg'=> '',
|
|
'isopen' => $user_db['isopen'],
|
|
'id' => $user_db['act_id'],
|
|
'info_list' => $user_db['info_list'],
|
|
));
|
|
}
|
|
|
|
protected function getfesActInfo($account_id)
|
|
{
|
|
$user_db = $this->readFesActDB($account_id);
|
|
$act_id = $user_db['act_id'];
|
|
$act = metatable\getNowActivity();
|
|
$info_list = array();
|
|
if (!$act) {
|
|
//活动未开启
|
|
$act_db = array(
|
|
'isopen' => 0,
|
|
'act_id' => 0,
|
|
'info_list' => $info_list,
|
|
);
|
|
$this->saveFesActDB($account_id, $act_db);
|
|
} else {
|
|
//活动开启
|
|
if (empty($user_db) || empty($user_db['info_list']) || $act_id != $act['id']) {
|
|
$info_list = $this->getActItem($act['id']);
|
|
$act_db = array(
|
|
'isopen' => 1,
|
|
'act_id' => $act['id'],
|
|
'info_list' => $info_list,
|
|
);
|
|
$this->saveFesActDB($account_id, $act_db);
|
|
}
|
|
}
|
|
}
|
|
|
|
protected function getActItem($id)
|
|
{
|
|
$act_conf = metatable\getActivityById($id);
|
|
if (!$act_conf) {
|
|
die();
|
|
return;
|
|
}
|
|
return metatable\getActInfo($act_conf);
|
|
}
|
|
|
|
public function getActReward()
|
|
{
|
|
$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 + 2, '没有这个玩家');
|
|
return;
|
|
}
|
|
$user_db = $this->readFesActDB($account_id);
|
|
if (empty($user_db) || $user_db['isopen'] == 0) {
|
|
phpcommon\sendError(ERR_USER_BASE + 3, '活动未开启');
|
|
return;
|
|
}
|
|
$reward = array();
|
|
$id = $_REQUEST['id'];
|
|
$status = 1;
|
|
foreach ($user_db['info_list'] as &$us) {
|
|
if ($us['id'] == $id) {
|
|
if ($us['status'] != 1) {
|
|
phpcommon\sendError(ERR_USER_BASE + 4, '奖励不可领');
|
|
return;
|
|
}
|
|
$us['status'] = 2;
|
|
$status = 2;
|
|
$reward = metatable\getRewardInfo($user_db['act_id'], $id, 0);
|
|
break;
|
|
}
|
|
}
|
|
if (empty($reward) || !$reward) {
|
|
phpcommon\sendError(ERR_USER_BASE + 5, '没有这个奖励');
|
|
return;
|
|
}
|
|
//更新奖励状态
|
|
$this->saveFesActDB($account_id, $user_db);
|
|
//领取奖励
|
|
$item_list = array();
|
|
$all_item_list = array();
|
|
$addreward = new classes\AddReward();
|
|
for ($i = 0; $i < count($reward); $i++) {
|
|
$item_id = $reward[$i][0];
|
|
$num = $reward[$i][1];
|
|
$time = $reward[$i][2];
|
|
array_push($item_list, array(
|
|
'item_id' => $item_id,
|
|
'item_num' => $num,
|
|
'time' => $time,
|
|
));
|
|
$items = $addreward->addReward($item_id, $num, $account_id, $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'],
|
|
));
|
|
}
|
|
}
|
|
$coin_num = $addreward->getCoinNum($account_id);
|
|
$diamond_num = $addreward->getDiamondNum($account_id);
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg' => '',
|
|
'item_list' => $item_list,
|
|
'coin_nums' => $coin_num,
|
|
'diamond_nums' => $diamond_num,
|
|
'all_item_list' => $all_item_list,
|
|
'status' => $status,
|
|
'id' => $id,
|
|
));
|
|
}
|
|
|
|
public function getActExtraReward()
|
|
{
|
|
$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;
|
|
}
|
|
|
|
$user_db = $this->readFesActDB($account_id);
|
|
if (empty($user_db) || $user_db['isopen'] == 0) {
|
|
phpcommon\sendError(ERR_USER_BASE + 3, '活动未开启');
|
|
return;
|
|
}
|
|
$reward = array();
|
|
$id = $_REQUEST['id'];
|
|
$status = 0;
|
|
$times = 0;
|
|
foreach ($user_db['info_list'] as &$us) {
|
|
if ($us['id'] == $id) {
|
|
if ($us['status'] != 0) {
|
|
phpcommon\sendError(ERR_USER_BASE + 4, '奖励不可领');
|
|
return;
|
|
}
|
|
if ($us['times'] + 1 >= $us['condition']) {
|
|
$status = 1;
|
|
$us['status'] = 1;
|
|
}
|
|
$times = $us['times'] + 1;
|
|
$us['times']++;
|
|
$reward = metatable\getRewardInfo($user_db['act_id'], $id, 1);
|
|
break;
|
|
}
|
|
}
|
|
//更新奖励状态
|
|
$this->saveFesActDB($account_id, $user_db);
|
|
$item_list = array();
|
|
$all_item_list = array();
|
|
$addreward = new classes\AddReward();
|
|
if ($reward && !empty($reward)) {
|
|
//领取奖励
|
|
for ($i = 0; $i < count($reward); $i++) {
|
|
$item_id = $reward[$i][0];
|
|
$num = $reward[$i][1];
|
|
$time = $reward[$i][2];
|
|
array_push($item_list, array(
|
|
'item_id' => $item_id,
|
|
'item_num' => $num,
|
|
'time' => $time,
|
|
));
|
|
$items = $addreward->addReward($item_id, $num, $account_id, $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'],
|
|
));
|
|
}
|
|
}
|
|
}
|
|
$coin_num = $addreward->getCoinNum($account_id);
|
|
$diamond_num = $addreward->getDiamondNum($account_id);
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg' => '',
|
|
'item_list' => $item_list,
|
|
'coin_nums' => $coin_num,
|
|
'diamond_nums' => $diamond_num,
|
|
'all_item_list' => $all_item_list,
|
|
'times' => $times,
|
|
'status' => $status,
|
|
'id' => $id,
|
|
));
|
|
}
|
|
|
|
|
|
|
|
protected function readHolidayDB($account_id) {
|
|
$conn = $this->getMysql($account_id);
|
|
$row = $conn->execQueryOne('SELECT blobdata FROM holiday WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id
|
|
));
|
|
if (!empty($row)) {
|
|
$hol_db_str = $row['blobdata'];
|
|
$hol_db = json_decode($hol_db_str, true);
|
|
return $hol_db;
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
protected function saveHolidayDB($account_id, $hol_db) {
|
|
$conn = $this->getMysql($account_id);
|
|
$row = $conn->execQueryOne('SELECT accountid FROM holiday WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id
|
|
));
|
|
$hol_db_str = "";
|
|
if (!empty($hol_db)) {
|
|
$hol_db_str = json_encode($hol_db);
|
|
}
|
|
if (!empty($row)) {
|
|
//update
|
|
$row = $conn->execScript('UPDATE holiday SET blobdata=:blobdata, modify_time=:modify_time WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id,
|
|
':blobdata' => $hol_db_str,
|
|
':modify_time' => time()
|
|
));
|
|
} else {
|
|
//insert
|
|
$row = $conn->execScript('INSERT INTO holiday(accountid, blobdata, create_time, modify_time) ' .
|
|
' VALUES(:account_id, :blobdata, :create_time, :modify_time) ' .
|
|
' ON DUPLICATE KEY UPDATE accountid=:account_id, blobdata=:blobdata, modify_time=:modify_time;',
|
|
array(
|
|
':account_id' => $account_id,
|
|
':blobdata' => $hol_db_str,
|
|
':create_time' => time(),
|
|
':modify_time' => time(),
|
|
));
|
|
}
|
|
}
|
|
|
|
//假日活动
|
|
public function holidayInfo()
|
|
{
|
|
$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 + 2, '没有这个玩家');
|
|
return;
|
|
}
|
|
//假日活动信息
|
|
$this->getHolidayInfo($account_id);
|
|
$user_db = $this->readHolidayDB($account_id);
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg'=> '',
|
|
'quest_list' => $user_db['quest_list'],
|
|
'exchange_list' => $user_db['exchange_list'],
|
|
));
|
|
}
|
|
|
|
protected function getHolidayInfo($account_id)
|
|
{
|
|
$user_db = $this->readHolidayDB($account_id);
|
|
//$quest_list = $this->getActQuestInfo(3, array(), $account_id);
|
|
//$exchange_list = $this->getActExchangeInfo(9, array(), $account_id);
|
|
$quest_list = $this->getActQuestInfo(3, $user_db['quest_list'], $account_id);
|
|
$exchange_list = $this->getActExchangeInfo(9, $user_db['exchange_list'], $account_id);
|
|
$hol_db = array(
|
|
'quest_list' => $quest_list,
|
|
'exchange_list' => $exchange_list,
|
|
);
|
|
$this->saveHolidayDB($account_id, $hol_db);
|
|
}
|
|
|
|
protected function insertQuestInfo($act, $id, $num, $account_id)
|
|
{
|
|
$info_list = array();
|
|
$reward = array();
|
|
$quest_list = $this->actQuestList($act['condition'], $account_id);
|
|
$reward = $this->actQuestRewardList($act['reward']);
|
|
array_push($info_list, array(
|
|
'id' => $id,
|
|
'idx' => $num,
|
|
'quest_list' => $quest_list,
|
|
'reward' => $reward,
|
|
'time' => time(),
|
|
'act' => $act,
|
|
));
|
|
return $info_list;
|
|
}
|
|
|
|
protected function updateQuestInfo($act, $info_list, $id, $num, $account_id)
|
|
{
|
|
$reward = array();
|
|
$temp_list = array();
|
|
$quest_list = $this->actQuestList($act['condition'], $account_id);
|
|
$reward = $this->actQuestRewardList($act['reward']);
|
|
//$info_list[$num] = $temp_list;
|
|
array_push($temp_list, array(
|
|
'id' => $id,
|
|
'idx' => $num,
|
|
'quest_list' => $quest_list,
|
|
'reward' => $reward,
|
|
'time' => time(),
|
|
'act' => $act,
|
|
));
|
|
$info_list = $temp_list;
|
|
return $info_list;
|
|
}
|
|
|
|
|
|
protected function actQuestList($quest, $account_id)
|
|
{
|
|
$task = new classes\Quest();
|
|
$quest_conf = $this->getExplode($quest);
|
|
$quest_list = array();
|
|
foreach ($quest_conf as $q) {
|
|
$status = 0;
|
|
if ($q[0] == 1) {
|
|
$status = 1;
|
|
}
|
|
$num = 0;
|
|
if ($q[0] == 72001 ||
|
|
$q[0] == 72010) {
|
|
$num++;
|
|
if ($num >= $q[1]) {
|
|
$status = 1;
|
|
}
|
|
}
|
|
array_push($quest_list, array(
|
|
'id' => $q[0],
|
|
'num' => $num,
|
|
'condition' => $q[1],
|
|
'status' => $status,
|
|
));
|
|
}
|
|
return $quest_list;
|
|
}
|
|
|
|
protected function actQuestRewardList($quest)
|
|
{
|
|
$quest_conf = $this->getExplode($quest);
|
|
$quest_list = array();
|
|
foreach ($quest_conf as $q) {
|
|
array_push($quest_list, array(
|
|
'item_id' => $q[0],
|
|
'item_num' => $q[1],
|
|
'time' => $q[2],
|
|
));
|
|
}
|
|
return $quest_list;
|
|
}
|
|
|
|
public function getActQuestInfo($type, $info_list, $account_id)
|
|
{
|
|
$quest = new classes\Quest();
|
|
$id_list = metatable\getActPlusInfo($type);
|
|
$num = 0;
|
|
if (empty($info_list) || !$info_list) {
|
|
$info_list = array();
|
|
foreach ($id_list as $i) {
|
|
$act = metatable\getActPlusById($i['id']);
|
|
if (!$act) {
|
|
return null;
|
|
}
|
|
if (time() < strtotime($act['time1']) || time() > strtotime($act['time2'])) {
|
|
array_push($info_list, array());
|
|
$num++;
|
|
continue;
|
|
}
|
|
$info_list = $this->insertQuestInfo($act, $i['id'], $num, $account_id);
|
|
$num++;
|
|
}
|
|
} else {
|
|
foreach ($id_list as $i) {
|
|
$act = metatable\getActPlusById($i['id']);
|
|
if (!$act) {
|
|
return null;
|
|
}
|
|
if (time() < strtotime($act['time1']) || time() > strtotime($act['time2'])) {
|
|
if (!empty($info_list[$num]) && $info_list[$num]) {
|
|
$info_list[$num] = array();
|
|
}
|
|
} else {
|
|
if (empty($info_list[$num]) || !$info_list[$num]) {
|
|
$info_list = $this->updateQuestInfo($act, $info_list, $i['id'], $num, $account_id);
|
|
} else {
|
|
if (phpcommon\getdayseconds(time()) - phpcommon\getdayseconds($info_list[$num]['time']) > 0) {
|
|
if ($act['isreset'] == 1) {
|
|
$quest_list = $this->actQuestList($act['condition'], $account_id);
|
|
$info_list[$num]['quest_list'] = $quest_list;
|
|
}
|
|
$info_list[$num]['time'] = time();
|
|
}
|
|
}
|
|
}
|
|
$num++;
|
|
}
|
|
}
|
|
return $info_list;
|
|
}
|
|
|
|
protected function actExchangeList($exc)
|
|
{
|
|
$exc_conf = $this->getExplode($exc);
|
|
$exc_list = array();
|
|
foreach ($exc_conf as $e) {
|
|
$status = 0;
|
|
$num = 0;
|
|
array_push($exc_list, array(
|
|
'id' => $e[0],
|
|
'num' => $num,
|
|
'condition' => $e[1],
|
|
'status' => $status,
|
|
));
|
|
}
|
|
return $exc_list;
|
|
}
|
|
|
|
public function actExchangeRewardList($exc)
|
|
{
|
|
$exc_list = explode('|', $exc);
|
|
return $exc_list;
|
|
}
|
|
|
|
protected function insertExchangeInfo($act, $id, $num)
|
|
{
|
|
$info_list = array();
|
|
$exc_list = $this->actExchangeList($act['condition']);
|
|
$reward = $this->actExchangeRewardList($act['reward']);
|
|
$times_list = explode('|', $act['exchange_times']);
|
|
array_push($info_list, array(
|
|
'id' => $id,
|
|
'idx' => $num,
|
|
'exc_list' => $exc_list,
|
|
'reward' => $reward,
|
|
'time' => time(),
|
|
'act' => $act,
|
|
'times_list' => $times_list,
|
|
));
|
|
return $info_list;
|
|
}
|
|
|
|
protected function updateExchangeInfo($act, $info_list, $id, $num)
|
|
{
|
|
$temp_list = array();
|
|
$exc_list = $this->actExchangeList($act['condition']);
|
|
$reward = $this->actExchangeRewardList($act['reward']);
|
|
$times_list = explode('|', $act['exchange_times']);
|
|
array_push($temp_list, array(
|
|
'id' => $id,
|
|
'idx' => $num,
|
|
'exc_list' => $exc_list,
|
|
'reward' => $reward,
|
|
'time' => time(),
|
|
'act' => $act,
|
|
'times_list' => $times_list,
|
|
));
|
|
$info_list = $temp_list;
|
|
return $info_list;
|
|
}
|
|
|
|
public function getActExchangeInfo($type, $info_list, $account_id)
|
|
{
|
|
$id_list = metatable\getActPlusInfo($type);
|
|
$num = 0;
|
|
if (empty($info_list) || !$info_list) {
|
|
$info_list = array();
|
|
foreach ($id_list as $i) {
|
|
$act = metatable\getActPlusById($i['id']);
|
|
if (!$act) {
|
|
return null;
|
|
}
|
|
if (time() < strtotime($act['time1']) || time() > strtotime($act['time2'])) {
|
|
array_push($info_list, array());
|
|
$num++;
|
|
continue;
|
|
}
|
|
$info_list = $this->insertExchangeInfo($act, $i['id'], $num);
|
|
$num++;
|
|
}
|
|
} else {
|
|
foreach ($id_list as $i) {
|
|
$act = metatable\getActPlusById($i['id']);
|
|
if (!$act) {
|
|
return null;
|
|
}
|
|
if (time() < strtotime($act['time1']) || time() > strtotime($act['time2'])) {
|
|
if (!empty($info_list[$num]) && $info_list[$num]) {
|
|
$info_list[$num] = array();
|
|
}
|
|
} else {
|
|
if (empty($info_list[$num]) || !$info_list[$num]) {
|
|
$info_list = $this->updateExchangeInfo($act, $info_list, $i['id'], $num);
|
|
}
|
|
}
|
|
$num++;
|
|
}
|
|
}
|
|
return $info_list;
|
|
}
|
|
|
|
//假日活动奖励
|
|
public function holidayReward()
|
|
{
|
|
$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 + 2, '没有这个玩家');
|
|
return;
|
|
}
|
|
$user_db = $this->readHolidayDB($account_id);
|
|
if (!$user_db || empty($user_db)) {
|
|
phpcommon\sendError(ERR_USER_BASE + 2, '没有这个玩家');
|
|
return;
|
|
}
|
|
$type = $_REQUEST['type'];
|
|
$id = $_REQUEST['id'];
|
|
$idx = $_REQUEST['idx'];
|
|
|
|
$addreward = new classes\AddReward();
|
|
$item_list = $this->getHolidayRewardList($account_id, $user_db, $type, $id, $idx);
|
|
$all_item_list = array();
|
|
foreach ($item_list as $item) {
|
|
$items = $addreward->addReward($item['item_id'], $item['item_num'], $account_id, $item['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);
|
|
$diamond_num = $addreward->getDiamondNum($account_id);
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg' => '',
|
|
'item_list' => $item_list,
|
|
'coin_nums' => $coin_num,
|
|
'diamond_nums' => $diamond_num,
|
|
'all_item_list' => $all_item_list,
|
|
));
|
|
}
|
|
|
|
protected function getHolidayRewardList($account_id, $user_db, $type, $id, $idx)
|
|
{
|
|
$item_list = array();
|
|
if ($type == 3) {
|
|
$item_list = $this->getQuestReward($account_id, $user_db, $type, $id, $idx);
|
|
} else if ($type == 9) {
|
|
$item_list = $this->getExchangeReward($account_id, $user_db, $type, $id, $idx);
|
|
}
|
|
return $item_list;
|
|
}
|
|
|
|
protected function getQuestReward($account_id, $user_db, $type, $id, $idx)
|
|
{
|
|
$item_list = array();
|
|
foreach ($user_db['quest_list'] as &$us) {
|
|
if ($us['id'] != $id) {
|
|
continue;
|
|
}
|
|
$num = 0;
|
|
foreach ($us['quest_list'] as &$q) {
|
|
if ($q['id'] != $idx || $q['status'] != 1) {
|
|
$num++;
|
|
continue;
|
|
}
|
|
array_push($item_list, array(
|
|
'item_id' => $us['reward'][$num]['item_id'],
|
|
'item_num' => $us['reward'][$num]['item_num'],
|
|
'time' => $us['reward'][$num]['time'],
|
|
));
|
|
$q['status'] = 2;
|
|
$num++;
|
|
break;
|
|
}
|
|
break;
|
|
}
|
|
$this->saveHolidayDB($account_id, $user_db);
|
|
return $item_list;
|
|
}
|
|
|
|
protected function getExchangeReward($account_id, $user_db, $type, $id, $idx)
|
|
{
|
|
$item_list = array();
|
|
foreach ($user_db['exchange_list'] as &$us) {
|
|
if ($us['id'] != $id) {
|
|
continue;
|
|
}
|
|
$num = 0;
|
|
foreach ($us['exc_list'] as &$q) {
|
|
if ($num != $idx || $q['status'] == 1) {
|
|
$num++;
|
|
continue;
|
|
}
|
|
$item_list = $this->subItem($q['id'], $q['condition'], $us['reward'][$num], $account_id);
|
|
$q['status'] = 0;
|
|
$q['num']++;
|
|
if ($q['num'] >= $us['times_list'][$num]) {
|
|
$q['status'] = 1;
|
|
}
|
|
$num++;
|
|
break;
|
|
}
|
|
break;
|
|
}
|
|
$this->saveHolidayDB($account_id, $user_db);
|
|
return $item_list;
|
|
}
|
|
|
|
protected function subItem($id, $num, $arr, $account_id)
|
|
{
|
|
$item_list = array();
|
|
$conn = $this->getMysql($account_id);
|
|
if (!$conn) {
|
|
return null;
|
|
}
|
|
$row = $conn->execQueryOne('SELECT num FROM bag WHERE accountid=:accountid AND id=:id;',
|
|
array(
|
|
':accountid' => $account_id,
|
|
'id' => $id
|
|
));
|
|
if (!$row || $row['num'] - $num < 0) {
|
|
phpcommon\sendError(ERR_USER_BASE + 3, '道具不足');
|
|
die();
|
|
return null;
|
|
}
|
|
$ret = $conn->execScript('UPDATE bag SET num=:num, modify_time=:modify_time ' .
|
|
' WHERE accountid=:accountid AND id =:id;',
|
|
array(
|
|
':accountid' => $account_id,
|
|
':id' => $id,
|
|
':num' => $row['num'] - $num,
|
|
':modify_time' => time()
|
|
));
|
|
if (!$ret) {
|
|
die();
|
|
return null;
|
|
}
|
|
$arr1 = explode(';', $arr);
|
|
$arr2 = array();
|
|
foreach ($arr1 as $a) {
|
|
$mul = explode(':', $a);
|
|
array_push($arr2, $mul);
|
|
}
|
|
|
|
foreach ($arr2 as $a2) {
|
|
array_push ($item_list, array(
|
|
'item_id' => $a2[0],
|
|
'item_num' => $a2[1],
|
|
'time' => $a2[2],
|
|
));
|
|
}
|
|
return $item_list;
|
|
}
|
|
}
|
|
?>
|