Example #1
0
 protected function initialize()
 {
     $this->config = $this->getDI()->get('config');
     $isClose = isset($_GET['close']) ? (bool) $_GET['close'] : true;
     if ((bool) $this->config->application->close && $isClose) {
         $this->forward("sample/error/countdown");
         return;
     }
     $this->view->setVar("controller", $this->dispatcher->getControllerName());
     $this->view->setVar("action", $this->dispatcher->getActionName());
     $this->view->setVar("module", $this->dispatcher->getModuleName());
     if ($this->di->has('user')) {
         $this->user = $this->di->get('user');
     } else {
         $this->user = null;
     }
     $cartDetail = CartController::getCartDetail();
     if (empty($cartDetail)) {
         $this->view->setVar('global_carts', array());
         $this->view->setVar('global_cart_totals', array());
         $this->view->setVar('global_cart_num', 0);
     } else {
         $this->view->setVar('global_carts', $cartDetail['carts']);
         $this->view->setVar('global_cart_totals', $cartDetail['totals_goods']);
         $this->view->setVar('global_cart_num', $cartDetail['totals_num']);
     }
     $this->view->setVar('login_user', $this->user);
 }
Example #2
0
 public function createAction()
 {
     $retVal = CartController::getCartDetail();
     if (empty($retVal)) {
         $this->flashJson(500);
         exit;
     }
     $carts = $retVal['carts'];
     foreach ($carts as $providerId => $cart) {
         $time = time("Y-m-d H:i:s");
         $order = array();
         $order['sn'] = $this->createGuid();
         $order['user_id'] = $this->user->id;
         $order['status'] = self::STATUS_UNPAY;
         $order['price'] = array_sum($retVal['totals_goods']) + array_sum($retVal['totals_shipments']);
         $order['detail'] = $cart->toJson();
         $order['addtime'] = $order['modtime'] = $time;
         $orderModel = new OrderModel();
         $orderModel->assign($order);
         $this->db->begin();
         if ($orderModel->save() == false) {
             foreach ($orderModel->getMessages() as $message) {
                 echo $message . PHP_EOL;
             }
             $this->db->rollback();
             $this->flashJson(500);
             exit;
         }
         foreach ($cart->getItemsAsArray() as $item) {
             $orderDetailModel = new OrderDetailModel();
             $orderDetailModel->user_id = $this->user->id;
             $orderDetailModel->order_id = $orderModel->id;
             $orderDetailModel->product_id = $item['id'];
             $orderDetailModel->product_name = $item['name'];
             $orderDetailModel->provider_id = $providerId;
             $orderDetailModel->qty = $item['qty'];
             $orderDetailModel->price = $item['price'];
             $orderDetailModel->discount = 1.0;
             $orderDetailModel->addtime = $orderDetailModel->modtime = $time;
             if ($orderDetailModel->save() == false) {
                 foreach ($orderDetailModel->getMessages() as $message) {
                     echo $message . PHP_EOL;
                 }
                 $this->db->rollback();
                 $this->flashJson(500);
                 exit;
             }
         }
         $this->db->commit();
     }
     CartController::destroyCart();
     $this->flashJson(200);
 }