feat:后台退款

This commit is contained in:
dzc committed 2025-01-22 21:04:28 +08:00
1 parent 1968a8ff6c
commit a5bfdd6ced
4 files changed
+93 -8

No files matched your search

@@ -0,0 +1,28 @@
package com.bsd.pjcloud.hard.api.dto.order;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
@Data
public class HardAdminRefundDto {
@Schema(description = "订单id不能为空")
@NotNull(message = "订单id不能为空")
private Long orderId;
@Schema(description = "售后方式")
@NotNull(message = "售后方式不能为空")
private String way;
@Schema(description = "退款原因")
@NotNull(message = "退款原因不能为空")
private String applyReason;
@Schema(description = "相关描述")
private String applyDescription;
@Schema(description="补充凭证图片")
private String applyPicUrls;
}
@@ -10,6 +10,7 @@ import com.bsd.pjcloud.common.idempotent.annotation.Idempotent;
import com.bsd.pjcloud.common.log.annotation.SysLog;
import com.bsd.pjcloud.common.security.service.PjcloudUser;
import com.bsd.pjcloud.common.security.util.SecurityUtils;
import com.bsd.pjcloud.hard.api.dto.order.HardAdminRefundDto;
import com.bsd.pjcloud.hard.api.dto.order.HardAfterSaleDto;
import com.bsd.pjcloud.hard.api.dto.order.HardDisagreeDto;
import com.bsd.pjcloud.hard.api.entity.order.HardAfterSaleEntity;
@@ -76,10 +77,13 @@ public class HardAfterSaleController {
}
/* ************************************* end app end ************************************* */
@GetMapping(value = "/refund")
@Operation(summary = "查询售后进度")
public R<Boolean> refund(@RequestParam Long id) {
return R.ok(hardAfterSaleService.refund(id));
@PostMapping(value = "/admin-refund")
@Operation(summary = "后台退款")
@Idempotent(expireTime = 10, info = "正在退款中,请勿重复操作")
@PreAuthorize("@pms.hasPermission('hard_hardAfterSale_adminRefund')")
public R<Boolean> adminRefund(@RequestBody HardAdminRefundDto dto) {
PjcloudUser user = SecurityUtils.getUser();
return R.ok(hardAfterSaleService.adminRefund(dto, user));
}
@GetMapping(value = "/history")
@@ -2,6 +2,8 @@ package com.bsd.pjcloud.hard.service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.bsd.pjcloud.common.security.service.PjcloudUser;
import com.bsd.pjcloud.hard.api.dto.order.HardAdminRefundDto;
import com.bsd.pjcloud.hard.api.dto.order.HardAfterSaleDto;
import com.bsd.pjcloud.hard.api.dto.order.HardDisagreeDto;
import com.bsd.pjcloud.hard.api.entity.order.HardAfterSaleEntity;
@@ -20,6 +22,7 @@ public interface HardAfterSaleService extends IService<HardAfterSaleEntity> {
/**
* 申请售后
*
* @param dto
* @return
*/
@@ -27,7 +30,8 @@ public interface HardAfterSaleService extends IService<HardAfterSaleEntity> {
/**
* 取消售后
* @param userId 用户id
*
* @param userId 用户id
* @param afterSaleId 售后id
* @return
*/
@@ -51,7 +55,7 @@ public interface HardAfterSaleService extends IService<HardAfterSaleEntity> {
* 同意售后
*
* @param userId 用户id
* @param id 售后id
* @param id 售后id
*/
Boolean agreeAfterSale(Long userId, Long id);
@@ -63,4 +67,12 @@ public interface HardAfterSaleService extends IService<HardAfterSaleEntity> {
* @return
*/
Boolean disagreeRefund(Long userId, HardDisagreeDto dto);
/**
* 后台退款
*
* @param dto
* @return
*/
Boolean adminRefund(HardAdminRefundDto dto, PjcloudUser user);
}
@@ -17,12 +17,14 @@ import com.bsd.pjcloud.common.core.util.BeanUtils;
import com.bsd.pjcloud.common.core.util.CollectionUtils;
import com.bsd.pjcloud.common.core.util.R;
import com.bsd.pjcloud.common.data.datascope.DataScope;
import com.bsd.pjcloud.common.security.service.PjcloudUser;
import com.bsd.pjcloud.hard.api.constant.order.HardOrderStatusEnum;
import com.bsd.pjcloud.hard.api.constant.order.HardOrderTypeEnum;
import com.bsd.pjcloud.hard.api.constant.refund.HardAfterSaleOperateTypeEnum;
import com.bsd.pjcloud.hard.api.constant.refund.HardRefundStatusEnum;
import com.bsd.pjcloud.hard.api.constant.refund.HardSaleStatusEnum;
import com.bsd.pjcloud.hard.api.constant.refund.HardSaleTypeEnum;
import com.bsd.pjcloud.hard.api.dto.order.HardAdminRefundDto;
import com.bsd.pjcloud.hard.api.dto.order.HardAfterSaleDto;
import com.bsd.pjcloud.hard.api.dto.order.HardDisagreeDto;
import com.bsd.pjcloud.hard.api.dto.order.HardOrderDto;
@@ -216,7 +218,10 @@ public class HardAfterSaleServiceImpl extends ServiceImpl<HardAfterSaleMapper, H
// 创建退款单
WalletRechargeRefundDto hardRefundDto = WalletRechargeRefundDto.builder().walletId(order.getWalletId()).orderId(order.getId()).afterSaleId(afterSale.getId()).refundCode(refundCode).reason("订单退款").price(order.getPayPrice()).build();
R<WalletRechargeVo> walletRefundResult = walletRechargeService.refund(hardRefundDto);
WalletRechargeVo walletRefund = Optional.of(walletRefundResult).map(R::getData).orElseThrow(() -> new RuntimeException("钱包退款错误"));
if (walletRefundResult.getCode() != 0 || ObjectUtil.isEmpty(walletRefundResult.getData())) {
throw new RuntimeException("钱包退款错误");
}
WalletRechargeVo walletRefund = walletRefundResult.getData();
HardOrderEntity updateObj = HardOrderEntity.builder()
.id(order.getId())
.orderStatus(HardOrderStatusEnum.REFUND.getType())
@@ -303,7 +308,7 @@ public class HardAfterSaleServiceImpl extends ServiceImpl<HardAfterSaleMapper, H
}
// 校验订单是否已退款
if (ObjectUtil.isNotEmpty(order.getPayRefundId())) {
throw new RuntimeException("发起退款失败,示例订单已退款");
throw new RuntimeException("发起退款失败,订单已退款");
}
return orderVo;
}
@@ -353,6 +358,42 @@ public class HardAfterSaleServiceImpl extends ServiceImpl<HardAfterSaleMapper, H
return saveObj;
}
@Override
// @GlobalTransactional
@Transactional(rollbackFor = Exception.class)
public Boolean adminRefund(HardAdminRefundDto dto, PjcloudUser user) {
// 校验订单是否可以退款
HardOrderVo order = validateOrderCanRefund(dto.getOrderId());
// 添加售后订单
HardAfterSaleEntity saveObj = BeanUtils.toBean(dto, HardAfterSaleEntity.class);
String refundCode = "hard_" + order.getId();
saveObj.setType(HardSaleTypeEnum.AFTER_SALE.getType());
saveObj.setStatus(HardSaleStatusEnum.COMPLETE.getStatus());
saveObj.setNo(refundCode);
saveObj.setOrderId(order.getId());
saveObj.setRefundPrice(order.getPayPrice());
saveObj.setUserId(order.getUserId());
saveObj.setAuditUserId(user.getId());
saveObj.setAuditTime(LocalDateTime.now());
saveObj.setAuditReason("后台退款");
baseMapper.insert(saveObj);
// 添加售后进度
HardAfterSaleLogEntity saveLogObj = HardAfterSaleLogEntity.builder()
.afterSaleId(saveObj.getId())
.userId(order.getUserId())
.operateType(HardAfterSaleOperateTypeEnum.ADMIN_REFUND.getType())
.beforeStatus(order.getOrderStatus())
.afterStatus(HardSaleStatusEnum.COMPLETE.getStatus())
.content(HardSaleStatusEnum.COMPLETE.getContent())
.build();
hardAfterSaleLogMapper.insert(saveLogObj);
// 执行退款
getSelf().refund(saveObj.getId());
// 退库存
hardOrderService.fastenerInventory(order, YesNoEnum.NO);
return true;
}
private HardAfterSaleServiceImpl getSelf() {
return SpringUtil.getBean(getClass());
}