$mysql_conf['host'], 'port' => $mysql_conf['port'], 'user' => $mysql_conf['user'], 'passwd' => $mysql_conf['passwd'], 'dbname' => 'gamedb2003_' . $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; } 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 = 'game2003api_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 collectReward() { $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 collect_status, pass_status ' . ' FROM user WHERE accountid=:accountid;', array( ':accountid' => $account_id )); if (!$row) { phpcommon\sendError(ERR_USER_BASE + 2, '没有这个玩家'); return; } $type = $_REQUEST['type']; switch ($type) { case 1: //收藏 if ($row['collect_status'] >= 1) { phpcommon\sendError(ERR_USER_BASE + 3, '奖励已领取'); return; } $this->updateCollectStatus($account_id); break; case 2: //浮窗 if ($row['pass_status'] >= 1) { phpcommon\sendError(ERR_USER_BASE + 3, '奖励已领取'); return; } $this->updateWindowStatus($account_id); break; default: break; } echo json_encode(array( 'errcode' => 0, 'errmsg' => '', )); } public function updateDailyReward($account_id) { $conn = $this->getMysql($account_id); $ret = $conn->execScript('UPDATE user SET daily_reward=daily_reward + 1, modify_time=:modify_time ' . ' WHERE accountid=:accountid;', array( ':modify_time' => time(), ':accountid' => $account_id )); if (!$ret) { die(); } } public function updateCollectStatus($account_id) { $conn = $this->getMysql($account_id); $ret = $conn->execScript('UPDATE user SET collect_status=1, modify_time=:modify_time ' . ' WHERE accountid=:accountid;', array( ':modify_time' => time(), ':accountid' => $account_id )); if (!$ret) { die(); } } public function updateWindowStatus($account_id) { $conn = $this->getMysql($account_id); $ret = $conn->execScript('UPDATE user SET pass_status=1, modify_time=:modify_time ' . ' WHERE accountid=:accountid;', array( ':modify_time' => time(), ':accountid' => $account_id )); if (!$ret) { die(); } } public function rewardList($key, $account_id) { $item_list = array(); $p = $this->getParameter($key); $item_id = 10003; $item_num = $p['value']; $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 )); return $item_list; } public function tryPlayInfo() { $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; } $play_list = array(); $rows = $conn->execQuery('SELECT appid, status FROM try_play WHERE accountid=:accountid;', array( ':accountid' => $account_id )); if ($rows) { foreach ($rows as $row) { array_push($play_list, array( 'appid' => $row['appid'], 'status' => $row['status'] )); } } echo json_encode(array( 'errcode' => 0, 'errmsg' => '', 'play_list' => $play_list )); } public function tryPlayReward() { $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); $appid = $_REQUEST['appid']; if (!$conn) { phpcommon\sendError(ERR_USER_BASE + 2, '没有这个玩家'); return; } $row = $conn->execQueryOne('SELECT status FROM try_play WHERE accountid=:accountid AND appid=:appid;', array( ':accountid' => $account_id, ':appid' => $appid )); if (!$row) { //插入 $ret = $conn->execScript('INSERT INTO try_play(accountid, appid, status, create_time, modify_time) ' . ' VALUES(:account_id, :appid, :status, :create_time, :modify_time) ' . ' ON DUPLICATE KEY UPDATE accountid=:account_id, appid=:appid, status=:status, modify_time=:modify_time;', array( ':account_id' => $account_id, ':appid' => $appid, ':status' => 1, ':create_time' => time(), ':modify_time' => time() )); if(!$ret){ die(); return; } } else { if ($row['status'] == 1) { phpcommon\sendError(ERR_USER_BASE + 2, '奖励已领取'); return; } //更新 $ret = $conn->execScript('UPDATE try_play SET status=1, modify_time=:modify_time ' . ' WHERE accountid=:accountid AND appid=:appid;', array( ':accountid' => $account_id, ':modify_time' => time(), ':appid' => $appid )); if (!$ret) { die(); return; } } //获得奖励 echo json_encode(array( 'errcode' => 0, 'errmsg' => '', )); } public function dailyInfo() { $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_coin_time, free_jewel_time, free_power_time ' . ' FROM daily_reward WHERE accountid=:accountid;', array( ':accountid' => $account_id )); if (!$row) { $ret = $conn->execScript('INSERT INTO daily_reward(accountid, free_coin_time, free_jewel_time, free_power_time, create_time, modify_time) ' . ' VALUES(:account_id, 0, 0, 0, :create_time, :modify_time) ' . ' ON DUPLICATE KEY UPDATE accountid=:account_id, free_coin_time=0, free_jewel_time=0, free_power_time=0, modify_time=:modify_time;', array( ':account_id' => $account_id, ':create_time' => time(), ':modify_time' => time() )); if(!$ret){ die(); return; } echo json_encode(array( 'errcode' => 0, 'errmsg' => '', 'free_coin_time' => 0, 'free_jewel_time' => 0, 'free_power_time' => 0 )); } else { echo json_encode(array( 'errcode' => 0, 'errmsg' => '', 'free_coin_time' => $row['free_coin_time'], 'free_jewel_time' => $row['free_jewel_time'], 'free_power_time' => $row['free_power_time'] )); } } public function dailyReward() { //error_log($_REQUEST['type']); $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_coin_time, free_jewel_time, free_power_time ' . ' FROM daily_reward WHERE accountid=:accountid;', array( ':accountid' => $account_id )); if (!$row) { phpcommon\sendError(ERR_USER_BASE + 2, '没有这个玩家'); return; } $type = $_REQUEST['type']; switch ($type) { case 1: //免费金币 $this->updateDailyStatus($account_id, 1); break; case 2: //免费钻石 if ($row['free_jewel_time'] >= 5) { phpcommon\sendError(ERR_USER_BASE + 3, '奖励已领取'); return; } $this->updateDailyStatus($account_id, 2); break; case 3: //免费体力 if ($row['free_power_time'] >= 5) { phpcommon\sendError(ERR_USER_BASE + 3, '奖励已领取'); return; } $this->updateDailyStatus($account_id, 3); break; default: break; } echo json_encode(array( 'errcode' => 0, 'errmsg' => '', )); } protected function updateDailyStatus($account_id, $type) { $conn = $this->getMysql($account_id); if ($type == 1) { $ret = $conn->execScript('UPDATE daily_reward SET free_coin_time=free_coin_time+1, modify_time=:modify_time ' . ' WHERE accountid=:accountid;', array( ':modify_time' => time(), ':accountid' => $account_id )); if (!$ret) { die(); } } else if ($type == 2) { $ret = $conn->execScript('UPDATE daily_reward SET free_jewel_time=free_jewel_time+1, modify_time=:modify_time ' . ' WHERE accountid=:accountid;', array( ':modify_time' => time(), ':accountid' => $account_id )); if (!$ret) { die(); } } else if ($type == 3) { $ret = $conn->execScript('UPDATE daily_reward SET free_power_time=free_power_time+1, modify_time=:modify_time ' . ' WHERE accountid=:accountid;', array( ':modify_time' => time(), ':accountid' => $account_id )); if (!$ret) { die(); } } } } ?>