221 lines
7.6 KiB
Java
221 lines
7.6 KiB
Java
|
|
package com.cdzy.payment.controller;
|
|||
|
|
|
|||
|
|
import cn.dev33.satoken.stp.StpUtil;
|
|||
|
|
import com.alibaba.fastjson2.JSONObject;
|
|||
|
|
import com.cdzy.common.model.response.JsonResult;
|
|||
|
|
import com.cdzy.payment.model.dto.*;
|
|||
|
|
import com.cdzy.payment.model.vo.*;
|
|||
|
|
import com.cdzy.payment.service.EbikeRefundService;
|
|||
|
|
import com.cdzy.payment.service.WxPayService;
|
|||
|
|
import com.mybatisflex.core.paginate.Page;
|
|||
|
|
import com.wechat.pay.java.service.payments.model.Transaction;
|
|||
|
|
import com.wechat.pay.java.service.refund.model.Refund;
|
|||
|
|
import jakarta.annotation.Resource;
|
|||
|
|
import lombok.extern.slf4j.Slf4j;
|
|||
|
|
import org.springframework.web.bind.annotation.*;
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 用户订单微信支付 控制层。
|
|||
|
|
*
|
|||
|
|
* @author: yanglei
|
|||
|
|
* @since: 2025-10-21 14:42
|
|||
|
|
*/
|
|||
|
|
|
|||
|
|
@Slf4j
|
|||
|
|
@RestController
|
|||
|
|
@RequestMapping("/wxPayment")
|
|||
|
|
public class EbikeWxPaymentController {
|
|||
|
|
|
|||
|
|
@Resource
|
|||
|
|
private WxPayService wxPayService;
|
|||
|
|
|
|||
|
|
@Resource
|
|||
|
|
private EbikeRefundService ebikeRefundService;
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 微信支付下单
|
|||
|
|
*
|
|||
|
|
* @param orderId 骑行订单id
|
|||
|
|
* @return 下单成功返回true,否则返回false
|
|||
|
|
*/
|
|||
|
|
@GetMapping("/prepay")
|
|||
|
|
public JsonResult<?> prepay(@RequestParam(name = "orderId") String orderId) {
|
|||
|
|
JSONObject r = wxPayService.prepay(orderId);
|
|||
|
|
return r.containsKey("error") ? JsonResult.failed("下单失败: " + r.getString("error")) : JsonResult.success(r);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 通过商户(骑行)订单号查询支付订单
|
|||
|
|
*
|
|||
|
|
* @param orderId 商户(骑行)订单号
|
|||
|
|
* @return 支付订单信息
|
|||
|
|
*/
|
|||
|
|
@GetMapping("/queryOrder/{orderId}")
|
|||
|
|
public JsonResult<?> queryOrderByOrderId(@PathVariable(name = "orderId") String orderId) {
|
|||
|
|
Transaction r = wxPayService.queryOrderByOrderId(orderId);
|
|||
|
|
return r == null ? JsonResult.failed(String.format("骑行订单号{%s}查询支付订单失败", orderId)) : JsonResult.success(r);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 通过商户(骑行)订单订单号查询支付订单状态
|
|||
|
|
*
|
|||
|
|
* @param orderId 微信支付订单号
|
|||
|
|
* @return 订单信息支付状态
|
|||
|
|
*/
|
|||
|
|
@GetMapping("/queryOrderStatus/{orderId}")
|
|||
|
|
public JsonResult<?> queryOrderStatusById(@PathVariable(name = "orderId") String orderId) {
|
|||
|
|
HandleNotifyVo r = wxPayService.queryOrderStatusByOrderId(orderId);
|
|||
|
|
return JsonResult.success(r);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 拆分为两个接口,一个是退款申请(生成退款记录),一个是提交退款(调用微信退款接口)
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 退款申请
|
|||
|
|
*
|
|||
|
|
* @param ebikeRefundDto 退款信息
|
|||
|
|
* @return 退款成功返回主键id,否则返回失败
|
|||
|
|
*/
|
|||
|
|
@PostMapping("/refundApply")
|
|||
|
|
public JsonResult<?> refundApply(@RequestBody EbikeRefundDto ebikeRefundDto) {
|
|||
|
|
Long r = wxPayService.refundApply(ebikeRefundDto.getOrderId(), ebikeRefundDto.getReason());
|
|||
|
|
return r == null ? JsonResult.failed("退款申请失败") : JsonResult.success(r);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 调用退款接口
|
|||
|
|
*
|
|||
|
|
* @param refundDto 退款请求参数
|
|||
|
|
* @return 退款成功返回true,否则返回false
|
|||
|
|
*/
|
|||
|
|
@PostMapping("/refund")
|
|||
|
|
public JsonResult<?> refund(@RequestBody RefundDto refundDto) {
|
|||
|
|
// 获取审核人信息
|
|||
|
|
String loginId = (String) StpUtil.getLoginId();
|
|||
|
|
HandleNotifyVo r = wxPayService.refund(refundDto, loginId);
|
|||
|
|
return r.isSuccess() ? JsonResult.success(true) : JsonResult.failed(r.getMessage());
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 通过退款记录主键id查询退款信息
|
|||
|
|
*
|
|||
|
|
* @param refundId 退款主键id
|
|||
|
|
* @return 退款状态信息
|
|||
|
|
*/
|
|||
|
|
@GetMapping("/queryRefundStatus/{refundId}")
|
|||
|
|
public JsonResult<?> queryRefundStatus(@PathVariable(name = "refundId") Long refundId) {
|
|||
|
|
HandleNotifyVo r = wxPayService.queryRefundStatusById(refundId);
|
|||
|
|
return JsonResult.success(r);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 审核退款申请
|
|||
|
|
*
|
|||
|
|
* @param processDto 退款处理信息
|
|||
|
|
* @return 审核成功返回true,否则返回false
|
|||
|
|
*/
|
|||
|
|
@PostMapping("/reviewRefund")
|
|||
|
|
public JsonResult<?> reviewRefund(@RequestBody RefundProcessDto processDto) {
|
|||
|
|
// 获取审核人信息id
|
|||
|
|
String loginId = (String) StpUtil.getLoginId();
|
|||
|
|
boolean r = wxPayService.refundReview(processDto, loginId);
|
|||
|
|
return r ? JsonResult.success(true) : JsonResult.failed("审核失败");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 通过退款单号查询退款信息
|
|||
|
|
*
|
|||
|
|
* @param refundId 商户(骑行)退款id
|
|||
|
|
* @return 退款信息
|
|||
|
|
*/
|
|||
|
|
@GetMapping("/queryRefund/{refundId}")
|
|||
|
|
public JsonResult<?> refundQuery(@PathVariable(name = "refundId") Long refundId) {
|
|||
|
|
Refund r = wxPayService.queryRefundById(refundId);
|
|||
|
|
return r == null ? JsonResult.failed(String.format("退款单号{%s}查询退款失败", refundId)) : JsonResult.success(r);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 获取退款列表
|
|||
|
|
*
|
|||
|
|
* @param refundDto 查询条件
|
|||
|
|
* @return 退款列表
|
|||
|
|
*/
|
|||
|
|
@PostMapping("/queryRefundList")
|
|||
|
|
public JsonResult<?> queryRefundList(@RequestBody RefundQueryDto refundDto) {
|
|||
|
|
Page<?> list = wxPayService.queryRefundList(refundDto);
|
|||
|
|
return JsonResult.success(list);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 退款订单详情
|
|||
|
|
*
|
|||
|
|
* @param refundId 退款id
|
|||
|
|
* @return 退款详情
|
|||
|
|
*/
|
|||
|
|
@GetMapping("/refundOrderDetail/{refundId}")
|
|||
|
|
public JsonResult<?> refundOrderDetail(@PathVariable(name = "refundId") Long refundId) {
|
|||
|
|
RefundOrderDetailVo r = wxPayService.queryRefundOrderById(refundId);
|
|||
|
|
return r == null ? JsonResult.failed(String.format("退款单号{%s}查询订单详情失败", refundId)) : JsonResult.success(r);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 退款申请订单详情
|
|||
|
|
*
|
|||
|
|
* @param orderId 订单id
|
|||
|
|
* @return 订单详情
|
|||
|
|
*/
|
|||
|
|
@GetMapping("/refundApplyOrderDetail/{orderId}")
|
|||
|
|
public JsonResult<?> refundApplyOrderDetail(@PathVariable(name = "orderId") String orderId) {
|
|||
|
|
RefundOrderInfoVo r = wxPayService.queryRefundApplyOrderById(orderId);
|
|||
|
|
return r == null ? JsonResult.failed(String.format("订单号{%s}查询订单详情失败", orderId)) : JsonResult.success(r);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 退款申请用户详情
|
|||
|
|
*
|
|||
|
|
* @param refundId 退款id
|
|||
|
|
* @return 退款申请用户详情
|
|||
|
|
*/
|
|||
|
|
@GetMapping("/refundApplyUserDetail/{refundId}")
|
|||
|
|
public JsonResult<?> refundApplyUserDetail(@PathVariable(name = "refundId") Long refundId) {
|
|||
|
|
RefundUserBasicInfoVo r = wxPayService.queryRefundUserInfoById(refundId);
|
|||
|
|
return r == null ? JsonResult.failed(String.format("退款单号{%s}查询用户详情失败", refundId)) : JsonResult.success(r);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 退款申请用户交易记录
|
|||
|
|
*
|
|||
|
|
* @param userQueryDto 查询条件
|
|||
|
|
*/
|
|||
|
|
@PostMapping("/refundApplyTradeRecord")
|
|||
|
|
public JsonResult<?> refundApplyTradeRecord(@RequestBody UserQueryDto userQueryDto) {
|
|||
|
|
Page<TransactionRecordVo> list = ebikeRefundService.queryRefundTradeRecordById(userQueryDto);
|
|||
|
|
return JsonResult.success(list);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 退款申请用户退款记录
|
|||
|
|
*
|
|||
|
|
* @param userQueryDto 查询条件
|
|||
|
|
*/
|
|||
|
|
@PostMapping("/refundApplyRefundRecord")
|
|||
|
|
public JsonResult<?> refundApplyRefundRecord(@RequestBody UserQueryDto userQueryDto) {
|
|||
|
|
Page<RefundRecordListVo> list = ebikeRefundService.queryRefundRefundRecordById(userQueryDto);
|
|||
|
|
return JsonResult.success(list);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 退款用户订单记录
|
|||
|
|
*
|
|||
|
|
* @param userQueryDto 查询条件
|
|||
|
|
* @return 退款记录列表 List<OrderRecord>
|
|||
|
|
*/
|
|||
|
|
@PostMapping("/refundOrderRecords")
|
|||
|
|
public JsonResult<?> refundOrderRecords(@RequestBody UserQueryDto userQueryDto) {
|
|||
|
|
Page<OrderRecordVo> list = ebikeRefundService.getRefundOrderRecords(userQueryDto);
|
|||
|
|
return JsonResult.success(list);
|
|||
|
|
}
|
|||
|
|
}
|