$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 getBag($bag_id) { $g_conf_bag_cluster = require('../res/bag@bag.php'); $bag_conf = getBagConfig($g_conf_bag_cluster, $bag_id); $b = array( 'id' => $bag_conf['id'], 'name' => $bag_conf['name'], 'fuction' => $bag_conf['fuction'], ); return $b; } protected function getItem($item_id) { $g_conf_item_cluster = require('../res/item@item.php'); $item_conf = getItemConfig($g_conf_item_cluster, $item_id); $it = array( 'id' => $item_conf['id'], 'diamond' => $item_conf['diamond'], 'dprice' => $item_conf['dprice'], 'type' => $item_conf['fuction'], 'diamond_hour' => $item_conf['diamond_hour'] ); return $it; } protected function getParameter($para_id) { $g_conf_para_cluster = require('../res/parameter@parameter.php'); $para_conf = getParameterConfig($g_conf_para_cluster, $para_id); $p = array( 'id' => $para_conf['id'], 'param_name' => $para_conf['param_name'], 'param_value' => $para_conf['param_value'], ); return $p; } public function getBagInfo() { $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; } $bag_list = array(); $rows = $conn->execQuery('SELECT * FROM bag WHERE accountid=:account_id;', array( ':account_id' => $account_id )); if ($rows) { foreach ($rows as $row){ $active_time = 0; $color_id = 0; $status = $row['status']; if (time() >= $row['active_time'] && $row['active_time'] != 0) { $ret = $conn->execScript('UPDATE bag SET active_time=0, color_id=0, status=2, modify_time=:modify_time ' . ' WHERE accountid=:account_id AND id=:id;', array( ':account_id' => $account_id, ':id' => $row['id'], ':modify_time' => time() )); if (!$ret) { die(); return; } $active_time = 0; $color_id = 0; $status = 2; } else { if ($row['active_time'] != 0) { $active_time = $row['active_time']; } $color_id = $row['color_id']; $status = $row['status']; } array_push($bag_list, array( 'id' => $row['id'], 'active_time' => $active_time, 'status' => $status, 'color_id' => $color_id, )); } } else { $ret = $conn->execScript('INSERT INTO bag(accountid, id, color_id, status, active_time, create_time, modify_time) ' . ' VALUES(:account_id, :id, 0, :status, :active_time, :create_time, :modify_time) ' . ' ON DUPLICATE KEY UPDATE accountid=:account_id, id=:id, color_id=0, status=:status, active_time=:active_time, modify_time=:modify_time;', array( ':account_id' => $account_id, ':id' => 16001, ':active_time' => 0, ':status' => 0, ':create_time' => time(), ':modify_time' => time() )); if(!$ret){ die(); return; } array_push($bag_list, array( 'id' => 16001, 'active_time' => 0, 'status' => 0, 'color_id' => 0, )); } echo json_encode(array( 'errcode' => 0, 'errmsg' => '', 'bag_list' => $bag_list )); } public function exchangeBagItem() { $account_id = $_REQUEST['account_id']; //登录校验 $login = loginVerify($account_id, $_REQUEST['session_id']); if (!$login) { phpcommon\sendError(ERR_USER_BASE + 1, 'session无效'); return; } $item_id = $_REQUEST['item_id']; $color_id = $_REQUEST['color_id']; $conn = $this->getMysql($account_id); if(!$conn){ phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); return; } $b = $this->getBag($item_id); $bag_meta_table = require('../res/bag@bag.php'); //正在装备的道具 if ($b['fuction'] != 5) { foreach ($bag_meta_table as $bag_info) { $id = $bag_info['id']; $bag = $this->getBag($id); if ($bag['fuction'] != $b['fuction']) { continue; } $row = $conn->execQueryOne('SELECT status, active_time FROM bag WHERE accountid=:accountid AND id=:id;', array( ':accountid' => $account_id, ':id' => $id, )); if ($row['status'] != 0 || !$row) { continue; } $status = 2; if ($row['active_time'] == 0) { $status = 1; } $using_ret = $conn->execScript('UPDATE bag SET status=:status, color_id=0, modify_time=:modify_time ' . ' WHERE accountid = :account_id AND id = :id;', array( ':account_id' => $account_id, ':id' => $id, ':status' => $status, ':modify_time' => time() )); if(!$using_ret){ die(); return; } } } //要装备的道具 $row = $conn->execQueryOne('SELECT status FROM bag WHERE accountid=:accountid AND id=:id;', array( ':accountid' => $account_id, ':id' => $item_id, )); if (!$row) { phpcommon\sendError(ERR_USER_BASE + 2, '没有这个道具'); return; } $exchange_ret = $conn->execScript('UPDATE bag SET status=0, color_id=:color_id, modify_time=:modify_time ' . ' WHERE accountid = :account_id AND id = :id;', array( ':account_id' => $account_id, ':id' => $item_id, ':color_id' => $color_id, ':modify_time' => time() )); if(!$exchange_ret){ die(); return; } echo json_encode(array( 'errcode' => 0, 'errmsg' => '', 'item_id' => $item_id, 'color_id' => $color_id )); } public function downItem() { $account_id = $_REQUEST['account_id']; //登录校验 $login = loginVerify($account_id, $_REQUEST['session_id']); if (!$login) { phpcommon\sendError(ERR_USER_BASE + 1, 'session无效'); return; } $item_id = $_REQUEST['item_id']; $conn = $this->getMysql($account_id); if(!$conn){ phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); return; } $b = $this->getBag($item_id); $row = $conn->execQueryOne('SELECT status,active_time FROM bag WHERE accountid=:accountid AND id=:id;', array( ':accountid' => $account_id, ':id' => $item_id, )); if (!$row) { phpcommon\sendError(ERR_USER_BASE + 2, '没有这个道具'); return; } $status = 2; if ($row['active_time'] == 0) { $status = 1; } $exchange_ret = $conn->execScript('UPDATE bag SET status=:status, color_id=0, modify_time=:modify_time ' . ' WHERE accountid = :account_id AND id = :id;', array( ':account_id' => $account_id, ':id' => $item_id, ':status' => $status, ':modify_time' => time() )); if(!$exchange_ret){ die(); return; } echo json_encode(array( 'errcode' => 0, 'errmsg' => '', 'item_id' => $item_id, 'color_id' => 0 )); } public function downItemColor() { $account_id = $_REQUEST['account_id']; //登录校验 $login = loginVerify($account_id, $_REQUEST['session_id']); if (!$login) { phpcommon\sendError(ERR_USER_BASE + 1, 'session无效'); return; } $item_id = $_REQUEST['item_id']; $conn = $this->getMysql($account_id); if(!$conn){ phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); return; } $exchange_ret = $conn->execScript('UPDATE bag SET status=:status, color_id=0, modify_time=:modify_time ' . ' WHERE accountid = :account_id AND id = :id;', array( ':account_id' => $account_id, ':id' => $item_id, ':status' => $status, ':modify_time' => time() )); if(!$exchange_ret){ die(); return; } echo json_encode(array( 'errcode' => 0, 'errmsg' => '', 'item_id' => $item_id, 'color_id' => 0 )); } public function tryItem() { $account_id = $_REQUEST['account_id']; //登录校验 $login = loginVerify($account_id, $_REQUEST['session_id']); if (!$login) { phpcommon\sendError(ERR_USER_BASE + 1, 'session无效'); return; } $item_id = $_REQUEST['item_id']; error_log($item_id); $conn = $this->getMysql($account_id); if(!$conn){ phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); return; } $addreward = new classes\AddReward(); $addreward->addReward($item_id, 1, $account_id, 1); echo json_encode(array( 'errcode' => 0, 'errmsg' => '', 'item_id' => $item_id, 'color_id' => 0 )); } } ?>