|
@@ -0,0 +1,104 @@
|
|
|
+package com.macro.mall.portal.service.impl;
|
|
|
+
|
|
|
+import com.macro.mall.mapper.OmsCartItemMapper;
|
|
|
+import com.macro.mall.model.OmsCartItem;
|
|
|
+import com.macro.mall.model.OmsCartItemExample;
|
|
|
+import com.macro.mall.portal.dao.PortalProductDao;
|
|
|
+import com.macro.mall.portal.domain.CartProduct;
|
|
|
+import com.macro.mall.portal.service.OmsCartItemService;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 购物车管理Service实现类
|
|
|
+ * Created by macro on 2018/8/2.
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class OmsCartItemServiceImpl implements OmsCartItemService {
|
|
|
+ @Autowired
|
|
|
+ private OmsCartItemMapper cartItemMapper;
|
|
|
+ @Autowired
|
|
|
+ private PortalProductDao productDao;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int add(OmsCartItem cartItem) {
|
|
|
+ OmsCartItem existCartItem = getCartItem(cartItem);
|
|
|
+ if (existCartItem == null) {
|
|
|
+ cartItemMapper.insert(cartItem);
|
|
|
+ } else {
|
|
|
+ existCartItem.setQuantity(existCartItem.getQuantity() + cartItem.getQuantity());
|
|
|
+ cartItemMapper.updateByPrimaryKey(existCartItem);
|
|
|
+ }
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据会员id,商品id和规格获取购物车中商品
|
|
|
+ */
|
|
|
+ private OmsCartItem getCartItem(OmsCartItem cartItem) {
|
|
|
+ OmsCartItemExample example = new OmsCartItemExample();
|
|
|
+ OmsCartItemExample.Criteria criteria = example.createCriteria().andMemberIdEqualTo(cartItem.getMemberId())
|
|
|
+ .andProductIdEqualTo(cartItem.getProductId()).andDeleteStatusEqualTo(0);
|
|
|
+ if (!StringUtils.isEmpty(cartItem.getSp1())) {
|
|
|
+ criteria.andSp1EqualTo(cartItem.getSp1());
|
|
|
+ }
|
|
|
+ if (!StringUtils.isEmpty(cartItem.getSp2())) {
|
|
|
+ criteria.andSp2EqualTo(cartItem.getSp2());
|
|
|
+ }
|
|
|
+ if (!StringUtils.isEmpty(cartItem.getSp3())) {
|
|
|
+ criteria.andSp3EqualTo(cartItem.getSp3());
|
|
|
+ }
|
|
|
+ List<OmsCartItem> cartItemList = cartItemMapper.selectByExample(example);
|
|
|
+ if (!CollectionUtils.isEmpty(cartItemList)) {
|
|
|
+ return cartItemList.get(0);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<OmsCartItem> list(Long memberId) {
|
|
|
+ OmsCartItemExample example = new OmsCartItemExample();
|
|
|
+ example.createCriteria().andDeleteStatusEqualTo(0).andMemberIdEqualTo(memberId);
|
|
|
+ return cartItemMapper.selectByExample(example);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int updateQuantity(Long id, Long memberId, Integer quantity) {
|
|
|
+ OmsCartItem cartItem = new OmsCartItem();
|
|
|
+ cartItem.setQuantity(quantity);
|
|
|
+ OmsCartItemExample example = new OmsCartItemExample();
|
|
|
+ example.createCriteria().andDeleteStatusEqualTo(0)
|
|
|
+ .andIdEqualTo(id).andMemberIdEqualTo(memberId);
|
|
|
+ return cartItemMapper.updateByExampleSelective(cartItem, example);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int delete(Long memberId, List<Long> ids) {
|
|
|
+ OmsCartItem record = new OmsCartItem();
|
|
|
+ record.setDeleteStatus(1);
|
|
|
+ OmsCartItemExample example = new OmsCartItemExample();
|
|
|
+ example.createCriteria().andIdIn(ids).andMemberIdEqualTo(memberId);
|
|
|
+ return cartItemMapper.updateByExampleSelective(record, example);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public CartProduct getCartProduct(Long productId) {
|
|
|
+ return productDao.getCartProduct(productId);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int updateAttr(OmsCartItem cartItem) {
|
|
|
+ //删除原购物车信息
|
|
|
+ OmsCartItem updateCart = new OmsCartItem();
|
|
|
+ updateCart.setId(cartItem.getId());
|
|
|
+ updateCart.setDeleteStatus(1);
|
|
|
+ cartItemMapper.updateByPrimaryKeySelective(updateCart);
|
|
|
+ cartItem.setId(null);
|
|
|
+ add(cartItem);
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+}
|