$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 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; $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(); $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) { $drop_multiply = $this->getExplode($seaPoint['weekreward']); for($s = 0; $s < count($drop_multiply); $s++) { array_push($week_reward, array( 'item_id' => $drop_multiply[$s][0], 'item_num' => $drop_multiply[$s][1], 'time' => $drop_multiply[$s][2], 'status' => $row['pass_status'] )); } $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; } } $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; 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' => time(), ':modify_time' => time() )); if (!$ret) { die(); return; } $rank_status = 0; } else { $rank_status = $rowpass['active_status']; } $delim = ':'; $item_multiply = explode($delim, $seaPoint['reward']); array_push($reward, array( 'item_id' => $item_multiply[0], 'item_num' => $item_multiply[1], 'time' => $item_multiply[2], 'status' => $rank_status )); } if ($rank == 0) { phpcommon\sendError(ERR_USER_BASE + 3, '未达到段位要求'); return; } 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, )); } 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 ' . ' FROM passinfo WHERE accountid=:accountid AND passid=:passid;', array( ':accountid' => $account_id, ':passid' => $passid )); if ($rowPass) { $status = $rowPass['active_status']; if ($status == 1) { phpcommon\sendError(ERR_USER_BASE + 2, '该奖励已领取'); return; } } $row = $conn->execQueryOne('SELECT integral FROM user WHERE accountid=:accountid;', array( ':accountid' => $account_id, )); if (!$row) { phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); return; } $this->updateStatus($account_id, $passid); //增加奖励 $seaPoint = $this->getSeasonPoint($passid); $delim = ':'; $drop_multiply = explode($delim, $seaPoint['reward']); $reward = array(); array_push($reward, array( 'item_id' => $drop_multiply[0], 'item_num' => $drop_multiply[1], 'time' => $drop_multiply[2], )); $addreward = new classes\AddReward(); $all_item_list = $addreward->addReward($drop_multiply[0], $drop_multiply[1], $account_id, $drop_multiply[2]); $coin_num = $addreward->getCoinNum($account_id); $diamond_num = $addreward->getDiamondNum($account_id); echo json_encode(array( 'errcode' => 0, 'errmsg'=> '', 'status' => 1, 'item_list' => $reward, 'coin_nums' => $coin_num, 'diamond_nums' => $diamond_num, 'all_item_list' => $all_item_list )); } protected function updateStatus($accountid, $passid) { $conn = $this->getMysql($accountid); if (!$conn) { phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); return; } $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; } } 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; } $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) { $drop_multiply = $this->getExplode($seaPoint['weekreward']); for($i = 0; $i < count($drop_multiply); $i++) { array_push($reward, array( 'item_id' => $drop_multiply[$i][0], 'item_num' => $drop_multiply[$i][1], 'time' => $drop_multiply[$i][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']); 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' => 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, '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) { $delim = ':'; $drop_multiply = explode($delim, $seaPoint['reward']); array_push($reward, array( 'item_id' => $drop_multiply[0], 'item_num' => $drop_multiply[1], 'time' => $drop_multiply[2] )); $level = $ii; } } $addreward = new classes\AddReward(); foreach ($reward as $r) { $addreward->addReward($r['item_id'], $r['item_num'], $account_id, $r['time']); } $ret = $conn->execScript('UPDATE user SET pass_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 )); } } ?>