$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 getRedis($shop_uuid) { $redis_conf = getRedisConfig(crc32($shop_uuid)); $r = new phpcommon\Redis(array( 'host' => $redis_conf['host'], 'port' => $redis_conf['port'], 'passwd' => $redis_conf['passwd'] )); return $r; } protected function getParameter($para_id) { $parameter_meta_cluster = require('../res/parameter@parameter.php'); $parameter_meta = getParameterConfig($parameter_meta_cluster, $para_id); $p = array( 'id' => $parameter_meta['id'], 'name' => $parameter_meta['param_name'], 'value' => $parameter_meta['param_value'], ); return $p; } protected function getDrop($drop_id) { $drop_meta_table = require('../res/drop@drop.php'); $drop_meta = getDropConfig($drop_meta_table, $drop_id); $d = array( 'drop_id' => $drop_meta['drop_id'], 'item_id' => $drop_meta['item_id'], 'num' => $drop_meta['num'], 'weight' => $drop_meta['weight'], 'type' => $drop_meta['type'] ); return $d; } 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 getLottery($lot_id) { $g_conf_lot_cluster = require('../res/lottery@lottery.php'); $lot_conf = getLotteryConfig($g_conf_lot_cluster, $lot_id); $l = array( 'id' => $lot_conf['id'], 'item_id' => $lot_conf['item_id'], 'num' => $lot_conf['num'], 'weight' => $lot_conf['weight'], 'quailty' => $lot_conf['quailty'], 'jilv' => $lot_conf['jilv'], 'time' => $lot_conf['time'], ); return $l; } protected function getreward($re_id) { $g_conf_re_cluster = require('../res/randreward@randreward.php'); $re_conf = getRandrewardConfig($g_conf_re_cluster, $re_id); $re = array( 'id' => $re_conf['id'], 'reward' => $re_conf['reward'], 'number' => $re_conf['number'], 'weight' => $re_conf['weight'], ); return $re; } public function luckDrawInfo() { $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; } $draw_uuid = 'game2004api_draw_uuid:' . md5($_REQUEST['account_id']); $draw_list = array(); $r = $this->getRedis($draw_uuid); if (!$r) { die(); return; } //刷新次数 $p_free = $this->getParameter(FREELOTTERY_TIME); $p_video = $this->getParameter(VIDEOLOTTERY_TIME); $free_times = $p_free['value']; $video_times = $p_video['value']; $row = $conn->execQueryOne('SELECT free_times, video_times FROM activity WHERE accountid=:accountid;', array( ':accountid' => $account_id )); if (!$row) { $ret = $conn->execScript('INSERT INTO activity(accountid, free_times, video_times, item_id, item_num, create_time, modify_time) ' . ' VALUES(:accountid, 0, 0, 0, 0, :create_time, :modify_time) ' . ' ON DUPLICATE KEY UPDATE accountid=:accountid, free_times=0, video_times=0, item_id=0, item_num=0, modify_time=:modify_time;', array( ':accountid' => $account_id, ':create_time' => time(), ':modify_time' => time() )); if (!$ret) { die(); return; } $free_times = $p_free['value']; $video_times = $p_video['value']; } else { $free_times = $p_free['value'] - $row['free_times']; $video_times = $p_video['value'] - $row['video_times']; } //道具物品 $user_db_str = $r->get($draw_uuid); if (empty($user_db_str)) { $draw_list = $this->randomReward(); $draw_db = array( 'draw_uuid' => $draw_uuid, 'draw_list' => $draw_list, ); $r -> set($draw_uuid, json_encode($draw_db)); $r -> pexpire($draw_uuid, 1000 * 3600 * 24); } else { $draw_db = json_decode($user_db_str, true); $rowTime = $conn->execQueryOne('SELECT modify_time FROM activity WHERE accountid=:accountid;', array( ':accountid' => $account_id )); if (phpcommon\getdayseconds(time()) - phpcommon\getdayseconds($rowTime['modify_time']) > 0) { $draw_list = $this->randomReward(); $draw_db = array( 'draw_uuid' => $draw_uuid, 'draw_list' => $draw_list, ); $r -> set($draw_uuid, json_encode($draw_db)); $r -> pexpire($draw_uuid, 1000 * 3600 * 24); } else { $user_db = json_decode($user_db_str, true); if (empty($user_db)) { phpcommon\sendError(ERR_USER_BASE + 1,'session失效'); return; } foreach ($user_db['draw_list'] as $draw) { array_push($draw_list, array( 'item_id' => $draw['item_id'], 'item_num' => $draw['item_num'], 'quailty' => $draw['quailty'], 'time' => $draw['time'], )); } } } echo json_encode(array( 'errcode' => 0, 'errmsg'=> '', 'draw_uuid' => $draw_uuid, 'free_times' => $free_times, 'video_times' => $video_times, 'item_list' => $draw_list, )); } public function getLuckDraw() { $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; } $row = $conn->execQueryOne('SELECT free_times, video_times FROM activity WHERE accountid=:accountid;', array( ':accountid' => $account_id )); if (!$row) { phpcommon\sendError(ERR_USER_BASE + 2, '没有这个玩家'); return; } //随机确认奖励 $weight_sum = 0; $g_conf_lot_cluster = require('../res/lottery@lottery.php'); for ($i = 1; $i <= count($g_conf_lot_cluster); $i++) { $l = $this->getLottery($i); $weight_sum += $l['jilv']; } $random = Rand(0, $weight_sum); $weight = 0; $key = 0; for ($ii = 1; $ii <= count($g_conf_lot_cluster); $ii++) { $l = $this->getLottery($ii); $weight += $l['jilv']; if ($weight > $random) { $key = $ii; break; } } $draw_uuid = $_REQUEST['draw_uuid']; $item_id = 0; $item_num = 0; $flag = 0; $r = $this->getRedis($draw_uuid); $user_db_str = $r->get($draw_uuid); if (empty($user_db_str)) { phpcommon\sendError(ERR_USER_BASE + 1,'session失效'); return; } $user_db = json_decode($user_db_str, true); if (empty($user_db)) { phpcommon\sendError(ERR_USER_BASE + 1,'session失效'); return; } foreach ($user_db['draw_list'] as $draw) { if ($draw['key'] == $key - 1) { $item_id = $draw['item_id']; $item_num = $draw['item_num']; $time = $draw['time']; $flag = 1; break; } } if ($flag == 0) { phpcommon\sendError(ERR_USER_BASE + 3, '没有这个物品'); return; } if ($_REQUEST['type'] == 0) { $p_flush = $this->getParameter(FREELOTTERY_TIME); if ($p_flush['value'] <= $row['free_times']) { phpcommon\sendError(ERR_USER_BASE + 3, '今日刷新次数已满'); return; } $ret = $conn->execScript('UPDATE activity SET free_times=:free_times, item_id=:item_id, item_num=:item_num, modify_time=:modify_time ' . ' WHERE accountid=:accountid;', array( ':accountid' => $account_id, ':free_times' => $row['free_times'] + 1, ':item_id' => $item_id, ':item_num' => $item_num, ':modify_time' => time() )); if (!$ret) { die(); return; } } if ($_REQUEST['type'] == 1) { $p_flush = $this->getParameter(VIDEOLOTTERY_TIME); if ($p_flush['value'] <= $row['video_times']) { phpcommon\sendError(ERR_USER_BASE + 3, '今日刷新次数已满'); return; } $ret = $conn->execScript('UPDATE activity SET video_times=:video_times,item_id=:item_id, item_num=:item_num, modify_time=:modify_time ' . ' WHERE accountid=:accountid;', array( ':accountid' => $account_id, ':video_times' => $row['video_times'] + 1, ':item_id' => $item_id, ':item_num' => $item_num, ':modify_time' => time() )); if (!$ret) { die(); return; } } //增加奖励 $addreward = new classes\AddReward(); $addreward->addReward($item_id, $item_num, $account_id, $time); $coin_num = $addreward->getCoinNum($account_id); $diamond_num = $addreward->getDiamondNum($account_id); $item_list = array(); array_push($item_list,array( 'item_id' => $item_id, 'item_num' => $item_num, )); echo json_encode(array( 'errcode' => 0, 'errmsg'=> '', 'item_id' => $item_id, 'item_num' => $item_num, 'coin_nums' => $coin_num, 'diamond_nums' => $diamond_num, 'item_list' => $item_list )); } public function doubleLuckDraw() { $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; } $row = $conn->execQueryOne('SELECT item_id, item_num FROM activity WHERE accountid=:accountid;', array( ':accountid' => $account_id )); if (!$row) { phpcommon\sendError(ERR_USER_BASE + 2, '没有这个玩家'); return; } //增加奖励 $p = $this->getParameter(REWARD_TIMES); $times = $p['value'] - 1; $addreward = new classes\AddReward(); $addreward->addReward($row['item_id'], $row['item_num'] * $times, $account_id); $coin_num = $addreward->getCoinNum($account_id); echo json_encode(array( 'errcode' => 0, 'errmsg'=> '', 'coin_nums' => $coin_num, )); } protected function randomReward() { $draw_list = array(); $g_conf_lot_cluster = require('../res/lottery@lottery.php'); for ($i = 1; $i <= count($g_conf_lot_cluster); $i++) { $item_id = 0; $item_num = 0; $key = 0; $l = $this->getLottery($i); //确定商品id和数量 $weight_sum = 0; $weight_array = $this->getExplode($l['weight']); for ($ii = 0; $ii < count($weight_array); $ii++) { $weight_sum += $weight_array[$ii][0]; } $random = Rand(0, $weight_sum); $weight = 0; for ($ii = 0; $ii < count($weight_array); $ii++) { $weight += $weight_array[$ii][0]; if ($weight > $random) { $key = $ii; break; } } $item_id_array = $this->getExplode($l['item_id']); $num_array = $this->getExplode($l['num']); $quailty_array = $this->getExplode($l['quailty']); $time_array = $this->getExplode($l['time']); $item_id = $item_id_array[$key][0]; $item_num = $num_array[$key][0]; $quailty = $quailty_array[$key][0]; $time = $time_array[$key][0]; array_push($draw_list, array( 'key' => $i - 1, 'item_id' => $item_id, 'item_num' => $item_num, 'quailty' => $quailty, 'time' => $time, )); } return $draw_list; } public function randRewardInfo() { $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; } $randreward_uuid = 'game2004api_randreward_uuid:' . md5($_REQUEST['account_id']); $randreward_list = array(); $r = $this->getRedis($randreward_uuid); $user_db_str = $r->get($randreward_uuid); if (!$r) { die(); return; } if (empty($user_db_str)) { $randreward_list = $this->getRandomReward(); $randreward_db = array( 'randreward_uuid' => $randreward_uuid, 'randreward_list' => $randreward_list, ); $r -> set($randreward_uuid, json_encode($randreward_db)); $r -> pexpire($randreward_uuid, 1000 * 7200); } else { $randreward_list = $this->getRandomReward(); $randreward_db = array( 'randreward_uuid' => $randreward_uuid, 'randreward_list' => $randreward_list, ); $r -> set($randreward_uuid, json_encode($randreward_db)); $r -> pexpire($randreward_uuid, 1000 * 7200); } $r = $this->getRedis($randreward_uuid); $user_db_str = $r->get($randreward_uuid); $user_db = json_decode($user_db_str, true); foreach ($user_db['randreward_list'] as $randreward) { //增加奖励 $addreward = new classes\AddReward(); $addreward->addReward($randreward['item_id'], $randreward['item_num'], $account_id); } echo json_encode(array( 'errcode' => 0, 'errmsg'=> '', 'randreward_uuid' => $randreward_uuid, 'item_list' => $randreward_list, )); } public function doubleRandReward() { $account_id = $_REQUEST['account_id']; //登录校验 $login = loginVerify($account_id, $_REQUEST['session_id']); if (!$login) { phpcommon\sendError(ERR_USER_BASE + 1, 'session无效'); return; } $randreward_uuid = $_REQUEST['randreward_uuid']; $r = $this->getRedis($randreward_uuid); if (!$r) { die(); return; } $user_db_str = $r->get($randreward_uuid); if (empty($user_db_str)) { phpcommon\sendError(ERR_USER_BASE + 1,'session失效'); return; } $user_db = json_decode($user_db_str, true); if (empty($user_db)) { phpcommon\sendError(ERR_USER_BASE + 1,'session失效'); return; } $p = $this->getParameter(REWARD_TIMES); $times = $p['value'] - 1; foreach ($user_db['randreward_list'] as $randreward) { //增加奖励 $addreward = new classes\AddReward(); $addreward->addReward($randreward['item_id'], $randreward['item_num'] * $times, $account_id); } $r->del($randreward_uuid, json_encode($user_db)); echo json_encode(array( 'errcode' => 0, 'errmsg'=> '', )); } protected function getRandomReward() { $randreward_list = array(); $g_conf_re_cluster = require('../res/randreward@randreward.php'); for ($i = 1; $i <= count($g_conf_re_cluster); $i++) { $item_id = 0; $item_num = 0; $key = 0; $re = $this->getreward($i); //确定商品id和数量 $weight_sum = 0; $weight_array = $this->getExplode($re['weight']); for ($ii = 0; $ii < count($weight_array); $ii++) { $weight_sum += $weight_array[$ii][0]; } $random = Rand(0, $weight_sum); $weight = 0; for ($ii = 0; $ii < count($weight_array); $ii++) { $weight += $weight_array[$ii][0]; if ($weight > $random) { $key = $ii; break; } } $item_id_array = $this->getExplode($re['reward']); $num_array = $this->getExplode($re['number']); $item_id = $item_id_array[$key][0]; $item_num = $num_array[$key][0]; array_push($randreward_list, array( 'item_id' => $item_id, 'item_num' => $item_num, )); } return $randreward_list; } } ?>