Esempio n. 1
0
 @RequestMapping(value = "/shop/{id}/category/{cid}")
 public String productAll(
     @PathVariable("id") String shopId,
     @PathVariable("cid") String categoryId,
     Pageable page,
     Model model) {
   List<Product> products = categoryService.listProductsInCategory(categoryId, page);
   model.addAttribute("prods", products);
   return "fragments/shopProducts";
 }
Esempio n. 2
0
  /**
   * 只获取店铺信息,不获取商品列表
   *
   * @param shopId
   * @param model
   * @param req
   * @return
   */
  @RequestMapping(value = "/shop/{id}/withoutProduct")
  public String viewWithoutProduct(
      @PathVariable("id") String shopId, Model model, HttpServletRequest req) {
    Shop shop = shopService.load(shopId);
    if (shop == null) {
      throw new BizException(
          GlobalErrorCode.NOT_FOUND, new RequestContext(req).getMessage("shop.not.found"));
    }

    model.addAttribute("shop", shop);
    model.addAttribute("owner", userService.load(shop.getOwnerId()));

    ShopStyle shopStyle = shopService.loadShopStyle(shopId);
    List<String> bodyClasses = new ArrayList<String>();
    bodyClasses.add(shopStyle.getAvatarStyle());
    bodyClasses.add(shopStyle.getBackgroundColor());
    bodyClasses.add(shopStyle.getFontColor());
    bodyClasses.add(shopStyle.getFontFamily());
    bodyClasses.add(
        StringUtils.isEmpty(shopStyle.getListView()) ? "smallimg" : shopStyle.getListView());
    model.addAttribute("styles", StringUtils.join(bodyClasses, " "));
    model.addAttribute("waterfall", "waterfall".equalsIgnoreCase(shopStyle.getListView()));

    List<Category> categories = categoryService.listRootCategoriesByShop(shop.getId());
    List<CategoryVO> categoryVOs = new ArrayList<CategoryVO>();
    for (int i = 0; i < categories.size(); i++) {
      CategoryVO categoryVO = new CategoryVO();
      BeanUtils.copyProperties(categories.get(i), categoryVO);
      categoryVO.setProductCount(
          categoryService.countProductsUnderCategory((categories.get(i)).getId()));
      categoryVOs.add(categoryVO);
    }
    model.addAttribute("categories", categoryVOs);

    model.addAttribute("recommendCount", productService.countByRecommend(shopId));
    model.addAttribute("allCount", productService.countProductsBySales(shopId));

    return "shop/shopView";
  }
Esempio n. 3
0
  @RequestMapping(value = "/shop/{id}")
  public String view(@PathVariable("id") String shopId, Model model, HttpServletRequest req) {
    Shop shop = shopService.load(shopId);
    if (shop == null || shop.getArchive() == Boolean.TRUE) {
      throw new BizException(
          GlobalErrorCode.NOT_FOUND, new RequestContext(req).getMessage("shop.not.found"));
    }

    model.addAttribute("shop", shop);
    model.addAttribute("owner", userService.load(shop.getOwnerId()));

    // 取推荐,和热卖商品
    List<Product> recommends =
        productService.listProductsByRecommend(shop.getId(), new PageRequest(0, 4));
    model.addAttribute("prodsRecommended", recommends);

    List<Product> prodsHot =
        productService.listProductsBySales(shop.getId(), new PageRequest(0, 12), Direction.DESC);
    model.addAttribute("prodsHot", prodsHot);

    boolean isShowAll = false;
    if (prodsHot.size() == 12) {
      Long count = productService.countProductsByStatus(shop.getId(), ProductStatus.ONSALE);
      isShowAll = (count.longValue() > 12);
    }
    model.addAttribute("isShowAll", isShowAll);

    ShopStyleVO shopStyle = shopService.loadShopStyle(shopId);
    List<String> bodyClasses = new ArrayList<String>();
    bodyClasses.add(shopStyle.getAvatarStyle());
    bodyClasses.add(shopStyle.getBackgroundColor());
    bodyClasses.add(shopStyle.getFontColor());
    bodyClasses.add(shopStyle.getFontFamily());
    bodyClasses.add(
        StringUtils.isEmpty(shopStyle.getListView()) ? "smallimg" : shopStyle.getListView());
    model.addAttribute("styles", StringUtils.join(bodyClasses, " "));
    model.addAttribute("waterfall", "waterfall".equalsIgnoreCase(shopStyle.getListView()));
    model.addAttribute("banner", shopStyle.getBannerImg());

    if (shop.getProvinceId() != null) {
      Zone province = zoneService.load(shop.getProvinceId().toString());
      model.addAttribute("province", province);
    }
    if (shop.getCityId() != null) {
      Zone city = zoneService.load(shop.getCityId().toString());
      model.addAttribute("city", city);
    }

    List<Category> categories = categoryService.listRootCategoriesByShop(shop.getId());
    List<CategoryVO> categoryVOs = new ArrayList<CategoryVO>();
    for (int i = 0; i < categories.size(); i++) {
      CategoryVO categoryVO = new CategoryVO();
      BeanUtils.copyProperties(categories.get(i), categoryVO);
      categoryVO.setProductCount(
          categoryService.countProductsUnderCategory((categories.get(i)).getId()));
      categoryVOs.add(categoryVO);
    }
    model.addAttribute("categories", categoryVOs);

    model.addAttribute("recommendCount", productService.countByRecommend(shopId));
    model.addAttribute("allCount", productService.countProductsBySales(shopId));

    return "shop/shopView";
  }