| | |
| | | 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.lmk.domain.entity.UserCheckTemplate; |
| | | import cn.lili.modules.lmk.domain.form.CustomizeTemplateForm; |
| | | import cn.lili.modules.lmk.service.UserCheckTemplateService; |
| | | 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.enums.CartTypeEnum; |
| | | import cn.lili.modules.order.cart.entity.vo.BindingTemplateParam; |
| | | import cn.lili.modules.order.cart.entity.vo.TradeParams; |
| | | import cn.lili.modules.order.cart.service.CartService; |
| | | import cn.lili.modules.order.order.entity.dos.Order; |
| | | import cn.lili.modules.order.order.entity.vo.ReceiptVO; |
| | | import cn.lili.modules.order.order.service.OrderService; |
| | | import cn.lili.utils.COSUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | | import io.swagger.annotations.ApiImplicitParams; |
| | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.http.MediaType; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | |
| | | import javax.validation.constraints.Min; |
| | | import javax.validation.constraints.NotEmpty; |
| | | import javax.validation.constraints.NotNull; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | /** |
| | |
| | | */ |
| | | @Autowired |
| | | private CartService cartService; |
| | | @Autowired |
| | | private COSUtil cosUtil; |
| | | |
| | | @Autowired |
| | | private OrderService orderService; |
| | | |
| | | |
| | | @Autowired |
| | | private UserCheckTemplateService userCheckTemplateService; |
| | | @ApiOperation(value = "向购物车中添加一个产品") |
| | | @PostMapping |
| | | @ApiImplicitParams({ |
| | |
| | | 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; |
| | |
| | | throw e; |
| | | } |
| | | } |
| | | |
| | | @PreventDuplicateSubmissions |
| | | @ApiOperation(value = "根据交易编号进行模板数据绑定") |
| | | @PostMapping("/binding/template") |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public ResultMessage<Object> bindingTemplate(@RequestBody BindingTemplateParam bindingTemplateParam) { |
| | | List<Order> byTradeSn = orderService.getByTradeSn(bindingTemplateParam.getSn()); |
| | | if (byTradeSn.isEmpty()) { |
| | | log.info("当前订单不存在{}", bindingTemplateParam.getSn()); |
| | | return ResultUtil.error(ResultCode.ORDER_ERROR); |
| | | } |
| | | if (byTradeSn.size() >1) { |
| | | log.info("当前订单数量异常{}", bindingTemplateParam.getSn()); |
| | | return ResultUtil.error(ResultCode.ORDER_ERROR); |
| | | } |
| | | Order order = byTradeSn.get(0); |
| | | String sn = order.getSn(); |
| | | LambdaQueryWrapper<UserCheckTemplate> eq = Wrappers.<UserCheckTemplate>lambdaQuery().eq(UserCheckTemplate::getOrderSn, sn); |
| | | List<UserCheckTemplate> list = userCheckTemplateService.list(eq); |
| | | if (!list.isEmpty()) { |
| | | log.info("订单不能重复绑定模板{}",bindingTemplateParam.getSn()); |
| | | return ResultUtil.error(ResultCode.ORDER_ERROR); |
| | | } |
| | | //定制商品特殊处理 |
| | | if (StringUtils.isNotBlank(bindingTemplateParam.getTemplateId())){ |
| | | List<CustomizeTemplateForm> templateForm = bindingTemplateParam.getTemplateForm(); |
| | | List<UserCheckTemplate> customizeTemplateForms = new ArrayList<>(); |
| | | for (CustomizeTemplateForm customizeTemplateForm : templateForm) { |
| | | UserCheckTemplate userCheckTemplate = new UserCheckTemplate(); |
| | | userCheckTemplate.setContentType(customizeTemplateForm.getContentType()); |
| | | userCheckTemplate.setChooseImg(bindingTemplateParam.getChooseImage()); |
| | | userCheckTemplate.setChooseImgId(bindingTemplateParam.getChooseImageId()); |
| | | userCheckTemplate.setTemplateName(bindingTemplateParam.getTemplateName()); |
| | | userCheckTemplate.setTemplateId(bindingTemplateParam.getTemplateId()); |
| | | userCheckTemplate.setOrderSn(sn); |
| | | userCheckTemplate.setSubId(customizeTemplateForm.getId()); |
| | | userCheckTemplate.setSubName(customizeTemplateForm.getTemplateTitle()); |
| | | userCheckTemplate.setContent(customizeTemplateForm.getValue()); |
| | | customizeTemplateForms.add(userCheckTemplate); |
| | | } |
| | | userCheckTemplateService.saveBatch(customizeTemplateForms); |
| | | |
| | | } |
| | | return ResultUtil.success(); |
| | | } |
| | | } |