diff --git a/third_party/phpcommon b/third_party/phpcommon index 8453d4b..d00056a 160000 --- a/third_party/phpcommon +++ b/third_party/phpcommon @@ -1 +1 @@ -Subproject commit 8453d4b26e65ad7cee91d26b1a2ede39910c7117 +Subproject commit d00056a7ea77d281991ae4f826a1d13b5ddd990b diff --git a/webapp/controller/DropBoxController.class.php b/webapp/controller/DropBoxController.class.php deleted file mode 100644 index cddc9cb..0000000 --- a/webapp/controller/DropBoxController.class.php +++ /dev/null @@ -1,254 +0,0 @@ - $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(); - } - } - } -} -?> diff --git a/webapp/controller/HangController.class.php b/webapp/controller/HangController.class.php deleted file mode 100644 index 19408bd..0000000 --- a/webapp/controller/HangController.class.php +++ /dev/null @@ -1,152 +0,0 @@ - $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 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 getTime() - { - $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; - } - $num = 0; - $row = $conn->execQueryOne('SELECT * FROM hang WHERE accountid=:accountid;', - array( - ':accountid' => $account_id - )); - if (!$row) { - $ret = $conn->execScript('INSERT INTO hang(accountid, hang_time, create_time, modify_time) ' . - ' VALUES(:accountid, :hang_time, :create_time, :modify_time) ' . - ' ON DUPLICATE KEY UPDATE accountid=:accountid, hang_time=:hang_time, modify_time=:modify_time;', - array( - ':accountid' => $account_id, - ':hang_time' => time(), - ':create_time' => time(), - ':modify_time' => time() - )); - if (!$ret) { - die(); - return; - } - } else { - /*$p_num = $this->getParameter(GOLD); - $p_time_limit = $this->getParameter(TIME_LIMIT); - $num = floor((time() - $row['hang_time']) / 5 * $p_num['param_value']); - if ((time() - $row['hang_time']) >= $p_time_limit['param_value']) { - $num = floor($p_time_limit['param_value'] / 5 * $p_num['param_value']); - }*/ - } - - echo json_encode(array( - 'errcode' => 0, - 'errmsg' => '', - 'time' => time(), - 'num' => $num - )); - } - - public function getHangReward() - { - $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); - $item_id = 0; - $num = 0; - $weight = $_REQUEST['weight']; - if (!$conn) { - phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); - return; - } - $row = $conn->execQueryOne('SELECT * FROM hang WHERE accountid=:accountid;', - array( - ':accountid' => $account_id - )); - if ($row) { - $ret = $conn->execScript('UPDATE hang SET hang_time=:hang_time, modify_time=:modify_time ' . - ' WHERE accountid=:accountid;', - array( - ':accountid' => $account_id, - ':hang_time' => time(), - ':modify_time' => time() - )); - if (!$ret) { - die(); - return; - } - - $item_id = 10001; - $p_num = $this->getParameter(GOLD); - $p_time_limit = $this->getParameter(TIME_LIMIT); - $num = floor((time() - $row['hang_time']) / 5 * $p_num['param_value']); - if ((time() - $row['hang_time']) >= $p_time_limit['param_value']) { - $num = floor($p_time_limit['param_value'] / 5 * $p_num['param_value']); - } - if ($weight != 0) { - $p = $this->getParameter(REWARD_TIMES); - $times = $p['param_value'] - 1; - $num = $num * $times; - } - $row = $conn->execQueryOne('SELECT * FROM user WHERE accountid=:accountid;', - array( - ':accountid' => $account_id - )); - $ret = $conn->execScript('UPDATE user SET coin_num=:coin_num, modify_time=:modify_time ' . - ' WHERE accountid=:accountid;', - array( - ':accountid' => $account_id, - ':coin_num' => $num + $row['coin_num'], - ':modify_time' => time() - )); - if (!$ret) { - die(); - return; - } - } - echo json_encode(array( - 'errcode' => 0, - 'errmsg' => '', - 'item_id' => $item_id, - 'num' => $num, - 'time' => time() - )); - } - -} -?> diff --git a/webapp/controller/ShareController.class.php b/webapp/controller/ShareController.class.php index 6351b04..8d3f9cf 100644 --- a/webapp/controller/ShareController.class.php +++ b/webapp/controller/ShareController.class.php @@ -178,7 +178,6 @@ class ShareController{ return; } $this->updateCollectStatus($account_id); - //$item_list = $this->rewardList(COLLECT_REWARDS, $account_id); break; case 2: //浮窗 if ($row['pass_status'] >= 1) { @@ -186,7 +185,6 @@ class ShareController{ return; } $this->updateWindowStatus($account_id); - //$item_list = $this->rewardList(WINDOWS_REWARDS, $account_id); break; default: break; @@ -194,7 +192,6 @@ class ShareController{ echo json_encode(array( 'errcode' => 0, 'errmsg' => '', - 'item_list' => $item_list )); } @@ -345,7 +342,6 @@ class ShareController{ } } //获得奖励 - //$item_list = $this->rewardList(NEWGAME_REWARDS, $account_id); echo json_encode(array( 'errcode' => 0, 'errmsg' => '', diff --git a/webapp/controller/SignController.class.php b/webapp/controller/SignController.class.php index c5b6907..5b88185 100644 --- a/webapp/controller/SignController.class.php +++ b/webapp/controller/SignController.class.php @@ -116,7 +116,6 @@ class SignController{ if ($nowTime - phpcommon\getdayseconds($last_sign_time) > 0) { //每日刷新 $this->updateDaily($account_id); - //$this->updateSeasonStatus($account_id); $passed_days = floor(($nowTime - phpcommon\getdayseconds($last_sign_time)) / (3600 * 24)); if ($passed_days > 7 - $last_sign_id) { //跨周时删除老数据 @@ -276,8 +275,6 @@ class SignController{ 'item_id' => $s['item_id'], 'item_num' => $s['num'], )); - //$addreward = new classes\AddReward(); - //$addreward->addReward($item_id, $num, $account_id); echo json_encode(array( 'errcode' => 0, 'errmsg' => '', @@ -320,8 +317,6 @@ class SignController{ $p = $this->getParameter(SIGNREWARD_TIMES); $times = $p['param_value'] - 1; $num = $num * $times; - //$addreward = new classes\AddReward(); - //$addreward->addReward($item_id, $num, $account_id); echo json_encode(array( 'errcode' => 0, 'errmsg' => '', diff --git a/webapp/controller/TankController.class.php b/webapp/controller/TankController.class.php index cff965b..b070f6b 100644 --- a/webapp/controller/TankController.class.php +++ b/webapp/controller/TankController.class.php @@ -162,609 +162,5 @@ class TankController{ 'errmsg' => '', )); } - /* 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 tankInfo() - { - $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; - } - //购买次数信息 - $buy_list = array(); - $row_times = $conn->execQueryOne('SELECT times FROM buy_times ' . - ' WHERE accountid=:accountid AND level=:level;', - array( - ':accountid' => $account_id, - ':level' => $level, - )); - if ($row_times) { - foreach ($row_times as $row_times) { - array_push($buy_list, array( - 'level' => $row_times['level'], - 'times' => $row_times['times'], - )); - } - } - //坦克列表 - $tank_list = array(); - //$curr_tank_uuid = ''; - $rows_tank = $conn->execQuery('SELECT tankInfo FROM tankInfo WHERE accountid=:account_id;', - array( - ':account_id' => $account_id, - )); - //新玩家默认赠送一级坦克 - if ($rows_tank) { - foreach ($rows_tank as $row_tank) { - if ($row_tank['tank_level'] == 0) { - continue; - } - array_push($tank_list, array( - 'tank_uuid' => $row_tank['tank_uuid'], - 'level' => $row_tank['tank_level'], - )); - } - } else { - $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, 1, :create_time, :modify_time)', - array( - ':account_id' => $account_id, - ':tank_uuid' => $curr_tank_uuid, - ':create_time' => time(), - ':modify_time' => time() - )); - if (!$ret) { - die(); - return; - } - //更新默认上阵坦克信息 - $ret = $conn->execScript('UPDATE user SET curr_tank_uuid=:tank_uuid, modify_time=:modify_time ' . - ' WHERE accountid=:account_id;', - array( - ':account_id' => $account_id, - ':tank_uuid' => $curr_tank_uuid, - ':modify_time' => time() - )); - if (!$ret) { - die(); - return; - } - array_push($tank_list, array( - 'tankInfo' => $row_tank['tankInfo'], - )); - } - $row = $conn->execQueryOne('SELECT coin_num FROM user WHERE accountid=:account_id;', - array( - ':account_id' => $account_id, - )); - if (!$row) { - phpcommon\sendError(ERR_USER_BASE + 1,'没有这个玩家'); - return; - } - $coin_num = $row['coin_num']; - echo json_encode(array( - 'errcode' => 0, - 'errmsg' => '', - 'buy_list' => $buy_list, - 'coin_num' => $coin_num, - 'tank_list' => $tank_list - )); - - } - - public function tankCompose() - { - $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; - } - $new_uuid = $_REQUEST['newtank_uuid']; - $del_uuid = $_REQUEST['deltank_uuid']; - //判断是否存在足够多的坦克 - $row_new = $this->selectTank($account_id, $new_uuid); - $row_del = $this->selectTank($account_id, $del_uuid); - //坦克合成 - $compose_level = $row_new['tank_level'] + 1; - $this->updateTankLevel($account_id, $new_uuid, $compose_level); - $this->updateTankLevel($account_id, $del_uuid, 0); - $compose_status = 0; - //判断是否合成新坦克 - $row = $conn->execQueryOne('SELECT max_level FROM user WHERE accountid=:accountid;', - array( - ':accountid' => $account_id, - )); - if ($compose_level > $row['max_level']) { - $compose_status = 1; - //更新新坦克上阵,更新坦克最大等级 - $ret = $conn->execScript('UPDATE user SET max_level=:level, curr_tank_uuid=:curr_tank_uuid, modify_time=:modify_time ' . - ' WHERE accountid=:account_id;', - array( - ':account_id' => $account_id, - ':level' => $compose_level, - ':curr_tank_uuid' => $new_uuid, - ':modify_time' => time() - )); - if (!$ret) { - die(); - return; - } - } - echo json_encode(array( - 'errcode' => 0, - 'errmsg' => '', - 'status' => $compose_status, - 'level' => $compose_level - )); - - } - - protected function selectTank($account_id, $tank_uuid) - { - $conn = $this->getMysql($account_id); - $row = $conn->execQueryOne('SELECT tank_uuid, tank_level FROM tank ' . - ' WHERE accountid=:account_id AND tank_uuid=:tank_uuid;', - array( - ':account_id' => $account_id, - ':tank_uuid' => $tank_uuid - )); - if (!$row) { - phpcommon\sendError(ERR_USER_BASE + 2,'坦克不存在'); - die(); - } - return $row; - } - - protected function updateTankLevel($account_id, $tank_uuid, $level) - { - $conn = $this->getMysql($account_id); - $ret = $conn->execScript('UPDATE tank SET tank_level=:level, modify_time=:modify_time ' . - ' WHERE accountid=:account_id AND tank_uuid=:tank_uuid;', - array( - ':account_id' => $account_id, - ':tank_uuid' => $tank_uuid, - ':level' => $level, - ':modify_time' => time() - )); - if (!$ret) { - die(); - } - } - */ - public function buyTank() - { - $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; - } - $level = $_REQUEST['level']; - $row = $conn->execQueryOne('SELECT coin_num, diamond_num FROM user WHERE accountid=:accountid;', - array( - ':accountid' => $account_id, - )); - if (!$row) { - phpcommon\sendError(ERR_USER_BASE + 1,'没有这个玩家'); - return; - } - //$max_tank = $this->getTank(10000 + $row['max_level']); - $t = $this->getTank(10000 + $level); - $num = 0; - $times = 0; - //$row_times = $conn->execQueryOne('SELECT times FROM buy_times ' . - // ' WHERE accountid=:accountid AND level=:level;', - // array( - // ':accountid' => $account_id, - // ':level' => $level, - // )); - //$this->buyLevelLimit($level, $max_tank['diamond_lv']); - if ($row['diamond_num'] < $t['diamond']) { - phpcommon\sendError(ERR_USER_BASE + 3,'钻石不足'); - return; - } - $cur_num = $row['diamond_num'] - $t['diamond']; - $this->updateBuyInfo($account_id, $cur_num, 0, 0); - /*switch ($_REQUEST['type']) - { - case 0: - //金币购买 - $this->buyLevelLimit($level, $max_tank['coin_lv']); - if (!$row_times) { - $times = 1; - $this->insertBuyInfo($account_id, $level); - } else { - $times = $row_times['times'] + 1; - } - $num = $this->test($t['coin_origin'], $times, $t['coin_times'] * 1000); - if ($row['coin_num'] < $num) { - phpcommon\sendError(ERR_USER_BASE + 3,'金币不足'); - return; - } - $cur_num = phpcommon\bnSub_s($row['coin_num'], $num); - $this->updateBuyInfo($account_id, $cur_num, $level, $times); - break; - case 1: - //钻石购买 - $this->buyLevelLimit($level, $max_tank['diamond_lv']); - if ($row['diamond_num'] < $t['diamond']) { - phpcommon\sendError(ERR_USER_BASE + 3,'钻石不足'); - return; - } - $cur_num = $row['diamond_num'] - $t['diamond']; - $this->updateBuyInfo($account_id, $cur_num, 0, 0); - break; - case 2: - //金币加视频购买 - $this->buyLevelLimit($level, $max_tank['buy_range2']); - if (!$row_times) { - $times = 1; - $this->insertBuyInfo($account_id, $level); - } else { - $times = $row_times['times'] + 1; - } - $num = $this->test($t['coin_origin'], $times, $t['coin_times'] * 1000); - if ($row['coin_num'] < $num) { - phpcommon\sendError(ERR_USER_BASE + 3,'金币不足'); - return; - } - $cur_num = phpcommon\bnSub_s($row['coin_num'], $num); - $this->updateBuyInfo($account_id, $cur_num, $level, $times); - $level = $level + 1; - break; - default: - break; - - } - //插入到坦克列表中 - $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(); - return; - }*/ - echo json_encode(array( - 'errcode' => 0, - 'errmsg' => '', - 'diamond_num' => $cur_num - )); - } - - protected function buyLevelLimit($level, $t_level) - { - if ($level > $t_level) { - phpcommon\sendError(ERR_USER_BASE + 2, '购买等级大于当前等级'); - die(); - } - } - - /* protected function insertBuyInfo($account_id, $level) - { - $conn = $this->getMysql($account_id); - $ret = $conn->execScript('INSERT INTO buy_times(accountid, level, times, create_time, modify_time) ' . - ' VALUES(:account_id, :level, 0, :create_time, :modify_time)', - array( - ':account_id' => $account_id, - ':level' => $level, - ':create_time' => time(), - ':modify_time' => time() - )); - if (!$ret) { - die(); - } - } - */ - protected function updateBuyInfo($account_id, $num, $level, $times) - { - $conn = $this->getMysql($account_id); - if ($times != 0) { - $ret = $conn->execScript('UPDATE user SET coin_num=:num, modify_time=:modify_time ' . - ' WHERE accountid=:account_id;', - array( - ':account_id' => $account_id, - ':num' => $num, - ':modify_time' => time() - )); - if (!$ret) { - die(); - } - $ret = $conn->execScript('UPDATE buy_times SET times=:times, modify_time=:modify_time ' . - ' WHERE accountid=:account_id AND level=:level;', - array( - ':account_id' => $account_id, - ':times' => $times, - ':level' => $level, - ':modify_time' => time() - )); - if (!$ret) { - die(); - } - } else { - $ret = $conn->execScript('UPDATE user SET diamond_num=:num, modify_time=:modify_time ' . - ' WHERE accountid=:account_id;', - array( - ':account_id' => $account_id, - ':num' => $num, - ':modify_time' => time() - )); - if (!$ret) { - die(); - } - } - } - /* - public function tankListInfo() - { - $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; - } - $tank_list = $_REQUEST['tank_list']; - $ret = $conn->execScript('UPDATE user SET tank_slot_list=:tank_slot_list, modify_time=:modify_time ' . - ' WHERE accountid=:account_id;', - array( - ':account_id' => $account_id, - ':tank_slot_list' => $tank_list, - ':modify_time' => time() - )); - if (!$ret) { - die(); - return; - } - echo json_encode(array( - 'errcode' => 0, - 'errmsg' => '', - )); - } - - public function currentTank() - { - $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; - } - $tank_uuid = $_REQUEST['tank_uuid']; - $ret = $conn->execScript('UPDATE user SET curr_tank_uuid=:curr_tank_uuid, modify_time=:modify_time ' . - ' WHERE accountid=:account_id;', - array( - ':account_id' => $account_id, - ':curr_tank_uuid' => $tank_uuid, - ':modify_time' => time() - )); - if (!$ret) { - die(); - return; - } - echo json_encode(array( - 'errcode' => 0, - 'errmsg' => '', - )); - } - - public function tankRecover() - { - $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; - } - $tank_uuid = $_REQUEST['tank_uuid']; - $row = $conn->execQueryOne('SELECT coin_num FROM user WHERE accountid=:accountid;', - array( - ':accountid' => $account_id, - )); - if (!$row) { - phpcommon\sendError(ERR_USER_BASE + 1,'没有这个玩家'); - return; - } - //删除坦克 - $row_tank = $this->selectTank($account_id, $tank_uuid); - $this->updateTankLevel($account_id, $tank_uuid, 0); - //增加金钱 - $t = $this->getTank(10000 + $row_tank['tank_level']); - $num = phpcommon\bnAdd_s($row['coin_num'], $t['coin_sell']); - $ret = $conn->execScript('UPDATE user SET coin_num=:num, modify_time=:modify_time ' . - ' WHERE accountid=:account_id;', - array( - ':account_id' => $account_id, - ':num' => $num, - ':modify_time' => time() - )); - if (!$ret) { - die(); - return; - } - echo json_encode(array( - 'errcode' => 0, - 'errmsg' => '', - )); - } - - public function sumComposeTank() - { - $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; - } - $rows = $conn->execQuery('SELECT tank_uuid, tank_level FROM tank WHERE accountid=:accountid;', - array( - ':accountid' => $account_id, - )); - if (!$rows) { - phpcommon\sendError(ERR_USER_BASE + 2,'没有这个坦克'); - return; - } - $tank_array = array(); - foreach ($rows as $row) { - $key = $row['tank_level']; - if (!array_key_exists($key, $tank_array)) { - $tank_array[$key] = array(); - } - array_push($tank_array[$key], array( - 'tank_uuid' => $row['tank_uuid'], - )); - } - $level = 1; - $max_level = 1; - $curr_tank_uuid = ''; - $row_user = $conn->execQueryOne('SELECT max_level FROM user WHERE accountid=:accountid;', - array( - ':accountid' => $account_id, - )); - if (!$row_user) { - phpcommon\sendError(ERR_USER_BASE + 1,'没有这个玩家'); - return; - } - //一键合成 - for (; $level <= $row_user['max_level']; $level++) { - if (!array_key_exists($level, $tank_array) || count($tank_array[$level]) < 2) { - continue; - } - $tank = $tank_array[$level]; - $len = count($tank_array[$level]); - $new_num = floor($len / 2); - for ($i = 0; $i < $len; $i = $i + 2) { - $this->updateTankLevel($account_id, $tank[$i]['tank_uuid'], $level + 1); - $this->updateTankLevel($account_id, $tank[$i + 1]['tank_uuid'], 0); - } - $max_level = $level + 1; - $curr_tank_uuid = $tank[0]['tank_uuid']; - } - $compose_status = 0; - if ($max_level > $row_user['max_level']) { - $compose_status = 1; - //更新新坦克上阵,更新坦克最大等级 - $ret = $conn->execScript('UPDATE user SET max_level=:level, curr_tank_uuid=:curr_tank_uuid, modify_time=:modify_time ' . - ' WHERE accountid=:account_id;', - array( - ':account_id' => $account_id, - ':level' => $max_level, - ':curr_tank_uuid' => $curr_tank_uuid, - ':modify_time' => time() - )); - if (!$ret) { - die(); - return; - } - } - echo json_encode(array( - 'errcode' => 0, - 'errmsg' => '', - 'status' => $compose_status, - )); - } - - public function test1() - { - $this->test(310, 1, 1175); - } - public function test($base_value, $times, $multiple) - { - $v = (int)$multiple; - $value = gmp_init($base_value); - $cfg_value = gmp_init($v); - $fada_exp = gmp_init('1000'); - $exp = gmp_pow($cfg_value, $times); - $exp2 = gmp_pow($fada_exp, $times); - $result = gmp_mul($value, $exp); - $real_result = gmp_div($result, $exp2); - return gmp_strval($real_result); - }*/ } ?>