}
        $notify_message .= " Примите наши поздравления и скидку чемпиона в размере " . ($bonus * 100 - 100) . "% на всех футболистов и тренеров";
        $notifyForUsers = array();
        $apiResult = NULL;
        $apiResult = $api->sendNotification($teamObject->vk_id, $notify_message);
        usleep(VK_MAILING_SPEED);
        /*      $teamId = $teamObject->vk_id; echo $teamId . "\n";
                $team = RAM::getInstance()->getTeamById($teamId);
                if(!empty($team)){
                    RAM::getInstance()->changeTeamField($teamId, 'tourBonus', $bonus);
                    RAM::getInstance()->changeTeamField($teamId, 'tourBonusTime', 0);
                }*/
    }
}
//////////////////// Это подготовка к новому //////////////////
TourSatellite::setTimerDate(time(), time() + 5 * 24 * 60 * 60, TOUR_NOTIFY_NEW);
$sql_template = "UPDATE teams SET tour_notify = " . TOUR_NOTIFY_NEW . ", tour_III = 0;";
// tour_III = 0
$SQLResultTeams = SQL::getInstance()->query($sql_template);
/*
//////////////////// Обновляем всех в памяти //////////////////

$sql_template = "SELECT vk_id FROM teams ;";
$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 ;
 public function action()
 {
     $this->result["isInstalled"] = $this->teamProfile->getIsInstalled();
     track_stats();
     // ќтслеживаем производительность
     $startAt = RAM::getInstance()->getTourStart();
     $finishAt = RAM::getInstance()->getTourFinish();
     track_stats();
     // ќтслеживаем производительность
     if (empty($startAt) || empty($finishAt)) {
         $tourTimer = TourSatellite::getTimerDate();
         $startAt = $tourTimer->startAt;
         $finishAt = $tourTimer->finishAt;
         RAM::getInstance()->setTourStart($startAt);
         RAM::getInstance()->setTourFinish($finishAt);
     }
     track_stats();
     // ќтслеживаем производительность
     $this->result["tourStartAt"] = $startAt;
     $this->result["tourFinishedAt"] = $finishAt;
     $this->result["serverTime"] = time();
     if ($this->teamProfile->getIsInstalled()) {
         track_stats();
         // ќтслеживаем производительность
         $energyTimer = RAM::getInstance()->getEnergyLastUpdate();
         if (empty($energyTimer)) {
             $energyTimer = filemtime(SYSTEM_LOGS . "/cron.updateEnergy.log");
             // microtime
             RAM::getInstance()->setEnergyLastUpdate($energyTimer);
         }
         $this->result['energyTimer'] = $energyTimer;
         track_stats();
         // ќтслеживаем производительность
         if ($this->teamProfile->isNeedDailyBonus()) {
             $dailyBonus = $this->teamProfile->getTotalStadiumBonus();
             $this->teamProfile->setMoney($this->teamProfile->getMoney() + $dailyBonus);
             $actionResult = TeamSatellite::accrueDailyBonus(UserParameters::getUserId(), $this->teamProfile->getMoney());
             if ($actionResult instanceof ErrorPoint) {
                 return $actionResult;
             }
         }
         track_stats();
         // ќтслеживаем производительность
         if ($this->teamProfile->isNewTour() && $this->teamProfile->getTourBonus() != 0 && $this->teamProfile->getTourBonusTime() == 0) {
             $finishBonusAt = time() + 1 * 24 * 60 * 60;
             $actionResult = TeamSatellite::startTourBonus(UserParameters::getUserId(), $finishBonusAt);
             if ($actionResult instanceof ErrorPoint) {
                 return $actionResult;
             }
             $this->teamProfile->setTourBonusTime($finishBonusAt);
         }
         track_stats();
         // ќтслеживаем производительность
         $this->result["teamInfo"] = JSONPrepare::team($this->teamProfile);
         track_stats();
         // ќтслеживаем производительность
         // Ёто надо обновить после отдачи профайла
         if ($this->teamProfile->getTourNotify() == TOUR_NOTIFY_START || $this->teamProfile->getTourNotify() == TOUR_NOTIFY_NEW) {
             $actionResult = TeamSatellite::updateTourNotify(UserParameters::getUserId(), $this->teamProfile->getTourNotify() - 2);
             if ($actionResult instanceof ErrorPoint) {
                 return $actionResult;
             }
         }
         track_stats();
         // ќтслеживаем производительность
         if ($this->teamProfile->isNewTour() && $this->teamProfile->getTourBonus() != 0 && $this->teamProfile->getTourBonusTime() > 0 && $this->teamProfile->getTourBonusTime() < time()) {
             $actionResult = TeamSatellite::eraseTourBonus(UserParameters::getUserId());
             if ($actionResult instanceof ErrorPoint) {
                 return $actionResult;
             }
             $this->teamProfile->setTourBonus(0);
             $this->teamProfile->setTourBonusTime(0);
         }
         track_stats();
         // ќтслеживаем производительность
         if ($this->teamProfile->getStudyPointsViaPrize() > 0) {
             $actionResult = TeamSatellite::resetPrizeStudyPoint(UserParameters::getUserId());
             if ($actionResult instanceof ErrorPoint) {
                 return $actionResult;
             }
         }
         //Utils::forDebug($this->teamProfile);
     }
 }
Example #3
0
 public function install()
 {
     $this->setLevel(GlobalParameters::START_LEVEL);
     $this->setExperience(0);
     $this->setMoney(GlobalParameters::START_MONEY);
     $this->setRealMoney(GlobalParameters::START_REAL_MONEY);
     $this->setEnergy(LevelsGrid::getInstance()->getBaseEnergy(GlobalParameters::START_LEVEL));
     $this->setMaxEnergy(LevelsGrid::getInstance()->getBaseEnergy(GlobalParameters::START_LEVEL));
     $this->setParameterSum($this->getParameterForward() + $this->getParameterHalf() + $this->getParameterSafe());
     $this->trainerId = 0;
     $this->inTeam = 0;
     $this->isInstalled = 1;
     $this->counterWon = 0;
     $this->counterChoose = 0;
     $this->counterLose = 0;
     $this->counterTie = 0;
     $this->isAbleToChoose = $this->getActiveCount() == GlobalParameters::MAX_TEAM ? 1 : 0;
     $sql_template = "INSERT INTO teams (\n    date_reg,\n\n    vk_id,\n    team_name,\n    team_logo_id,\n    auth_key,\n    energy,\n    \n    level,\n    money,\n    money_real,\n    stady_point,\n    in_team,\n    \n    able_to_choose,\n    param_forward,\n    param_half,\n    param_safe,\n    energy_max,\n\n    user_photo,\n    user_year,\n    user_country,\n    user_name,\n\n    stadium_id,\n\n    `country`,\n    `city`,\n    `university`,\n    `param_sum`,\n    `tour_notify`\n\n) VALUES (\n    NOW(),\n\n    %d,\n    '%s',\n    %d,\n    '%s',\n    %d,\n\n    %d,\n    %d,\n    %d,\n    %d,\n    %d,\n\n    %d,\n    " . $this->getParameterForward() . ",\n    " . $this->getParameterHalf() . ",\n    " . $this->getParameterSafe() . ",\n    " . $this->getEnergyMax() . ",\n\n    '" . SQL::getInstance()->real_escape_string($this->userPhoto) . "',\n    %d,\n    %d,\n    '" . SQL::getInstance()->real_escape_string($this->userName) . "',\n\n    " . $this->getStadiumId() . ",\n\n    " . $this->getUserCountry() . ",\n    " . $this->getUserCity() . ",\n    " . $this->getUserUniversity() . ",\n    " . $this->getParameterSum() . ",\n    %d\n     \n)";
     $periodType = RAM::getInstance()->getPeriodType();
     if (empty($periodType)) {
         $tourTimer = TourSatellite::getTimerDate();
         $periodType = $tourTimer->periodType;
         RAM::getInstance()->setPeriodType($periodType);
     }
     $sql = sprintf($sql_template, UserParameters::getUserId(), SQL::getInstance()->real_escape_string($this->teamName), $this->teamLogoId, SQL::getInstance()->real_escape_string(UserParameters::getAuthKey()), $this->getCurrentEnergy(), $this->getLevel(), $this->getMoney(), $this->getRealMoney(), $this->getStudyPoints(), $this->getStudyPointsViaPrize(), 0, $this->isAbleToChoose, $this->userYear, $this->userCountry, $periodType);
     RAM::getInstance()->setTeam($this);
     $result = SQL::getInstance()->query($sql);
     if ($result instanceof ErrorPoint) {
         return $result;
     }
     $sql_template = "INSERT INTO user_actions (\n    date,\n    date_sing_in,\n    vk_id,\n    command\n) VALUES (\n    NOW(),\n    NOW(),\n    %d,\n    '%s') ";
     $sql = sprintf($sql_template, UserParameters::getUserId(), SQL::getInstance()->real_escape_string(GlobalParameters::getCommand()));
     $result = SQL::getInstance()->query($sql);
     if ($result instanceof ErrorPoint) {
         return $result;
     }
 }
        $teamId = $teamObject->vk_id;
        $team = RAM::getInstance()->getTeamById($teamId);
        if(!empty($team)){
            RAM::getInstance()->changeTeamField($teamId, 'tourNotify', TOUR_NOTIFY_START);

            RAM::getInstance()->changeTeamField($teamId, 'tourPlaceVK', 0);
            RAM::getInstance()->changeTeamField($teamId, 'tourPlaceCountry', 0);
            RAM::getInstance()->changeTeamField($teamId, 'tourPlaceCity', 0);
            RAM::getInstance()->changeTeamField($teamId, 'tourPlaceUniversity', 0);

            RAM::getInstance()->changeTeamField($teamId, 'tourBonus', 0);
            RAM::getInstance()->changeTeamField($teamId, 'tourBonusTime', 0); 
        }
    }
}*/
echo "Getting tours and place : " . PHP_EOL;
$sql_template = "SELECT tour_type, tour_placer_id FROM tour_groups WHERE was_closed = 0 GROUP BY tour_type, tour_placer_id;";
$SQLResultTeams = SQL::getInstance()->query($sql_template);
if ($SQLResultTeams instanceof ErrorPoint) {
    return $SQLResultTeams;
}
if ($SQLResultTeams->num_rows) {
    while ($res = $SQLResultTeams->fetch_object()) {
        createPlayOff($res->tour_type, $res->tour_placer_id);
    }
}
TourSatellite::setTimerDate(time(), time() + 1 * 24 * 60 * 60, TOUR_NOTIFY_START);
//TourSatellite::setTimerDate(time(), time());
RAM::getInstance()->flush();
echo str_repeat(" ", strlen($startString)) . date("[Y-m-d H:i:s.m]") . " Finished " . PHP_EOL;