コード例 #1
0
ファイル: AgentController.php プロジェクト: Dionnit/Touristic
 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');
     }
 }
コード例 #2
0
ファイル: Orders.php プロジェクト: Dionnit/Touristic
 public function getOrderCalc()
 {
     return $this->hasOne(OrderCalc::className(), ['OrderID' => 'ID']);
 }