Exemplo n.º 1
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->ID]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Exemplo n.º 2
0
 public function actionCreate($type = null, $id = null)
 {
     $request = Yii::$app->request;
     //Проверяем наличие параметров
     if ((!$type || !$id) && $request->isGet) {
         return $this->goBack();
     }
     if ($request->isPost) {
         $post = $request->post();
         //print_r($post);die;
         $mainContact = '';
         foreach ($post['tourist'] as $key => $value) {
             //print_r($value);die;
             // Записываем туристов в контакты
             $model = new Contact(['Name' => $value['name'], 'SurName' => $value['surName'], 'CreatedOn' => date('Y-m-d H:i:s.z', time())]);
             $model->save();
             $lastContactId = Yii::$app->db2->createCommand("SELECT ID FROM {{%Contact}} ORDER BY CreatedOn DESC")->queryOne();
             $lastContactId = $lastContactId['ID'];
             if ($key == '0') {
                 $mainContact = $lastContactId;
             }
             // Записываем паспортные данные
             $model = new ContactPassport(['Name' => $value['name'], 'SurName' => $value['surName'], 'CreatedOn' => date('Y-m-d H:i:s.z', time()), 'Series' => $value['series'], 'Number' => $value['number'], 'Granted' => $value['granted'], 'ContactID' => $lastContactId, 'CreatedOn' => date('Y-m-d H:i:s.z', time())]);
             $model->save();
         }
         // Создаем заявку
         $model = new Orders(['ContactID' => $mainContact, 'CreatedOn' => date('Y-m-d H:i:s.z', time()), 'Status' => '99a1047e-1078-4d26-b5b2-b4abffff4160', 'CustomerAccountID' => Yii::$app->user->identity->companyId]);
         $model->save();
         $lastOrderId = Yii::$app->db2->createCommand("SELECT ID FROM {{%Orders}} ORDER BY CreatedOn DESC")->queryOne();
         $lastOrderId = $lastOrderId['ID'];
         // Привязываем тур или отель
         if ($post['type'] == 'hotel') {
             /* Привязвваем отель */
             $hotelPriceId = HotelPartner::findOne(['HotelID' => $post['id']]);
             if ($hotelPriceId) {
                 $hotelPriceId = $hotelPriceId->hotelPrice['ID'];
             }
             $model = new OrderCalc(['OrderID' => $lastOrderId, 'HotelPriceID' => $hotelPriceId]);
             $model->save();
         } else {
             /* Привязвваем тур */
             $model = new TourPriceMain(['ID' => $post['id']]);
             $model->save();
             $model = new OrderCalc(['TourID' => $post['id'], 'OrderID' => strtolower($lastOrderId)]);
             $model->save();
         }
         return $this->redirect(Url::to(['agent/list']));
     } else {
         return $this->render('create');
     }
 }