예제 #1
0
}
//Таким проект был в базе
$project = $tmpPrj->getProject();
//Юзер пытается купить скрытый
$tmpPrj->setProjectField('hide', 't');
//Записываются данные о скрытом и срочном. будут сохранены в кэш при $tmpPrj->fix()
$oproject = $project;
if ($tmpPrj->isEdit()) {
    $tmpPrj->setProjectField('o_hide', $oproject['hide']);
    $tmpPrj->setProjectField('o_urgent', $oproject['urgent']);
}
$tmpPrj->fix();
$account_sum = $account->sum;
$account_bonus_sum = $account->bonus_sum;
$bill = new billing($uid);
$bill->cancelAllNewAndReserved();
//Здесь впервые считается цена
if ($tmpPrj->getAmmount()) {
    $tmpProject = $tmpPrj->getProject();
    //Цена считается повторно, в $items формируется список услуг
    $price = $tmpPrj->getPrice($items, $__temp, true);
    $option = array('is_edit' => $tmpPrj->isEdit(), 'items' => $items, 'prj_id' => $project['id'], 'logo_id' => $logo['id'], 'logo_link' => $tmpProject['link']);
    if ($items['top']) {
        $option['addTop'] = $tmpPrj->getAddedTopDays();
    }
    if ($tmpPrj->isKonkurs()) {
        if (new_projects::isNewContestBudget()) {
            $cost = $tmpPrj->getCostRub();
            $op_code = new_projects::getContestTaxOpCode($tmpPrj->getCostRub(), is_pro());
            $items['contest']['no_pro'] = $tmpPrj->isEdit() ? 0 : new_projects::getContestTax($cost, is_pro());
            $items['contest']['pro'] = $tmpPrj->isEdit() ? 0 : new_projects::getContestTax($cost, true);
예제 #2
0
 /**
  * ищет фрилансеров у которых заканчивается срок размещения объявления
  */
 public static function autoPayedReminder($days = 1, $interval = 'days', $test = false)
 {
     require_once $_SERVER['DOCUMENT_ROOT'] . "/classes/bar_notify.php";
     require_once $_SERVER['DOCUMENT_ROOT'] . "/classes/billing.php";
     require_once $_SERVER['DOCUMENT_ROOT'] . "/classes/smail.php";
     require_once $_SERVER['DOCUMENT_ROOT'] . "/classes/professions.php";
     global $DB;
     $sql = "\n                SELECT ufa.*, a.sum, a.id as acc_id, p.name as prof_name, u.uname, u.login, u.email, u.usurname, u.subscr, u.is_banned, substr(u.subscr::text,16,1) = '1' as bill_subscribe, ufl.to_date\n                FROM users_first_page_autopay ufa\n                INNER JOIN (\n                    SELECT user_id, profession, MAX(from_date + to_date) as to_date\n                    FROM users_first_page\n                    WHERE payed = true\n                        AND ordered = true\n                    GROUP BY user_id, profession\n                ) as ufl\n                ON ufl.user_id = ufa.user_id\n                AND ufl.profession = ufa.profession ";
     if (!$test && $interval == 'days') {
         $sql .= "\n                AND  ufl.to_date >= now()::date + interval '{$days} days' AND  ufl.to_date < now()::date + interval '" . ($days + 1) . " days'";
     } elseif (!$test && $interval == 'hour') {
         $sql .= "\n                AND  ufl.to_date >= now() + interval '{$days} hour' AND  ufl.to_date < now() + interval '" . ($days + 1) . " hour'";
     } else {
         $uid = $DB->val("SELECT uid FROM users WHERE login = ?", $test);
         $sql .= $DB->parse(" AND  ufl.to_date >= now()::date AND ufl.user_id = ?", $uid);
     }
     $sql .= "\n                INNER JOIN account a ON a.uid = ufa.user_id\n                INNER JOIN professions p ON p.id = ufa.profession\n                INNER JOIN users u ON u.uid = ufa.user_id AND u.is_banned = B'0'";
     $res = $DB->rows($sql);
     if (!$res) {
         return false;
     }
     $price = self::getPrice();
     $users = array();
     foreach ($res as $user) {
         $cost = $price[$user['profession']] ? $price[$user['profession']] : $price['n'];
         $users[$user['user_id']]['profs'][] = array('id' => $user['profession'], 'cost' => $cost, 'name' => $user['prof_name'], 'to_date' => $user['to_date']);
         $users[$user['user_id']]['userData'] = $user;
         $users[$user['user_id']]['user'] = $user;
         $users[$user['user_id']]['sum_cost'] += $cost;
     }
     if (!$users) {
         return;
     }
     // если остается от 1 до 2 дней до окончания, то формируем списки заказов
     if ($days == 1) {
         $mail = new smail();
         foreach ($users as $uid => $user) {
             $bill = new billing($uid);
             $bill->cancelAllNewAndReserved();
             $barNotify = new bar_notify($uid);
             // отдельный блок для каждой профессии
             foreach ($user['profs'] as $userProf) {
                 $tarif = self::getBillingTarif($userProf['id']);
                 $options = array('prof_id' => $userProf['id'], 'week' => 1);
                 $bill->setOptions($options);
                 $create = $bill->create($tarif, true, false);
                 if (!$create) {
                     continue;
                 }
                 $queue[] = $create;
             }
             $billing = new billing($uid);
             if (!empty($queue)) {
                 //Проталкиваем дальше автопродление для оплаты
                 $billing->preparePayments($user['sum_cost'], false, $queue);
                 $complete = billing::autoPayed($billing, $user['sum_cost']);
                 $user['prof'] = $user['profs'];
                 if ($complete) {
                     $barNotify->addNotify('bill', '', 'Услуга успешно продлена.');
                 } else {
                     if ($interval == 'days') {
                         // Первая попытка
                         $barNotify->addNotify('bill', '', 'Ошибка списания, услуга не продлена.');
                     } else {
                         // Вторая попытка не удачная
                         $barNotify->addNotify('bill', '', 'Ошибка списания, автопродление отключено.');
                     }
                 }
             }
         }
     }
 }