2
0

feat: 退款审批

This commit is contained in:
caiyuchao
2025-03-31 10:25:14 +08:00
parent 1a65c76613
commit 5f46f3044b
36 changed files with 942 additions and 88 deletions

View File

@@ -0,0 +1,83 @@
package org.wfc.system.controller;
import cn.hutool.core.collection.CollUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.wfc.common.core.domain.R;
import org.wfc.common.core.web.controller.BaseController;
import org.wfc.common.core.web.domain.AjaxResult;
import org.wfc.common.core.web.page.TableDataInfo;
import org.wfc.system.domain.URefund;
import org.wfc.system.domain.bo.URefundApproveBo;
import org.wfc.system.service.IURefundService;
import java.util.List;
/**
* <p>
* 用户平台-退款表 前端控制器
* </p>
*
* @author sys
* @since 2025-03-27
*/
@RestController
@RequestMapping("/refund")
public class URefundController extends BaseController {
@Autowired
private IURefundService uRefundService;
@GetMapping("/page")
public TableDataInfo page(URefund uRefund) {
startPage();
List<URefund> list = uRefundService.queryList(uRefund);
return getDataTable(list);
}
@GetMapping("/list")
public AjaxResult list(URefund uRefund) {
List<URefund> list = uRefundService.queryList(uRefund);
return success(list);
}
@GetMapping(value = "/{id}")
public AjaxResult getById(@PathVariable("id") Long id) {
return success(uRefundService.getById(id));
}
@PostMapping
public AjaxResult add(@RequestBody URefund uRefund) {
return toAjax(uRefundService.save(uRefund));
}
@PutMapping
public AjaxResult edit(@RequestBody URefund uRefund) {
return toAjax(uRefundService.updateById(uRefund));
}
@DeleteMapping("/{ids}")
public AjaxResult remove(@PathVariable Long[] ids) {
return toAjax(uRefundService.removeByIds(CollUtil.newArrayList(ids)));
}
@PostMapping("pass")
public R<Boolean> pass(@RequestBody URefundApproveBo refundApproveBo) {
uRefundService.pass(refundApproveBo);
return R.ok(true);
}
@PostMapping("reject")
public R<Boolean> reject(@RequestBody URefundApproveBo refundApproveBo) {
uRefundService.reject(refundApproveBo);
return R.ok(true);
}
}

View File

@@ -0,0 +1,48 @@
package org.wfc.system.domain;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import org.wfc.common.mybatis.domain.BaseData;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;
/**
* <p>
* 用户平台-退款表
* </p>
*
* @author sys
* @since 2025-03-27
*/
@Getter
@Setter
@TableName("u_refund")
@Schema(name = "URefund", description = "用户平台-退款表")
public class URefund extends BaseData {
private static final long serialVersionUID = 1L;
@Schema(description = "订单ID")
private Long orderId;
@Schema(description = "申请时间")
private Date applyTime;
@Schema(description = "申请原因")
private String applyReason;
@Schema(description = "退款金额")
private BigDecimal refundAmount;
@Schema(description = "退款方式")
private Integer refundMethod;
@Schema(description = "审批状态")
private Integer status;
@Schema(description = "备注")
private String remark;
}

View File

@@ -0,0 +1,14 @@
package org.wfc.system.domain.bo;
import lombok.Data;
/**
* @description: 退款审批Bo
* @author: cyc
* @since: 2025-03-27
*/
@Data
public class URefundApproveBo {
private Long id;
private String remark;
}

View File

@@ -0,0 +1,18 @@
package org.wfc.system.mapper;
import com.baomidou.dynamic.datasource.annotation.DS;
import org.wfc.system.domain.URefund;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
/**
* <p>
* 用户平台-退款表 Mapper 接口
* </p>
*
* @author sys
* @since 2025-03-27
*/
@DS("user")
public interface URefundMapper extends BaseMapper<URefund> {
}

View File

@@ -0,0 +1,25 @@
package org.wfc.system.service;
import org.wfc.system.domain.URefund;
import com.baomidou.mybatisplus.extension.service.IService;
import org.wfc.system.domain.bo.URefundApproveBo;
import java.util.List;
/**
* <p>
* 用户平台-退款表 服务类
* </p>
*
* @author sys
* @since 2025-03-27
*/
public interface IURefundService extends IService<URefund> {
List<URefund> queryList(URefund uRefund);
void pass(URefundApproveBo refundApproveBo);
void reject(URefundApproveBo refundApproveBo);
}

View File

@@ -0,0 +1,113 @@
package org.wfc.system.service.impl;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.wfc.common.core.domain.R;
import org.wfc.common.core.enums.OrderStatusEnum;
import org.wfc.common.core.enums.PaymentTypeEnum;
import org.wfc.common.core.enums.RefundStatusEnum;
import org.wfc.system.domain.UOrder;
import org.wfc.system.domain.URefund;
import org.wfc.system.domain.bo.URefundApproveBo;
import org.wfc.system.mapper.UOrderMapper;
import org.wfc.system.mapper.URefundMapper;
import org.wfc.system.service.IURefundService;
import org.wfc.user.api.RemoteUPaymentService;
import org.wfc.user.api.RemoteUUserService;
import java.util.List;
/**
* <p>
* 用户平台-退款表 服务实现类
* </p>
*
* @author sys
* @since 2025-03-27
*/
@Service
public class URefundServiceImpl extends ServiceImpl<URefundMapper, URefund> implements IURefundService {
@Autowired
private UOrderMapper orderMapper;
@Autowired
private RemoteUUserService remoteUUserService;
@Autowired
private RemoteUPaymentService remoteUPaymentService;
@Override
public List<URefund> queryList(URefund uRefund) {
return this.list(buildQueryWrapper(uRefund));
}
private LambdaQueryWrapper<URefund> buildQueryWrapper(URefund bo) {
LambdaQueryWrapper<URefund> lqw = Wrappers.lambdaQuery();
lqw.eq(bo.getOrderId() != null, URefund::getOrderId, bo.getOrderId());
lqw.eq(bo.getApplyTime() != null, URefund::getApplyTime, bo.getApplyTime());
lqw.like(StrUtil.isNotBlank(bo.getApplyReason()), URefund::getApplyReason, bo.getApplyReason());
lqw.eq(bo.getRefundAmount() != null, URefund::getRefundAmount, bo.getRefundAmount());
lqw.eq(bo.getRefundMethod() != null, URefund::getRefundMethod, bo.getRefundMethod());
lqw.eq(bo.getStatus() != null, URefund::getStatus, bo.getStatus());
lqw.like(StrUtil.isNotBlank(bo.getRemark()), URefund::getRemark, bo.getRemark());
return lqw;
}
@Transactional(rollbackFor = Exception.class)
public void pass(URefundApproveBo refundApproveBo) {
// 只有待审批状态的才能审批
URefund refund = this.getById(refundApproveBo.getId());
if (!RefundStatusEnum.PENDING.getCode().equals(refund.getStatus())) {
return;
}
// 更新审批原因
refund.setRemark(refundApproveBo.getRemark());
this.updateById(refund);
UOrder order = orderMapper.selectById(refund.getOrderId());
switch (PaymentTypeEnum.getByCode(order.getPaymentId().intValue())) {
case ALIPAY:
// 支付宝
// 调用退款接口
R<Boolean> result = remoteUPaymentService.aliPayRefund(refund.getOrderId(), "inner");
if (result.getData()) {
remoteUUserService.refundSuccess(PaymentTypeEnum.ALIPAY.getCode(), refund.getId(), "inner");
}
break;
case WX_PAY:
// 微信
remoteUPaymentService.wxPayRefund(refund.getOrderId(), "inner");
break;
case BALANCE:
// 余额
remoteUUserService.refundSuccess(PaymentTypeEnum.BALANCE.getCode(), refund.getId(), "inner");
break;
default:
break;
}
}
@Transactional(rollbackFor = Exception.class)
public void reject(URefundApproveBo refundApproveBo) {
// 只有待审批状态的才能审批
URefund refund = this.getById(refundApproveBo.getId());
if (!RefundStatusEnum.PENDING.getCode().equals(refund.getStatus())) {
return;
}
// 修改审批状态
refund.setRemark(refundApproveBo.getRemark());
refund.setStatus(RefundStatusEnum.REJECTED.getCode());
this.save(refund);
// 修改订单状态
UOrder order = new UOrder();
order.setId(refund.getOrderId());
order.setStatus(OrderStatusEnum.PAID.getCode());
orderMapper.updateById(order);
}
}

View File

@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.wfc.system.mapper.URefundMapper">
</mapper>