购物车完成
This commit is contained in:
1 parent
8a1e515b94
commit
54f15edc6c
6 files changed
+115
-5
No files matched your search
@@ -1,5 +1,6 @@
|
|||||||
package com.ruoyi.app.modular.shop.controller;
|
package com.ruoyi.app.modular.shop.controller;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.itmuch.lightsecurity.jwt.UserOperator;
|
import com.itmuch.lightsecurity.jwt.UserOperator;
|
||||||
import com.ruoyi.app.common.R;
|
import com.ruoyi.app.common.R;
|
||||||
import com.ruoyi.app.common.exception.BadRequestException;
|
import com.ruoyi.app.common.exception.BadRequestException;
|
||||||
@@ -127,4 +128,29 @@ public class MallController {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/shop/mall-cart-del")
|
||||||
|
@ApiOperation(value = "删除购物车",notes = "删除购物车")
|
||||||
|
public R delCart(@RequestParam(value = "goods_ids",defaultValue = "") String goodsIds){
|
||||||
|
int userId = userOperator.getUser().getId();
|
||||||
|
if(StrUtil.isEmpty(goodsIds)){
|
||||||
|
return R.error(4000,"参数缺失");
|
||||||
|
}
|
||||||
|
boolean result = goodsService.delCart(goodsIds,userId);
|
||||||
|
if(result){
|
||||||
|
return R.success("操作成功");
|
||||||
|
}else{
|
||||||
|
return R.error(4000,"操作失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@GetMapping("/shop/mall-cart-list")
|
||||||
|
@ApiOperation(value = "获取购物车列表",notes = "获取购物车列表")
|
||||||
|
public R cartList(@Validated @RequestBody PageVO pageVO){
|
||||||
|
int userId = userOperator.getUser().getId();
|
||||||
|
//goodsService.cartList(pageVO,userId);
|
||||||
|
return R.success(goodsService.cartList(pageVO,userId));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -6,8 +6,10 @@ package com.ruoyi.app.modular.shop.service;
|
|||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
import com.ruoyi.app.common.persistence.model.StoreGoods;
|
import com.ruoyi.app.common.persistence.model.StoreGoods;
|
||||||
import com.ruoyi.app.common.persistence.model.StoreSpecGoodsPrice;
|
import com.ruoyi.app.common.persistence.model.StoreSpecGoodsPrice;
|
||||||
|
import com.ruoyi.app.modular.shop.service.dto.CartDTO;
|
||||||
import com.ruoyi.app.modular.shop.service.dto.GoodsDTO;
|
import com.ruoyi.app.modular.shop.service.dto.GoodsDTO;
|
||||||
import com.ruoyi.app.modular.shop.service.vo.CartVO;
|
import com.ruoyi.app.modular.shop.service.vo.CartVO;
|
||||||
|
import com.ruoyi.app.modular.shop.service.vo.PageVO;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -26,4 +28,8 @@ public interface IGoodsService extends IService<StoreGoods> {
|
|||||||
public boolean addOrCancelCollect(int goodsId,int userId,int type);
|
public boolean addOrCancelCollect(int goodsId,int userId,int type);
|
||||||
|
|
||||||
public boolean addCart(CartVO cartVO,int userId);
|
public boolean addCart(CartVO cartVO,int userId);
|
||||||
|
|
||||||
|
public boolean delCart(String goodsIds,int userId);
|
||||||
|
|
||||||
|
public List<CartDTO> cartList(PageVO pageVO,int userId);
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package com.ruoyi.app.modular.shop.service.dto;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class CartAttrDTO implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
private BigDecimal goodsPrice;
|
||||||
|
|
||||||
|
private int goodsNum;
|
||||||
|
|
||||||
|
private String specKeyName;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -6,20 +6,23 @@ import lombok.Data;
|
|||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class CartDTO implements Serializable {
|
public class CartDTO implements Serializable {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
private Integer id;
|
private Integer goodsId;
|
||||||
|
|
||||||
private String goodsName;
|
private String goodsName;
|
||||||
|
|
||||||
private BigDecimal goodsPrice;
|
private BigDecimal goodsPrice;
|
||||||
|
|
||||||
private Integer goodsNum;
|
private String goodsSn;
|
||||||
|
|
||||||
private String specKeyName;
|
private String goodsLogo;
|
||||||
|
|
||||||
|
private List<CartAttrDTO> specList;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -20,13 +20,16 @@ import com.ruoyi.app.common.persistence.model.StoreGoods;
|
|||||||
import com.ruoyi.app.common.persistence.model.StoreGoodsCollect;
|
import com.ruoyi.app.common.persistence.model.StoreGoodsCollect;
|
||||||
import com.ruoyi.app.common.persistence.model.StoreSpecGoodsPrice;
|
import com.ruoyi.app.common.persistence.model.StoreSpecGoodsPrice;
|
||||||
import com.ruoyi.app.modular.shop.service.IGoodsService;
|
import com.ruoyi.app.modular.shop.service.IGoodsService;
|
||||||
|
import com.ruoyi.app.modular.shop.service.dto.CartDTO;
|
||||||
import com.ruoyi.app.modular.shop.service.dto.GoodsDTO;
|
import com.ruoyi.app.modular.shop.service.dto.GoodsDTO;
|
||||||
import com.ruoyi.app.modular.shop.service.dto.ItemDTO;
|
import com.ruoyi.app.modular.shop.service.dto.ItemDTO;
|
||||||
import com.ruoyi.app.modular.shop.service.dto.SpecItemDTO;
|
import com.ruoyi.app.modular.shop.service.dto.SpecItemDTO;
|
||||||
|
import com.ruoyi.app.modular.shop.service.mapper.CartMapper;
|
||||||
import com.ruoyi.app.modular.shop.service.mapper.CateMapper;
|
import com.ruoyi.app.modular.shop.service.mapper.CateMapper;
|
||||||
import com.ruoyi.app.modular.shop.service.mapper.GoodsMapper;
|
import com.ruoyi.app.modular.shop.service.mapper.GoodsMapper;
|
||||||
import com.ruoyi.app.modular.shop.service.vo.CartAttrVO;
|
import com.ruoyi.app.modular.shop.service.vo.CartAttrVO;
|
||||||
import com.ruoyi.app.modular.shop.service.vo.CartVO;
|
import com.ruoyi.app.modular.shop.service.vo.CartVO;
|
||||||
|
import com.ruoyi.app.modular.shop.service.vo.PageVO;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@@ -44,6 +47,7 @@ public class GoodsServiceImpl extends ServiceImpl<StoreGoodsMapper, StoreGoods>
|
|||||||
private final StoreGoodsCollectMapper storeGoodsCollectMapper;
|
private final StoreGoodsCollectMapper storeGoodsCollectMapper;
|
||||||
private final StoreSpecGoodsPriceMapper storeSpecGoodsPriceMapper;
|
private final StoreSpecGoodsPriceMapper storeSpecGoodsPriceMapper;
|
||||||
private final StoreCartMapper storeCartMapper;
|
private final StoreCartMapper storeCartMapper;
|
||||||
|
private final CartMapper cartMapper;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -172,6 +176,12 @@ public class GoodsServiceImpl extends ServiceImpl<StoreGoodsMapper, StoreGoods>
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加购物车
|
||||||
|
* @param cartVO
|
||||||
|
* @param userId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean addCart(CartVO cartVO,int userId) {
|
public boolean addCart(CartVO cartVO,int userId) {
|
||||||
StoreGoods storeGoods = getById(cartVO.getGoodsId());
|
StoreGoods storeGoods = getById(cartVO.getGoodsId());
|
||||||
@@ -209,4 +219,46 @@ public class GoodsServiceImpl extends ServiceImpl<StoreGoodsMapper, StoreGoods>
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean delCart(String goodsIds,int userId) {
|
||||||
|
String[] goodsArr = goodsIds.split(",");
|
||||||
|
QueryWrapper<StoreCart> cartQueryWrapper = new QueryWrapper<>();
|
||||||
|
cartQueryWrapper.in("goods_id",Arrays.asList(goodsArr)).eq("user_id",userId);
|
||||||
|
int result = storeCartMapper.delete(cartQueryWrapper);
|
||||||
|
if(result > 0) return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 购物车列表
|
||||||
|
* @param pageVO
|
||||||
|
* @param userId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<CartDTO> cartList(PageVO pageVO,int userId) {
|
||||||
|
QueryWrapper<StoreCart> cartQueryWrapper = new QueryWrapper<>();
|
||||||
|
cartQueryWrapper.eq("user_id",userId).groupBy("goods_id");
|
||||||
|
Page<StoreCart> pageModel = new Page<>(pageVO.getPage(), pageVO.getLimit());
|
||||||
|
IPage<StoreCart> storeCarts = storeCartMapper
|
||||||
|
.selectPage(pageModel,cartQueryWrapper);
|
||||||
|
List<StoreCart> storeCartList = storeCarts.getRecords();
|
||||||
|
List<CartDTO> carts = new ArrayList<>();
|
||||||
|
CartDTO cartDTO = new CartDTO();
|
||||||
|
for (StoreCart storeCart : storeCartList) {
|
||||||
|
StoreGoods storeGoods = getById(storeCart.getGoodsId());
|
||||||
|
cartDTO.setGoodsId(storeCart.getGoodsId());
|
||||||
|
cartDTO.setGoodsName(storeGoods.getGoodsName());
|
||||||
|
cartDTO.setGoodsSn(storeGoods.getGoodsSn());
|
||||||
|
cartDTO.setGoodsLogo(storeGoods.getGoodsLogo());
|
||||||
|
QueryWrapper<StoreCart> wrapper = new QueryWrapper<>();
|
||||||
|
wrapper.eq("user_id",userId).eq("goods_id",storeCart.getGoodsId());
|
||||||
|
cartDTO.setSpecList(cartMapper.toDto(storeCartMapper.selectList(wrapper)));
|
||||||
|
carts.add(cartDTO);
|
||||||
|
}
|
||||||
|
return carts;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -4,7 +4,7 @@ package com.ruoyi.app.modular.shop.service.mapper;
|
|||||||
|
|
||||||
import com.ruoyi.app.common.persistence.model.StoreCart;
|
import com.ruoyi.app.common.persistence.model.StoreCart;
|
||||||
import com.ruoyi.app.modular.mapper.EntityMapper;
|
import com.ruoyi.app.modular.mapper.EntityMapper;
|
||||||
import com.ruoyi.app.modular.shop.service.dto.CartDTO;
|
import com.ruoyi.app.modular.shop.service.dto.CartAttrDTO;
|
||||||
import org.mapstruct.Mapper;
|
import org.mapstruct.Mapper;
|
||||||
import org.mapstruct.ReportingPolicy;
|
import org.mapstruct.ReportingPolicy;
|
||||||
|
|
||||||
@@ -13,6 +13,6 @@ import org.mapstruct.ReportingPolicy;
|
|||||||
* @date 2019-09-10
|
* @date 2019-09-10
|
||||||
*/
|
*/
|
||||||
@Mapper(componentModel = "spring",uses = {},unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
@Mapper(componentModel = "spring",uses = {},unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
||||||
public interface CartMapper extends EntityMapper<CartDTO, StoreCart> {
|
public interface CartMapper extends EntityMapper<CartAttrDTO, StoreCart> {
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user