From 8220af689c0e7c224b17a777bc01584ad30aa20c Mon Sep 17 00:00:00 2001 From: czc Date: Mon, 17 Jul 2023 10:10:39 +0800 Subject: [PATCH] =?UTF-8?q?H5=E5=8F=96=E6=B6=88=E5=94=AE=E5=90=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ruoyi/common/enums/AftersaleStatus.java | 31 ++++++++++++ .../cyl/h5/controller/H5OrderController.java | 21 ++++++++ .../com/cyl/h5/service/H5OrderService.java | 49 ++++++++++++++++++- 3 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 ruoyi-common/src/main/java/com/ruoyi/common/enums/AftersaleStatus.java diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/enums/AftersaleStatus.java b/ruoyi-common/src/main/java/com/ruoyi/common/enums/AftersaleStatus.java new file mode 100644 index 0000000..c18c799 --- /dev/null +++ b/ruoyi-common/src/main/java/com/ruoyi/common/enums/AftersaleStatus.java @@ -0,0 +1,31 @@ +package com.ruoyi.common.enums; + +/** + * 售后状态 + * + * @author ruoyi + */ +public enum AftersaleStatus +{ + APPLY(0, "待处理"), + WAIT(1, "退货中"), + SUCCESS(2, "已完成"), + REJECT(3, "已拒绝"), + CANCEL(4,"用户取消"); + + private final Integer type; + private final String msg; + + private AftersaleStatus(Integer type, String msg) { + this.type = type; + this.msg = msg; + } + + public Integer getType() { + return this.type; + } + + public String getMsg() { + return this.msg; + } +} diff --git a/ruoyi-mall/src/main/java/com/cyl/h5/controller/H5OrderController.java b/ruoyi-mall/src/main/java/com/cyl/h5/controller/H5OrderController.java index cbb096e..9aad934 100644 --- a/ruoyi-mall/src/main/java/com/cyl/h5/controller/H5OrderController.java +++ b/ruoyi-mall/src/main/java/com/cyl/h5/controller/H5OrderController.java @@ -178,4 +178,25 @@ public class H5OrderController { } } } + + @ApiOperation("取消售后") + @GetMapping("/cancelRefund") + public ResponseEntity cancelRefund(Long orderId){ + log.info("【取消售后】订单id:" + orderId); + String redisKey = "h5_oms_order_cancelRefund_" + orderId; + String redisValue = orderId + "_" + System.currentTimeMillis(); + try{ + redisService.lock(redisKey, redisValue, 60); + return ResponseEntity.ok(service.cancelRefund(orderId)); + }catch (Exception e){ + log.error("取消售后发生异常",e); + throw new RuntimeException(e.getMessage()); + }finally { + try { + redisService.unLock(redisKey, redisValue); + } catch (Exception e) { + log.error("", e); + } + } + } } diff --git a/ruoyi-mall/src/main/java/com/cyl/h5/service/H5OrderService.java b/ruoyi-mall/src/main/java/com/cyl/h5/service/H5OrderService.java index 169a427..906ba99 100644 --- a/ruoyi-mall/src/main/java/com/cyl/h5/service/H5OrderService.java +++ b/ruoyi-mall/src/main/java/com/cyl/h5/service/H5OrderService.java @@ -39,6 +39,7 @@ import com.github.pagehelper.PageHelper; import com.ruoyi.common.constant.Constants; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.redis.RedisService; +import com.ruoyi.common.enums.AftersaleStatus; import com.ruoyi.common.enums.OrderRefundStatus; import com.ruoyi.common.enums.OrderStatus; import com.ruoyi.common.enums.TradeStatusEnum; @@ -600,7 +601,7 @@ public class H5OrderService { addAftersale.setOrderId(order.getId()); addAftersale.setReturnAmount(order.getPayAmount()); addAftersale.setType(applyRefundDTO.getApplyRefundType()); - addAftersale.setStatus(OrderRefundStatus.APPLY.getType()); + addAftersale.setStatus(AftersaleStatus.APPLY.getType()); addAftersale.setReason(applyRefundDTO.getReason()); addAftersale.setQuantity(applyRefundDTO.getQuantity()); addAftersale.setReason(applyRefundDTO.getReason()); @@ -684,4 +685,50 @@ public class H5OrderService { throw new RuntimeException("售后正在处理中"); } } + + /** + * 取消售后 + * @param orderId 订单id + * @return + */ + public String cancelRefund(Long orderId) { + Order order = orderMapper.selectById(orderId); + if (order == null){ + throw new RuntimeException("未查询到该订单"); + } + //查询是否有(待处理和退货中)售后单 + QueryWrapper aftersaleQw = new QueryWrapper<>(); + aftersaleQw.eq("order_id", orderId); + aftersaleQw.in("status", Arrays.asList(AftersaleStatus.APPLY.getType(), AftersaleStatus.WAIT.getType())); + Aftersale aftersale = aftersaleMapper.selectOne(aftersaleQw); + if (aftersale == null){ + throw new RuntimeException("无售后单"); + } + if (OrderRefundStatus.SUCCESS.getType().equals(order.getAftersaleStatus())){ + throw new RuntimeException("已退款成功"); + } + Member member = (Member) LocalDataUtil.getVar(Constants.MEMBER_INFO); + LocalDateTime optDate = LocalDateTime.now(); + //更新售后单状态 + UpdateWrapper aftersaleUpdateWrapper = new UpdateWrapper<>(); + aftersaleUpdateWrapper.eq("id", aftersale.getId()); + aftersaleUpdateWrapper.set("status", AftersaleStatus.CANCEL.getType()); + aftersaleUpdateWrapper.set("update_time", optDate); + aftersaleUpdateWrapper.set("update_by", member.getId()); + int rows = aftersaleMapper.update(null, aftersaleUpdateWrapper); + if (rows < 1){ + throw new RuntimeException("更新售后单失败"); + } + //更新订单售后状态 + // 更新订单 + UpdateWrapper updateOrderWrapper = new UpdateWrapper<>(); + updateOrderWrapper.eq("id", orderId) + .set("aftersale_status", OrderRefundStatus.NO_REFUND.getType()).set("update_time", optDate) + .set("update_by", member.getId()); + rows = orderMapper.update(null, updateOrderWrapper); + if (rows != 1) { + throw new RuntimeException("更新订单状态失败"); + } + return "售后取消成功"; + } }