$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; } protected function getTank($tank_id) { $tank_meta_table = require('../res/tank_economy@tank_economy.php'); $tank_meta = getTankConfig($tank_meta_table, $tank_id); $t = array( 'id' => $tank_meta['tank_id'], 'level' => $tank_meta['level'], 'coin_origin' => $tank_meta['coin_origin'], 'coin_times' => $tank_meta['coin_times'], 'coin_sell' => $tank_meta['coin_sell'], 'diamond' => $tank_meta['diamond'], 'coin_produce' => $tank_meta['coin_produce'], 'coin_lv' => $tank_meta['coin_lv'], 'diamond_lv' => $tank_meta['diamond_lv'], 'drop_level' => $tank_meta['drop_level'], 'drop_number' => $tank_meta['drop_number'], 'ad_level' => $tank_meta['ad_level'], 'buy_range1' => $tank_meta['buy_range1'], 'buy_times1' => $tank_meta['buy_times1'], 'free_lv1' => $tank_meta['free_lv1'], 'buy_range2' => $tank_meta['buy_range2'], 'buy_times2' => $tank_meta['buy_times2'], 'free_lv2' => $tank_meta['free_lv2'], ); return $t; } protected function getTankuuid($accountid) { $mysql_conf = getMysqlConfig(crc32($accountid)); $conn = $this->getMysql($accountid); $ret = $conn->execScript("INSERT INTO id_pool(createtime) VALUES(:createtime);", array( 'createtime' => time() )); if (!$ret) { die(); } $row = $conn->execQueryOne('SELECT LAST_INSERT_ID();', array()); if (empty($row)) { die(); } $orderid = $this->getIdPool($mysql_conf['instance_id'] , $row[0]); return $orderid; } protected function getIdPool($db_instance_id, $idx) { if ($db_instance_id >= 100 || $db_instance_id <= 0) { phpcommon\sendError(ERR_USER_BASE + 1, 'instance_id无效'); die(); } if ($idx >= 4294967295 || $idx <= 0) { phpcommon\sendError(ERR_USER_BASE + 1, 'idx无效'); die(); } $instance_id = sprintf('%02d', $db_instance_id); $id = sprintf('%010d',$idx); $tank_uuid = strftime('%y%m%d%H%M%S') . $instance_id . $id; return $tank_uuid; } public function airDropBoxReward() { $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 box_num, max_level FROM user WHERE accountid=:accountid;', array( ':accountid' => $account_id )); if (!$row) { phpcommon\sendError(ERR_USER_BASE + 2, '没有这个玩家'); return; } /*if ($row['box_num'] <= 0) { phpcommon\sendError(ERR_USER_BASE + 2, '今日开箱子次数已用完'); return; }*/ $airReward_uuid = 'game2003api_airReward_uuid:' . md5($_REQUEST['account_id']); $airReward_list = array(); $r = $this->getRedis($airReward_uuid); if (!$r) { die(); return; } $user_db_str = $r->get($airReward_uuid); $airReward_num = 0; $last_time = 0; if (empty($user_db_str)) { $airReward_list = $this->getRandomAirReward($row['max_level']); $airReward_db = array( 'airReward_uuid' => $airReward_uuid, 'airReward_list' => $airReward_list, ); $r -> set($airReward_uuid, json_encode($airReward_db)); $r -> pexpire($airReward_uuid, 1000 * 7200); } else { $user_db = json_decode($user_db_str, true); unset($user_db['airReward_list']); $airReward_list = $this->getRandomAirReward($row['max_level']); $airReward_db = array( 'airReward_uuid' => $airReward_uuid, 'airReward_list' => $airReward_list, ); $r -> set($airReward_uuid, json_encode($airReward_db)); $r -> pexpire($airReward_uuid, 1000 * 7200); } /*$ret = $conn->execScript('UPDATE user SET box_num=:box_num, modify_time=:modify_time ' . ' WHERE accountid=:accountid;', array( ':accountid' => $account_id, ':box_num' => $row['box_num'] - 1, ':modify_time' => time() )); if (!$ret) { die(); return; }*/ foreach ($airReward_list as $airReward) { //添加坦克 $this->insertTank($account_id, $airReward['item_id'], $airReward['item_num']); } echo json_encode(array( 'errcode' => 0, 'errmsg'=> '', 'item_list' => $airReward_list )); } public function airDoubleReward() { $account_id = $_REQUEST['account_id']; //登录校验 $login = loginVerify($account_id, $_REQUEST['session_id']); if (!$login) { phpcommon\sendError(ERR_USER_BASE + 1, 'session无效'); return; } $airReward_uuid = 'game2003api_airReward_uuid:' . md5($_REQUEST['account_id']); $airReward_list = array(); $r = $this->getRedis($airReward_uuid); if (!$r) { die(); return; } $user_db_str = $r->get($airReward_uuid); if (empty($user_db_str)) { phpcommon\sendError(ERR_USER_BASE + 2,'session失效'); return; } $user_db = json_decode($user_db_str, true); if (empty($user_db)) { phpcommon\sendError(ERR_USER_BASE + 3,'session失效'); return; } $p = $this->getParameter(AIRDROPREWARD_TIMES); $times = $p['value'] - 1; foreach ($user_db['airReward_list'] as $airReward) { //添加坦克 $this->insertTank($account_id, $airReward['item_id'], $airReward['item_num'] * $times); } $r->del($airReward_uuid, json_encode($user_db)); echo json_encode(array( 'errcode' => 0, 'errmsg'=> '', )); } protected function getRandomAirReward($max_level) { $airReward_list = array(); //随机奖励 $max_tank = $this->getTank(10000 + $max_level); array_push($airReward_list, array( 'item_id' => $max_tank['drop_level'], 'item_num' => $max_tank['drop_number'], )); return $airReward_list; } protected function insertTank($account_id, $level, $num) { $conn = $this->getMysql($account_id); for ($i = 0; $i < $num; $i++) { $curr_tank_uuid = $this->getTankuuid($account_id); $ret = $conn->execScript('INSERT INTO tank(accountid, tank_uuid, tank_level, create_time, modify_time) ' . ' VALUES(:account_id, :tank_uuid, :tank_level, :create_time, :modify_time)', array( ':account_id' => $account_id, ':tank_uuid' => $curr_tank_uuid, ':tank_level' => $level, ':create_time' => time(), ':modify_time' => time() )); if (!$ret) { die(); } } } } ?>