/**
  * Creates a new Reservation model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Reservation();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Esempio n. 2
0
 public function actionOrder()
 {
     $roomId = Yii::$app->request->get('id', null);
     //echo Yii::$app->user->getId();
     if ($roomId != null) {
         $newReservaion = new Reservation();
         $newReservaion->room_id = $roomId;
         $newReservaion->customer_id = Yii::$app->user->getId();
         $newReservaion->price_per_day = Room::findOne($roomId)->price_per_day;
         $newReservaion->date_from = date('Y-m-d');
         $newReservaion->date_to = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d") + 1, date("Y")));
         $newReservaion->reservation_date = date('Y-m-d H:i:s');
         //var_dump($newReservaion);
         if ($newReservaion->save()) {
             return $this->render('order', ['reservation' => $newReservaion]);
         }
     }
     echo "下订单失败";
 }
Esempio n. 3
0
 public function actionCreateCustomerAndReservation()
 {
     $customer = new Customer();
     $reservation = new Reservation();
     $reservation->customer_id = 1;
     if ($customer->load(Yii::$app->request->post()) && $customer->validate() && $reservation->load(Yii::$app->request->post()) && $reservation->validate()) {
         $dbTrans = Yii::$app->db->beginTransaction();
         $customerSaved = $customer->save();
         if ($customerSaved) {
             $reservation->customer_id = $customer->id;
             $reservationSaved = $reservation->save();
             if ($reservationSaved) {
                 $dbTrans->commit();
                 $this->redirect(['grid']);
             } else {
                 $dbTrans->rollBack();
             }
         } else {
             $dbTrans->rollBack();
         }
     }
     return $this->render('createCustomerAndReservation', compact('customer', 'reservation'));
 }
 public function actionCreateCustomerAndReservation()
 {
     $customer = new \app\models\Customer();
     $reservation = new \app\models\Reservation();
     // It is useful to set fake customer_id to reservation model to avoid validationerror (because customer_id is mandatory)
     $reservation->customer_id = 0;
     if ($customer->load(Yii::$app->request->post()) && $reservation->load(Yii::$app->request->post()) && $customer->validate() && $reservation->validate()) {
         $dbTrans = Yii::$app->db->beginTransaction();
         $customerSaved = $customer->save();
         if ($customerSaved) {
             $reservation->customer_id = $customer->id;
             $reservationSaved = $reservation->save();
             if ($reservationSaved) {
                 $dbTrans->commit();
             } else {
                 $dbTrans->rollback();
             }
         } else {
             $dbTrans->rollback();
         }
     }
     return $this->render('createCustomerAndReservation', ['customer' => $customer, 'reservation' => $reservation]);
 }