| | |
| | | package cn.lili.controller.order; |
| | | |
| | | import cn.hutool.json.JSONUtil; |
| | | import cn.lili.common.aop.annotation.PreventDuplicateSubmissions; |
| | | import cn.lili.common.enums.ResultCode; |
| | | import cn.lili.common.enums.ResultUtil; |
| | | import cn.lili.common.exception.ServiceException; |
| | | import cn.lili.common.utils.StringUtils; |
| | | import cn.lili.common.vo.ResultMessage; |
| | | import cn.lili.modules.order.cart.entity.dto.BuyBackDTO; |
| | | import cn.lili.modules.order.cart.entity.dto.TradeDTO; |
| | |
| | | import cn.lili.modules.order.cart.entity.vo.TradeParams; |
| | | import cn.lili.modules.order.cart.service.CartService; |
| | | import cn.lili.modules.order.order.entity.vo.ReceiptVO; |
| | | import cn.lili.utils.COSUtil; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | | import io.swagger.annotations.ApiImplicitParams; |
| | |
| | | */ |
| | | @Autowired |
| | | private CartService cartService; |
| | | @Autowired |
| | | private COSUtil cosUtil; |
| | | |
| | | |
| | | @ApiOperation(value = "向购物车中添加一个产品") |
| | |
| | | throw new ServiceException(ResultCode.CART_ERROR); |
| | | } |
| | | } |
| | | @ApiOperation(value = "向购物车中覆盖添加一个产品") |
| | | @PostMapping("/addCard") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "skuId", value = "产品ID", required = true, dataType = "Long", paramType = "query"), |
| | | @ApiImplicitParam(name = "num", value = "此产品的购买数量", required = true, dataType = "int", paramType = "query"), |
| | | @ApiImplicitParam(name = "cartType", value = "购物车类型,默认加入购物车", paramType = "query") |
| | | }) |
| | | public ResultMessage<Object> addCard(@NotNull(message = "产品id不能为空") String skuId, |
| | | @NotNull(message = "购买数量不能为空") @Min(value = 1, message = "加入购物车数量必须大于0") Integer num) { |
| | | try { |
| | | //读取选中的列表 |
| | | cartService.add(skuId, num, CartTypeEnum.CART.name(), true); |
| | | return ResultUtil.success(); |
| | | } catch (ServiceException se) { |
| | | log.info(se.getMsg(), se); |
| | | throw se; |
| | | } catch (Exception e) { |
| | | log.error(ResultCode.CART_ERROR.message(), e); |
| | | throw new ServiceException(ResultCode.CART_ERROR); |
| | | } |
| | | } |
| | | |
| | | |
| | | @ApiOperation(value = "获取购物车页面购物车详情") |
| | | @GetMapping("/all") |
| | | public ResultMessage<TradeDTO> cartAll() { |
| | | return ResultUtil.data(this.cartService.getAllTradeDTO()); |
| | | TradeDTO allTradeDTO = this.cartService.getAllTradeDTO(); |
| | | allTradeDTO.getSkuList().forEach(item->{ |
| | | String goodsVideo = item.getGoodsSku().getGoodsVideo(); |
| | | if (StringUtils.isNotBlank(goodsVideo)&&!goodsVideo.contains("http")) { |
| | | item.getGoodsSku().setGoodsVideo(cosUtil.getPreviewUrl(goodsVideo)); |
| | | } |
| | | |
| | | String thumbnail = item.getGoodsSku().getThumbnail(); |
| | | if (StringUtils.isNotBlank(thumbnail)&&!thumbnail.contains("http")) { |
| | | item.getGoodsSku().setThumbnail(cosUtil.getPreviewUrl(thumbnail)); |
| | | } |
| | | }); |
| | | return ResultUtil.data(allTradeDTO); |
| | | } |
| | | |
| | | @ApiOperation(value = "获取购物车数量") |
| | |
| | | public ResultMessage<TradeDTO> cartChecked(@NotNull(message = "读取选中列表") String way) { |
| | | try { |
| | | //读取选中的列表 |
| | | return ResultUtil.data(this.cartService.getCheckedTradeDTO(CartTypeEnum.valueOf(way))); |
| | | TradeDTO checkedTradeDTO = this.cartService.getCheckedTradeDTO(CartTypeEnum.valueOf(way)); |
| | | checkedTradeDTO.getSkuList().forEach(item->{ |
| | | |
| | | |
| | | String goodsVideo = item.getGoodsSku().getGoodsVideo(); |
| | | if (StringUtils.isNotBlank(goodsVideo)&&!goodsVideo.contains("http")) { |
| | | item.getGoodsSku().setGoodsVideo(cosUtil.getPreviewUrl(goodsVideo)); |
| | | } |
| | | |
| | | String thumbnail = item.getGoodsSku().getThumbnail(); |
| | | if (StringUtils.isNotBlank(thumbnail)&&!thumbnail.contains("http")) { |
| | | item.getGoodsSku().setThumbnail(cosUtil.getPreviewUrl(thumbnail)); |
| | | } |
| | | }); |
| | | System.err.println(JSONUtil.toJsonStr(checkedTradeDTO)); |
| | | return ResultUtil.data(checkedTradeDTO); |
| | | } catch (ServiceException se) { |
| | | log.error(se.getMsg(), se); |
| | | throw se; |