238 lines
8.4 KiB
Java
238 lines
8.4 KiB
Java
package com.cdzy.payment.controller;
|
||
|
||
import cn.dev33.satoken.stp.StpUtil;
|
||
import com.alibaba.fastjson2.JSONObject;
|
||
import com.cdzy.common.enums.Code;
|
||
import com.cdzy.common.model.JsonResult;
|
||
import com.cdzy.payment.model.dto.req.*;
|
||
import com.cdzy.payment.model.dto.res.*;
|
||
import com.cdzy.payment.service.EbikeRefundService;
|
||
import com.cdzy.payment.service.WxPayService;
|
||
import com.ebike.feign.clients.StaffFeignClient;
|
||
import com.ebike.feign.model.rsp.StaffFeign;
|
||
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 dingchao
|
||
* @since 2025-04-24
|
||
*/
|
||
@Slf4j
|
||
@RestController
|
||
@RequestMapping("/wxPayment")
|
||
public class EbikeWxPaymentController {
|
||
|
||
@Resource
|
||
private WxPayService wxPayService;
|
||
@Resource
|
||
private StaffFeignClient staffFeignClient;
|
||
@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) {
|
||
HandleNotifyResult r = wxPayService.queryOrderStatusByOrderId(orderId);
|
||
return JsonResult.success(r);
|
||
}
|
||
|
||
// 拆分为两个接口,一个是退款申请(生成退款记录),一个是提交退款(调用微信退款接口)
|
||
|
||
/**
|
||
* 退款申请
|
||
*
|
||
* @param refundDto 退款信息
|
||
* @return 退款成功返回主键id,否则返回失败
|
||
*/
|
||
@PostMapping("/refundApply")
|
||
public JsonResult<?> refundApply(@RequestBody EbikeRefundDto refundDto) {
|
||
String r = wxPayService.refundApply(refundDto.getOrderId(), refundDto.getReason());
|
||
return r == null ? JsonResult.failed("退款申请失败") : JsonResult.success((Object) r);
|
||
}
|
||
|
||
/**
|
||
* 调用退款接口
|
||
*
|
||
* @param refundDto 退款请求参数
|
||
* @return 退款成功返回true,否则返回false
|
||
*/
|
||
@PostMapping("/refund")
|
||
public JsonResult<?> refund(@RequestBody ReqRefundDto refundDto) {
|
||
// 获取审核人信息
|
||
String tokenValue = StpUtil.getTokenValue();
|
||
String userId = null;
|
||
JsonResult<StaffFeign> result = staffFeignClient.getInfoByToken(tokenValue);
|
||
if (result.getCode() == Code.SUCCESS) {
|
||
StaffFeign staffFeign = result.getData();
|
||
userId = String.valueOf(staffFeign.getStaffId());
|
||
}
|
||
HandleNotifyResult r = wxPayService.refund(refundDto, userId);
|
||
return r.isSuccess() ? JsonResult.success(true) : JsonResult.failed(r.getMessage());
|
||
}
|
||
|
||
|
||
/**
|
||
* 通过退款记录主键id查询退款信息
|
||
*
|
||
* @param refundId 退款主键id
|
||
* @return 退款状态信息
|
||
*/
|
||
@GetMapping("/queryRefundStatus/{refundId}")
|
||
public JsonResult<?> queryRefundStatus(@PathVariable(name = "refundId") String refundId) {
|
||
HandleNotifyResult r = wxPayService.queryRefundStatusById(refundId);
|
||
return JsonResult.success(r);
|
||
}
|
||
|
||
|
||
/**
|
||
* 审核退款申请
|
||
*
|
||
* @param processDto 退款处理信息
|
||
* @return 审核成功返回true,否则返回false
|
||
*/
|
||
@PostMapping("/reviewRefund")
|
||
public JsonResult<?> reviewRefund(@RequestBody ReqRefundProcessDto processDto) {
|
||
// 获取审核人信息
|
||
String tokenValue = StpUtil.getTokenValue();
|
||
String userId = null;
|
||
JsonResult<StaffFeign> result = staffFeignClient.getInfoByToken(tokenValue);
|
||
if (result.getCode() == Code.SUCCESS) {
|
||
StaffFeign staffFeign = result.getData();
|
||
userId = String.valueOf(staffFeign.getStaffId());
|
||
}
|
||
boolean r = wxPayService.refundReview(processDto, userId);
|
||
return r ? JsonResult.success(true) : JsonResult.failed("审核失败");
|
||
}
|
||
|
||
/**
|
||
* 通过退款单号查询退款信息
|
||
*
|
||
* @param refundId 商户(骑行)退款id
|
||
* @return 退款信息
|
||
*/
|
||
@GetMapping("/queryRefund/{refundId}")
|
||
public JsonResult<?> refundQuery(@PathVariable(name = "refundId") String 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 ReqRefundQueryDto refundDto) {
|
||
Page<?> list = wxPayService.queryRefundList(refundDto);
|
||
return JsonResult.success(list);
|
||
}
|
||
|
||
/**
|
||
* 退款订单详情
|
||
*
|
||
* @param refundId 退款id
|
||
* @return 退款详情
|
||
*/
|
||
@GetMapping("/refundOrderDetail/{refundId}")
|
||
public JsonResult<?> refundOrderDetail(@PathVariable(name = "refundId") String refundId) {
|
||
ResOrderInfoDto 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) {
|
||
ResRefundOrderInfo 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") String refundId) {
|
||
UserBasicInformation r = wxPayService.queryRefundUserInfoById(refundId);
|
||
return r == null ? JsonResult.failed(String.format("退款单号{%s}查询用户详情失败", refundId)) : JsonResult.success(r);
|
||
}
|
||
|
||
/**
|
||
* 退款申请用户交易记录
|
||
*
|
||
* @param reqTradeRecordDto
|
||
* @return
|
||
*/
|
||
@PostMapping("/refundApplyTradeRecord")
|
||
public JsonResult<?> refundApplyTradeRecord(@RequestBody ReqUserQueryDto reqTradeRecordDto) {
|
||
Page<TransactionRecord> list = ebikeRefundService.queryRefundTradeRecordById(reqTradeRecordDto);
|
||
return JsonResult.success(list);
|
||
}
|
||
|
||
/**
|
||
* 退款申请用户退款记录
|
||
*
|
||
* @param reqRefundRecordDto
|
||
* @return
|
||
*/
|
||
@PostMapping("/refundApplyRefundRecord")
|
||
public JsonResult<?> refundApplyRefundRecord(@RequestBody ReqUserQueryDto reqRefundRecordDto) {
|
||
Page<RefundRecordListDto> list = ebikeRefundService.queryRefundRefundRecordById(reqRefundRecordDto);
|
||
return JsonResult.success(list);
|
||
}
|
||
|
||
/**
|
||
* 退款用户订单记录
|
||
*
|
||
* @param reqRefundRecordDto 查询条件
|
||
* @return 退款记录列表 List<OrderRecord>
|
||
*/
|
||
@PostMapping("/refundOrderRecords")
|
||
public JsonResult<?> refundOrderRecords(@RequestBody ReqUserQueryDto reqRefundRecordDto) {
|
||
Page<OrderRecord> list = ebikeRefundService.getRefundOrderRecords(reqRefundRecordDto);
|
||
return JsonResult.success(list);
|
||
}
|
||
}
|