コード例 #1
0
ファイル: MainController.php プロジェクト: barricade86/raui
 public function actionAdmin()
 {
     $countNewsProduct = NewsProduct::getCountNoShow();
     if ($countNewsProduct > 0) {
         Yii::app()->user->setFlash('info', Yii::t('common', 'There are new product news') . ': ' . CHtml::link(Yii::t('common', '{n} news', $countNewsProduct), array('/news/backend/main/product')));
     }
     $this->rememberPage();
     $this->getMaxSorter();
     $this->getMinSorter();
     $model = new Apartment('search');
     $model->resetScope();
     $model->unsetAttributes();
     // clear any default values
     if (isset($_GET[$this->modelName])) {
         $model->attributes = $_GET[$this->modelName];
     }
     $model->setRememberScenario('ads_remember');
     $model = $model->with(array('user'));
     $this->params['paidServicesArray'] = array();
     if (issetModule('paidservices')) {
         $paidServices = PaidServices::model()->findAll('id != ' . PaidServices::ID_ADD_FUNDS);
         $this->params['paidServicesArray'] = CHtml::listData($paidServices, 'id', 'name');
     }
     $this->render('admin', array_merge(array('model' => $model), $this->params));
 }
コード例 #2
0
ファイル: MainController.php プロジェクト: barricade86/raui
 public function actionAddPaid($id = 0, $withDate = 0)
 {
     $model = new AddToAdForm();
     $paidServices = PaidServices::model()->findAll('id != ' . PaidServices::ID_ADD_FUNDS);
     $paidServicesArray = CHtml::listData($paidServices, 'id', 'name');
     $request = Yii::app()->request;
     $data = $request->getPost('AddToAdForm');
     if ($data) {
         $apartmentId = $request->getPost('ad_id');
         $withDate = $request->getPost('withDate');
         $model->attributes = $data;
         if ($model->validate()) {
             $apartment = Apartment::model()->findByPk($apartmentId);
             $paidService = PaidServices::model()->findByPk($model->paid_id);
             if (!$paidService || !$apartment) {
                 throw new CException('Not valid data');
             }
             if (PaidServices::applyToApartment($apartmentId, $paidService->id, $model->date_end)) {
                 echo CJSON::encode(array('status' => 'ok', 'apartmentId' => $apartmentId, 'html' => $apartment->getPaidHtml($withDate, true)));
                 Yii::app()->end();
             }
         } else {
             echo CJSON::encode(array('status' => 'err', 'html' => $this->renderPartial('_add_to_form', array('id' => $apartmentId, 'model' => $model, 'withDate' => $withDate, 'paidServicesArray' => $paidServicesArray), true)));
             Yii::app()->end();
         }
     }
     $renderData = array('id' => $id, 'model' => $model, 'withDate' => $withDate, 'paidServicesArray' => $paidServicesArray);
     if (Yii::app()->request->isAjaxRequest) {
         $this->renderPartial('_add_to_ad', $renderData);
     } else {
         $this->render('_add_to_ad', $renderData);
     }
 }
コード例 #3
0
ファイル: update.php プロジェクト: barricade86/raui
<h1 class="title highlight-left-right">
	<span><?php 
echo tt('Update apartment', 'apartments');
?>
</span>
</h1>
<div class="clear"></div><br />

<?php 
$this->pageTitle .= ' - ' . tt('Update apartment', 'apartments');
$this->breadcrumbs = array(Yii::t('common', 'Control panel') => array('/usercpanel/main/index'), tt('Update apartment', 'apartments'));
if (!Yii::app()->user->isGuest) {
    $menuItems = array(array('label' => tt('Manage apartments', 'apartments'), 'url' => array('/usercpanel/main/index')), array('label' => tt('Add apartment', 'apartments'), 'url' => array('create')), array('label' => tt('Delete apartment', 'apartments'), 'url' => '#', 'linkOptions' => array('submit' => array('delete', 'id' => $model->id), 'confirm' => tc('Are you sure you want to delete this item?'))));
} else {
    $menuItems = array();
}
if (issetModule('paidservices')) {
    $paidServices = PaidServices::model()->findAll('active = 1');
    foreach ($paidServices as $paid) {
        $menuItems[] = array('label' => $paid->name, 'url' => array('/paidservices/main/index', 'id' => $model->id, 'paid_id' => $paid->id), 'linkOptions' => array('class' => 'fancy'));
    }
}
$this->widget('CustomMenu', array('items' => $menuItems));
if (isset($show) && $show) {
    Yii::app()->clientScript->registerScript('scroll-to', '
			scrollto("' . CHtml::encode($show) . '");
		', CClientScript::POS_READY);
}
//$model->metroStations = $model->getMetroStations();
$this->renderPartial('_form', array('model' => $model, 'supportvideoext' => $supportvideoext, 'supportvideomaxsize' => $supportvideomaxsize));
コード例 #4
0
ファイル: PaidServices.php プロジェクト: barricade86/raui
 public static function getListForEdit()
 {
     return CHtml::listData(PaidServices::model()->findAll('id!=' . self::ID_ADD_FUNDS), 'id', 'name');
 }
コード例 #5
0
ファイル: Apartment.php プロジェクト: alexjkitty/estate
 public function getPaidHtml($withDateEnd = false, $withAddLink = false, $icon = false)
 {
     $content = '';
     $htmlArray = $issetPaids = array();
     # применённые платные услуги
     if (isset($this->paids)) {
         foreach ($this->paids as $apartmentPaid) {
             if (isset($apartmentPaid->paidService) && strtotime($apartmentPaid->date_end) > time()) {
                 $issetPaids[$apartmentPaid->paidService->id] = $apartmentPaid;
             }
         }
     }
     # все платные услуги
     $allPaidServices = PaidServices::model()->findAll('id != ' . PaidServices::ID_ADD_FUNDS . ' AND active = 1');
     if ($allPaidServices) {
         foreach ($allPaidServices as $service) {
             if (!Yii::app()->user->getState('isAdmin')) {
                 # пользователь
                 if (array_key_exists($service->id, $issetPaids)) {
                     $html = '<div class="paid_row">' . CHtml::link($icon ? $service->getImageIcon(tc('is valid till') . ' ' . $issetPaids[$service->id]->date_end) : $service->name, array('/paidservices/main/index', 'id' => $this->id, 'paid_id' => $service->id), array('class' => 'fancy'));
                     $html .= $withDateEnd ? '<span class="valid_till"> (' . tc('is valid till') . ' ' . $issetPaids[$service->id]->date_end . ')</span>' : '';
                     $html .= '</div>';
                 } else {
                     $html = '<div class="paid_row_no"><span class="boldText">' . CHtml::link($icon ? $service->getImageIcon() : $service->name, array('/paidservices/main/index', 'id' => $this->id, 'paid_id' => $service->id), array('class' => 'fancy')) . '</span>';
                     $html .= '</div>';
                 }
                 if (isset($html) && $html) {
                     $htmlArray[] = $html;
                     unset($html);
                 }
             } else {
                 # администратор
                 if (array_key_exists($service->id, $issetPaids) && $withDateEnd) {
                     $html = '<div class="paid_row"><span class="boldText">' . $service->name . '</span>';
                     $html .= $withDateEnd ? '<span class="valid_till"> (' . tc('is valid till') . ' ' . $issetPaids[$service->id]->date_end . ')</span>' : '';
                     $html .= '</div>';
                 }
                 if (isset($html) && $html) {
                     $htmlArray[] = $html;
                     unset($html);
                 }
             }
         }
     }
     if (count($htmlArray) > 0) {
         $content = implode('', $htmlArray);
     } else {
         $content = '<div class="paid_row">' . tc('No') . '</div>';
     }
     if (Yii::app()->user->getState('isAdmin') && $withAddLink) {
         $addUrl = Yii::app()->createUrl('/paidservices/backend/main/addPaid', array('id' => $this->id, 'withDate' => (int) $withDateEnd));
         $content .= CHtml::link(tc('Add'), $addUrl, array('class' => 'tempModal boldText', 'title' => tc('Apply a paid service to the listing')));
     }
     return CHtml::tag('div', array('id' => 'paid_row_el_' . $this->id), $content);
 }
コード例 #6
0
ファイル: MainController.php プロジェクト: barricade86/raui
 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));
         }
     }
 }