Esempio n. 1
0
 public function wishlistAction()
 {
     if (!$this->user) {
         $this->flashJson(403);
         exit;
     }
     $wishlist = WishlistModel::find('user_id=' . $this->user->id);
     $this->view->setVar('wishlist', $wishlist);
 }
Esempio n. 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);
 }
Esempio n. 3
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;
 }