示例#1
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);
 }
示例#2
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);
 }
示例#3
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);
 }