@Override public String addShoppingCart(String accountId, Integer productId, Integer productNum) { Account account = accountDAO.find(Account.class, accountId); if (account == null) { return "账号不存在"; } ProductInfo productInfo = productInfoDAO.find(ProductInfo.class, productId); if (productInfo == null) { return "商品不存在"; } ShoppingCart shoppingCart = shoppingCartDAO.getShoppingCartByProduct(accountId, productId); if (shoppingCart == null) { shoppingCart = new ShoppingCart(); shoppingCart.setProductInfo(productInfo); shoppingCart.setCreateTime(new Date()); shoppingCart.setSellerInfo(productInfo.getSellerInfo()); shoppingCart.setAccountId(accountId); shoppingCart.setProductNum(productNum); shoppingCartDAO.add(ShoppingCart.class, shoppingCart); } else { shoppingCart.setProductNum(shoppingCart.getProductNum() + productNum); shoppingCartDAO.update(ShoppingCart.class, shoppingCart); } return null; }
@Override public String modifyShoppingCartNum(String accountId, Integer cartId, Integer modifyNum) { ShoppingCart shoppingCart = shoppingCartDAO.find(ShoppingCart.class, cartId); if (shoppingCart == null || ObjectUtils.notEqual(accountId, shoppingCart.getAccountId())) { return "记录不存在"; } if (shoppingCart.getProductNum() + modifyNum <= 0) { return TextConstant.PARAM_ERROR; } shoppingCart.setProductNum(shoppingCart.getProductNum() + modifyNum); shoppingCartDAO.update(ShoppingCart.class, shoppingCart); return null; }