public function actionBuy() { if (!Auth::isLogged()) { $this->redirect("/"); } $abonems = AbonemModel::model()->findAll(); if (isset($_POST['abonem'])) { $abonem = AbonemModel::model()->where("`id`=" . (int) $_POST['abonem'])->findRow(); $userAbon = UserAbonemModel::model()->where("`user_id`='" . Auth::getUser()['id'] . "'")->findRow(); if (!$userAbon) { $userAbon = new UserAbonemModel(); $userAbon->user_id = Auth::getUser()['id']; $userAbon->end_date = date('Y-m-d', strtotime('+' . $abonem->months . ' month', strtotime('today'))); $userAbon->insert(); } else { if (strtotime($userAbon->end_date) > strtotime('today')) { $userAbon->end_date = date('Y-m-d', strtotime('+' . $abonem->months . ' month', strtotime($userAbon->end_date))); } else { $userAbon->end_date = date('Y-m-d', strtotime('+' . $abonem->months . ' month', strtotime('today'))); } $userAbon->update(); } Abonement::setAbonement(); $this->view("success", array("message" => Lang::get("abonement_success")), false); } $this->view("abonem/buy", array("abonems" => $abonems), false); }
public static function addMonths($abonem) { $userAbon = UserAbonemModel::model()->where("`user_id`='" . Auth::getUser()['id'] . "'")->findRow(); if (!$userAbon) { $userAbon = new UserAbonemModel(); $userAbon->user_id = Auth::getUser()['id']; //$userAbon->end_date = date('Y-m-d', strtotime('+' . $months . ' month', strtotime('today'))); if ($abonem->no_time == 1) { $abonem->months = 1000; $userAbon->end_date = date('Y-m-d', strtotime('+' . $abonem->months . ' month', strtotime('today'))); } elseif ($abonem->days != 0) { $userAbon->end_date = date('Y-m-d', strtotime('+' . $abonem->days . ' day', strtotime('today'))); } else { $userAbon->end_date = date('Y-m-d', strtotime('+' . $abonem->months . ' month', strtotime('today'))); } $userAbon->insert(); } else { if (strtotime($userAbon->end_date) > strtotime('today')) { $userAbon->end_date = date('Y-m-d', strtotime('+' . $abonem->months . ' month', strtotime($userAbon->end_date))); } else { $userAbon->end_date = date('Y-m-d', strtotime('+' . $abonem->months . ' month', strtotime('today'))); } $userAbon->update(); } self::setAbonement(); }