示例#1
0
 /**
  * Создание нового предложения
  *
  * @param array $create    Переменная типа array(name=>value) где name - поле таблицы, value - значение для записи (@see Таблица freelance_offers) 
  * @return boolean|string
  */
 public function Create($create)
 {
     global $DB;
     $uid = $create['user_id'];
     if ($_SESSION['uid'] == $uid && !is_emp()) {
         $account = new account();
         $transaction_id = $account->start_transaction($uid, $tr_id);
         $error = $account->Buy($billing_id, $transaction_id, self::FM_OP_CODE, $uid, "Покупка публикации предложения фрилансера", "Покупка публикации предложения", 1, 0);
         if ($error) {
             return $error;
         }
         $account->commit_transaction($transaction_id, $uid, $billing_id);
         $create['bill_id'] = $billing_id;
         $create['moderator_status'] = is_pro() ? NULL : 0;
         $id_offer = $DB->insert('freelance_offers', $create, 'id');
         if ($id_offer > 0) {
             if (!is_pro()) {
                 require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/stop_words.php';
                 require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/user_content.php';
                 $stop_words = new stop_words();
                 $nStopWordsCnt = $stop_words->calculate($fields['descr'], $fields['title']);
                 $DB->insert('moderation', array('rec_id' => $id_offer, 'rec_type' => user_content::MODER_SDELAU, 'stop_words_cnt' => $nStopWordsCnt));
             }
             return $id_offer;
         }
         return false;
     } else {
         return false;
     }
 }
示例#2
0
 /**
  * Обработка оплаты операций
  * 
  * @param type $operations  Операции к оплате
  * @return boolean 
  */
 function paymentOptions($operations)
 {
     require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/wizard/step_freelancer.php';
     require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/wizard/step_employer.php';
     require_once $_SERVER['DOCUMENT_ROOT'] . "/classes/account.php";
     require_once $_SERVER['DOCUMENT_ROOT'] . "/classes/projects_offers_answers.php";
     require_once $_SERVER['DOCUMENT_ROOT'] . "/classes/payed.php";
     require_once $_SERVER['DOCUMENT_ROOT'] . "/classes/drafts.php";
     require_once $_SERVER['DOCUMENT_ROOT'] . "/classes/projects.php";
     require_once $_SERVER['DOCUMENT_ROOT'] . "/classes/log.php";
     $this->log = new log('wizard/payed-' . SERVER . '-%d.log', 'a', '%d.%m.%Y %H:%M:%S : ');
     $payed_operation = $this->getDraftAccountOperationsByIds($operations, $this->uid);
     $account = new account();
     if ($payed_operation) {
         // выбран ли или уже куплен аккаунт ПРО
         $is_pro = is_pro();
         if (!$is_pro) {
             foreach ($payed_operation as $option) {
                 if ($option['op_code'] == 15) {
                     $is_pro = true;
                     break;
                 }
             }
         }
         // перебираем все позиции и переделываем с учетом ПРО
         if ($is_pro) {
             foreach ($payed_operation as &$option) {
                 switch ($option['op_code']) {
                     case new_projects::OPCODE_KON_NOPRO:
                         $option['op_code'] = new_projects::OPCODE_KON;
                         break;
                     case new_projects::OPCODE_PAYED:
                         $option['ammount'] = $option['ammount'] - new_projects::PRICE_ADDED;
                         break;
                     default:
                         break;
                 }
             }
         }
         unset($option);
         $transaction_id = $account->start_transaction($this->uid);
         foreach ($payed_operation as $option) {
             $ok[$option['id']] = $this->billingOperation($option, $transaction_id);
             if ($ok[$option['id']]) {
                 $delete = $this->deleteDraftAccountOperation($option['id']);
                 if (!$delete) {
                     $this->log->writeln("Error delete draft account operation - user (" . wizard::getUserIDReg() . ") - option #{$option['id']}");
                 }
             } else {
                 $this->log->writeln("Error billing operation - user (" . wizard::getUserIDReg() . ") - option #{$option['id']}");
             }
         }
         $account->commit_transaction($transaction_id, $this->uid, null);
         return true;
     }
     return false;
 }
示例#3
0
 /**
  * Функция оплаты акции.
  *  
  * @global object $DB база данных
  *
  * @param int $transaction_id ИД транзакции сделки
  * @param int $user_id        ИД пользователя
  *
  * @return int
  */
 public function setPayed($transaction_id, $user_id)
 {
     global $DB;
     require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/account.php';
     $account = new account();
     if (is_emp($_SESSION['role'])) {
         return 0;
     }
     $bill_id = 0;
     $error = $account->Buy($bill_id, $transaction_id, $this->getConst_OP_CODE(), $user_id, $this->title, $this->descr, $this->getConst_PAYED_SUM(), 0);
     if ($error !== 0) {
         return 0;
     }
     if ($bill_id) {
         require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/pay_place.php';
         $pay_place = new pay_place(1);
         $account->commit_transaction($transaction_id, $user_id, $bill_id);
         $this->setUserPro($user_id, $bill_id);
         $pay_place->addUserTop($user_id);
         return $bill_id;
     }
     return 0;
 }
 private function setIMakeValues()
 {
     global $DB;
     $uid = (int) $_POST['uid'];
     $rawIds = $_POST['ids'];
     $role = $DB->val("SELECT role FROM users WHERE uid = {$uid}");
     $role = $role[0];
     if ($role === '0') {
         $aIds = explode(',', $rawIds);
         foreach ($aIds as $i) {
             $pair = explode(':', $i);
             $group = $pair[0];
             $spec = $pair[1];
             if ($spec === '0' || intval($spec) != 0) {
                 if ($group === '0' || intval($group) != 0) {
                     //----------------------------------------
                     $frl_offers = new freelancer_offers();
                     $create = array('user_id' => $uid, 'title' => iconv('UTF-8', 'WINDOWS-1251//IGNORE', $_POST['title']), 'descr' => iconv('UTF-8', 'WINDOWS-1251//IGNORE', $_POST['text']), 'category_id' => intval($group), 'subcategory_id' => intval($spec));
                     $account = new account();
                     $transaction_id = $account->start_transaction($uid, $tr_id);
                     $error = $account->Buy($billing_id, $transaction_id, freelancer_offers::FM_OP_CODE, $uid, 'Покупка публикации предложения фрилансера', 'Покупка публикации предложения', 1, 0);
                     if ($error) {
                         $this->jsonError($error);
                     }
                     $account->commit_transaction($transaction_id, $uid, $billing_id);
                     $create['bill_id'] = $billing_id;
                     $id_offer = $DB->insert('freelance_offers', $create, 'id');
                     if ($id_offer > 0) {
                         $this->jsonOk();
                     }
                 }
             }
         }
     } else {
         $this->jsonError('Пользователь не найден или является работодателем');
     }
 }
示例#5
0
            $error['spec'] = 'Ќе верно указано заначение количества доп. специализаций ';
        }
    }
}
if ($answer_pay) {
    if ($_POST['answers_sum'] > 0) {
        $num_answers = intval($_POST['num_answers']);
        if (!($err = $answers->BuyByFM($uid, $num_answers, $tr_id, 0))) {
            $_SESSION['answers_ammount'] = $_POST['num_answers'];
        }
        if ($err) {
            $error['answers'] = $err;
        }
    }
}
if ($account->check_transaction($tr_id, $uid) && !$error) {
    $account->commit_transaction($tr_id, $uid, 'null');
}
if (!$error) {
    header("Location: /bill/success/");
    exit;
} else {
    $_SESSION['bill.GET']['error'] = current($error);
    header("Location: /bill/fail/");
    exit;
}
$content = "content.php";
$js_file = array('payed.js');
$header = "../header.php";
$footer = "../footer.html";
include "../template2.php";
/**
 * Сохранение предложения по проектам
 * 
 * @param object $objResponse xajaxResponse
 * @param string $rec_id идентификатор записи
 * @param string $rec_type тип записи
 * @param array $aForm массив данных
 * @param string $sDrawFunc имя функции для выполнения после сохранения
 */
function _admEditPrjOfferSaveForm(&$objResponse, $rec_id = '', $rec_type = '', $aForm = array(), $sDrawFunc = '')
{
    require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/messages.php';
    require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/user_content.php';
    require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/projects_offers.php';
    $obj_offer = new projects_offers();
    $payed_items = $aForm['ps_payed_items'];
    $payed_color = $aForm['ps_payed_items'][0] == '1';
    if ($aForm['is_color'] && !$payed_color) {
        $account = new account();
        $transaction_id = $account->start_transaction(get_uid());
        $error_buy = $account->Buy($billing_id, $transaction_id, $answers->color_op_code, get_uid(), "Выделение ответа на проект цветом", "Выделение <a href='" . getFriendlyURL("project", $project['id']) . "#freelancer_{$_SESSION['uid']}' target='_blank'>предложения</a> цветом", 1, 1);
        $payed_items = '1';
        if ($error_buy) {
            $aForm['is_color'] = false;
            $payed_items = '0';
        }
    }
    $sReason = _parseReason($aForm['user_id'], $aForm['adm_edit_text']);
    $error = $obj_offer->AddOffer($aForm['user_id'], $aForm['pid'], $aForm['ps_cost_from'], $aForm['ps_cost_to'], $aForm['ps_cost_type'], $aForm['ps_time_from'], $aForm['ps_time_to'], $aForm['ps_time_type'], antispam(stripslashes($aForm['ps_text'])), $aForm['ps_work_1_id'], $aForm['ps_work_2_id'], $aForm['ps_work_3_id'], $aForm['ps_work_1_link'], $aForm['ps_work_2_link'], $aForm['ps_work_3_link'], $aForm['ps_work_1_name'], $aForm['ps_work_2_name'], $aForm['ps_work_3_name'], $aForm['ps_work_1_pict'], $aForm['ps_work_2_pict'], $aForm['ps_work_3_pict'], $aForm['ps_work_1_prev_pict'], $aForm['ps_work_2_prev_pict'], $aForm['ps_work_3_prev_pict'], isset($aForm['ps_for_customer_only']), $aForm['edit'], 0, isset($aForm['prefer_sbr']), $aForm['is_color'], null, $payed_items, 0, $_SESSION['uid'], $sReason);
    if (!$error && !$error_buy && !$payed_color && $account) {
        $account->commit_transaction($transaction_id, get_uid(), $billing_id);
        $is_payed_color = true;
    }
    if ($error) {
        $objResponse->alert('Ошибка сохранения предложения' . $error);
        $sParent = $sDrawFunc == 'stream0' || $sDrawFunc == 'stream1' || $sDrawFunc == 'stream2' ? 'parent.' : '';
        $objResponse->script("{$sParent}adm_edit_content.disabled = false; {$sParent}adm_edit_content.button();");
    } else {
        messages::prjOfferModifiedNotification($aForm['user_id'], $aForm['pid'], $sReason);
        $content_id = user_content::MODER_PRJ_OFFERS;
        _admEditAfterAll($objResponse, $content_id, $rec_id, $rec_type, $sDrawFunc, $aForm);
    }
}
示例#7
0
 /**
  * Изменение позиции пользователя
  * @param   integer   $user              uid пользователя
  * @param   integer   $transaction_id    id транзакции
  * @param   array     $bids              массив, в котором индекс элементов - id места размещения, значения - сумма для поднятия позиции
  * @return  boolean                      успех операции
  */
 function BidPlaces($user, $transaction_id, $bids)
 {
     global $DB;
     if ($bids) {
         foreach ($bids as $prof => $sum) {
             require_once $_SERVER['DOCUMENT_ROOT'] . "/classes/account.php";
             $account = new account();
             $error = $account->Buy($bill_id, $transaction_id, 21, $user, "", "", $sum, 0);
             if ($error !== 0) {
                 return 0;
             }
             $sql = "UPDATE users_first_page SET psum=psum+?i WHERE id IN (SELECT id FROM users_first_page \n\t\t\t\tWHERE user_id = ?i AND from_date+to_date >= now() AND payed=true\n\t\t\t\tAND ordered = true AND profession=? )";
             $res = $DB->query($sql, $sun, $user, $prof);
             $id = 1;
         }
     }
     if ($bill_id) {
         $account->commit_transaction($transaction_id, $user, $bill_id);
     }
     $memBuff = new memBuff();
     $ret = $memBuff->flushGroup("firstpg");
     return $id;
 }
示例#8
0
 /**
  * Продляет специализации по ID пользователя
  *
  * @param integer $uid ID пользователя
  * @param boolean $is_autopaid Учитывать только отмеченные для автопродления
  * @param string $period Период продления
  * @param boolean $prolong_only
  * @return string Сообщение об ошибке если есть
  */
 function prolongSpecs($uid, $is_autopaid = false, $period = '1 mon', $prolong_only = false)
 {
     global $DB;
     return;
     // #0022795
     require_once $_SERVER['DOCUMENT_ROOT'] . "/classes/account.php";
     $account = new account();
     $specs = self::getPaidSpecs($uid, true, $is_autopaid, $prolong_only);
     if (!$specs) {
         return 'Нет специализаций';
     }
     $transaction_id = $account->start_transaction($uid);
     $billing_id = NULL;
     $sum = 0;
     foreach ($specs as $i => $spec) {
         $DB->start();
         $sql = "UPDATE spec_paid_choise SET paid_to = paid_to + '{$period}'::interval\n                    WHERE id = {$spec['id']} AND user_id = {$uid} RETURNING paid_to, (paid_to - '{$period}'::interval) as paid_from";
         if ($res = $DB->query($sql)) {
             $paid_to = pg_fetch_result($res, 0, 0);
             $paid_from = pg_fetch_result($res, 0, 1);
             $descr = 'Продление "' . $spec['name'] . '" до ' . date('d.m.Y', strtotime($paid_to));
             if ($error = $account->Buy($bill_id, $transaction_id, self::OP_PAID_SPEC, $uid, $descr, $descr, 1, 0)) {
                 $DB->rollback();
                 break;
             }
             if ($DB->commit()) {
                 $billing_id = $bill_id;
                 $sum++;
                 $sql = "INSERT INTO spec_paid_acc_operations (billing_id, paid_from, paid_to)\n                            VALUES ({$bill_id}, '{$paid_from}'::timestamp, '{$paid_to}'::timestamp)";
                 $rs = $DB->query($sql);
             }
         }
     }
     if ($billing_id) {
         $account->commit_transaction($transaction_id, $uid, $billing_id);
         require_once $_SERVER['DOCUMENT_ROOT'] . "/classes/smail.php";
         require_once $_SERVER['DOCUMENT_ROOT'] . "/classes/op_codes.php";
         $mail = new smail();
         $ops = new op_codes();
         $price = $ops->getCodes(self::OP_PAID_SPEC);
         if ($price) {
             $price = $price[self::OP_PAID_SPEC];
             $mail->PaidSpecsAutopayed($uid, $sum * $price['sum']);
         }
     }
     return $error;
 }
 /**
  * Возврат ответов в случае блокировки проекта.
  *
  * @param int $project_id - ID проекта
  *
  * @return mixed - сообщение об ошибке или 0 в случае успеха
  */
 public function ReturnAnswers($project_id)
 {
     global $DB;
     $descr = 'Возврат ответа на проект в связи с блокировкой проекта';
     $op_code = $this->return_op_code;
     require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/projects_offers.php';
     $of = new projects_offers();
     $offers = $of->GetPrjOffers($count, $project_id, 'ALL', 0, 0, true);
     if (!$count) {
         return;
     }
     require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/account.php';
     $account = new account();
     foreach ($offers as $offer) {
         $uid = $offer['user_id'];
         if ($offer['type'] == 0) {
             continue;
         }
         $transaction_id = $account->start_transaction($uid);
         $error = $account->Buy($billing_id, $transaction_id, $op_code, $uid, $descr, $descr, 0, 0);
         if ($error) {
             return $error;
         }
         if ($offer['type'] == 2) {
             $DB->query('UPDATE projects_offers_answers SET pay_offers = pay_offers + 1 WHERE uid = ?', $uid);
         } else {
             $free_cnt = self::FREE_ANSWERS_CNT;
             $DB->query("UPDATE projects_offers_answers \n                    SET free_offers = free_offers + (CASE WHEN free_offers < {$free_cnt} THEN 1 ELSE 0 END) WHERE uid = ?", $uid);
         }
         $account->commit_transaction($transaction_id, $uid, $billing_id);
     }
 }
示例#10
0
     if ($error_buy) {
         $_POST['is_color'] = false;
         $payed_items = '0';
     }
 }
 if (isset($_POST['contacts'])) {
     $error_offer = users::validateContacts($_POST['contacts'], $contacts_freelancer);
 }
 if (!$error_offer) {
     $save_contacts = serialize($contacts_freelancer);
     $error_offer = $obj_offer->AddOffer($uid, $project['id'], $_POST['ps_cost_from'], $_POST['ps_cost_to'], $_POST['ps_cost_type'], $_POST['ps_time_from'], $_POST['ps_time_to'], $_POST['ps_time_type'], antispam(stripslashes($_POST['ps_text'])), $_POST['ps_work_1_id'], $_POST['ps_work_2_id'], $_POST['ps_work_3_id'], $_POST['ps_work_1_link'], $_POST['ps_work_2_link'], $_POST['ps_work_3_link'], $_POST['ps_work_1_name'], $_POST['ps_work_2_name'], $_POST['ps_work_3_name'], $_POST['ps_work_1_pict'], $_POST['ps_work_2_pict'], $_POST['ps_work_3_pict'], $_POST['ps_work_1_prev_pict'], $_POST['ps_work_2_prev_pict'], $_POST['ps_work_3_prev_pict'], isset($_POST['ps_for_customer_only']), InGetPost('edit', 0), 0, isset($_POST['prefer_sbr']), $_POST['is_color'], $save_contacts, $payed_items);
 } else {
     $error = true;
 }
 if (!$error_offer && !$error_buy && !$payed_color && $account) {
     $account->commit_transaction($transaction_id, get_uid(), $billing_id);
     $is_payed_color = true;
 }
 if ($is_payed_color) {
     header('Location: /bill/success/');
     exit;
 }
 if ($error === 403) {
     include ABS_PATH . '/403.php';
     exit;
 }
 $kind = $project['kind'];
 if (!$error) {
     header('Location: ' . getFriendlyURL('project', $project['id']) . '?' . $from_prm_s);
     exit;
 }
示例#11
0
 public function payedAdvice($id_advice, $uid, $transaction_id, $tarif, $trs_sum)
 {
     require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/account.php';
     $tarif = floatval($tarif);
     $account = new account();
     $link = "<a href='{$GLOBALS['host']}/users/{$_SESSION['login']}/opinions/#p_" . $id_advice * 2 . "' target='_blank'>Рекомендация</a>";
     $error = $account->Buy($bill_id, $transaction_id, self::OP_CODE, $uid, 'Оплата рекомендации', $link, $tarif, 0, 0, $trs_sum);
     if ($error !== 0) {
         return 0;
     }
     if ($bill_id) {
         $account->commit_transaction($transaction_id, $uid, $bill_id);
         $this->setPayed($id_advice, $bill_id);
         return $bill_id;
     }
     return 0;
 }