Exemplo n.º 1
0
 // 检查商品库存
 @RequestMapping(value = "/cart/checkStockCount.jspx")
 public void checkStockCount(
     Long productId,
     String productFashionId,
     Integer count,
     HttpServletRequest request,
     HttpServletResponse response,
     ModelMap model)
     throws JSONException {
   ShopMember member = MemberThread.get();
   JSONObject json = new JSONObject();
   if (member == null) {
     json.put("status", 0);
   } else {
     Product product = productMng.findById(productId);
     if (productFashionId.equals("undefined")) {
       if (count > product.getStockCount()) {
         json.put("status", 2);
         json.put("error", product.getName() + "该商品库存不足。");
       } else {
         json.put("status", 1);
       }
     } else {
       ProductFashion productFashion =
           productFashionMng.findById(Long.parseLong(productFashionId));
       if (count > productFashion.getStockCount()) {
         json.put("error", product.getName() + productFashion.getAttitude() + "该款式库存不足。");
         json.put("status", 2);
       } else {
         json.put("status", 1);
       }
     }
   }
   ResponseUtils.renderJson(response, json.toString());
 }
Exemplo n.º 2
0
  public Integer getTotalStore(Long productId) {
    Product bean = productDao.findById(productId);
    Set<ProductFashion> set = bean.getFashions();
    Integer store = 0;
    if (set != null) {
      for (ProductFashion f : set) {
        store = store + f.getStockCount();
      }
    }

    return store;
  }
Exemplo n.º 3
0
 // 加入购物车
 @RequestMapping(value = "/cart/add_orderItem.jspx")
 public void addToCart(
     Long productId,
     Integer productAmount,
     Long fashId,
     HttpServletRequest request,
     HttpServletResponse response,
     ModelMap model)
     throws JSONException {
   Website web = SiteUtils.getWeb(request);
   // 0:未登录;1:正常,商品总数;2:数量过大,最大数量;
   ShopMember member = MemberThread.get();
   JSONObject json = new JSONObject();
   if (member == null) {
     json.put("status", 0);
   } else {
     Product product = productMng.findById(productId);
     if (fashId == null) {
       if (productAmount > product.getStockCount()) {
         json.put("status", 2);
         json.put("error", "库存不足");
       } else {
         Cart cart =
             shoppingSvc.collectAddToCart(
                 product, fashId, null, productAmount, true, member, web, request, response);
         json.put("status", 1);
         json.put("count", cart.getTotalItems());
       }
     } else {
       ProductFashion productFashion = productFashionMng.findById(fashId);
       if (productAmount > productFashion.getStockCount()) {
         json.put("status", 2);
         json.put("error", productFashion.getAttitude() + "库存不足");
       } else {
         Cart cart =
             shoppingSvc.collectAddToCart(
                 product, fashId, null, productAmount, true, member, web, request, response);
         json.put("status", 1);
         json.put("count", cart.getTotalItems());
       }
     }
   }
   log.info("add to cart productId={}, count={}", productId, productAmount);
   ResponseUtils.renderJson(response, json.toString());
 }
Exemplo n.º 4
0
 public Integer getStoreByProductPattern(Long id, Long fashId) { // 获得商品款式库存wangzewu
   ProductFashion bean = productFashionDao.getPfashion(id, fashId);
   return bean.getStockCount();
 }