Example #1
0
 public function removeAction()
 {
     if (!$this->user) {
         $this->flashJson(403);
         return;
     }
     $productId = $this->request->getPost("product_id", "int");
     if ($productId < 1) {
         $this->flashJson(500, array(), "非法请求");
         return;
     }
     $productModel = ProductModel::findFirst($productId);
     if (empty($productModel)) {
         $this->flashJson(500, array(), "商品不存在");
         return;
     }
     $model = WishlistModel::findFirst("user_id=" . $this->user->id . " AND product_id=" . $productId);
     if (!empty($model)) {
         if ($model->delete() == false) {
             $this->flashJson(500, array('type' => 'remove'), "数据库delete失败");
             return;
         }
     }
     $wishlistModel = WishlistModel::find("product_id=" . $productId);
     $this->flashJson(200, array('type' => 'remove', 'count' => $wishlistModel->count()));
     return;
 }
Example #2
0
 public function homeAction()
 {
     if (!$this->user) {
         $this->flashJson(403);
         exit;
     }
     $products = \BullSoft\Sample\Models\Product::find('user_id=' . $this->user->id);
     $this->view->setVar('products', $products);
 }
Example #3
0
 public function indexAction()
 {
     $products = ProductModel::find();
     $categories = CategoryModel::find();
     if (empty($products)) {
         $this->view->setVar("categories", $categories);
         $this->view->setVar("products", $products);
         return;
     }
     $productIds = array();
     $wishlist = array();
     if ($this->user) {
         foreach ($products as $product) {
             $productIds[] = $product->id;
         }
         $wishes = WishlistModel::find("product_id IN (" . join(",", $productIds) . ") AND user_id =" . $this->user->id);
         foreach ($wishes as $wish) {
             $wishlist[$wish->product_id] = "";
         }
     }
     $this->view->setVar("wishlist", $wishlist);
     $this->view->setVar("categories", $categories);
     $this->view->setVar("products", $products);
 }
Example #4
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 #5
0
 public function detailAction($productId)
 {
     $productId = intval($productId);
     if ($productId <= 0) {
         $this->flash->error("产品ID必须大于0!");
         exit(1);
     }
     $product = ProductModel::findFirst('id=' . $productId);
     if (empty($product)) {
         $this->flash->error("抱歉,您请求的产品不存在!");
         exit(1);
     }
     $comments = CommentModel::find(array("product_id={$productId} AND reply_to_comment_id=0", 'order' => "addtime DESC", 'limit' => 10));
     $otherProducts = ProductModel::find(array('id != ' . $productId, 'order' => 'likeit DESC', 'limit' => 9));
     $this->view->setVar("other_products", $otherProducts);
     $this->view->setVar("comments", $comments);
     $this->view->setVar("product", $product);
 }
Example #6
0
 public function createAction()
 {
     if (!$this->user) {
         $this->flashJson(403);
         return;
     }
     $comment = array();
     $comment['product_id'] = intval($this->request->getPost('product_id', 'int'));
     if ($comment['product_id'] < 1) {
         $this->flashJson(500, array(), "非法请求");
         return;
     }
     $productModel = ProductModel::findFirst($comment['product_id']);
     if (empty($productModel)) {
         $this->flashJson(500, array(), "商品不存在");
         return;
     }
     $content = trim($this->request->getPost('comment'));
     if (mb_strlen($content, "UTF-8") < 4) {
         $this->flashJson(500, array('comment'), "内容长度至少4个字");
         return;
     }
     $comment['content'] = $content;
     $comment['reply_to_comment_id'] = intval($this->request->getPost('comment_id', 'int'));
     if ($comment['reply_to_comment_id'] < 0) {
         $this->flashJson(500, array(), "非法请求");
         return;
     }
     if ($comment['reply_to_comment_id'] > 0) {
         $commentModel = CommentModel::findFirst($comment['reply_to_comment_id']);
         if (empty($commentModel)) {
             $this->flashJson(500, array(), "你所评论的主题不存在");
             return;
         }
     }
     $comment['reply_to_user_id'] = intval($this->request->getPost('user_id', 'int'));
     if ($comment['reply_to_user_id'] < 0) {
         $this->flashJson(500, array(), "非法请求");
         return;
     }
     if ($comment['reply_to_user_id'] > 0) {
         $userModel = UserModel::findFirst($comment['reply_to_user_id']);
     } else {
         if ($comment['reply_to_comment_id'] > 0) {
             $comment['reply_to_user_id'] = $commentModel->user_id;
             $userModel = $commentModel->user;
         } else {
             if ($comment['reply_to_comment_id'] == 0) {
                 $comment['reply_to_user_id'] = $productModel->user_id;
                 $userModel = $productModel->user;
             }
         }
     }
     if (empty($userModel)) {
         $this->flashJson(500, array(), "你所评论的用户不存在");
         return;
     }
     $comment['user_id'] = $this->user->id;
     $time = date('Y-m-d H:i:s');
     $comment['addtime'] = $time;
     $comment['modtime'] = $time;
     $model = new CommentModel();
     $model->assign($comment);
     if ($model->save() == false) {
         $this->flashJson(500, array(), '评论插入失败');
     } else {
         if (isset($userModel)) {
             $comment['reply_to']["user_id"] = $userModel->id;
             $comment['reply_to']["nickname"] = $userModel->nickname;
             $comment['reply_to']["image_url"] = $userModel->photo;
         }
         $comment['id'] = $model->id;
         $comment['user']["user_id"] = $this->user->id;
         $comment['user']["nickname"] = $this->user->nickname;
         $comment['user']["image_url"] = $this->user->photo;
         $this->flashJson(200, $comment);
     }
     return;
 }