2025-04-27 17:50:45 +08:00
|
|
|
|
package com.cdzy.payment.controller;
|
|
|
|
|
|
|
2025-05-20 16:46:49 +08:00
|
|
|
|
import cn.dev33.satoken.stp.StpUtil;
|
2025-04-27 17:50:45 +08:00
|
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
2025-05-20 16:46:49 +08:00
|
|
|
|
import com.cdzy.common.enums.Code;
|
2025-04-27 17:50:45 +08:00
|
|
|
|
import com.cdzy.common.model.JsonResult;
|
2025-05-16 15:51:00 +08:00
|
|
|
|
import com.cdzy.payment.model.dto.*;
|
2025-05-21 17:08:58 +08:00
|
|
|
|
import com.cdzy.payment.service.EbikeRefundService;
|
2025-04-27 17:50:45 +08:00
|
|
|
|
import com.cdzy.payment.service.WxPayService;
|
2025-05-20 16:46:49 +08:00
|
|
|
|
import com.ebike.feign.clients.StaffFeignClient;
|
|
|
|
|
|
import com.ebike.feign.model.rsp.StaffFeign;
|
2025-05-16 15:51:00 +08:00
|
|
|
|
import com.mybatisflex.core.paginate.Page;
|
2025-04-27 17:50:45 +08:00
|
|
|
|
import com.wechat.pay.java.service.payments.model.Transaction;
|
|
|
|
|
|
import com.wechat.pay.java.service.refund.model.Refund;
|
|
|
|
|
|
import jakarta.annotation.Resource;
|
2025-04-29 14:31:26 +08:00
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
2025-05-09 17:49:33 +08:00
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
2025-04-27 17:50:45 +08:00
|
|
|
|
|
2025-05-16 15:51:00 +08:00
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
2025-04-27 17:50:45 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 用户订单微信支付 控制层。
|
|
|
|
|
|
*
|
|
|
|
|
|
* @author dingchao
|
|
|
|
|
|
* @since 2025-04-24
|
|
|
|
|
|
*/
|
2025-04-29 14:31:26 +08:00
|
|
|
|
@Slf4j
|
2025-04-27 17:50:45 +08:00
|
|
|
|
@RestController
|
|
|
|
|
|
@RequestMapping("/wxPayment")
|
|
|
|
|
|
public class EbikeWxPaymentController {
|
|
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
|
private WxPayService wxPayService;
|
2025-05-20 16:46:49 +08:00
|
|
|
|
@Resource
|
|
|
|
|
|
private StaffFeignClient staffFeignClient;
|
2025-05-21 17:08:58 +08:00
|
|
|
|
@Resource
|
|
|
|
|
|
private EbikeRefundService ebikeRefundService;
|
2025-04-27 17:50:45 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 微信支付下单
|
|
|
|
|
|
*
|
2025-05-09 17:49:33 +08:00
|
|
|
|
* @param orderId 骑行订单id
|
2025-04-27 17:50:45 +08:00
|
|
|
|
* @return 下单成功返回true,否则返回false
|
|
|
|
|
|
*/
|
2025-05-14 17:47:36 +08:00
|
|
|
|
@GetMapping("/prepay")
|
2025-05-09 17:49:33 +08:00
|
|
|
|
public JsonResult<?> prepay(@RequestParam(name = "orderId") String orderId) {
|
|
|
|
|
|
JSONObject r = wxPayService.prepay(orderId);
|
2025-05-21 16:16:16 +08:00
|
|
|
|
return r.containsKey("error") ? JsonResult.failed("下单失败: " + r.getString("error")) : JsonResult.success(r);
|
2025-04-27 17:50:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 通过商户(骑行)订单号查询支付订单
|
|
|
|
|
|
*
|
2025-05-09 17:49:33 +08:00
|
|
|
|
* @param orderId 商户(骑行)订单号
|
2025-04-27 17:50:45 +08:00
|
|
|
|
* @return 支付订单信息
|
|
|
|
|
|
*/
|
2025-05-09 17:49:33 +08:00
|
|
|
|
@GetMapping("/queryOrder/{orderId}")
|
2025-05-14 17:47:36 +08:00
|
|
|
|
public JsonResult<?> queryOrderByOrderId(@PathVariable(name = "orderId") String orderId) {
|
|
|
|
|
|
Transaction r = wxPayService.queryOrderByOrderId(orderId);
|
2025-05-21 16:16:16 +08:00
|
|
|
|
return r == null ? JsonResult.failed(String.format("骑行订单号{%s}查询支付订单失败", orderId)) : JsonResult.success(r);
|
2025-04-27 17:50:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-04-30 16:28:43 +08:00
|
|
|
|
/**
|
2025-05-09 17:49:33 +08:00
|
|
|
|
* 通过商户(骑行)订单订单号查询支付订单状态
|
2025-04-30 16:28:43 +08:00
|
|
|
|
*
|
2025-05-09 17:49:33 +08:00
|
|
|
|
* @param orderId 微信支付订单号
|
|
|
|
|
|
* @return 订单信息支付状态
|
2025-04-30 16:28:43 +08:00
|
|
|
|
*/
|
2025-05-09 17:49:33 +08:00
|
|
|
|
@GetMapping("/queryOrderStatus/{orderId}")
|
2025-05-14 17:47:36 +08:00
|
|
|
|
public JsonResult<?> queryOrderStatusById(@PathVariable(name = "orderId") String orderId) {
|
|
|
|
|
|
HandleNotifyResult r = wxPayService.queryOrderStatusByOrderId(orderId);
|
2025-04-30 16:28:43 +08:00
|
|
|
|
return JsonResult.success(r);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-05-12 11:07:14 +08:00
|
|
|
|
// 拆分为两个接口,一个是退款申请(生成退款记录),一个是提交退款(调用微信退款接口)
|
2025-05-21 16:16:16 +08:00
|
|
|
|
|
2025-04-27 17:50:45 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 退款申请
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param refundDto 退款信息
|
2025-05-19 17:13:09 +08:00
|
|
|
|
* @return 退款成功返回主键id,否则返回失败
|
2025-04-27 17:50:45 +08:00
|
|
|
|
*/
|
2025-05-12 11:07:14 +08:00
|
|
|
|
@PostMapping("/refundApply")
|
|
|
|
|
|
public JsonResult<?> refundApply(@RequestBody EbikeRefundDto refundDto) {
|
|
|
|
|
|
String r = wxPayService.refundApply(refundDto.getOrderId(), refundDto.getReason());
|
2025-05-21 16:16:16 +08:00
|
|
|
|
return r == null ? JsonResult.failed("退款申请失败") : JsonResult.success((Object) r);
|
2025-04-27 17:50:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-05-12 11:07:14 +08:00
|
|
|
|
/**
|
2025-05-12 18:10:11 +08:00
|
|
|
|
* 调用退款接口
|
2025-05-12 11:07:14 +08:00
|
|
|
|
*
|
2025-05-16 15:51:00 +08:00
|
|
|
|
* @param refundDto 退款请求参数
|
2025-05-12 11:07:14 +08:00
|
|
|
|
* @return 退款成功返回true,否则返回false
|
|
|
|
|
|
*/
|
|
|
|
|
|
@PostMapping("/refund")
|
2025-05-16 15:51:00 +08:00
|
|
|
|
public JsonResult<?> refund(@RequestBody ReqRefundDto refundDto) {
|
2025-05-20 16:46:49 +08:00
|
|
|
|
// 获取审核人信息
|
|
|
|
|
|
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);
|
2025-05-21 16:16:16 +08:00
|
|
|
|
return r.isSuccess() ? JsonResult.success(true) : JsonResult.failed(r.getMessage());
|
2025-05-16 15:51:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 审核退款申请
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param processDto 退款处理信息
|
2025-05-19 15:04:54 +08:00
|
|
|
|
* @return 审核成功返回true,否则返回false
|
2025-05-16 15:51:00 +08:00
|
|
|
|
*/
|
|
|
|
|
|
@PostMapping("/reviewRefund")
|
2025-05-19 15:04:54 +08:00
|
|
|
|
public JsonResult<?> reviewRefund(@RequestBody ReqRefundProcessDto processDto) {
|
2025-05-20 16:46:49 +08:00
|
|
|
|
// 获取审核人信息
|
|
|
|
|
|
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);
|
2025-05-21 16:16:16 +08:00
|
|
|
|
return r ? JsonResult.success(true) : JsonResult.failed("审核失败");
|
2025-05-12 11:07:14 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-04-27 17:50:45 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 通过退款单号查询退款信息
|
|
|
|
|
|
*
|
2025-05-09 17:49:33 +08:00
|
|
|
|
* @param refundId 商户(骑行)退款单号
|
2025-04-27 17:50:45 +08:00
|
|
|
|
* @return 退款信息
|
|
|
|
|
|
*/
|
2025-05-09 17:49:33 +08:00
|
|
|
|
@GetMapping("/queryRefund/{refundId}")
|
2025-05-14 17:47:36 +08:00
|
|
|
|
public JsonResult<?> refundQuery(@PathVariable(name = "refundId") String refundId) {
|
2025-05-09 17:49:33 +08:00
|
|
|
|
Refund r = wxPayService.queryRefundByOutNo(refundId);
|
2025-05-21 16:16:16 +08:00
|
|
|
|
return r == null ? JsonResult.failed(String.format("退款单号{%s}查询退款失败", refundId)) : JsonResult.success(r);
|
2025-04-27 17:50:45 +08:00
|
|
|
|
}
|
2025-04-29 14:31:26 +08:00
|
|
|
|
|
2025-05-16 15:51:00 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 获取退款列表
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param refundDto 查询条件
|
|
|
|
|
|
* @return 退款列表
|
|
|
|
|
|
*/
|
|
|
|
|
|
@PostMapping("/queryRefundList")
|
|
|
|
|
|
public JsonResult<?> queryRefundList(@RequestBody ReqRefundQueryDto refundDto) {
|
|
|
|
|
|
Page<?> list = wxPayService.queryRefundList(refundDto);
|
|
|
|
|
|
return JsonResult.success(list);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-05-19 15:04:54 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 退款订单详情
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param refundId 退款id
|
|
|
|
|
|
* @return 退款详情
|
|
|
|
|
|
*/
|
|
|
|
|
|
@GetMapping("/refundOrderDetail/{refundId}")
|
|
|
|
|
|
public JsonResult<?> refundOrderDetail(@PathVariable(name = "refundId") String refundId) {
|
|
|
|
|
|
ResOrderInfoDto r = wxPayService.queryRefundOrderById(refundId);
|
2025-05-21 16:16:16 +08:00
|
|
|
|
return r == null ? JsonResult.failed(String.format("退款单号{%s}查询订单详情失败", refundId)) : JsonResult.success(r);
|
2025-05-19 15:04:54 +08:00
|
|
|
|
}
|
2025-05-21 15:46:19 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 退款申请订单详情
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param orderId 订单id
|
|
|
|
|
|
* @return 订单详情
|
|
|
|
|
|
*/
|
|
|
|
|
|
@GetMapping("/refundApplyOrderDetail/{orderId}")
|
|
|
|
|
|
public JsonResult<?> refundApplyOrderDetail(@PathVariable(name = "orderId") String orderId) {
|
|
|
|
|
|
ResRefundOrderInfo r = wxPayService.queryRefundApplyOrderById(orderId);
|
2025-05-21 16:16:16 +08:00
|
|
|
|
return r == null ? JsonResult.failed(String.format("订单号{%s}查询订单详情失败", orderId)) : JsonResult.success(r);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2025-05-21 17:08:58 +08:00
|
|
|
|
* 退款申请用户详情
|
2025-05-21 16:16:16 +08:00
|
|
|
|
*
|
|
|
|
|
|
* @param refundId 退款id
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
|
|
|
|
|
@PostMapping("/refundApplyUserDetail/{refundId}")
|
|
|
|
|
|
public JsonResult<?> refundApplyUserDetail(@PathVariable(name = "refundId") String refundId) {
|
|
|
|
|
|
UserBasicInformation r = wxPayService.queryRefundUserInfoById(refundId);
|
2025-05-21 17:08:58 +08:00
|
|
|
|
return r == null ? JsonResult.failed(String.format("退款单号{%s}查询用户详情失败", refundId)) : JsonResult.success(r);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 退款申请用户交易记录
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param reqTradeRecordDto
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
|
|
|
|
|
@PostMapping("/refundApplyTradeRecord")
|
|
|
|
|
|
public JsonResult<?> refundApplyTradeRecord(@RequestBody ReqTradeRecordDto reqTradeRecordDto) {
|
|
|
|
|
|
Page<TransactionRecord> list = ebikeRefundService.queryRefundTradeRecordById(reqTradeRecordDto);
|
|
|
|
|
|
return JsonResult.success(list);
|
2025-05-21 15:46:19 +08:00
|
|
|
|
}
|
2025-04-27 17:50:45 +08:00
|
|
|
|
}
|