/**
  * @return string
  */
 public function actionSendorder()
 {
     $session = Yii::$app->session;
     $session->open();
     $model = new Orders();
     $query = new Query();
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         $model->total_sum = $_SESSION['total_price'];
         $model->date = date('d-m-Y');
         $model->time = Yii::$app->getFormatter()->asTime(time());
         $id = array_keys($_SESSION['cart']);
         $model->complite = 0;
         for ($i = 0; $i < count($id); $i++) {
             $products[] = $query->select('title')->from('data')->where(['id' => $id[$i]])->one();
             $products[$i]['quantity'] = $_SESSION['cart'][$id[$i]]['quant'];
         }
         $model->adres = strip_tags($model->adres);
         $model->product = serialize($products);
         $model->save();
         //				$session->destroy();
         //////
         $mrh_login = Yii::$app->params['mrh_login'];
         $mrh_pass1 = Yii::$app->params['mrh_pass1'];
         $inv_id = $model->id;
         $inv_desc = Yii::$app->params['inv_desc'];
         $out_summ = $model->total_sum;
         $crc = md5("{$mrh_login}:{$out_summ}:{$inv_id}:{$mrh_pass1}");
         return $this->render('pay', ['name' => $model->name, 'out_summ' => $out_summ, 'mrh_login' => $mrh_login, 'inv_id' => $inv_id, 'inv_desc' => $inv_desc, 'crc' => $crc]);
     } else {
         return $this->render('error', ['message' => "Ошибка приложения!"]);
     }
 }
Example #2
0
 /**
  * Creates a new Orders model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Orders();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->orderID]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Example #3
0
 /**
  * Creates a new Orders model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $industry = Yii::$app->request->get('industry');
     $process = Yii::$app->request->get('process');
     if (Yii::$app->session['cart'] != null && ($industry != null || $process != null)) {
         foreach (Yii::$app->session['cart']['industry'] as $key => $ind) {
             if ($key == $industry) {
                 $cart[$key] = $ind;
             }
         }
         $service = \common\models\CsServices::findOne($cart[$industry]['data'][1]['service']);
         $objects = $this->getObjectModels($cart[$industry]['data'][1]['object_models']);
         $user = !Yii::$app->user->isGuest ? \common\models\User::findOne(Yii::$app->user->id) : null;
         // orderer
         $model = new Orders();
         $model->service = $service;
         // skill model
         $model_skill = $this->loadServiceSkills($service);
         $location = new Locations();
         $location->control = $service->location;
         $location->userControl = Yii::$app->user->isGuest ? 0 : 1;
         $location_end = new Locations();
         $new_user = $user == null ? Yii::createObject(RegistrationProviderForm::className()) : null;
         // register provider
         $returning_user = $user == null ? Yii::createObject(LoginForm::className()) : null;
         // login existing user
         if ($model->load(Yii::$app->request->post())) {
             if (Yii::$app->user->isGuest) {
                 // register $ login user
                 if ($new_user->load(Yii::$app->request->post())) {
                     if ($user = $new_user->signup()) {
                         if (!Yii::$app->getUser()->login($user)) {
                             return $this->goBack();
                         }
                     }
                 }
                 // login user
                 if ($returning_user->load(Yii::$app->request->post())) {
                     if (!$returning_user->login()) {
                         return $this->goBack();
                     }
                 }
             }
             // continue
             $activity = Activities::loadActivity(Yii::$app->user->id);
             if ($activity->save()) {
                 // new activity saved
                 $model->activity_id = $activity->id;
                 $this->saveOrderLocation($model, $location, $service);
                 $this->saveOrderEndLocation($model, $location_end, $service);
                 if ($model->save()) {
                     $this->saveOrderSkills($model, $cart, $service);
                     $this->saveOrderServices($model, $activity, $cart, $service);
                     $this->eraseSessionData($industry);
                     // izbaci snimljene usluge iz korpe
                     return $this->redirect('/order/' . $model->id);
                 }
             } else {
                 return $this->redirect('/services');
             }
             return $this->redirect('/services');
         } else {
             return $this->render('create', ['service' => $service, 'model' => $model, 'model_skills' => $model_skill, 'location' => $location, 'location_end' => $location_end, 'objects' => $objects, 'new_user' => $new_user, 'returning_user' => $returning_user]);
         }
     } else {
         return $this->redirect('/services');
     }
 }