コード例 #1
0
 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));
 }
コード例 #2
0
ファイル: MainController.php プロジェクト: barricade86/raui
 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();
     }
 }