/** * для имитация окончания PRO у пользователя * * @param $attempt текущая попытка продления */ function checkAutoProTest($login, $attempt = 1) { require_once $_SERVER['DOCUMENT_ROOT'] . "/classes/billing.php"; require_once $_SERVER['DOCUMENT_ROOT'] . "/classes/bar_notify.php"; require_once $_SERVER['DOCUMENT_ROOT'] . "/classes/smail.php"; require_once $_SERVER['DOCUMENT_ROOT'] . "/classes/wallet/wallet.php"; global $DB; if ($attempt <= 0) { $attempt = 1; } $sql = "\n SELECT users.uid, a.id as acc_id, email, login, uname, usurname, subscr, role, substr(subscr::text,16,1) = '1' as bill_subscribe\n FROM users\n INNER JOIN account a ON a.uid = users.uid\n WHERE users.login = ?"; $user = $DB->row($sql, $login); if (!$user) { return; } $user['date_end'] = date('Y-m-d H:i:s', time()); $op_code = !is_emp($user['role']) ? 48 : 15; $price = !is_emp($user['role']) ? self::PRICE_FRL_PRO : self::PRICE_EMP_PRO; $billing = new billing($user['uid']); $queueID = $billing->create($op_code, 1); if (!$queueID) { return; } //Проталкиваем дальше автопродление для оплаты $billing->preparePayments($price, false, array($queueID)); $complete = billing::autoPayed($billing, $price); // @todo отключать ли автопродление или нет при второй попытке ( по идее на систему никак влиять не будет ) // Автопродление не будет куплено уведомляем об этом пользователя $barNotify = new bar_notify($user['uid']); $mail = new smail(); if ($complete) { $barNotify->addNotify('bill', '', 'Услуга успешно продлена.'); $mail->successAutoprolong(array('user' => $user, 'sum_cost' => $price), 'pro'); //$mail->sendAutoPROEnding(( $user['role'] == 'freelancer' ? 'FRL' : 'EMP' ), array($user)); } else { if ($attempt == 1) { $barNotify->addNotify('bill', '', 'Ошибка списания, услуга не продлена.'); $mail->attemptAutoprolong(array('user' => $user, 'sum_cost' => $price), 'pro'); } else { $barNotify->addNotify('bill', '', 'Ошибка списания, автопродление отключено.'); $mail->failAutoprolong(array('user' => $user, 'sum_cost' => $price), 'pro'); } } }