From 67050eeaa8047c57df1f5e81bac9e79185f9476a Mon Sep 17 00:00:00 2001 From: YunaiV Date: Thu, 17 Nov 2022 00:10:59 +0800 Subject: [PATCH] =?UTF-8?q?trade=EF=BC=9A=E3=80=90=E4=BA=A4=E6=98=93?= =?UTF-8?q?=E5=94=AE=E5=90=8E=E3=80=91=E7=A1=AE=E8=AE=A4=E6=94=B6=E8=B4=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../trade/enums/ErrorCodeConstants.java | 3 +- .../aftersale/TradeAfterSaleController.java | 9 +++ .../vo/TradeAfterSaleAuditReqVO.java | 2 +- .../vo/TradeAfterSaleConfirmReqVO.java | 25 ++++++++ .../aftersale/TradeAfterSaleService.java | 10 +++ .../aftersale/TradeAfterSaleServiceImpl.java | 62 +++++++++++++++++-- 6 files changed, 105 insertions(+), 6 deletions(-) create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/aftersale/vo/TradeAfterSaleConfirmReqVO.java diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java index cea7ceb4e..c50ee3610 100644 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java @@ -32,7 +32,8 @@ public interface ErrorCodeConstants { ErrorCode AFTER_SALE_CREATE_FAIL_ORDER_ITEM_APPLIED = new ErrorCode(1011000105, "订单项已申请售后,无法重复申请"); ErrorCode AFTER_SALE_AUDIT_FAIL_STATUS_NOT_APPLY = new ErrorCode(1011000106, "审批失败,售后状态不处于审批中"); ErrorCode AFTER_SALE_UPDATE_STATUS_FAIL = new ErrorCode(1011000107, "操作售后单失败,请刷新后重试"); - ErrorCode AFTER_SALE_DELIVERY_FAIL_STATUS_NOT_BUYER_RETURN = new ErrorCode(1011000108, "退货失败,售后单状态不处于【买家退货】"); + ErrorCode AFTER_SALE_DELIVERY_FAIL_STATUS_NOT_SELLER_PASS = new ErrorCode(1011000108, "退货失败,售后单状态不处于【待买家退货】"); + ErrorCode AFTER_SALE_CONFIRM_FAIL_STATUS_NOT_BUYER_RETURN = new ErrorCode(1011000109, "确认收货失败,售后单状态不处于【待确认收货】"); // ========== Cart 模块 1-011-001-000 ========== ErrorCode CARD_ITEM_NOT_FOUND = new ErrorCode(1011002000, "购物车项不存在"); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/aftersale/TradeAfterSaleController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/aftersale/TradeAfterSaleController.java index 9a6311860..b5c517253 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/aftersale/TradeAfterSaleController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/aftersale/TradeAfterSaleController.java @@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.trade.controller.admin.aftersale; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.TradeAfterSaleAuditReqVO; +import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.TradeAfterSaleConfirmReqVO; import cn.iocoder.yudao.module.trade.service.aftersale.TradeAfterSaleService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -37,4 +38,12 @@ public class TradeAfterSaleController { return success(true); } + @PutMapping("/confirm") + @ApiOperation("确认收货") + @PreAuthorize("@ss.hasPermission('trade:after-sale:audit')") + public CommonResult confirmAfterSale(@RequestBody TradeAfterSaleConfirmReqVO confirmReqVO) { + afterSaleService.confirmAfterSale(getLoginUserId(), getClientIP(), confirmReqVO); + return success(true); + } + } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/aftersale/vo/TradeAfterSaleAuditReqVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/aftersale/vo/TradeAfterSaleAuditReqVO.java index 1df9a383a..2ee605e44 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/aftersale/vo/TradeAfterSaleAuditReqVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/aftersale/vo/TradeAfterSaleAuditReqVO.java @@ -17,7 +17,7 @@ public class TradeAfterSaleAuditReqVO { @ApiModelProperty(value = "审批结果", required = true, example = "true", notes = "true - 通过;false - 不通过") @NotNull(message = "审批结果不能为空") - private Boolean audit; + private Boolean pass; @ApiModelProperty(value = "审批备注", example = "你猜") private String auditReason; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/aftersale/vo/TradeAfterSaleConfirmReqVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/aftersale/vo/TradeAfterSaleConfirmReqVO.java new file mode 100644 index 000000000..1c9a1fe6e --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/aftersale/vo/TradeAfterSaleConfirmReqVO.java @@ -0,0 +1,25 @@ +package cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.validation.constraints.NotNull; + +@ApiModel("管理后台 - 交易售后确认收货 Request VO") +@Data +public class TradeAfterSaleConfirmReqVO { + + @ApiModelProperty(value = "售后编号", required = true, example = "1024") + @NotNull(message = "售后编号不能为空") + private Long id; + + @ApiModelProperty(value = "收货结果", required = true, example = "true", + notes = "true - 确认收货;false - 拒绝收货") + @NotNull(message = "审批结果不能为空") + private Boolean pass; + + @ApiModelProperty(value = "收货备注", example = "你猜") + private String receiptMemo; + +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/aftersale/TradeAfterSaleService.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/aftersale/TradeAfterSaleService.java index d0ef09342..82f577981 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/aftersale/TradeAfterSaleService.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/aftersale/TradeAfterSaleService.java @@ -1,6 +1,7 @@ package cn.iocoder.yudao.module.trade.service.aftersale; import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.TradeAfterSaleAuditReqVO; +import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.TradeAfterSaleConfirmReqVO; import cn.iocoder.yudao.module.trade.controller.app.aftersale.vo.AppTradeAfterSaleCreateReqVO; import cn.iocoder.yudao.module.trade.controller.app.aftersale.vo.AppTradeAfterSaleDeliveryReqVO; @@ -39,4 +40,13 @@ public interface TradeAfterSaleService { */ void deliveryAfterSale(Long userId, AppTradeAfterSaleDeliveryReqVO deliveryReqVO); + /** + * 确认收货 + * + * @param userId 管理员用户编号 + * @param userIp 操作 IP + * @param confirmReqVO 收货 Request 信息 + */ + void confirmAfterSale(Long userId, String userIp, TradeAfterSaleConfirmReqVO confirmReqVO); + } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/aftersale/TradeAfterSaleServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/aftersale/TradeAfterSaleServiceImpl.java index 11b439940..f9033fb65 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/aftersale/TradeAfterSaleServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/aftersale/TradeAfterSaleServiceImpl.java @@ -1,9 +1,11 @@ package cn.iocoder.yudao.module.trade.service.aftersale; +import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.RandomUtil; import cn.iocoder.yudao.module.pay.api.refund.PayRefundApi; import cn.iocoder.yudao.module.pay.api.refund.dto.PayRefundCreateReqDTO; import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.TradeAfterSaleAuditReqVO; +import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.TradeAfterSaleConfirmReqVO; import cn.iocoder.yudao.module.trade.controller.app.aftersale.vo.AppTradeAfterSaleCreateReqVO; import cn.iocoder.yudao.module.trade.controller.app.aftersale.vo.AppTradeAfterSaleDeliveryReqVO; import cn.iocoder.yudao.module.trade.convert.aftersale.TradeAfterSaleConvert; @@ -129,12 +131,12 @@ public class TradeAfterSaleServiceImpl implements TradeAfterSaleService { if (afterSale == null) { throw exception(AFTER_SALE_NOT_FOUND); } - if (afterSale.getStatus().equals(TradeAfterSaleStatusEnum.APPLY.getStatus())) { + if (ObjectUtil.notEqual(afterSale.getStatus(), TradeAfterSaleStatusEnum.APPLY.getStatus())) { throw exception(AFTER_SALE_AUDIT_FAIL_STATUS_NOT_APPLY); } // 进行审批 - if (auditReqVO.getAudit()) { + if (auditReqVO.getPass()) { auditAfterSalePass(userId, userIp, auditReqVO, afterSale); } else { auditAfterSaleReject(userId, auditReqVO, afterSale); @@ -207,8 +209,8 @@ public class TradeAfterSaleServiceImpl implements TradeAfterSaleService { if (afterSale == null) { throw exception(AFTER_SALE_NOT_FOUND); } - if (afterSale.getStatus().equals(TradeAfterSaleStatusEnum.SELLER_PASS.getStatus())) { - throw exception(AFTER_SALE_DELIVERY_FAIL_STATUS_NOT_BUYER_RETURN); + if (ObjectUtil.notEqual(afterSale.getStatus(), TradeAfterSaleStatusEnum.SELLER_PASS.getStatus())) { + throw exception(AFTER_SALE_DELIVERY_FAIL_STATUS_NOT_SELLER_PASS); } // 更新售后单的物流信息 @@ -222,4 +224,56 @@ public class TradeAfterSaleServiceImpl implements TradeAfterSaleService { // TODO 发送售后消息 } + @Override + public void confirmAfterSale(Long userId, String userIp, + TradeAfterSaleConfirmReqVO confirmReqVO) { + // 校验售后单存在,并状态未审批 + TradeAfterSaleDO afterSale = tradeAfterSaleMapper.selectById(confirmReqVO.getId()); + if (afterSale == null) { + throw exception(AFTER_SALE_NOT_FOUND); + } + if (ObjectUtil.notEqual(afterSale.getStatus(), TradeAfterSaleStatusEnum.BUYER_RETURN.getStatus())) { + throw exception(AFTER_SALE_CONFIRM_FAIL_STATUS_NOT_BUYER_RETURN); + } + + // 进行审批 + if (confirmReqVO.getPass()) { + confirmAfterSalePass(userId, userIp, confirmReqVO, afterSale); + } else { + confirmAfterSaleReject(userId, confirmReqVO, afterSale); + } + } + + private void confirmAfterSalePass(Long userId, String userIp, + TradeAfterSaleConfirmReqVO confirmReqVO, TradeAfterSaleDO afterSale) { + // 更新售后单的状态 + Integer newStatus = TradeAfterSaleStatusEnum.WAIT_REFUND.getStatus(); + updateAfterSaleStatus(afterSale.getId(), TradeAfterSaleStatusEnum.BUYER_RETURN.getStatus(), new TradeAfterSaleDO() + .setStatus(newStatus).setReceiptTime(LocalDateTime.now()).setReceiptMemo(confirmReqVO.getReceiptMemo())); + + // 如果直接退款,则发起售后退款 + if (afterSale.getType().equals(TradeAfterSaleTypeEnum.REFUND.getType())) { + createPayRefund(userIp, afterSale); + } + + // TODO 记录售后日志 + + // TODO 发送售后消息 + } + + private void confirmAfterSaleReject(Long userId, TradeAfterSaleConfirmReqVO confirmReqVO, TradeAfterSaleDO afterSale) { + // 更新售后单的状态 + Integer newStatus = TradeAfterSaleStatusEnum.SELLER_TERMINATION.getStatus(); + updateAfterSaleStatus(afterSale.getId(), TradeAfterSaleStatusEnum.BUYER_RETURN.getStatus(), new TradeAfterSaleDO() + .setStatus(newStatus).setReceiptTime(LocalDateTime.now()).setReceiptMemo(confirmReqVO.getReceiptMemo())); + + // 更新交易订单项的售后状态为【未申请】 + tradeOrderService.updateOrderItemAfterSaleStatus(afterSale.getOrderItemId(), + TradeOrderItemAfterSaleStatusEnum.APPLY.getStatus(), TradeOrderItemAfterSaleStatusEnum.NONE.getStatus()); + + // TODO 记录售后日志 + + // TODO 发送售后消息 + } + }