コード例 #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]);
     }
 }
コード例 #2
0
 public function actionAdd()
 {
     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 {
         if (isset($_GET['id'])) {
             $request = Yii::$app->request;
             $id = $request->get('id');
             $product = Product::find()->where(['product_id' => $id])->one();
             $card = new Card();
             $customer = Card::find()->where(['user_id' => Yii::$app->user->identity->id])->one();
             if (is_null($customer)) {
                 $card->user_id = Yii::$app->user->identity->id;
                 $card->date_time = date('Y-m-d H:i:s');
                 $card->save();
             }
             $customer = Card::find()->where(['user_id' => Yii::$app->user->identity->id])->one();
             $cardlist = new CardList();
             $num = $cardlist->CheckNumberOfProducts($customer['card_id'], $id);
             if (!$num) {
                 $cardlist->product_id = $id;
                 $cardlist->quantity = '1';
                 $cardlist->card_id = $customer['card_id'];
                 $cardlist->save();
             } else {
                 $cardlist->AddQuantity($customer['card_id'], $id);
             }
             return $this->render('index', ['product' => $product]);
         } else {
             return $this->goHome();
         }
     }
 }
コード例 #3
0
ファイル: CardList.php プロジェクト: keszfeayym/Nzi_Project
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCard()
 {
     return $this->hasOne(Card::className(), ['card_id' => 'card_id']);
 }