$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 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'], 'season_overreward' => $season_meta['season_overreward'], 'reward2' => $season_meta['season_reward2'], ); 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 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; $sea_reward = array(); $sea_reward2 = array(); $rank_status = 0; $season = metatable\getNowSeason(); $number = metatable\getNowSeasonNum(); $open_time = strtotime($season['time1']); $end_time = strtotime($season['time2']); $item_multiply = $this->getExplode($season['season_reward']); $item_multiply2 = $this->getExplode($season['season_reward2']); for($ii = 1; $ii <= count($item_multiply); $ii++) { $rowpass = $conn->execQueryOne('SELECT active_status, honor_status ' . ' FROM passinfo WHERE accountid=:accountid AND passid=:passid;', array( ':accountid' => $account_id, ':passid' => $ii, )); $rank_status = 0; $rank_status2 = 0; 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' => $ii, ':create_time' => phpcommon\getNowTime(), ':modify_time' => phpcommon\getNowTime() )); if (!$ret) { die(); return; } $rank_status = 0; $rank_status2 = 0; } else { $rank_status = $rowpass['active_status']; $rank_status2 = $rowpass['honor_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, '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, )); } 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; } $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) { $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 ($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' => $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, 'min_rank_score' => $min_rank_score, 'seareward2' => $sea_reward2, 'cost' => $cost, 'pass_array' => $pass_array, )); } 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; $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 = $this->getSeason($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 (!$conn) { phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); return; } 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']; //登录校验 $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 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 = $this->getSeasonPoint($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 = $this->getSeason($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']; //登录校验 $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) { $level = $ii; break; } } //奖励结算 $season_meta_table = require('../res/season@season.php'); $id = 0; for ($i = 1; $i <= count($season_meta_table); $i++) { $season = $this->getSeason($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 = $this->getSeason($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']; //登录校验 $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 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']; //登录校验 $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 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 = $this->getSeason($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; } } ?>