$mysql_conf['host'], 'port' => $mysql_conf['port'], 'user' => $mysql_conf['user'], 'passwd' => $mysql_conf['passwd'], 'dbname' => 'gamedb2001_' . $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'], 'season' => $seaReward_meta['reward3'] ); 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'], ); 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']); $number = $i; break; } } if ($number == 0) { phpcommon\sendError(ERR_USER_BASE + 2, '赛季未开启'); return; } //当前段位及积分 $rank = 0; $next_score = 0; $max_score = 0; $sum_score = 0; $score = 0; $row = $conn->execQueryOne('SELECT integral, pass_status 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'] || $seaPoint['max'] == -1) { $rank = $ii; if ($ii == count($seaPoint_meta_table)) { $next_score = $seaPoint['max']; } else { $next_score = $seaPoint['max'] + 1 - $seaPoint['min']; } $score = $row['integral'] - $seaPoint['min']; } if ($ii == count($seaPoint_meta_table)) { $max_score = $seaPoint['min']; } else { $max_score = $seaPoint['max']; } } if ($rank == 0) { phpcommon\sendError(ERR_USER_BASE + 3, '未达到段位要求'); return; } //奖励信息 $item_list = array(); $seaReward_meta_table = require('../res/seasonReward@seasonReward.php'); for ($j = 1; $j <= count($season_meta_table); $j++) { $id = $j + $number * 100; if ($id >= ($number + 1) * 100 || $id <= ($number - 1) * 100) { continue; } $drop_multiply = array(); $status = 0; $seaReward = $this->getSeasonReward($j + $number * 100); $rowPass = $conn->execQueryOne('SELECT active_status, honor_status ' . ' FROM passinfo WHERE accountid=:accountid AND passid=:passid;', array( ':accountid' => $account_id, ':passid' => $seaReward['id'] )); for ($t = 1; $t <= 2; $t++) { $delim = ":"; if ($t == 1) { $drop_multiply = explode($delim, $seaReward['active']); if ($rowPass) { $status = $rowPass['active_status']; } } if ($t == 2) { $drop_multiply = explode($delim, $seaReward['honor']); if ($rowPass) { $status = $rowPass['honor_status']; } } array_push($item_list, array( 'id' => $id, 'type' => $t, 'point' => $seaReward['point'], 'item_id' => $drop_multiply[0], 'item_num' => $drop_multiply[1], '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, 'sum_score' => $row['integral'], 'score' => $score, 'max_score' => $max_score, 'next_score' => $next_score, '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 integral, pass_status FROM user WHERE accountid=:accountid;', array( ':accountid' => $account_id, )); if (!$row) { phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); return; } if ($seaReward['point'] > $row['integral']) { 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) { $drop_multiply = explode($delim, $seaReward['active']); } if ($type == 2) { $drop_multiply = explode($delim, $seaReward['honor']); } $addreward = new classes\AddReward(); $addreward->addReward($drop_multiply[0], $drop_multiply[1], $account_id); echo json_encode(array( 'errcode' => 0, 'errmsg'=> '', 'status' => 1, )); } 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; } } } } ?>