Exemplo n.º 1
0
 /**
  * Creates a new ShopOrder model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     //禁止后台添加订单
     Yii::$app->session->setFlash('alert', ['body' => '后台不允许添加订单', 'options' => ['class' => 'alert alert-warning']]);
     $this->redirect('index', [302]);
     $model = new ShopOrder();
     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 actionShiWuOrder($slug)
 {
     $shopOrder = new ShopOrder();
     $shopProducts = ShopProduct::findOne(['slug' => $slug]);
     //myVarDump($shopOrder->validate());
     if ($shopOrder->load(\Yii::$app->request->post()) && $shopOrder->validate()) {
         $transaction = $shopOrder->getDb()->beginTransaction();
         $shopOrder->user_id = \Yii::$app->user->getId();
         $shopOrder->setOrderSn();
         $shopOrder->save(false);
         $shopOrderItem = new ShopOrderItem();
         $shopOrderItem->order_id = $shopOrder->id;
         $shopOrderItem->title = $shopProducts['title'];
         $shopOrderItem->price = $shopProducts['price'];
         $shopOrderItem->product_id = $shopProducts['id'];
         $shopOrderItem->quantity = 1;
         if (!$shopOrderItem->save(false)) {
             $transaction->rollBack();
             \Yii::$app->session->addFlash('error', '暂时不能处理您的订单!');
             return $this->redirect(['catalog/list']);
         }
         $transaction->commit();
         \Yii::$app->cart->removeAll();
         \Yii::$app->session->addFlash('success', '谢谢您的订单,我们会尽快处理!');
         $shopOrder->sendEmail();
         return $this->redirect(['product/my-order']);
     }
     return $this->render('shi-wu-order', ['shopOrder' => $shopOrder, 'shopProducts' => $shopProducts]);
 }