Example #1
0
 /**
  * Creates a new Order model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Order();
     $session = Yii::$app->session;
     if ($model->load(Yii::$app->request->post())) {
         $model->setIsNewRecord(true);
         $model->createTime = date('Y-m-d H:i:s');
         $model->session = $session->get('session_order');
         $model->fullCost = $session->get('fullcost');
         $model->save();
         $fullCart = $session['cart'];
         $fioCart = $session['cart_fio'];
         if ($fullCart && $fioCart) {
             for ($i = 0; $i < $session->get('cards'); $i++) {
                 $inOrder = new Inorder();
                 $inOrder->setIsNewRecord(true);
                 $inOrder->orderID = $model->id;
                 $inOrder->cardID = $session['cart'][$i];
                 $thisCard = Cards::find()->where(['id' => $session['cart'][$i]])->one();
                 $inOrder->cost = $thisCard->cost;
                 $inOrder->fio = $session['cart_fio'][$i];
                 $inOrder->save();
             }
         }
         $session->remove('cards');
         $session->remove('session_order');
         $session->remove('cart');
         $session->remove('fullcost');
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
 public function actionOrder()
 {
     $order = new Order();
     $products = $this->_cart->getPositions();
     $total = $this->_cart->getCost();
     if ($order->load(\Yii::$app->request->post()) && $order->validate()) {
         $order->user_id = 1;
         $order->cart_id = "text";
         if ($order->save(false)) {
             foreach ($products as $product) {
                 $orderItem = new OrderItem();
                 $orderItem->order_id = $order->id;
                 $orderItem->product_id = $product->id;
                 $orderItem->price = $product->getPrice();
                 $orderItem->quantity = $product->getQuantity();
                 if (!$orderItem->save(false)) {
                     \Yii::$app->session->addFlash('error', 'Cannot place your order. Please contact us.');
                     return $this->redirect('site/index');
                 }
             }
         }
         $this->_cart->removeAll();
         \Yii::$app->session->addFlash('success', 'Thanks for your order. We\'ll contact you soon.');
         //$order->sendEmail();
         return $this->redirect('site/index');
     }
     return $this->render('order', ['order' => $order, 'products' => $products, 'total' => $total]);
 }
Example #3
0
 public function actionPayment()
 {
     if (\Yii::$app->session->has('customer')) {
         $modelCustomer = new Customer();
         $infoCustomer = $modelCustomer->getInformation($_SESSION['customer']);
         $modelOrder = new Order();
         $modelOrderDetail = new OrderDetail();
         $modelProduct = new Product();
         $ids = array();
         foreach ($_SESSION['cart_items'] as $id => $quantity) {
             array_push($ids, $id);
         }
         $products = $modelProduct->getWithIDs($ids);
         if (\Yii::$app->request->post()) {
             $modelOrder->load(\Yii::$app->request->post());
             $modelOrder->save();
             $orderId = $modelOrder->id;
             foreach ($_SESSION['cart_items'] as $id => $quantity) {
                 $unitPrice = $modelProduct->getPrice($id) * $quantity;
                 \Yii::$app->db->createCommand()->insert('order_detail', ['orderId' => $orderId, 'productId' => $id, 'unitPrice' => $unitPrice, 'quantity' => $quantity])->execute();
             }
             \Yii::$app->session->remove('cart_items');
             return $this->redirect(['cart/index', 'success' => 'Thanh toán thành công! Chúng tôi sẽ liên hệ bạn trong thời gian sớm nhất! Xin cảm ơn!']);
         } else {
             return $this->render('payment', ['infoCustomer' => $infoCustomer, 'modelOrder' => $modelOrder, 'products' => $products]);
         }
     } else {
         $this->redirect(['customer/login', 'error' => 'Vui lòng đăng nhập trước khi thanh toán']);
     }
 }
 /**
  * Creates a new Order model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Order();
     $modelItems = [new OrderDetail()];
     $customers_model = new Customers();
     $modelUser = new User();
     $model->scenario = 'managerAdd';
     $good_base = $customers_model->find()->where(['isWork' => 1])->orderBy('id')->asArray()->all();
     $customers_base = $arr_keys = $arr_vals = array();
     foreach ($good_base as $key => $value) {
         array_push($arr_keys, $value["id"]);
         array_push($arr_vals, $value["customerName"]);
     }
     $customers_base = array_combine(array($arr_keys), array($arr_vals));
     if ($model->load(Yii::$app->request->post())) {
         $modelItems = OrderDetail::createMultiple(OrderDetail::classname());
         // $modelItems = Model::createMultiple(OrderDetail::classname());
         Model::loadMultiple($modelItems, Yii::$app->request->post());
         // ajax validation
         if (Yii::$app->request->isAjax) {
             Yii::$app->response->format = Response::FORMAT_JSON;
             return ArrayHelper::merge(ActiveForm::validateMultiple($modelItems), ActiveForm::validate($model));
         }
         // validate all models
         $valid = $model->validate();
         echo "==model valid  " . $valid . "  <br/>";
         $valid = print_r(Model::validateMultiple($modelItems)) && $valid;
         echo "==model items valid  " . print_r(Model::validateMultiple($modelItems)) . "  <br/>";
         if ($valid) {
             $transaction = \Yii::$app->db->beginTransaction();
             echo "==(trasaction) start<br/>";
             try {
                 if ($flag = $model->save(false)) {
                     echo "==(trasaction) model saved<br/>";
                     foreach ($modelItems as $modelItem) {
                         echo "==(trasaction) item saved<br/>";
                         $modelItem->orderId = $model->orderId;
                         if (!($flag = $modelItem->save(false))) {
                             $transaction->rollBack();
                             break;
                         }
                     }
                 }
                 if ($flag) {
                     $transaction->commit();
                     echo "==(trasaction) commit<br/>";
                     return $this->redirect(['view', 'id' => $model->orderId]);
                     echo "==(trasaction) start redirect<br/>";
                 }
             } catch (Exception $e) {
                 echo "==(trasaction) rollback and exception<br/>";
                 $transaction->rollBack();
             }
         }
     }
     return $this->render('create', ['model' => $model, 'modelItems' => empty($modelItems) ? [new OrderDetail()] : $modelItems, 'customers_base' => $customers_base]);
 }
Example #5
0
 /**
  * Creates a new Order model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Order();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->order_id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Example #6
0
 /**
  * Creates a new Order model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     if (Yii::$app->user->isGuest || Yii::$app->user->identity->user_role != 4 && Yii::$app->user->identity->user_role != 3 && Yii::$app->user->identity->user_role != 2 && Yii::$app->user->identity->user_role != 1) {
         return $this->goHome();
     }
     $model = new Order(['scenario' => Order::SCENARIO_CREATE]);
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->order_id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Example #7
0
 public function actionCreate()
 {
     $model = new Order();
     if ($model->load(Yii::$app->request->getBodyParams(), '')) {
         $model->file = UploadedFile::getInstance($model, 'file');
         var_dump(Yii::$app->request->getBodyParams());
         Yii::$app->end();
         if ($model->file != null) {
             $model->file->saveAs('img/orders/' . $model->file->name);
             $model->picture = 'img/orders/' . $model->file->name;
         }
         if ($model->save()) {
             return ['success' => true];
         }
     } else {
         return $model;
     }
 }
 /**
  * Creates a new Order model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate($build_id)
 {
     $model = new Order();
     $model->build_fk = $build_id;
     $build = $model->getBuildFk()->one();
     //$build2 = $this->findBuild($build_id);
     $parts = new ActiveDataProvider(['query' => $build->getParts(), 'sort' => false]);
     $address = $this->getAddress($build->user_fk);
     //$model->build_fk = $build->build_guide_id;
     $model->customer_fk = $build->user_fk;
     $model->status_fk = Order::STAT_PENDING;
     $model->date_of_order = date("Y-m-d H:i:s");
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->order_id]);
     } else {
         return $this->render('create', ['model' => $model, 'build' => $build, 'parts' => $parts, 'address' => $address]);
     }
 }
Example #9
0
 /**
  * Creates a new Order model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Order();
     $model->load(Yii::$app->request->post());
     $model->order_user_id = Yii::$app->user->identity->id;
     if ($model->save()) {
         $request = Yii::$app->request;
         if (isset($request->post()['Order']['order_items'])) {
             $items = $request->post()['Order']['order_items'];
             foreach ($items as $key => $val) {
                 $order_item = new OrderItem();
                 $order_item->item_id = $key;
                 $order_item->count = $val;
                 $order_item->order_id = $model->order_id;
                 $order_item->save();
             }
         }
         return $this->redirect(['view', 'id' => $model->order_id]);
     } else {
         return $this->render('create', ['model' => $model, 'locations' => $this->getAllLocations(), 'all_menu' => $this->getAllMenu(), 'addons' => Item::find()->asArray()->where(['item_type' => Item::ADDON_TYPE])->all()]);
     }
 }
Example #10
0
 public function actionOrder($id)
 {
     $this->layout = 'page';
     $model = new Order();
     $categories = Category::findAll(['status' => Category::STATUS_ENABLED]);
     $product = Product::find()->where(['id' => $id, 'status' => Product::STATUS_ENABLED])->limit(1)->one();
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         $order = new Order();
         $order->key = strtoupper(Yii::$app->security->generateRandomString(6));
         $order->name = $product->name;
         $order->thumbnail = $product->thumbnail;
         $order->price = $product->price;
         $order->count = $model->count;
         $order->email = $model->email;
         $order->message = $model->message;
         $order->date = time();
         $order->insert();
         Yii::$app->session->set('orderID', $order->id);
         return $this->redirect(['product/confirm']);
     } else {
         return $this->render('order', ['model' => $model, 'categories' => $categories, 'product' => $product]);
     }
 }
 public function actionCreateany()
 {
     $model = new Order();
     if ($model->load(Yii::$app->request->post())) {
         $model->order_amount = number_format($model->number_bales * 4.5, 2, '.', '');
         if ($model->save()) {
             return $this->redirect(['index', 'id' => $model->id]);
         } else {
             return $this->render('create', ['model' => $model]);
         }
     } else {
         $scoutlist = ArrayHelper::map(Scout::find()->all(), 'id', 'name');
         return $this->render('create', ['model' => $model, 'scoutlist' => $scoutlist]);
     }
 }
Example #12
0
 public function actionGuestCreate()
 {
     $model = new Order();
     if ($model->load(Yii::$app->request->post())) {
         $model->scenario = 'create';
         $model->create_time = date('Y-m-d H:i:s');
         $model->uid = 0;
         $model->statu = Order::$_AUDIT_PEND;
         $commodityOrderDetail = (new Query())->select('*')->from(CommodityOrder::tableName())->leftJoin(CommodityOrderDetail::tableName(), CommodityOrderDetail::tableName() . '.coid = ' . CommodityOrder::tableName() . '.id')->where('commodity_id = :commodity_id and entrance = :entrance', [':commodity_id' => $model->commodity, ':entrance' => $model->entrance])->one();
         $model->shop = $commodityOrderDetail['shop'];
         $model->fee = $commodityOrderDetail['fee'];
         if ($model->save()) {
             echo "\t<meta charset='utf-8'>";
             echo "<script>alert('提交成功')</script>";
             $model = new Order();
         }
     }
     return $this->render('create', array('model' => $model));
 }