$userId = null; if (isset($_GET['userId'])) { $userId = $_GET['userId']; } if (!UtilFunctions::checkUserSession($userId)) { $result->result = "401 : auth error"; header("HTTP/1.1 401 Unauthorized"); echo json_encode($result); exit(1); } if (!empty($userId)) { $user = GameUsers::getGameUserById($userId); if (!empty($user)) { $userId = $user->getUserId(); if (!empty($userId)) { $user->dailyBonus = BonusUtils::getUserDailyBonus($user->userId); $user->items = ItemUtils::getUserItems($user->userId); $result->success = true; $result->result = new stdClass(); $result->result->user = $user; unset($userId); unset($user); } else { $result->result = "User not found userId empty"; } } else { $result->result = "User not found"; } } else { $result->result = "User Id empty"; }
public static function getDailyBonusPrice($user) { if (!empty($user) && !empty($user->userId)) { $start = strtotime(date("Y-m-d") . " 00:00:00"); $end = strtotime(date("Y-m-d") . " 00:00:00 +1 day"); $SQL = "SELECT * FROM " . TBL_GAME_USER_COIN_LOG . " WHERE userId=" . DBUtils::mysql_escape($user->userId, 1) . " AND type='" . GameUserXpLog::$CONSTANT_LOG_TYPE_DAILYBONUS . "' AND time<" . $end . " AND time>" . $start; $coinLog = null; try { $coinLog = GameUserCoinLog::findBySql(DBUtils::getConnection(), $SQL); } catch (Exception $exc) { error_log($exc->getTraceAsString()); } if (empty($coinLog) || sizeof($coinLog) < 1) { $gain = 0; $order = 0; $bonuses = BonusUtils::getUserDailyBonus($user->userId); if (!empty($bonuses) && sizeof($bonuses) > 0) { for ($i = 0; $i < sizeof($bonuses); $i++) { $bonus = $bonuses[$i]; if (!empty($bonus) && !empty($bonus->coin)) { if ($gain < $bonus->coin && !empty($bonus->active)) { $gain = $bonus->coin; $order = $bonus->order; } } } } if ($gain > 0) { $time = time(); $user->setCoins($user->getCoins() + $gain); $user->updateToDatabase(DBUtils::getConnection()); $userCoinLog = new GameUserCoinLog(); $userCoinLog->setUserId($user->userId); $userCoinLog->setCoin($user->getCoins()); $userCoinLog->setDifCoin($gain); $userCoinLog->setTime($time); $userCoinLog->setType(GameUserXpLog::$CONSTANT_LOG_TYPE_DAILYBONUS); $userCoinLog->setAdd(1); $userCoinLog->setResult(GameUserXpLog::$CONSTANT_LOG_TYPE_DAILYBONUS . "->" . $order); $userCoinLog->setUserLevel($user->userLevelNumber); //$userCoinLog->setUserSpentCoin($user->opponentId); try { $userCoinLog->insertIntoDatabase(DBUtils::getConnection()); } catch (Exception $exc) { error_log($exc->getTraceAsString()); } Queue::addUserLeaderBoard($user->userId, $gain, $time); return true; } } } return false; }