Exemplo n.º 1
0
 @RequestMapping(value = "/shop/{id}/productByPage")
 public String productAll(@PathVariable("id") String shopId, Pageable page, Model model) {
   List<Product> products = productService.listProductsBySales(shopId, page, Direction.DESC);
   Long cnt = productService.countProductsByStatus(shopId, ProductStatus.ONSALE);
   model.addAttribute("prods", products);
   model.addAttribute("total", cnt);
   return "fragments/shopProducts";
 }
Exemplo n.º 2
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";
  }