Ejemplo n.º 1
0
 public function actionCreate($id)
 {
     $this->layout = 'column2';
     try {
         $createOrderForm = new CreateOrderForm($id);
     } catch (InvalidParamException $e) {
         throw new BadRequestHttpException($e->getMessage());
     }
     if ($createOrderForm->load(Yii::$app->request->post()) && $createOrderForm->validate()) {
         try {
             Yii::info('用户开始创建订单,用户id:' . Yii::$app->user->id);
             if ($createOrderForm->create(false)) {
                 Yii::info("用户创建订单成功!订单号:{$createOrderForm->order->order_sn}");
                 if ($createOrderForm->payment === Order::PAYMENT_ONLINE) {
                     Yii::$app->session->setFlash('success', '订单创建成功!');
                     return $this->redirect(['pay', 'order' => $createOrderForm->order->order_sn]);
                 } else {
                     if ($createOrderForm->store->enable_sms && !empty($createOrderForm->store->cellphone)) {
                         Yii::$app->smser->send($createOrderForm->store->cellphone, "亲爱的店长,刚刚有人下了订单,订单号为{$createOrderForm->order->order_sn},请您快去查看。");
                     }
                     return $this->render('create-success', ['order' => $createOrderForm->order]);
                 }
             } else {
                 Yii::error('用户创建订单失败!用户id:' . Yii::$app->user->id);
                 Yii::$app->session->setFlash('danger', '订单创建失败!');
             }
         } catch (\Exception $e) {
             Yii::error('用户创建订单失败!用户id:' . Yii::$app->user->id . ' 错误信息:' . $e->getMessage());
             Yii::$app->session->setFlash('danger', $e->getMessage());
         }
     }
     return $this->render('create', ['createOrderForm' => $createOrderForm, 'store' => $createOrderForm->store, 'cartGoodsList' => $createOrderForm->cartGoodsList, 'addressList' => $createOrderForm->addressList]);
 }
Ejemplo n.º 2
0
 public function actionCreate($id)
 {
     try {
         $createOrderForm = new CreateOrderForm($id);
     } catch (InvalidParamException $e) {
         throw new BadRequestHttpException($e->getMessage());
     }
     if (Yii::$app->request->method === 'GET') {
         return ['fee' => Yii::$app->user->identity->getCartGoodsRealVolume($id), 'store' => $createOrderForm->store, 'cartGoodsList' => $createOrderForm->cartGoodsList, 'addressList' => $createOrderForm->addressList, 'preferentialItems' => $createOrderForm->preferentialItems, 'bookTimeItems' => $createOrderForm->bookTimeItems];
     } else {
         if ($createOrderForm->load(Yii::$app->request->post(), '') && $createOrderForm->validate()) {
             try {
                 Yii::info('用户开始创建订单,用户id:' . Yii::$app->user->id);
                 if ($createOrderForm->create(false)) {
                     Yii::info("用户创建订单成功!订单号:{$createOrderForm->order->order_sn}");
                     if ($createOrderForm->payment === Order::PAYMENT_ONLINE) {
                     } else {
                         if ($createOrderForm->store->enable_sms && !empty($createOrderForm->store->cellphone)) {
                             Yii::$app->smser->send($createOrderForm->store->cellphone, "亲爱的店长,刚刚有人下了订单,订单号为{$createOrderForm->order->order_sn},请您快去查看。");
                         }
                     }
                     return ['status' => 'success', 'data' => ['id' => $createOrderForm->order->id, 'orderSn' => $createOrderForm->order->order_sn, 'payment' => $createOrderForm->order->payment]];
                 } else {
                     Yii::error('用户创建订单失败!用户id:' . Yii::$app->user->id);
                 }
             } catch (\Exception $e) {
                 Yii::error('用户创建订单失败!用户id:' . Yii::$app->user->id . ' 错误信息:' . $e->getMessage());
                 return ['status' => 'fail', 'data' => ['errors' => [$e->getMessage()]]];
             }
         }
         return ['status' => 'fail', 'data' => ['errors' => $createOrderForm->getFirstErrors() ?: ['订单创建失败!']]];
     }
 }