feat:新增机库执行异常自动退款逻辑,并发送服务号通知
This commit is contained in:
+75
-1
@@ -2,11 +2,14 @@ package com.central.order.controller;
|
||||
|
||||
import com.central.common.model.PageResult;
|
||||
import com.central.common.model.Result;
|
||||
import com.central.common.model.SysUser;
|
||||
import com.central.order.enums.OrderStatus;
|
||||
import com.central.order.enums.RefundState;
|
||||
import com.central.order.feign.UserCenterService;
|
||||
import com.central.order.model.Order;
|
||||
import com.central.order.service.IOrderService;
|
||||
import com.central.order.service.IRefundService;
|
||||
import com.central.order.service.IWxTemplateMessageService;
|
||||
import com.central.wechat.config.WxPayConfigFactory;
|
||||
import com.wechat.pay.java.service.refund.model.AmountReq;
|
||||
import com.wechat.pay.java.service.refund.model.CreateRequest;
|
||||
@@ -15,6 +18,8 @@ import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import io.swagger.v3.oas.annotations.enums.ParameterIn;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -23,6 +28,8 @@ import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
@Tag(name = "订单退款管理")
|
||||
@RestController
|
||||
@RequestMapping("/refund")
|
||||
public class RefundController {
|
||||
@@ -36,6 +43,12 @@ public class RefundController {
|
||||
@Autowired
|
||||
private IRefundService refundService;
|
||||
|
||||
@Autowired
|
||||
private IWxTemplateMessageService templateMessageService;
|
||||
|
||||
@Autowired
|
||||
private UserCenterService userCenterService;
|
||||
|
||||
@Value("${tencent.refund-notify-url}")
|
||||
private String refundNotifyUrl;
|
||||
|
||||
@@ -115,6 +128,68 @@ public class RefundController {
|
||||
return Result.failed("处理退款失败");
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/auto")
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Result<String> autoRefundProcess(@RequestParam String orderNo) {
|
||||
try {
|
||||
|
||||
// 1. 获取订单信息
|
||||
Order order = orderService.getOrderByNumber(orderNo);
|
||||
Assert.notNull(order, "订单不存在");
|
||||
|
||||
String refundNo = "RF" + order.getOrderNo();
|
||||
com.central.order.model.Refund existRefund = refundService.getRefundByNo(refundNo);
|
||||
if (existRefund != null) {
|
||||
return Result.succeed("退款逻辑已处理");
|
||||
}
|
||||
|
||||
SysUser user = userCenterService.findUserById(order.getUserId());
|
||||
Assert.notNull(user,"订单用户数据不存在");
|
||||
|
||||
// 2. 发送退款通知
|
||||
templateMessageService.sendPaymentSuccessNotice(
|
||||
user.getOpenId(), orderNo, order.getTourismName(), 1);
|
||||
|
||||
|
||||
// 3. 创建退款单
|
||||
com.central.order.model.Refund refund = new com.central.order.model.Refund();
|
||||
refund.setRefundNo(refundNo);
|
||||
refund.setOrderNo(order.getOrderNo());
|
||||
refund.setUserId(order.getUserId());
|
||||
refund.setOrderAmount(order.getOrderAmount());
|
||||
refund.setRefundAmount(order.getOrderAmount());
|
||||
refund.setStatus(OrderStatus.REFUNDING.getId());
|
||||
refund.setState(RefundState.APPROVING.getId());
|
||||
refund.setRefundReason("机库执行任务异常自动退款");
|
||||
|
||||
boolean refundCreated = refundService.createRefund(refund);
|
||||
if (!refundCreated) {
|
||||
return Result.failed("创建退款单失败");
|
||||
}
|
||||
|
||||
// 4. 更新订单状态
|
||||
order.setOrderStatus(OrderStatus.REFUNDING.getId());
|
||||
orderService.updateOrder(order);
|
||||
|
||||
// 5. 自动审批通过
|
||||
refund.setState(RefundState.APPROVED.getId());
|
||||
refundService.updateById(refund);
|
||||
|
||||
// 6. 调用微信退款接口
|
||||
dealRefundRequest(order);
|
||||
|
||||
return Result.succeed("自动退款流程成功");
|
||||
} catch (Exception e) {
|
||||
log.error("退款流程测试失败", e);
|
||||
return Result.failed("退款流程测试失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 微信退款申请
|
||||
* @param order
|
||||
*/
|
||||
private void dealRefundRequest(Order order) {
|
||||
try {
|
||||
// 创建微信退款请求
|
||||
@@ -142,5 +217,4 @@ public class RefundController {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+9
-5
@@ -2,20 +2,24 @@ package com.central.order.controller;
|
||||
|
||||
import com.central.common.model.Result;
|
||||
import com.central.order.service.IWxTemplateMessageService;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@Slf4j
|
||||
@Tag(name = "公众号通知")
|
||||
@RestController
|
||||
@RequestMapping("/wx/test")
|
||||
@RequestMapping("/mp")
|
||||
@RequiredArgsConstructor
|
||||
public class WxTestController {
|
||||
public class WxMpMessageController {
|
||||
|
||||
private final IWxTemplateMessageService templateMessageService;
|
||||
@Autowired
|
||||
private IWxTemplateMessageService templateMessageService;
|
||||
|
||||
@GetMapping("/template/send")
|
||||
public Result<String> testSendTemplate(
|
||||
@@ -24,8 +28,6 @@ public class WxTestController {
|
||||
@RequestParam String serviceName,
|
||||
@RequestParam Integer rank) {
|
||||
try {
|
||||
|
||||
|
||||
// 发送消息
|
||||
templateMessageService.sendPaymentSuccessNotice(
|
||||
openId, orderNo, serviceName, rank);
|
||||
@@ -36,4 +38,6 @@ public class WxTestController {
|
||||
return Result.failed("发送失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -148,7 +148,8 @@ zlt:
|
||||
/api-device/stream-urls,
|
||||
/api-device/token/query,
|
||||
/api-order/user/temp,
|
||||
/api-file/file/expires
|
||||
/api-file/file/expires,
|
||||
/api-order/refund/auto
|
||||
auth:
|
||||
urlPermission:
|
||||
#是否开启url级别权限
|
||||
|
||||
Reference in New Issue
Block a user