Example #1
0
 public function shipmentAction($productId = 0, $providerId = 0, $shipmentSeq = 1)
 {
     $productId = intval($productId);
     $providerId = intval($providerId);
     $shipmentSeq = intval($shipmentSeq);
     $productId = $productId > 0 ? $productId : $this->request->getPost("product_id", "int");
     $providerId = $providerId > 0 ? $providerId : $this->request->getPost("provider_id", "int");
     $shipmentSeq = $shipmentSeq > 0 ? $shipmentSeq : $this->request->getPost("shipment_seq", "int");
     if ($productId < 1 || $providerId < 1 || $shipmentSeq < 1 || $shipmentSeq > 3) {
         $this->flashJson(500, array(), "非法请求");
         exit;
     }
     $product = ProductModel::findFirst($productId);
     if (empty($product)) {
         $this->flashJson(500, array(), '抱歉,该商品不存在');
         exit;
     }
     $displayCart = self::getCart();
     if (empty($displayCart)) {
         $this->flashJson(500, array(), "非法请求");
         exit;
     }
     if (isset($displayCart[$providerId])) {
         $cart = $displayCart[$providerId];
     } else {
         $this->flashJson(500, array(), "过期请求");
         exit;
     }
     $provider = ProviderModel::findFirst("user_id={$providerId} AND product_id={$productId}");
     if (empty($provider)) {
         $this->flashJson(500, array(), "非法请求");
         exit;
     }
     $shipmentId = $provider->{"shipment_id_" . $shipmentSeq};
     if (!empty($provider->{"shipment" . $shipmentSeq})) {
         if ($cart->hasShipment($providerId . '-' . $providerId, false)) {
             $cart->unsetShipment($productId . '-' . $providerId, false);
         }
         $shipmentDetail = array('id' => $providerId . '-' . $productId, 'vendor' => $provider->{"shipment" . $shipmentSeq}->slug, 'method' => $provider->{"shipment" . $shipmentSeq}->method, 'price' => $provider->{"shipment_price_" . $shipmentSeq});
         $cartShipment = new Cart\Shipment();
         $cartShipment->importJson(json_encode($shipmentDetail));
         $cart->setShipment($cartShipment);
         $displayCart[$providerId] = $cart;
         self::putCart($displayCart);
         $this->flashJson(200);
     }
 }
Example #2
0
 public function providersAction()
 {
     if (!$this->user) {
         $this->flashJson(403);
         exit;
     }
     $providers = ProviderModel::find('user_id=' . $this->user->id);
     $this->view->setVar('providers', $providers);
 }