Esempio 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());
 }
Esempio n. 2
0
 // 删除购物车项
 @RequestMapping(value = "/cart/ajaxDeleteCartItem.jspx")
 public void ajaxDeleteCartItem(
     Long cartItemId, HttpServletRequest request, HttpServletResponse response, ModelMap model)
     throws JSONException {
   ShopMember member = MemberThread.get();
   JSONObject json = new JSONObject();
   if (member == null) {
     json.put("status", 0);
   }
   CartItem cartItem = cartItemMng.findById(cartItemId);
   Cart cart = cartItem.getCart();
   PopularityGroup popularityGroup = cartItem.getPopularityGroup();
   cart.getItems().remove(cartItem);
   cartMng.update(cart);
   if (cart != null && popularityGroup != null) {
     List<CartItem> list = cartItemMng.getlist(cart.getId(), popularityGroup.getId());
     list.remove(cartItem);
     for (CartItem item : list) {
       item.setPopularityGroup(null);
       cartItemMng.updateByUpdater(item);
     }
     update(cart, popularityGroup);
   }
   log.info("delete to cartItem cartItemId={}", cartItemId);
   json.put("status", 1);
   ResponseUtils.renderJson(response, json.toString());
 }
Esempio n. 3
0
 // 订单再次加入购物车
 @RequestMapping(value = "/cart/add_orderItem1.jspx")
 public String orderAddToCart(
     Long orderId,
     Boolean isAdd,
     HttpServletRequest request,
     HttpServletResponse response,
     ModelMap model)
     throws JSONException {
   Website web = SiteUtils.getWeb(request);
   // 0:未登录;1:正常,商品总数;2:数量过大,最大数量;
   ShopMember member = MemberThread.get();
   if (member == null) {
     return "redirect:../login.jspx";
   }
   Order order = orderMng.findById(orderId);
   Product product = null;
   Integer productAmount = 0;
   Long fashId = null;
   Cart cart = null;
   for (OrderItem item : order.getItems()) {
     product = item.getProduct();
     productAmount = item.getCount();
     if (item.getProductFash() != null) {
       fashId = item.getProductFash().getId();
     }
     cart =
         shoppingSvc.collectAddToCart(
             product, fashId, null, productAmount, true, member, web, request, response);
   }
   return "redirect:shopping_cart.jspx";
 }
Esempio n. 4
0
 // 加入购物车
 @RequestMapping(value = "/cart/add_popularity.jspx")
 public void addToPopularity(
     Long popularityId, 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 {
     if (getinventory(popularityId)) {
       Cart cart = null;
       for (Product product : popularityGroupMng.findById(popularityId).getProducts()) {
         cart =
             shoppingSvc.collectAddToCart(
                 product, null, popularityId, 1, true, member, web, request, response);
       }
       popularityItemMng.save(cart, popularityId);
       json.put("status", 1);
       json.put("count", cart.getTotalItems());
     } else {
       json.put("status", 2);
       json.put("error", "库存不足");
     }
   }
   ResponseUtils.renderJson(response, json.toString());
 }
Esempio n. 5
0
 /** 会员中心优惠劵 */
 @RequestMapping(value = "/myCoupon.jspx", method = RequestMethod.GET)
 public String pay1(HttpServletRequest request, ModelMap model) {
   Website web = SiteUtils.getWeb(request);
   ShopMember member = MemberThread.get();
   List<MemberCoupon> list = memberCouponMng.getList(member.getId());
   model.addAttribute("couList", list);
   model.addAttribute("historyProductIds", getHistoryProductIds(request));
   ShopFrontHelper.setCommonData(request, model, web, 1);
   return web.getTplSys("member", MessageResolver.getMessage(request, "tpl.myCoupon"));
 }
Esempio n. 6
0
  // 选择收货地址、付款方式、配送方式
  @RequestMapping(value = "/cart/checkout_shipping.jspx")
  public String shippingInput(
      Long[] cart2Checkbox,
      HttpServletRequest request,
      HttpServletResponse response,
      ModelMap model) {
    Website web = SiteUtils.getWeb(request);
    ShopMember member = MemberThread.get();
    if (member == null) {
      return "redirect:../login.jspx";
    }
    Cart cart = shoppingSvc.getCart(member.getId());
    if (cart == null) {
      return "redirect:shopping_cart.jspx";
    }
    List<PopularityItem> popularityItems = null;
    Double popularityPrice = 0.0;
    if (cart != null) {
      popularityItems = popularityItemMng.getlist(cart.getId(), null);
      for (PopularityItem popularityItem : popularityItems) {
        popularityPrice +=
            popularityItem.getPopularityGroup().getPrivilege() * popularityItem.getCount();
      }
    }

    Set<CartItem> items = getItems(cart2Checkbox, cart);
    Double price = getPrice(items);
    // 配送方式
    List<Shipping> splist = shippingMng.getList(web.getId(), true);
    // 会员地址
    List<ShopMemberAddress> smalist = shopMemberAddressMng.getList(member.getId());
    // 所处省份
    List<Address> plist = addressMng.getListById(null);
    // 付款方式
    List<Payment> paylist = paymentMng.getList((long) 1, true);
    model.addAttribute(
        "memberCouponlist", memberCouponMng.getList(member.getId(), new BigDecimal(price)));
    model.addAttribute("items", getItems(cart2Checkbox, cart));
    model.addAttribute("smalist", smalist);
    model.addAttribute("plist", plist);
    model.addAttribute("paylist", paylist);
    model.addAttribute("splist", splist);
    model.addAttribute("popularityPrice", popularityPrice);
    ShopFrontHelper.setCommonData(request, model, web, 1);
    return web.getTplSys(MEMBER_SYS, MessageResolver.getMessage(request, CHECKOUT_SHIPPING));
  }
Esempio n. 7
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());
 }
Esempio n. 8
0
 // 计算运费
 @RequestMapping(value = "/cart/ajaxtotalDeliveryFee.jspx")
 public void ajaxtotalDeliveryFee(
     Long deliveryMethod,
     Double weight,
     HttpServletRequest request,
     HttpServletResponse response,
     ModelMap model)
     throws JSONException {
   ShopMember member = MemberThread.get();
   JSONObject json = new JSONObject();
   if (member == null) {
     json.put("status", 0);
   }
   Shipping shipping = shippingMng.findById(deliveryMethod);
   // 计算运费
   Double freight = shipping.calPrice(weight);
   json.put("status", 1);
   json.put("freight", freight);
   ResponseUtils.renderJson(response, json.toString());
 }
Esempio n. 9
0
 // 购物车
 @RequestMapping(value = "/cart/shopping_cart.jspx")
 public String shoppingCart(
     String backUrl, HttpServletRequest request, HttpServletResponse response, ModelMap model) {
   ShopMember member = MemberThread.get();
   if (member == null) {
     return "redirect:../login.jspx";
   }
   Website web = SiteUtils.getWeb(request);
   Cart cart = shoppingSvc.getCart(member, request, response);
   List<PopularityItem> popularityItems = null;
   if (cart != null) {
     popularityItems = popularityItemMng.getlist(cart.getId(), null);
   }
   model.addAttribute("cart", cart);
   if (!StringUtils.isBlank(backUrl)) {
     model.addAttribute(BACK_URL, backUrl);
   }
   model.addAttribute("popularityItems", popularityItems);
   ShopFrontHelper.setCommonData(request, model, web, 1);
   return web.getTplSys(MEMBER_SYS, MessageResolver.getMessage(request, SHOPPING_CART));
 }
Esempio n. 10
0
 // 更新购物车项
 @RequestMapping(value = "/cart/ajaxUpdateCartItem.jspx")
 public void ajaxUpdateCartItem(
     Long cartItemId,
     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);
   }
   CartItem cartItem = cartItemMng.findById(cartItemId);
   cartItem.setCount(count);
   cartItem.setScore(cartItem.getProduct().getScore() * count);
   cartItemMng.updateByUpdater(cartItem);
   log.info("update to cartItem cartItemId={}", cartItemId);
   json.put("status", 1);
   ResponseUtils.renderJson(response, json.toString());
 }