diff --git a/webapp/controller/RoleController.class.php b/webapp/controller/RoleController.class.php index add504b..2231637 100644 --- a/webapp/controller/RoleController.class.php +++ b/webapp/controller/RoleController.class.php @@ -18,6 +18,18 @@ class RoleController{ return $conn; } + protected function getRedis($account_id) + { + $redis_conf = getRedisConfig(crc32($account_id)); + $r = new phpcommon\Redis(array( + 'host' => $redis_conf['host'], + 'port' => $redis_conf['port'], + 'passwd' => $redis_conf['passwd'] + + )); + return $r; + } + protected function getActivityRewardConfig($activityReward_id) { $g_conf_activityReward_cluster = require('../res/activityReward@activityReward.php'); @@ -80,12 +92,14 @@ class RoleController{ $account_id = $_REQUEST['account_id']; $user_name = $_REQUEST['name']; $avatar_url = $_REQUEST['avatar_url']; + $switch_id = $_REQUEST['switch_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, '没有这个玩家'); @@ -95,6 +109,9 @@ class RoleController{ phpcommon\sendError(ERR_USER_BASE + 1, 'session无效'); return; } + + $this->updateSwitch($account_id, $switch_id); + $row = $conn->execQueryOne('SELECT * FROM user WHERE accountid=:accountid;', array( ':accountid' => $account_id @@ -169,7 +186,19 @@ class RoleController{ ':modify_time' => time() )); } - $daily_first_login = $this->updateDaily($account_id, $row['daily_first_login'], $row['daily_time']); + $nowTime = phpcommon\getdayseconds(time()); + if ($row['daily_time'] == 0 || ($nowTime - phpcommon\getdayseconds($row['daily_time']) > 0)) { + $ret = $conn->execScript('UPDATE user SET daily_first_login=0, ' . + 'modify_time=:modify_time WHERE accountid=:accountid;', + array( + ':accountid' => $account_id, + ':modify_time' => time(), + )); + if (!$ret) { + die(); + return; + } + } echo json_encode(array( 'errcode' => 0, 'errmsg' => '', @@ -194,12 +223,12 @@ class RoleController{ 'sum_coin' => $row['sum_coin'], 'recharge_times_total' => $row['recharge_times_total'], 'first_login' => 1, - 'daily_first_login' => $daily_first_login + 'daily_first_login' => $row['daily_first_login'] )); } } - protected function updateDaily($account_id, $daily_first_login, $daily_time) + protected function updateDaily($account_id, $daily_time) { $nowTime = phpcommon\getdayseconds(time()); $conn = $this->getMysql($account_id); @@ -335,7 +364,12 @@ class RoleController{ if ($daily_time == 0 || ($nowTime - phpcommon\getdayseconds($daily_time) > 0)) { $daily_time = time(); } - $ret = $conn->execScript('UPDATE user SET game_times=:game_times, kills=:kills, harm=:harm, add_HP=:add_HP, alive_time=:alive_time, kill_his=:kill_his, alive_time_his=:alive_time_his, harm_his=:harm_his, add_HP_his=:add_HP_his, coin_num=:coin_num, modify_time=:modify_time, first_fight=1, box_num=:box_num, score=:score, daily_time=:daily_time ' . + $daily_first_login = $row['daily_first_login']; + $switch = $this->getSwitch($account_id); + if ($switch == 1) { + $daily_first_login = $daily_first_login + 1; + } + $ret = $conn->execScript('UPDATE user SET game_times=:game_times, kills=:kills, harm=:harm, add_HP=:add_HP, alive_time=:alive_time, kill_his=:kill_his, alive_time_his=:alive_time_his, harm_his=:harm_his, add_HP_his=:add_HP_his, coin_num=:coin_num, modify_time=:modify_time, first_fight=1, box_num=:box_num, score=:score, daily_time=:daily_time, daily_first_login=:daily_first_login ' . 'WHERE accountid=:accountid;', array( ':game_times' => $row['game_times'] + 1, @@ -352,7 +386,8 @@ class RoleController{ ':modify_time' => time(), ':box_num' => $box_num, ':score' => $row['score'] + $score, - ':daily_time' => $daily_time + ':daily_time' => $daily_time, + ':daily_first_login' => $daily_first_login )); if (!$ret) { die(); @@ -805,5 +840,31 @@ class RoleController{ 'num' => $coin, )); } + + protected function updateSwitch($account_id, $switch_id) + { + $r = $this->getRedis($account_id); + if (!$r) { + die(); + return; + } + $switch_uuid = 'game2001api_switch:' . $account_id; + $r -> set($switch_uuid, $switch_id); + $r -> pexpire($switch_uuid, 1000 * 3600 * 24); + + } + + protected function getSwitch($account_id) + { + $r = $this->getRedis($account_id); + if (!$r) { + die(); + return; + } + $switch_uuid = 'game2001api_switch:' . $account_id; + $user_db_str = $r->get($switch_uuid); + $switch = json_decode($user_db_str, true); + return $switch; + } } ?>