diff --git a/sql/gamedb.sql b/sql/gamedb.sql index 4f2f0f4..d669279 100644 --- a/sql/gamedb.sql +++ b/sql/gamedb.sql @@ -61,6 +61,7 @@ CREATE TABLE `user` ( `life_times` int(11) NOT NULL DEFAULT '0' COMMENT '复活次数', `new_info` mediumblob NOT NULL COMMENT '新手信息', `daily_buy_times` int(11) NOT NULL DEFAULT '0' COMMENT '每日购买次数', + `daily_time` int(11) NOT NULL DEFAULT '0' COMMENT '每日刷新时间', PRIMARY KEY (`idx`), UNIQUE KEY `accountid` (`accountid`) ) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; diff --git a/webapp/controller/RoleController.class.php b/webapp/controller/RoleController.class.php index 4c2ceb2..f7cfcc7 100644 --- a/webapp/controller/RoleController.class.php +++ b/webapp/controller/RoleController.class.php @@ -22,9 +22,9 @@ class RoleController{ $avatar_url = $_REQUEST['avatar_url']; //登录校验() $login = loginVerify($account_id, $_REQUEST['session_id']); - if (!$login) { - phpcommon\sendError(ERR_USER_BASE + 1, 'session无效'); - return; + if (!$login) { + phpcommon\sendError(ERR_USER_BASE + 1, 'session无效'); + return; } $conn = $this->getMysql($account_id); if (!$conn) { @@ -40,8 +40,8 @@ class RoleController{ ':accountid' => $account_id )); if (!$row) { - $ret = $conn->execScript('INSERT INTO user(accountid, user_name, avatar_url, coin_num, create_time, modify_time, collect_status, kefu_status, sign_sum, diamond_num, pass_status, pass, energy, buy_data, tank_data, cumul_coin, off_time, battlecount, invite_status, life_times, new_info, daily_buy_times) ' . - ' VALUES(:accountid, :user_name, :avatar_url, 100, :create_time, :modify_time, 0, 0, 0, 0, 0, 0, 0, :buy_data, :tank_data, 0, :off_time, 0, 0, 0, :new_info, 0)', + $ret = $conn->execScript('INSERT INTO user(accountid, user_name, avatar_url, coin_num, create_time, modify_time, collect_status, kefu_status, sign_sum, diamond_num, pass_status, pass, energy, buy_data, tank_data, cumul_coin, off_time, battlecount, invite_status, life_times, new_info, daily_buy_times, daily_time) ' . + ' VALUES(:accountid, :user_name, :avatar_url, 100, :create_time, :modify_time, 0, 0, 0, 0, 0, 0, 0, :buy_data, :tank_data, 0, :off_time, 0, 0, 0, :new_info, 0, 0)', array( ':accountid' => $account_id, ':user_name' => $user_name, @@ -77,6 +77,25 @@ class RoleController{ 'daily_buy_times' => 0, )); } else { + if ($user_name != $row['user_name']) { + $ret = $conn->execScript('UPDATE user SET user_name=:user_name, modify_time=:modify_time ' . + ' WHERE accountid=:accountid;', + array( + ':accountid' => $account_id, + ':user_name' => $user_name, + ':modify_time' => time() + )); + } + if ($avatar_url != $row['avatar_url']) { + $ret = $conn->execScript('UPDATE user SET avatar_url=:avatar_url, modify_time=:modify_time ' . + ' WHERE accountid=:accountid;', + array( + ':accountid' => $account_id, + ':avatar_url' => $avatar_url, + ':modify_time' => time() + )); + } + $this->updateDaily($account_id, $row['daily_time']); echo json_encode(array( 'errcode' => 0, 'errmsg' => '', @@ -164,5 +183,50 @@ class RoleController{ 'diamond_num' => $row['diamond_num'], )); } + + protected function updateDaily($account_id, $daily_time) + { + $conn = $this->getMysql($account_id); + $nowTime = phpcommon\getdayseconds(time()); + if ($nowTime - phpcommon\getdayseconds($daily_time) > 0) { + //更新每日奖励次数 + $ret = $conn->execScript('UPDATE daily_reward SET free_coin_time=0, free_jewel_time=0, free_power_time=0, ' . + ' modify_time=:modify_time WHERE accountid=:accountid;', + array( + ':accountid' => $account_id, + ':modify_time' => time() + )); + if (!$ret) { + die(); + } + //更新每日任务 + $ret = $conn->execScript('DELETE FROM quest WHERE accountid=:accountid;', + array( + ':accountid' => $account_id, + )); + if (!$ret) { + die(); + } + //更新试玩次数 + $ret = $conn->execScript('DELETE FROM try_play WHERE accountid=:accountid;', + array( + ':accountid' => $account_id, + )); + if (!$ret) { + die(); + } + //更新人物信息 + $ret = $conn->execScript('UPDATE user SET invite_status=0, life_times=0, daily_buy_times=0, ' . + ' modify_time=:modify_time, daily_time=:daily_time WHERE accountid=:accountid;', + array( + ':accountid' => $account_id, + ':modify_time' => time(), + ':daily_time' => time() + )); + if (!$ret) { + die(); + } + } + } } ?> diff --git a/webapp/controller/SignController.class.php b/webapp/controller/SignController.class.php index 2938160..b0d447f 100644 --- a/webapp/controller/SignController.class.php +++ b/webapp/controller/SignController.class.php @@ -115,7 +115,6 @@ class SignController{ if ($nowTime - phpcommon\getdayseconds($last_sign_time) > 0) { //每日刷新 - $this->updateDaily($account_id); $passed_days = floor(($nowTime - phpcommon\getdayseconds($last_sign_time)) / (3600 * 24)); if ($passed_days > 7 - $last_sign_id) { //跨周时删除老数据 @@ -322,45 +321,5 @@ class SignController{ )); } - protected function updateDaily($account_id) - { - $conn = $this->getMysql($account_id); - //更新每日奖励次数 - $ret = $conn->execScript('UPDATE daily_reward SET free_coin_time=0, free_jewel_time=0, free_power_time=0, ' . - ' modify_time=:modify_time WHERE accountid=:accountid;', - array( - ':accountid' => $account_id, - ':modify_time' => time() - )); - if (!$ret) { - die(); - } - //更新每日任务 - $ret = $conn->execScript('DELETE FROM quest WHERE accountid=:accountid;', - array( - ':accountid' => $account_id, - )); - if (!$ret) { - die(); - } - //更新试玩次数 - $ret = $conn->execScript('DELETE FROM try_play WHERE accountid=:accountid;', - array( - ':accountid' => $account_id, - )); - if (!$ret) { - die(); - } - //更新分享好友信息 - $ret = $conn->execScript('UPDATE user SET invite_status=0, life_times=0, daily_buy_times=0, ' . - ' modify_time=:modify_time WHERE accountid=:accountid;', - array( - ':accountid' => $account_id, - ':modify_time' => time() - )); - if (!$ret) { - die(); - } - } } ?>