| | |
| | | package com.panzhihua.service_community.service.impl; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.panzhihua.common.model.dtos.shop.ComShopCartDTO; |
| | |
| | | import com.panzhihua.service_community.model.dos.ComShopGoodsDO; |
| | | import com.panzhihua.service_community.model.dos.ComShopStoreDO; |
| | | import com.panzhihua.service_community.service.ComShopCartService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | /** |
| | | * @auther lyq |
| | |
| | | @Resource |
| | | private ComShopGoodsAttrDAO shopGoodsAttrDAO; |
| | | |
| | | |
| | | /** |
| | | * 根据用户id查询购物车列表 |
| | | * @param userId 用户id |
| | | * |
| | | * @param userId |
| | | * 用户id |
| | | * @return 购物车列表 |
| | | */ |
| | | @Override |
| | |
| | | //有效宝贝集合 |
| | | List<ComShopCartStoreVO> cartList = new ArrayList<>(); |
| | | |
| | | List<ComShopCartDO> shopCartDOList = this.baseMapper.selectList(new QueryWrapper<ComShopCartDO>().eq("user_id",userId)); |
| | | List<ComShopCartDO> shopCartDOList = |
| | | this.baseMapper.selectList(new QueryWrapper<ComShopCartDO>().eq("user_id", userId)); |
| | | if(!shopCartDOList.isEmpty()){ |
| | | shopCartDOList.forEach(shopCart->{ |
| | | //查询当前商品是否是有效商品 |
| | | ComShopGoodsDO goodsDO = shopGoodsDAO.selectOne(new QueryWrapper<ComShopGoodsDO>() |
| | | .eq("id",shopCart.getGoodsId()).eq("delete_status",ComShopGoodsDO.deleteStatus.no) |
| | | .eq("status",ComShopGoodsDO.status.sell)); |
| | | ComShopGoodsDO goodsDO = |
| | | shopGoodsDAO.selectOne(new QueryWrapper<ComShopGoodsDO>().eq("id", shopCart.getGoodsId()) |
| | | .eq("delete_status", ComShopGoodsDO.deleteStatus.no).eq("status", ComShopGoodsDO.status.sell)); |
| | | if(goodsDO == null){ |
| | | ComShopCartVO invalidCart = new ComShopCartVO(); |
| | | BeanUtils.copyProperties(shopCart,invalidCart); |
| | |
| | | |
| | | } |
| | | |
| | | |
| | | }); |
| | | //设置返回参数 |
| | | comShopCart.setInvalidCartList(invalidCartList); |
| | |
| | | |
| | | /** |
| | | * 购物车添加 |
| | | * @param comShopCartDTO 请求参数 |
| | | * |
| | | * @param comShopCartDTO |
| | | * 请求参数 |
| | | * @return 添加结果 |
| | | */ |
| | | @Override |
| | | public R shopAddCart(ComShopCartDTO comShopCartDTO){ |
| | | //查询当前商品是否已经在购物车中 |
| | | ComShopCartDO shopCartDO = this.baseMapper.selectOne(new QueryWrapper<ComShopCartDO>().eq("user_id",comShopCartDTO.getUserId()) |
| | | ComShopCartDO shopCartDO = |
| | | this.baseMapper.selectOne(new QueryWrapper<ComShopCartDO>().eq("user_id", comShopCartDTO.getUserId()) |
| | | .eq("goods_id",comShopCartDTO.getGoodsId()).eq("goods_attr_id",comShopCartDTO.getGoodsAttrId())); |
| | | if(shopCartDO == null){//购物车表里未有该商品的记录 |
| | | shopCartDO = new ComShopCartDO(); |
| | |
| | | |
| | | /** |
| | | * 购物车内商品数量修改 |
| | | * @param shopEditNubCartDTO 请求参数 |
| | | * |
| | | * @param shopEditNubCartDTO |
| | | * 请求参数 |
| | | * @return 修改结果 |
| | | */ |
| | | @Override |
| | |
| | | |
| | | /** |
| | | * 删除购物车记录 |
| | | * @param Ids 购物车id集合 |
| | | * |
| | | * @param Ids |
| | | * 购物车id集合 |
| | | * @return 删除结果 |
| | | */ |
| | | public R shopDelCart(List<Long> Ids){ |
| | |
| | | |
| | | /** |
| | | * 查询用户购物车商品数量 |
| | | * @param userId 用户id |
| | | * |
| | | * @param userId |
| | | * 用户id |
| | | * @return 用户购物车商品数量 |
| | | */ |
| | | public R shopCartUserTotal(Long userId){ |
| | | int goodsNum = 0; |
| | | //查询用户购物车所有商品集合 |
| | | List<ComShopCartDO> shopCartDOList = this.baseMapper.selectList(new QueryWrapper<ComShopCartDO>().eq("user_id",userId)); |
| | | List<ComShopCartDO> shopCartDOList = |
| | | this.baseMapper.selectList(new QueryWrapper<ComShopCartDO>().eq("user_id", userId)); |
| | | if(!shopCartDOList.isEmpty()){ |
| | | for (ComShopCartDO cartDO:shopCartDOList) { |
| | | //查询当前商品是否是有效商品 |
| | | ComShopGoodsDO goodsDO = shopGoodsDAO.selectOne(new QueryWrapper<ComShopGoodsDO>() |
| | | .eq("id",cartDO.getGoodsId()).eq("delete_status",ComShopGoodsDO.deleteStatus.no) |
| | | .eq("status",ComShopGoodsDO.status.sell)); |
| | | ComShopGoodsDO goodsDO = |
| | | shopGoodsDAO.selectOne(new QueryWrapper<ComShopGoodsDO>().eq("id", cartDO.getGoodsId()) |
| | | .eq("delete_status", ComShopGoodsDO.deleteStatus.no).eq("status", ComShopGoodsDO.status.sell)); |
| | | |
| | | if(goodsDO != null){ |
| | | goodsNum++; |