$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 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 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 getShare($share_id) { $share_meta_table = require('../res/share@share.php'); $share_meta = getShareConfig($share_meta_table, $share_id); $sh = array( 'id' => $share_meta['id'], 'rewards' => $share_meta['rewards'], 'people' => $share_meta['people'], ); return $sh; } 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 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'], 'param_name' => $parameter_meta['param_name'], 'param_value' => $parameter_meta['param_value'], ); return $p; } protected function subCoin($coin_num, $account_id) { $conn = $this->getMysql($account_id); if (!$conn) { phpcommon\sendError(ERR_USER_BASE + 2, '没有这个玩家'); return; } $row = $conn->execQueryOne('SELECT diamond_num FROM user WHERE accountid=:accountid;', array( ':accountid' => $account_id )); if (!$row) { phpcommon\sendError(ERR_USER_BASE + 2, '没有这个玩家'); die(); } if ($row['diamond_num'] < $diamond_num) { phpcommon\sendError(ERR_USER_BASE + 3, '钻石不足'); die(); } $ret = $conn->execScript('UPDATE user SET diamond_num=:diamond_num, modify_time=:modify_time ' . ' WHERE accountid=:accountid;', array( ':accountid' => $account_id, ':diamond_num' => $row['diamond_num'] - $diamond_num, ':modify_time' => time() )); if (!$ret) { die(); } } public function keyBoxInfo() { $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; } $free = $_REQUEST['free']; if ($free != 0) { $drop_id = 24002; } else { $drop_id = 24001; } //扣除钻石 $p = $this->getParameter(DIAMONDBOX); $diamond_num = $p['param_value']; $this->subCoin($diamond_num, $account_id); //随机奖励 $drop_id = 0; $d = $this->getDrop($drop_id); if (!$d) { phpcommon\sendError(ERR_USER_BASE + 3, '没有这个奖励'); return; } $item_id_array = $this->getExplode($d['item_id']); $weight_sum = 0; $keys = 0; $item_num_array = $this->getExplode($d['num']); $weight_array = $this->getExplode($d['weight']); for ($i = 0; $i < count($weight_array); $i++) { $weight_sum += $weight_array[$i][0]; } $keys = $row['keys_num'] - 1; srand(crc32($account_id . $keys)); $random = Rand(0, $weight_sum); $weight = 0; for ($i = 0; $i < count($weight_array); $i++) { $weight += $weight_array[$i][0]; if ($weight > $random) { $keys = $i; break; } } $item_id = $item_id_array[$keys][0]; $item_num = $item_num_array[$keys][0]; $item_list = array(); array_push($item_list, array( 'item_id' => $item_id, 'item_num' => $item_num, )); //保存开宝箱奖励 $boxreward_uuid = 'game2001api_boxreward_uuid:' . md5($_REQUEST['account_id']); $boxreward_list = array(); $r = $this->getRedis($boxreward_uuid); $user_db_str = $r->get($boxreward_uuid); if (!$r) { die(); return; } if (empty($user_db_str)) { $boxreward_db = array( 'boxreward_uuid' => $boxreward_uuid, 'boxreward_list' => $item_list, ); $r -> set($boxreward_uuid, json_encode($boxreward_db)); $r -> pexpire($boxreward_uuid, 1000 * 7200); } else { $boxreward_db = array( 'boxreward_uuid' => $boxreward_uuid, 'boxreward_list' => $item_list, ); $r -> set($boxreward_uuid, json_encode($boxreward_db)); $r -> pexpire($boxreward_uuid, 1000 * 7200); } $quest = new classes\Quest(); $quest->triggerQuest(71004, 1, 1, $account_id); $quest->triggerQuest(72004, 2, 1, $account_id); $addreward = new classes\AddReward(); $addreward->addReward($item_id, $item_num, $account_id); echo json_encode(array( 'errcode' => 0, 'errmsg' => '', 'item_list' => $item_list, 'keys_num' => $row['keys_num'] - 1 )); } public function keyBoxDoubleReward() { $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 keys_num FROM user WHERE accountid=:accountid;', array( ':accountid' => $account_id )); if (!$row) { phpcommon\sendError(ERR_USER_BASE + 2, '没有这个玩家'); return; } $boxreward_uuid = 'game2001api_boxreward_uuid:' . md5($_REQUEST['account_id']); $r = $this->getRedis($boxreward_uuid); $user_db_str = $r->get($boxreward_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['param_value'] - 1; foreach ($user_db['boxreward_list'] as $boxreward) { //增加奖励 $addreward = new classes\AddReward(); $addreward->addReward($boxreward['item_id'], $boxreward['item_num'] * $times, $account_id); } $r->del($boxreward_uuid, json_encode($user_db)); echo json_encode(array( 'errcode' => 0, 'errmsg' => '', )); } public function shareFriendInfo() { $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; } $info_list = array(); $rows = $conn->execQuery('SELECT ach_id, status FROM share_achievement WHERE accountid=:accountid;', array( ':accountid' => $account_id )); if (count($rows) == 0) { $share_meta_table = require('../res/share@share.php'); for ($i = 1; $i <= count($share_meta_table); $i++) { $id = $i; $share_meta = getShareConfig($share_meta_table, $id); if ($share_meta == NULL) { $id = -10000; } $ret = $conn->execScript('INSERT INTO share_achievement(accountid, ach_id, status, create_time, modify_time) ' . ' VALUES(:account_id, :ach_id, :status, :create_time, :modify_time) ' . ' ON DUPLICATE KEY UPDATE accountid=:account_id, ach_id=:ach_id, status=:status, modify_time=:modify_time;', array( ':account_id' => $account_id, ':ach_id' => $id, ':status' => 0, ':create_time' => time(), ':modify_time' => time() )); if(!$ret){ die(); return; } $sh = $this->getShare($id); $array = $this->getExplode($sh['rewards']); array_push($info_list, array( 'achivement_id' => $id, 'status' => 0, 'item_id' => $array[0][0], 'num' => $array[0][1], 'people_num' => $sh['people'], )); } } else { foreach ($rows as $row) { $sh = $this->getShare($row['ach_id']); $array = $this->getExplode($sh['rewards']); array_push($info_list, array( 'achivement_id' => $row['ach_id'], 'status' => $row['status'], 'item_id' => $array[0][0], 'num' => $array[0][1], 'people_num' => $sh['people'], )); } } echo json_encode(array( 'errcode' => 0, 'errmsg' => '', 'info_list' => $info_list )); } public function shareFriendReward() { $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; } $ach_id = $_REQUEST['ach_id']; $row = $conn->execQueryOne('SELECT status FROM share_achievement WHERE accountid=:accountid AND ach_id=:ach_id;', array( ':accountid' => $account_id, ':ach_id' => $ach_id, )); if (!$row) { phpcommon\sendError(ERR_USER_BASE + 2, '没有这个玩家'); return; } if ($row['status'] != 0) { phpcommon\sendError(ERR_USER_BASE + 3, '奖励已领取'); return; } //获取奖励信息 $url = ''; if (SERVER_ENV == _ONLINE) { $url = 'https://service.kingsome.cn/webapp/index.php?c=DailyMission&a=getInviteeNum&'; } else { $url = 'https://service-test.kingsome.cn/webapp/index.php?c=DailyMission&a=getInviteeNum&'; } $timestamp = time(); $params = array( 'account_id' => $_REQUEST['account_id'], 'session_id' => $_REQUEST['session_id'], 'activity_param' => $_REQUEST['activity_param'], ); $response = ''; if (!phpcommon\HttpClient::get($url, $params, $response)) { phpcommon\sendError(ERR_RETRY, '系统繁忙'); return; } //领取奖励 $data = json_decode($response, true); $peo_num = $data['invitee_num']; $sh = $this->getShare($ach_id); if ($peo_num < $sh['people']) { phpcommon\sendError(ERR_USER_BASE + 4, '未达到人数要求'); return; } $array = $this->getExplode($sh['rewards']); $addreward = new classes\AddReward(); $addreward->addReward($array[0][0], $array[0][1], $account_id); //更新状态 $ret = $conn->execScript('UPDATE share_achievement SET status=1, modify_time=:modify_time ' . ' WHERE accountid=:accountid AND ach_id=:ach_id;', array( ':accountid' => $account_id, ':modify_time' => time(), ':ach_id' => $ach_id )); if (!$ret) { die(); return; } echo json_encode(array( 'errcode' => 0, 'errmsg' => '', )); } public function shareDobleReward() { $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; } $ach_id = $_REQUEST['ach_id']; //获取奖励信息 $url = ''; if (SERVER_ENV == _ONLINE) { $url = 'https://service.kingsome.cn/webapp/index.php?c=DailyMission&a=getInviteeNum&'; } else { $url = 'https://service-test.kingsome.cn/webapp/index.php?c=DailyMission&a=getInviteeNum&'; } $timestamp = time(); $params = array( 'account_id' => $_REQUEST['account_id'], 'session_id' => $_REQUEST['session_id'], 'activity_param' => $_REQUEST['activity_param'], ); $response = ''; if (!phpcommon\HttpClient::get($url, $params, $response)) { phpcommon\sendError(ERR_RETRY, '系统繁忙'); return; } //领取奖励 $data = json_decode($response, true); $peo_num = $data['invitee_num']; $sh = $this->getShare($ach_id); if ($peo_num < $sh['people']) { phpcommon\sendError(ERR_USER_BASE + 4, '未达到人数要求'); return; } $array = $this->getExplode($sh['rewards']); $p = $this->getParameter(REWARD_TIMES); $times = $p['param_value'] - 1; $addreward = new classes\AddReward(); $addreward->addReward($array[0][0], $array[0][1] * $times, $account_id); echo json_encode(array( 'errcode' => 0, 'errmsg' => '', )); } public function getKefuReward() { $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; } $mail_id = $_REQUEST['mail_ids']; $url = ''; if (SERVER_ENV == _ONLINE) { $url = 'https://gamemail.kingsome.cn/webapp/index.php?c=Mail&a=getAttachment&'; } else { $url = 'https://gamemail-test.kingsome.cn/webapp/index.php?c=Mail&a=getAttachment&'; } $params = array( 'account_id' => $_REQUEST['account_id'], 'mail_ids' => $mail_id, 'session_id' => $_REQUEST['session_id'] ); if (!phpcommon\HttpClient::get($url, $params, $response)) { phpcommon\sendError(ERR_RETRY, '系统繁忙'); return; } $row = $conn->execQueryOne('SELECT kefu_status FROM user WHERE accountid=:accountid;', array( ':accountid' => $account_id )); if (!$row) { phpcommon\sendError(ERR_USER_BASE + 2, '没有这个玩家'); return; } if ($row['kefu_status'] != 0) { phpcommon\sendError(ERR_USER_BASE + 3, '客服奖励已领取'); die(); return; } $item_list = array(); $item_id = 0; $item_num = 0; $data = json_decode($response, true); $errcode = $data['errcode']; $errmsg = $data['errmsg']; if ($errcode == 0) { foreach($data['attachments'] as $kefu){ $item_id = $kefu['itemid']; $item_num = $kefu['itemnum']; } $addreward = new classes\AddReward(); $addreward->addReward($item_id, $item_num, $account_id); array_push($item_list, array( 'item_id' => $item_id, 'item_num' => $item_num, )); //保存客服奖励 $kefureward_uuid = 'game2001api_kefureward_uuid:' . md5($_REQUEST['account_id']); $kefureward_list = array(); $r = $this->getRedis($kefureward_uuid); $user_db_str = $r->get($kefureward_uuid); if (!$r) { die(); return; } if (empty($user_db_str)) { $kefureward_db = array( 'kefureward_uuid' => $kefureward_uuid, 'kefureward_list' => $item_list, ); $r -> set($kefureward_uuid, json_encode($kefureward_db)); $r -> pexpire($kefureward_uuid, 1000 * 7200); } else { $kefureward_db = array( 'kefureward_uuid' => $kefureward_uuid, 'kefureward_list' => $item_list, ); $r -> set($kefureward_uuid, json_encode($kefureward_db)); $r -> pexpire($kefureward_uuid, 1000 * 7200); } //更新状态 $ret = $conn->execScript('UPDATE user SET kefu_status=1, modify_time=:modify_time ' . ' WHERE accountid=:accountid;', array( ':accountid' => $account_id, ':modify_time' => time(), )); if (!$ret) { die(); return; } } echo json_encode(array( 'errcode' => $errcode, 'errmsg' => $errmsg, 'item_list' => $item_list )); } public function kefuDoubleReward() { $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; } $mail_id = $_REQUEST['mail_ids']; $kefureward_uuid = 'game2001api_kefureward_uuid:' . md5($_REQUEST['account_id']); $r = $this->getRedis($kefureward_uuid); $user_db_str = $r->get($kefureward_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['param_value'] - 1; foreach ($user_db['kefureward_list'] as $kefureward) { //增加奖励 $addreward = new classes\AddReward(); $addreward->addReward($kefureward['item_id'], $kefureward['item_num'] * $times, $account_id); } $r->del($kefureward_uuid, json_encode($user_db)); echo json_encode(array( 'errcode' => 0, 'errmsg' => '', )); } } ?>