public function action()
 {
     $teamLogoId = intval($this->parameters->teamLogoId);
     $teamTitle = trim($this->parameters->teamTitle);
     if (empty($teamLogoId) || empty($teamTitle)) {
         $actionResult = new ErrorPoint(ErrorPoint::CODE_SECURITY, "Не указан логотип или название команды", ErrorPoint::TYPE_USER);
         return $actionResult;
     }
     track_stats();
     // Отслеживаем производительность
     $this->teamProfile->setTeamName($teamTitle);
     $this->teamProfile->setTeamLogoId($teamLogoId);
     $actionResult = $this->teamProfile->save();
     if ($actionResult instanceof ErrorPoint) {
         SQL::getInstance()->rollback();
     } else {
         SQL::getInstance()->commit();
     }
     track_stats();
     // Отслеживаем производительность
     $api = new VKapi(VK_API_SECRET, VK_API_ID, VK_MAILING_SPEED);
     $actionResult = $api->setStatus(UserParameters::getUserId(), sprintf(VK_APPLICATION_STATUS, $this->teamProfile->getTeamName()));
     track_stats();
     // Отслеживаем производительность
     if ($actionResult instanceof ErrorPoint) {
         return $actionResult;
     }
     return $actionResult;
 }
 public static function resetPrizeStudyPoint($teamId)
 {
     $sql_template = "UPDATE teams SET\n  `prize_stady_point` = 0\nWHERE\n    vk_id = %d";
     $sql = sprintf($sql_template, $teamId);
     $SQLResult = SQL::getInstance()->query($sql);
     if ($SQLResult instanceof ErrorPoint) {
         return $SQLResult;
     }
     $team = RAM::getInstance()->getTeamById($teamId);
     if (!empty($team)) {
         RAM::getInstance()->changeTeamField($teamId, 'studyPointsViaPrize', 0);
     }
     $api = new VKapi(VK_API_SECRET, VK_API_ID, VK_MAILING_SPEED);
     $api->setCounter($teamId, 0);
 }
 public function action()
 {
     $friendId = intval($this->parameters->friendId);
     if (empty($friendId)) {
         $actionResult = new ErrorPoint(ErrorPoint::CODE_SECURITY, "Получен не правильный номер друга", ErrorPoint::TYPE_USER);
         return $actionResult;
     }
     track_stats();
     // Отслеживаем производительность
     $actionResult = TeamSatellite::isAvailableToPrize($friendId);
     if ($actionResult instanceof ErrorPoint) {
         return $actionResult;
     }
     if ($actionResult === false) {
         return new ErrorPoint(ErrorPoint::CODE_LOGIC, "Выбранному пользователю вы уже дарили подарок. Теперь только завтра", ErrorPoint::TYPE_USER);
     }
     track_stats();
     // Отслеживаем производительность
     SQL::getInstance()->autocommit(false);
     if ($actionResult instanceof ErrorPoint) {
         SQL::getInstance()->rollback();
         return $actionResult;
     }
     track_stats();
     // Отслеживаем производительность
     $actionResult = TeamSatellite::cratePrizeDateLabel($friendId);
     if ($actionResult instanceof ErrorPoint) {
         SQL::getInstance()->rollback();
         return $actionResult;
     }
     track_stats();
     // Отслеживаем производительность
     $actionResult = TeamSatellite::prizeStudyPoint($friendId);
     if ($actionResult instanceof ErrorPoint) {
         SQL::getInstance()->rollback();
         return $actionResult;
     }
     SQL::getInstance()->commit();
     track_stats();
     // Отслеживаем производительность
     $api = new VKapi(VK_API_SECRET, VK_API_ID, VK_MAILING_SPEED);
     $api->setCounter($friendId, TeamSatellite::getPrizeStudyPoint($friendId));
     return $actionResult;
 }
 public function action()
 {
     $withdraw = intval($this->parameters->value);
     $moneyType = intval($this->parameters->moneyType);
     $api = new VKapi(VK_API_SECRET, VK_API_ID, VK_MAILING_SPEED);
     $balanceResult = $api->getBalance(UserParameters::getUserId());
     if (isset($balanceResult["error"])) {
         if (isset($balanceResult["error"]["error_code"]) && $balanceResult["error"]["error_msg"]) {
             return new ErrorPoint(ErrorPoint::CODE_VK, "Ошибка социальной сети (" . $balanceResult["error"]["error_code"] . ":" . $balanceResult["error"]["error_msg"] . ")", ErrorPoint::TYPE_SYSTEM);
         } else {
             return new ErrorPoint(ErrorPoint::CODE_VK, "Ошибка социальной сети", ErrorPoint::TYPE_SYSTEM);
         }
     }
     $userBalance = $balanceResult["response"];
     if ($withdraw * 100 > $userBalance) {
         return new ErrorPoint(ErrorPoint::CODE_SECURITY, "На вашем балансе недостаточно средств", ErrorPoint::TYPE_USER);
     }
     track_stats();
     // Отслеживаем производительность
     $balanceResult = $api->withdrawVotes(UserParameters::getUserId(), $withdraw * 100);
     track_stats();
     // Отслеживаем производительность
     if ($balanceResult instanceof ErrorPoint) {
         return $balanceResult;
     }
     if (isset($balanceResult["error"])) {
         return new ErrorPoint(ErrorPoint::CODE_VK, "Ошибка социальной сети (" . $balanceResult["error"]["error_code"] . ":" . $balanceResult["error"]["error_msg"] . ")", ErrorPoint::TYPE_SYSTEM);
     }
     if ($moneyType == MONEY_TYPE_GAME) {
         $this->teamProfile->setMoney($withdraw * EXCHANGE_RATE_GAME + $this->teamProfile->getMoney());
     } else {
         $this->teamProfile->setRealMoney($withdraw * EXCHANGE_RATE_REAL + $this->teamProfile->getRealMoney());
     }
     $actionResult = $this->teamProfile->save();
     track_stats();
     // Отслеживаем производительность
     $this->result['balance']['money'] = $this->teamProfile->getMoney();
     $this->result['balance']['realMoney'] = $this->teamProfile->getRealMoney();
     Utils::logPayment($withdraw);
     track_stats();
     // Отслеживаем производительность
     return $actionResult;
 }
 private function install($teamParam)
 {
     $team = json_decode($teamParam);
     /*if(empty($team)){
           return new ErrorPoint(ErrorPoint::CODE_LOGIC, "Информация о команде получена неполностью, повторите попытку", ErrorPoint::TYPE_USER, $teamParam);  
       }*/
     track_stats();
     // Отслеживаем производительность
     $actionResult = $this->teamProfile->initById(UserParameters::getUserId());
     if ($actionResult instanceof ErrorPoint) {
         return $actionResult;
     }
     if ($actionResult === true) {
         return;
     }
     SQL::getInstance()->autocommit(false);
     $addOnStudyPoints = 0;
     $this->teamProfile->setTeamName(isset($team->teamName) ? $team->teamName : "Футболлер");
     $this->teamProfile->setTeamLogoId(isset($team->teamLogoId) ? $team->teamLogoId : "42326");
     $this->teamProfile->setUserPhoto($this->parameters->userPhoto);
     $this->teamProfile->setUserName($this->parameters->userName);
     $this->teamProfile->setUserYear(isset($this->parameters->userYear) ? intval($this->parameters->userYear) : 0);
     $this->teamProfile->setUserCountry(isset($this->parameters->userCountry) ? intval($this->parameters->userCountry) : 0);
     $this->teamProfile->setParameterForward(0);
     $this->teamProfile->setParameterHalf(0);
     $this->teamProfile->setParameterSafe(0);
     $this->teamProfile->setInGroup(0);
     $installResult = $this->teamProfile->install();
     track_stats();
     // Отслеживаем производительность
     if ($installResult instanceof ErrorPoint) {
         SQL::getInstance()->rollback();
         return $actionResult;
     }
     if ($addOnStudyPoints > GlobalParameters::MAX_TEAM) {
         SQL::getInstance()->rollback();
         return new ErrorPoint(ErrorPoint::CODE_LOGIC, "Друзей в команду набрано больше чем допустимо", ErrorPoint::TYPE_USER);
     }
     $needRandomFootballers = GlobalParameters::MAX_TEAM - $addOnStudyPoints;
     track_stats();
     // Отслеживаем производительность
     if ($needRandomFootballers) {
         $prototypes = FootballerSatellite::getRandomPrototypes($needRandomFootballers);
         if ($prototypes instanceof ErrorPoint) {
             SQL::getInstance()->rollback();
             return $prototypes;
         }
         foreach ($prototypes as $footballerPrototype) {
             $footballer = new Footballer();
             $actionResult = $footballer->add($footballerPrototype, $needRandomFootballers--);
             if ($actionResult instanceof ErrorPoint) {
                 SQL::getInstance()->rollback();
                 return $actionResult;
             }
             $this->teamProfile->addFootballerToStore($footballer);
         }
     }
     track_stats();
     // Отслеживаем производительность
     $this->teamProfile->updateTeamParameters();
     $addOnStudyPoints += 5;
     // Дадим ещё немного очков, для заманухи
     $this->teamProfile->setStudyPoints($addOnStudyPoints);
     $installResult = $this->teamProfile->save();
     track_stats();
     // Отслеживаем производительность
     if ($installResult instanceof ErrorPoint) {
         SQL::getInstance()->rollback();
         return $actionResult;
     } else {
         SQL::getInstance()->commit();
     }
     /*        $getResult = $this->teamProfile->initById(UserParameters::getUserId());
     
             if($getResult instanceof ErrorPoint){
                 SQL::getInstance()->rollback();
                 return $actionResult;
             }
     */
     track_stats();
     // Отслеживаем производительность
     $api = new VKapi(VK_API_SECRET, VK_API_ID, VK_MAILING_SPEED);
     $api->setStatus(UserParameters::getUserId(), sprintf(VK_APPLICATION_STATUS, $this->teamProfile->getTeamName()));
     track_stats();
     // Отслеживаем производительность
     return $installResult;
 }
    $actionResult = new ErrorPoint(ErrorPoint::CODE_SQL, "Соединение провалено (" . SQL::getInstance()->connect_error . ")", ErrorPoint::TYPE_SYSTEM);
    die("No connection");
}
// TODO: надо дописать установку дат
// И раздачу конечный коофициента акции
// пометить для учавствующих игроков что для них закончены соревнования
//////////////////// Обновляем всех в памяти //////////////////
$sql_template = "SELECT vk_id, user_name, tour_place_vk, tour_place_country, tour_place_city, tour_place_uni FROM teams\nWHERE ( tour_place_vk > 0 or tour_place_country > 0 or tour_place_city > 0 or tour_place_uni > 0 ) AND date_reg IS NOT NULL ;";
$sql = $sql_template;
$SQLresultSeelctTeam = SQL::getInstance()->query($sql);
if ($SQLresultSeelctTeam instanceof ErrorPoint) {
    return $SQLresultSeelctTeam;
}
echo "Upgrading for All users, count records: " . $SQLresultSeelctTeam->num_rows . " teams" . PHP_EOL;
if ($SQLresultSeelctTeam->num_rows) {
    $api = new VKapi(VK_API_SECRET, VK_API_ID, VK_MAILING_SPEED);
    while ($teamObject = $SQLresultSeelctTeam->fetch_object()) {
        $bonus = 1;
        $bonus *= GoldCointsGrid::getInstance()->getBonusByPlace(TOUR_TYPE_VK, $teamObject->tour_place_vk);
        $bonus *= GoldCointsGrid::getInstance()->getBonusByPlace(TOUR_TYPE_COUNTRY, $teamObject->tour_place_country);
        $bonus *= GoldCointsGrid::getInstance()->getBonusByPlace(TOUR_TYPE_CITY, $teamObject->tour_place_city);
        $bonus *= GoldCointsGrid::getInstance()->getBonusByPlace(TOUR_TYPE_UNI, $teamObject->tour_place_uni);
        if ($bonus > GlobalParameters::MAX_TOUR_BONUS) {
            $bonus = GlobalParameters::MAX_TOUR_BONUS;
        }
        $bonus = round($bonus, 2);
        $sql_template = "UPDATE teams set tour_bonus = %f, tour_bonus_time = 0 WHERE vk_id = %d;";
        $sql = sprintf($sql_template, $bonus, $teamObject->vk_id);
        $SQLResultTeamsFake = SQL::getInstance()->query($sql);
        $notify_message = $teamObject->user_name . ", ";
        if ($teamObject->tour_place_vk) {
$sql = sprintf($sql_template, NOTIFY_STATUS_NEW);
$SQLresult = SQL::getInstance()->query($sql);
if ($SQLresult instanceof ErrorPoint) {
    return $SQLresult;
}
if ($SQLresult->num_rows) {
    $usersCount = 0;
    while ($messageObject = $SQLresult->fetch_object()) {
        $send = true;
        $sql_template = 'UPDATE notify SET notify_status = %d WHERE notify_id = ' . $messageObject->notify_id . ';';
        $sql = sprintf($sql_template, NOTIFY_STATUS_STARTED);
        $SQLresultTemp = SQL::getInstance()->query($sql);
        if ($SQLresultTemp instanceof ErrorPoint) {
            break;
        }
        $api = new VKapi(VK_API_SECRET, VK_API_ID, VK_MAILING_SPEED);
        $sql_template = "SELECT vk_id from teams;";
        $sql = $sql_template;
        $SQLresultTeam = SQL::getInstance()->query($sql);
        if ($SQLresultTeam instanceof ErrorPoint) {
            break;
        }
        $notifyForUsers = array();
        $apiResult = NULL;
        /*
                $notifyForUsers = "100206819";
                $apiResult = $api->sendNotification($notifyForUsers, $messageObject->notify_message);
        
                Utils::forDebug($apiResult);
        */
        if ($SQLresultTeam->num_rows) {