/**
  * Finds the PriceSertificate model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return PriceSertificate the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = PriceSertificate::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 public function actionSertificat()
 {
     $model = new Order();
     $city = City::find()->All();
     $arrCity = array();
     $error = array();
     $msg = array();
     $price_kids = PriceSertificate::findOne(["name" => "kids"]);
     $price_adult = PriceSertificate::findOne(["name" => "adult"]);
     if (count($city)) {
         foreach ($city as $val) {
             $arrCity[$val->id] = $val->name;
         }
     }
     $post = Yii::$app->request->post();
     if (isset($post["Order"])) {
         $post = $post["Order"];
         foreach ($post as $key => $value) {
             $model->{$key} = $value;
         }
         if ($post["id_city"] == "") {
             $error["id_city"] = 1;
         }
         if ($post["count_kids"] == "") {
             $error["count_kids"] = 1;
         }
         if ($post["count_adult"] == "") {
             $error["count_adult"] = 1;
         }
         if (count($error) == 0) {
             $session = Yii::$app->session;
             $model->date = time();
             $model->type_ticket = $_REQUEST["type_ticket"];
             $model->id_user = Yii::$app->user->id;
             $model->save();
             $model_id = $model->id;
             $session["order_id"] = $model_id;
             $order = Order::findOne($model_id);
             if (isset($_REQUEST["pay"])) {
                 if ($ch = @curl_init()) {
                     $url = Url::base("http") . "/index.php?r=online-pay/finish&orderId=" . $order->id;
                     $id_order = $order->id;
                     $amount = (int) $_REQUEST["Order"]["summ"] * 100;
                     @curl_setopt($ch, CURLOPT_URL, 'https://securepayments.sberbank.ru/payment/rest/register.do?userName=masterslavl-api&password=shrjkisi&orderNumber=' . $id_order . '&amount=' . $amount . '&returnUrl=' . $url);
                     @curl_setopt($ch, CURLOPT_HEADER, false);
                     @curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                     @curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
                     @curl_setopt($ch, CURLOPT_USERAGENT, 'Masterslavl');
                     $data = @curl_exec($ch);
                     $dt = json_decode($data);
                     @curl_close($ch);
                     if (isset($dt->orderId)) {
                         if (isset($_REQUEST["date_enter"])) {
                             $order->date = strtotime($_REQUEST["date_enter"]);
                             $order->save();
                         }
                         $order->summ = $amount;
                         $order->bankOrderId = $dt->orderId;
                         $order->bankFormUrl = $dt->formUrl;
                         $order->save();
                         $this->redirect($dt->formUrl);
                     } elseif ($order->bankFormUrl != "") {
                         $this->redirect($order->bankFormUrl);
                     }
                 }
             }
         }
     }
     $options_tiket = GeneralOptions::findOne(["name" => "gen_options_tikets"]);
     $opt_val = $options_tiket->value;
     $TypeHours = TypeHours::find()->where(["options" => $opt_val])->all();
     foreach ($TypeHours as $val) {
         $type_hours[$val->id] = $val->value;
     }
     return $this->render('sertificat', ['model' => $model, 'p_kids' => $price_kids, 'p_adult' => $price_adult]);
 }