コード例 #1
0
ファイル: UserController.php プロジェクト: luoshulin/falcon
 public function orderlistAction()
 {
     if (!$this->user) {
         $this->flashJson(403);
         exit;
     }
     $orderlist = OrderModel::find('user_id=' . $this->user->id);
     $this->view->setVar('orderlist', $orderlist);
 }
コード例 #2
0
ファイル: OrderController.php プロジェクト: luoshulin/falcon
 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);
 }