ShoppingCartServiceImpl.java 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package com.caimei.service.impl;
  2. import com.caimei.mapper.ShoppingCartMapper;
  3. import com.caimei.model.ResponseJson;
  4. import com.caimei.model.dto.CartDto;
  5. import com.caimei.model.po.CmMallCartPo;
  6. import com.caimei.model.vo.ShopVo;
  7. import com.caimei.service.ShoppingCartService;
  8. import org.springframework.stereotype.Service;
  9. import javax.annotation.Resource;
  10. import java.util.HashMap;
  11. import java.util.List;
  12. import java.util.Map;
  13. /**
  14. * Description
  15. *
  16. * @author : plf
  17. * @date : 2021/3/23
  18. */
  19. @Service
  20. public class ShoppingCartServiceImpl implements ShoppingCartService {
  21. @Resource
  22. private ShoppingCartMapper shoppingCartMapper;
  23. @Override
  24. public ResponseJson<Integer> addShoppingCart(CartDto cart) {
  25. CmMallCartPo cartPo = shoppingCartMapper.findCartProduct(cart.getUserId(), cart.getProductId());
  26. if (cartPo == null) {
  27. shoppingCartMapper.insertCart(cart);
  28. } else {
  29. int productCount = cartPo.getProductCount() + cart.getProductCount();
  30. shoppingCartMapper.updateByProductCount(cartPo.getId(), productCount);
  31. }
  32. Integer cartQuantity = shoppingCartMapper.getCartQuantity(cart.getUserId());
  33. return ResponseJson.success(cartQuantity);
  34. }
  35. @Override
  36. public ResponseJson<Integer> getCartQuantity(Integer userId) {
  37. Integer cartQuantity = shoppingCartMapper.getCartQuantity(userId);
  38. return ResponseJson.success(cartQuantity);
  39. }
  40. @Override
  41. public ResponseJson<Map<String, Object>> shoppingInfo(Integer userId) {
  42. Map<String, Object> map = new HashMap<>(3);
  43. List<ShopVo> shopList = shoppingCartMapper.findCartShop(userId);
  44. shopList.forEach(shop -> {
  45. });
  46. return null;
  47. }
  48. }