Exemplo n.º 1
0
 public function actionIndexadd()
 {
     if (Yii::$app->user->isGuest) {
         $model = new LoginForm();
         if ($model->load(Yii::$app->request->post()) && $model->login()) {
             return $this->goBack();
         } else {
             return $this->render('/site/login', ['model' => $model]);
         }
     } else {
         $Order = new Order();
         $Order->user_id = Yii::$app->user->identity->id;
         $Order->date_time = date('Y-m-d H:i:s');
         $Order->status_id = '1';
         $Order->save();
         $Card = new CardList();
         $Products = $Card->getCardAndCardList(Yii::$app->user->identity->id);
         $Ord = new Order();
         $order_id = $Ord->GetOrderId(Yii::$app->user->identity->id);
         for ($i = 0; $i < sizeof($Products); $i++) {
             $Orderlist = new Orderlist();
             $Orderlist->order_id = $order_id[0]['MAX(`order_id`)'];
             $Orderlist->product_id = $Products[$i]['product_id'];
             $Orderlist->quantity = $Products[$i]['quantity'];
             $Orderlist->save();
         }
         $card = new Card();
         $card->DeleteCardId(Yii::$app->user->identity->id);
         $order = $Ord->GetOrdersFromID(Yii::$app->user->identity->id);
         $user = User::find()->where(['id' => Yii::$app->user->identity->id])->one();
         return $this->render('index', ['user' => $user, 'order' => $order]);
     }
 }