Beispiel #1
0
 public function actionAddPaid($id = 0, $withDate = 0)
 {
     $model = new AddToUserForm();
     $tariffs = TariffPlans::getAllTariffPlans(true, true);
     $tariffsArray = CHtml::listData($tariffs, 'id', 'name');
     $request = Yii::app()->request;
     $data = $request->getPost('AddToUserForm');
     if ($data) {
         $userId = $request->getPost('user_id');
         $withDate = $request->getPost('withDate');
         $model->attributes = $data;
         if ($model->validate()) {
             $user = User::model()->findByPk($userId);
             $tariff = TariffPlans::getFullTariffInfoById($model->tariff_id);
             if (!$tariff || !$user) {
                 throw new CException('Not valid data');
             }
             if (TariffPlans::applyToUser($userId, $tariff['id'], $model->date_end, null, true)) {
                 echo CJSON::encode(array('status' => 'ok', 'userId' => $userId, 'html' => TariffPlans::getTariffPlansHtml($withDate, true, $user)));
                 Yii::app()->end();
             }
         } else {
             echo CJSON::encode(array('status' => 'err', 'html' => $this->renderPartial('_add_to_user', array('id' => $userId, 'model' => $model, 'withDate' => $withDate, 'tariffsArray' => $tariffsArray), true)));
             Yii::app()->end();
         }
     }
     $renderData = array('id' => $id, 'model' => $model, 'withDate' => $withDate, 'tariffsArray' => $tariffsArray);
     if (Yii::app()->request->isAjaxRequest) {
         $this->renderPartial('_add_to_user', $renderData);
     } else {
         $this->render('_add_to_user', $renderData);
     }
 }
 public function run()
 {
     if (!$this->userId) {
         $this->userId = Yii::app()->user->id;
     }
     $info = TariffPlans::getTariffInfoByUserId($this->userId);
     $this->render('userTariffInfoViewWidget', array('id' => $info['id'], 'name' => $info['name'], 'description' => $info['description'], 'limitObjects' => $info['limitObjects'], 'limitPhotos' => $info['limitPhotos'], 'price' => $info['price'], 'duration' => $info['duration'], 'showAddress' => $info['showAddress'], 'showPhones' => $info['showPhones'], 'currency' => Currency::getDefaultCurrencyModel()->name, 'userCountObjects' => TariffPlans::getCountUserObjects($this->userId), 'tariffDateStart' => $info['tariffDateStart'], 'tariffDateEnd' => $info['tariffDateEnd'], 'tariffStatus' => $info['tariffStatus'], 'tariffDateStartFormat' => $info['tariffDateStartFormat'], 'tariffDateEndFormat' => $info['tariffDateEndFormat'], 'isDefaultTariffPlan' => $info['id'] == TariffPlans::DEFAULT_TARIFF_PLAN_ID ? true : false));
 }
Beispiel #3
0
 public function actionUpload($id)
 {
     $model = $this->checkOwner($id);
     $maxImgs = 0;
     # unlimited
     $currImgCount = 0;
     if (issetModule('tariffPlans') && issetModule('paidservices')) {
         $sql = 'SELECT COUNT(id) FROM {{images}} WHERE id_object = ' . $model->id;
         $currImgCount = Yii::app()->db->createCommand($sql)->queryScalar();
         $userTariffInfo = TariffPlans::getTariffInfoByUserId($model->owner_id);
         $maxImgs = $userTariffInfo['limitPhotos'];
         if (Yii::app()->user->checkAccess("backend_access")) {
             # admin or moderator
             $maxImgs = 0;
         }
     }
     if ($maxImgs > 0 && $currImgCount >= $maxImgs) {
         $result['error'] = Yii::t("module_tariffPlans", "You are trying to download more than {num} pictures ( your tariff limit )", array("{num}" => $maxImgs));
         $result = htmlspecialchars(json_encode($result), ENT_NOQUOTES);
         echo $result;
         Yii::app()->end();
     }
     Yii::import("ext.EAjaxUpload.qqFileUploader");
     $allowedExtensions = param('allowedImgExtensions', array('jpg', 'jpeg', 'gif', 'png'));
     //$sizeLimit = param('maxImgFileSize', 8 * 1024 * 1024);
     $sizeLimit = Images::getMaxSizeLimit();
     $uploader = new qqFileUploader($allowedExtensions, $sizeLimit);
     $path = Yii::getPathOfAlias('webroot.uploads.objects.' . $model->id . '.' . Images::ORIGINAL_IMG_DIR);
     $pathMod = Yii::getPathOfAlias('webroot.uploads.objects.' . $model->id . '.' . Images::MODIFIED_IMG_DIR);
     $oldUMask = umask(0);
     if (!is_dir($path)) {
         @mkdir($path, 0777, true);
     }
     if (!is_dir($pathMod)) {
         @mkdir($pathMod, 0777, true);
     }
     umask($oldUMask);
     if (is_writable($path) && is_writable($pathMod)) {
         touch($path . DIRECTORY_SEPARATOR . 'index.htm');
         touch($pathMod . DIRECTORY_SEPARATOR . 'index.htm');
         $result = $uploader->handleUpload($path . DIRECTORY_SEPARATOR, false, uniqid());
         if (isset($result['success']) && $result['success']) {
             $resize = new CImageHandler();
             if ($resize->load($path . DIRECTORY_SEPARATOR . $result['filename'])) {
                 $resize->thumb(param('maxImageWidth', 1024), param('maxImageHeight', 768), Images::KEEP_PHOTO_PROPORTIONAL)->save();
                 $image = new Images();
                 $image->id_object = $model->id;
                 $image->id_owner = $model->owner_id;
                 $image->file_name = $result['filename'];
                 if ($image->save() && $model->hasAttribute('count_img')) {
                     $model->count_img++;
                     $model->update('count_img');
                 }
             } else {
                 $result['error'] = 'Wrong image type.';
                 @unlink($path . DIRECTORY_SEPARATOR . $result['filename']);
             }
         }
     } else {
         $result['error'] = 'Access denied.';
     }
     // to pass data through iframe you will need to encode all html tags
     $result = htmlspecialchars(json_encode($result), ENT_NOQUOTES);
     echo $result;
 }
Beispiel #4
0
 public static function renderViewRows($rows, Apartment $model)
 {
     if (!$rows) {
         return '';
     }
     foreach ($rows as $row) {
         if (!$model->canShowInView($row['field'])) {
             continue;
         }
         if ($row['standard_type'] != FormDesigner::STANDARD_TYPE_NEW && file_exists(ROOT_PATH . '/protected/views/common/apartments/fields/' . $row['field'] . '.php')) {
             //
             Yii::app()->controller->renderPartial('//../views/common/apartments/fields/' . $row['field'], array('data' => $model));
             continue;
         }
         if ($row->type == FormDesigner::TYPE_REFERENCE) {
             $sql = "SELECT title_" . Yii::app()->language . " FROM {{apartment_reference_values}} WHERE id=" . $model->{$row}['field'];
             $value = CHtml::encode(Yii::app()->db->createCommand($sql)->queryScalar());
         } else {
             $value = is_string($model->{$row}['field']) ? CHtml::encode($model->{$row}['field']) : '???';
             if ($row->type == FormDesigner::TYPE_TEXT_AREA_WS) {
                 $value = purify($model->{$row}['field']);
             }
         }
         if ($row->type == FormDesigner::TYPE_INT && $row->measure_unit) {
             $value .= ' ' . CHtml::encode($row->measure_unit);
         }
         if ($value) {
             if ($row['standard_type'] > 0) {
                 echo '<dt>' . CHtml::encode($model->getAttributeLabel($row['field'])) . ':</dt>';
             } else {
                 echo '<dt>' . CHtml::encode($row['label_' . Yii::app()->language]) . ':</dt>';
             }
             if ($row->field == 'phone') {
                 if (issetModule('tariffPlans') && issetModule('paidservices') && $model->owner_id != Yii::app()->user->id) {
                     if (Yii::app()->user->isGuest) {
                         $defaultTariffInfo = TariffPlans::getFullTariffInfoById(TariffPlans::DEFAULT_TARIFF_PLAN_ID);
                         if (!$defaultTariffInfo['showPhones']) {
                             echo '<dd>' . Yii::t('module_tariffPlans', 'Please <a href="{n}">login</a> to view', Yii::app()->controller->createUrl('/site/login')) . '</dd>';
                         } else {
                             echo '<dd><span id="owner-phone">' . CHtml::link(tc('Show phone'), 'javascript: void(0);', array('onclick' => 'generatePhone();')) . '</span>' . '</dd>';
                         }
                     } else {
                         if (TariffPlans::checkAllowShowPhone()) {
                             echo '<dd>' . $value . '</dd>';
                         } else {
                             echo '<dd>' . Yii::t('module_tariffPlans', 'Please <a href="{n}">change the tariff plan</a> to view', Yii::app()->controller->createUrl('/tariffPlans/main/index')) . '</dd>';
                         }
                     }
                 } else {
                     echo '<dd><span id="owner-phone">' . CHtml::link(tc('Show phone'), 'javascript: void(0);', array('onclick' => 'generatePhone();')) . '</span>' . '</dd>';
                 }
             } else {
                 echo '<dd>' . $value . '</dd>';
             }
         }
     }
 }
Beispiel #5
0
 public static function checkTariffPlansUsers()
 {
     if (issetModule('tariffPlans') && issetModule('paidservices')) {
         TariffPlans::checkDeactivateTariffUsers();
     }
 }
Beispiel #6
0
 public function getUserTariff()
 {
     if (issetModule('tariffPlans') && issetModule('paidservices')) {
         if ($this) {
             if (isset($this->userTariffPlan) && $this->userTariffPlan) {
                 $info = TariffPlans::getFullTariffInfoById($this->userTariffPlan->tariff_id);
                 $info['tariff_status'] = $this->userTariffPlan->status;
                 $info['tariff_date_start'] = $this->userTariffPlan->date_start;
                 $info['tariff_date_end'] = $this->userTariffPlan->date_end;
                 $info['tariff_date_start_format'] = Yii::app()->dateFormatter->format(Yii::app()->locale->getDateFormat('long'), CDateTimeParser::parse($this->userTariffPlan->date_start, 'yyyy-MM-dd hh:mm:ss'));
                 $info['tariff_date_end_format'] = Yii::app()->dateFormatter->format(Yii::app()->locale->getDateFormat('long'), CDateTimeParser::parse($this->userTariffPlan->date_end, 'yyyy-MM-dd hh:mm:ss'));
             } else {
                 $info = TariffPlans::getFullTariffInfoById(TariffPlans::DEFAULT_TARIFF_PLAN_ID);
             }
             return $info;
         }
     }
     return null;
 }
Beispiel #7
0
 public function actionUpdate($id)
 {
     $this->setActiveMenu('add_ad');
     $model = $this->loadModelUserAd($id);
     if (issetModule('bookingcalendar')) {
         $model = $model->with(array('bookingCalendar'));
     }
     $this->performAjaxValidation($model);
     if (isset($_GET['type'])) {
         $model->type = HApartment::getRequestType();
     }
     if (isset($_POST[$this->modelName])) {
         $originalActive = $model->active;
         $model->attributes = $_POST[$this->modelName];
         if ($model->type != Apartment::TYPE_BUY && $model->type != Apartment::TYPE_RENTING) {
             // video, panorama, lat, lon
             HApartment::saveOther($model);
         }
         $model->scenario = 'savecat';
         $model->owner_active = Apartment::STATUS_ACTIVE;
         if (issetModule('tariffPlans') && issetModule('paidservices')) {
             $return = TariffPlans::checkAllowUserActivateAd(Yii::app()->user->id, true, '>=');
             if ($return === false) {
                 $model->owner_active = Apartment::STATUS_INACTIVE;
             }
         }
         $isUpdate = Yii::app()->request->getPost('is_update');
         $model->isAjaxLoadOnUpdate = $isUpdate;
         if ($isUpdate) {
             $model->save(false);
         } elseif ($model->validate()) {
             if (param('useUseradsModeration', 1)) {
                 $model->active = Apartment::STATUS_MODERATION;
             } else {
                 $model->active = Apartment::STATUS_ACTIVE;
             }
             if ($model->save(false)) {
                 if ($model->owner_active == Apartment::STATUS_INACTIVE) {
                     $this->redirect(array('/usercpanel/main/index'));
                 } else {
                     $this->redirect(array('/apartments/main/view', 'id' => $model->id));
                 }
             }
         } else {
             $model->active = $originalActive;
         }
     }
     HApartment::getCategoriesForUpdate($model);
     if ($model->active == Apartment::STATUS_DRAFT) {
         Yii::app()->user->setState('menu_active', 'apartments.create');
         $this->render('create', array('model' => $model, 'supportvideoext' => ApartmentVideo::model()->supportExt, 'supportvideomaxsize' => ApartmentVideo::model()->fileMaxSize));
         return;
     }
     $this->render('update', array('model' => $model, 'supportvideoext' => ApartmentVideo::model()->supportExt, 'supportvideomaxsize' => ApartmentVideo::model()->fileMaxSize));
 }
Beispiel #8
0
            if ($model->locCountry || $model->locRegion) {
                $adressFull .= ',&nbsp;';
            }
            $adressFull .= $model->locCity->getStrByLang('name');
        }
    } else {
        if (isset($model->city) && isset($model->city->name)) {
            $cityName = $model->city->name;
            if ($cityName) {
                $adressFull = ' ' . $cityName;
            }
        }
    }
    if ($model->canShowInView('address')) {
        if (issetModule('tariffPlans') && issetModule('paidservices')) {
            if (!Yii::app()->user->isGuest && TariffPlans::checkAllowShowAddress()) {
                $adressFull .= ', ' . CHtml::encode($model->getStrByLang('address'));
            }
        } else {
            $adressFull .= ', ' . CHtml::encode($model->getStrByLang('address'));
        }
    }
    if ($adressFull) {
        echo '<div><strong>' . tt('Address', 'apartments') . ':</strong> ' . $adressFull . '</div>';
    }
}
?>
</div>
<br />

<div>
Beispiel #9
0
 public static function checkDeactivateTariffUsers()
 {
     $activePaids = UsersTariffPlans::model()->findAll('date_end <= NOW() AND status=' . UsersTariffPlans::STATUS_ACTIVE);
     if ($activePaids) {
         $users = array();
         foreach ($activePaids as $paid) {
             $allow = true;
             $tariffInfo = TariffPlans::getFullTariffInfoById($paid->tariff_id);
             if ($tariffInfo && $tariffInfo['duration'] <= 0 && !$paid->setByAdmin) {
                 $allow = false;
             }
             if ($allow) {
                 $paid->status = UsersTariffPlans::STATUS_NO_ACTIVE;
                 if (!$paid->update(array('status'))) {
                     //deb($paid->getErrors());
                 }
                 $users[$paid->user_id] = $paid->user_id;
             }
         }
         if ($users) {
             TariffPlans::deactivateUserAdsByTariffPlan($users);
         }
     }
 }
Beispiel #10
0
            $cityName = $data->city->name;
            if ($cityName) {
                $adressFull = ' ' . $cityName;
            }
        }
    }
    $adress = CHtml::encode($data->getStrByLang('address'));
    if ($adress) {
        if (issetModule('tariffPlans') && issetModule('paidservices') && $data->owner_id != Yii::app()->user->id) {
            if (Yii::app()->user->isGuest) {
                $defaultTariffInfo = TariffPlans::getFullTariffInfoById(TariffPlans::DEFAULT_TARIFF_PLAN_ID);
                if (!$defaultTariffInfo['showAddress']) {
                    $adressFull = Yii::t('module_tariffPlans', 'Please <a href="{n}">login</a> to view', Yii::app()->controller->createUrl('/site/login'));
                } else {
                    $adressFull .= ', ' . $adress;
                }
            } else {
                if (TariffPlans::checkAllowShowAddress()) {
                    $adressFull .= ', ' . $adress;
                } else {
                    $adressFull = ' ' . Yii::t('module_tariffPlans', 'Please <a href="{n}">change the tariff plan</a> to view', Yii::app()->controller->createUrl('/tariffPlans/main/index'));
                }
            }
        } else {
            $adressFull .= ', ' . $adress;
        }
    }
    if ($adressFull) {
        echo '<dt>' . tt('Address') . ':</dt><dd>' . $adressFull . '</dd>';
    }
}
Beispiel #11
0
 public function actionBuyTariffPlan()
 {
     $this->layout = '//layouts/usercpanel';
     $user = HUser::getModel();
     $tariffId = Yii::app()->request->getParam('tariffid');
     if (!$user || !$tariffId) {
         throw404();
     }
     $currentTariffModel = TariffPlans::model()->findByPk($tariffId);
     if (!$currentTariffModel || $currentTariffModel->active != TariffPlans::STATUS_ACTIVE) {
         throw404();
     }
     // check current user tariff plan
     $currentTariffPlanInfo = TariffPlans::getTariffInfoByUserId($user->id);
     if ($currentTariffPlanInfo['issetTariff'] && $currentTariffPlanInfo['tariffDuration']) {
         if (!$currentTariffPlanInfo['activeTariff']) {
             Yii::app()->user->setFlash('error', Yii::t("module_tariffPlans", "You can only extend the tariff plan {name}", array("{name}" => $currentTariffPlanInfo['tariffName'])));
             $this->redirect(array('choosetariffplans'));
             Yii::app()->end();
         }
     }
     // check balance
     if ($currentTariffModel->price) {
         # платный тариф
         if ($currentTariffModel->price > $user->balance) {
             Yii::app()->user->setFlash('error', tt('On your balance is not enough money to buy the chosen tariff plan', 'tariffPlans'));
             $this->redirect(array('choosetariffplans'));
             Yii::app()->end();
         }
     }
     // check object count
     if ($currentTariffModel->limit_objects) {
         $usersObjects = TariffPlans::getCountUserObjects($user->id);
         if ($usersObjects > $currentTariffModel->limit_objects) {
             Yii::app()->user->setFlash('error', tt('The number of added ads exceeds the limit of the tariff. Remove its not relevant your ads and try again.', 'tariffPlans'));
             $this->redirect(array('choosetariffplans'));
             Yii::app()->end();
         }
     }
     // apply action
     $interval = 'INTERVAL ' . $currentTariffModel->duration . ' DAY';
     $dateEnd = new CDbExpression('NOW() + ' . $interval);
     if (TariffPlans::applyToUser($user->id, $tariffId, $dateEnd, $interval)) {
         if ($currentTariffModel->price) {
             # платный тариф
             $user->deductBalance($currentTariffModel->price);
         }
         Yii::app()->user->setFlash('success', tt('Tariff plan has been successfully applied', 'tariffPlans'));
         $this->redirect(array('tariffhistory'));
     } else {
         Yii::app()->user->setFlash('error', tc('Error. Repeat attempt later'));
         $this->redirect(array('choosetariffplans'));
         Yii::app()->end();
     }
 }
Beispiel #12
0
 <?php 
echo $owner->getLinkToAllListings();
?>
</div>
    <div class="intext">Телефон: </div><div class="ininfo"><?php 
if ($model->canShowInView('phone')) {
    if (issetModule('tariffPlans') && issetModule('paidservices') && $model->owner_id != Yii::app()->user->id) {
        if (Yii::app()->user->isGuest) {
            $defaultTariffInfo = TariffPlans::getFullTariffInfoById(TariffPlans::DEFAULT_TARIFF_PLAN_ID);
            if (!$defaultTariffInfo['showPhones']) {
                echo '' . Yii::t('module_tariffPlans', 'Please <a href="{n}">login</a> to view', Yii::app()->controller->createUrl('/site/login')) . '';
            } else {
                echo '<span id="owner-phone">' . CHtml::link(tc('Show phone'), 'javascript: void(0);', array('onclick' => 'generatePhone();')) . '</span>' . '';
            }
        } else {
            if (TariffPlans::checkAllowShowPhone()) {
                echo '<span id="owner-phone">' . CHtml::link(tc('Show phone'), 'javascript: void(0);', array('onclick' => 'generatePhone();')) . '</span>' . '';
            } else {
                echo '' . Yii::t('module_tariffPlans', 'Please <a href="{n}">change the tariff plan</a> to view', Yii::app()->controller->createUrl('/tariffPlans/main/index')) . '';
            }
        }
    } else {
        echo '<span id="owner-phone">' . CHtml::link(tc('Show phone'), 'javascript: void(0);', array('onclick' => 'generatePhone();')) . '</span>' . '';
    }
}
?>
</div>
    
    
    
    </div>
Beispiel #13
0
 public function actionIndex()
 {
     if (Yii::app()->user->isGuest) {
         throw404();
     }
     $this->setActiveMenu('my_payments');
     $request = Yii::app()->request;
     $ad_id = $request->getParam('id', 0);
     $paid_id = $request->getParam('paid_id');
     $isFancy = $request->getParam('isFancy', 0);
     $paySubmit = $request->getParam('pay_submit');
     $tariffId = $request->getParam('tariffid', 0);
     if ($paySubmit) {
         $optionId = $request->getParam('option_id');
         $paySystemId = $request->getParam('pay_id');
         $amount = $request->getParam('amount', 0);
         $error = 0;
         // Если это поплнение баланса
         if ($paid_id == PaidServices::ID_ADD_FUNDS && $amount <= 0) {
             $this->setActiveMenu('my_balance');
             Yii::app()->user->setFlash('error', tc('Please specify the amount of the payment'));
             $error = 1;
         }
         Yii::app()->getModule('payment');
         $paysystem = Paysystem::model()->findByPk($paySystemId);
         if (!$paysystem) {
             throw404();
         }
         # покупка тарифного плана
         if ($tariffId && issetModule('tariffPlans')) {
             $tariffPlanInfo = TariffPlans::getFullTariffInfoById($tariffId);
             $paidOption = new PaidOptions();
             $paidOption->id = 0;
             if (!$tariffPlanInfo || $tariffPlanInfo['active'] == TariffPlans::STATUS_INACTIVE) {
                 throw404();
             }
             if ($tariffPlanInfo['price'] && $tariffPlanInfo['price'] > 0) {
                 // Если оплата тарифа с баланса пользователя
                 if ($paySystemId == Paysystem::ID_BALANCE) {
                     $user = User::model()->findByPk(Yii::app()->user->id);
                     if ($user->balance < $tariffPlanInfo['price']) {
                         Yii::app()->user->setFlash('error', tc('Please refill the balance'));
                         $error = 2;
                         $this->redirect(array('/tariffPlans/main/index'));
                     }
                 }
             } else {
                 # бесплатный тариф
                 Yii::app()->user->setFlash('error', tt('Selected tariff plan is free. Please contact the site administrator for transit to this tariff.', 'tariffPlans'));
                 $error = 2;
                 $this->redirect(array('/tariffPlans/main/index'));
             }
         } else {
             if ($paid_id != PaidServices::ID_ADD_FUNDS) {
                 $ad = Apartment::model()->findByPk($ad_id);
                 $paidOption = PaidOptions::model()->findByPk($optionId);
                 if (!$ad || !$paidOption || !isset($paidOption->paidService)) {
                     throw404();
                 }
                 // Если оплата платной услуги с баланса пользователя
                 if ($paySystemId == Paysystem::ID_BALANCE) {
                     $user = User::model()->findByPk(Yii::app()->user->id);
                     if ($user->id != $ad->owner_id || $ad->deleted) {
                         throw404();
                     }
                     if ($user->balance < $paidOption->price) {
                         Yii::app()->user->setFlash('error', tc('Please refill the balance'));
                         $error = 2;
                     }
                 }
             }
         }
         $paysystem->createPayModel();
         if ($paysystem->payModel === null) {
             throw404();
         }
         if ($error == 0) {
             // Создаем платеж и ставим ему статус "Ожидает оплаты"
             $payment = new Payments();
             $payment->user_id = Yii::app()->user->id;
             $payment->paid_id = $paid_id;
             if ($paid_id != PaidServices::ID_ADD_FUNDS) {
                 $payment->paid_option_id = $paidOption->id;
             }
             $payment->apartment_id = $ad_id;
             $payment->tariff_id = $tariffId;
             if ($tariffId && issetModule('tariffPlans')) {
                 $payment->amount = $tariffPlanInfo['price'];
             } else {
                 $payment->amount = $paid_id == PaidServices::ID_ADD_FUNDS ? $amount : $paidOption->price;
             }
             $payment->currency_charcode = Currency::getDefaultCurrencyModel()->char_code;
             $payment->status = Payments::STATUS_WAITPAYMENT;
             $payment->paysystem_id = $paysystem->id;
             $payment->save();
             /*echo '<pre>';
             		print_r($payment->getErrors());
             		echo '</pre>';
             		exit;*/
             // Передаем платеж на обработку в модель платежки.
             // Приложение либо звершается (происходит редирект по нужному адресу),
             // либо выдает сообщение, которое будет отображено пользователю
             $return = $paysystem->payModel->processPayment($payment);
             switch ($return['status']) {
                 case Paysystem::RESULT_OK:
                     Yii::app()->user->setFlash('success', $return['message']);
                     $this->redirect(array('/usercpanel/main/payments'));
                     break;
                 case Paysystem::RESULT_NOTICE:
                     Yii::app()->user->setFlash('notice', $return['message']);
                     $this->redirect(array('/userads/main/update', 'id' => $payment->apartment_id));
                     break;
                 case Paysystem::RESULT_ERROR:
                     Yii::app()->user->setFlash('error', $return['message']);
                     $this->redirect(array('/userads/main/update', 'id' => $payment->apartment_id));
                     break;
                 default:
                     $this->render('result', array('payment' => $payment, 'paysystem' => $paysystem, 'message' => $return['message']));
             }
             echo 'Loading ... ';
             exit;
         }
     }
     if ($paid_id != PaidServices::ID_ADD_FUNDS) {
         $apartment = Apartment::model()->findByPk($ad_id);
         if ($apartment->active != Apartment::STATUS_ACTIVE || $apartment->owner_active != 1) {
             echo '<h2>' . tt('To apply a paid service for the listing, it should be active.', 'paidservices') . '</h2>';
             exit;
         }
     }
     $paidService = PaidServices::model()->findByPk($paid_id);
     if (!$paidService || !$paidService->active) {
         throw404();
     }
     if ($paid_id == PaidServices::ID_ADD_IN_SLIDER) {
         $img = Images::getMainImageData(null, $apartment->id);
         if (!$img) {
             Yii::app()->user->setFlash('error', tt('Error! You must upload the image for the ad.', 'paidservices'));
             if (!$isFancy) {
                 $this->redirect(array('/userads/main/update', 'id' => $ad_id));
             } else {
                 echo tt('Error! You must upload the image for the ad.', 'paidservices');
             }
             Yii::app()->end();
         }
     }
     if (!isset($user)) {
         $user = User::model()->findByPk(Yii::app()->user->id);
     }
     if ($isFancy || Yii::app()->request->isAjaxRequest) {
         $this->excludeJs();
         if ($tariffId && issetModule('tariffPlans')) {
             $this->redirect(array('/tariffPlans/main/index'));
         } else {
             $this->renderPartial('paidform', array('paidService' => $paidService, 'user' => $user, 'ad_id' => $ad_id, 'isFancy' => true), false, true);
         }
     } else {
         if ($tariffId && issetModule('tariffPlans')) {
             $this->redirect(array('/tariffPlans/main/index'));
         } else {
             $this->render('paidform', array('paidService' => $paidService, 'user' => $user, 'ad_id' => $ad_id, 'isFancy' => false));
         }
     }
 }
Beispiel #14
0
 public function complete()
 {
     if ($this->tariff_id) {
         # оплата за тарифный план
         $tariffInfo = TariffPlans::getFullTariffInfoById($this->tariff_id);
         if ($tariffInfo['duration']) {
             $interval = 'INTERVAL ' . $tariffInfo["duration"] . ' DAY';
         } else {
             $interval = 'INTERVAL 1460 DAY';
         }
         $dateEnd = new CDbExpression('NOW() + ' . $interval);
         TariffPlans::applyToUser($this->user_id, $this->tariff_id, $dateEnd, $interval);
     } else {
         if ($this->paid_id != PaidServices::ID_ADD_FUNDS) {
             $paidOption = $this->paidOption;
             $interval = 'INTERVAL ' . $paidOption->duration_days . ' DAY';
             $dateEnd = new CDbExpression('NOW() + ' . $interval);
             PaidServices::applyToApartment($this->apartment_id, $this->paid_id, $dateEnd, $interval);
         } else {
             $user = User::model()->findByPk($this->user_id);
             if (!$user) {
                 throw new CHttpException('Not user with ID ' . $this->user_id);
             }
             $user->addToBalance($this->amount);
         }
     }
     $this->status = Payments::STATUS_PAYMENTCOMPLETE;
     $this->update('status');
     return true;
 }