feat[订单中心]:退款相关逻辑实现
This commit is contained in:
+14
@@ -4,6 +4,7 @@ import com.wechat.pay.java.core.Config;
|
|||||||
import com.wechat.pay.java.core.RSAAutoCertificateConfig;
|
import com.wechat.pay.java.core.RSAAutoCertificateConfig;
|
||||||
import com.wechat.pay.java.core.notification.NotificationConfig;
|
import com.wechat.pay.java.core.notification.NotificationConfig;
|
||||||
import com.wechat.pay.java.service.payments.jsapi.JsapiServiceExtension;
|
import com.wechat.pay.java.service.payments.jsapi.JsapiServiceExtension;
|
||||||
|
import com.wechat.pay.java.service.refund.RefundService;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
@@ -54,6 +55,19 @@ public class TencentPayConfiguration {
|
|||||||
return new JsapiServiceExtension.Builder().config(config).build();
|
return new JsapiServiceExtension.Builder().config(config).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public RefundService initialRefundService() {
|
||||||
|
Config config =
|
||||||
|
new RSAAutoCertificateConfig.Builder()
|
||||||
|
.merchantId(merchantId)
|
||||||
|
.privateKeyFromPath(privateKeyPath)
|
||||||
|
.merchantSerialNumber(merchantSerialNumber)
|
||||||
|
.apiV3Key(apiV3Key)
|
||||||
|
.build();
|
||||||
|
// 构建service
|
||||||
|
return new RefundService.Builder().config(config).build();
|
||||||
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public NotificationConfig initialNotificationConfig() {
|
public NotificationConfig initialNotificationConfig() {
|
||||||
// . 如果你仍在使用微信支付平台证书,则使用 RSAAutoCertificateConfig
|
// . 如果你仍在使用微信支付平台证书,则使用 RSAAutoCertificateConfig
|
||||||
|
|||||||
+67
@@ -0,0 +1,67 @@
|
|||||||
|
package com.central.order.controller;
|
||||||
|
|
||||||
|
import com.central.common.model.Result;
|
||||||
|
import com.central.order.model.Order;
|
||||||
|
import com.central.order.service.IOrderService;
|
||||||
|
import com.central.order.service.IRefundService;
|
||||||
|
import com.wechat.pay.java.service.refund.RefundService;
|
||||||
|
import com.wechat.pay.java.service.refund.model.AmountReq;
|
||||||
|
import com.wechat.pay.java.service.refund.model.CreateRequest;
|
||||||
|
import com.wechat.pay.java.service.refund.model.Refund;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.util.Assert;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/orders")
|
||||||
|
public class OrderRefundController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RefundService service;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IOrderService orderService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IRefundService refundService;
|
||||||
|
|
||||||
|
@Operation(summary = "微信支付退款")
|
||||||
|
@PostMapping("/{orderId}/refund")
|
||||||
|
public Result<Refund> refundOrder(@PathVariable("orderId") Long orderId) {
|
||||||
|
Order order = orderService.getById(orderId);
|
||||||
|
Assert.notNull(order,"ORDER DATA不存在");
|
||||||
|
CreateRequest request = new CreateRequest();
|
||||||
|
request.setOutTradeNo(order.getOrderNo());
|
||||||
|
request.setOutRefundNo("RF"+order.getOrderNo());
|
||||||
|
request.setReason("用户申请退款");
|
||||||
|
// 退款结果回调通知地址
|
||||||
|
request.setNotifyUrl("your_notify_url");
|
||||||
|
|
||||||
|
// 设置退款金额
|
||||||
|
AmountReq amount = new AmountReq();
|
||||||
|
// 订单总金额,单位为分
|
||||||
|
amount.setTotal(100l);
|
||||||
|
// 退款金额,单位为分
|
||||||
|
amount.setRefund(100l);
|
||||||
|
|
||||||
|
request.setAmount(amount);
|
||||||
|
|
||||||
|
// 发起退款请求
|
||||||
|
Refund response = service.create(request);
|
||||||
|
|
||||||
|
Assert.notNull(response,"退款失败");
|
||||||
|
|
||||||
|
//创建退款订单
|
||||||
|
com.central.order.model.Refund refund = new com.central.order.model.Refund();
|
||||||
|
refund.setRefundReason(refund.getRefundReason());
|
||||||
|
refund.setRefundNo(refund.getRefundNo());
|
||||||
|
refund.setOrderNo(order.getOrderNo());
|
||||||
|
refund.setUserId(order.getUserId());
|
||||||
|
refundService.createRefund(refund);
|
||||||
|
return Result.succeed("退款成功");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package com.central.order.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.central.db.mapper.SuperMapper;
|
||||||
|
import com.central.order.model.Refund;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Order information
|
||||||
|
*
|
||||||
|
* @author lsl
|
||||||
|
* @date 2024-12-19 17:52:54
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface RefundMapper extends SuperMapper<Refund> {
|
||||||
|
/**
|
||||||
|
* 分页查询用户列表
|
||||||
|
* @param page
|
||||||
|
* @param params
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<Refund> findList(Page<Refund> page, @Param("p") Map<String, Object> params);
|
||||||
|
}
|
||||||
@@ -28,6 +28,7 @@ public class Order extends SuperEntity {
|
|||||||
|
|
||||||
private Long userId;
|
private Long userId;
|
||||||
private Long tourismId;
|
private Long tourismId;
|
||||||
|
private transient String tourismName;
|
||||||
private String workspaceId;
|
private String workspaceId;
|
||||||
|
|
||||||
private String orderAmount;
|
private String orderAmount;
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
package com.central.order.model;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import com.central.common.model.SuperEntity;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Refund information
|
||||||
|
*
|
||||||
|
* @author lsl
|
||||||
|
* @date 2025-2-19 17:51:47
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
@TableName("orders_refund")
|
||||||
|
public class Refund extends SuperEntity {
|
||||||
|
private static final long serialVersionUID=1L;
|
||||||
|
|
||||||
|
private String orderNo;
|
||||||
|
private String refundNo;
|
||||||
|
|
||||||
|
private Long userId;
|
||||||
|
|
||||||
|
private String refundReason;
|
||||||
|
private Integer status;
|
||||||
|
|
||||||
|
private Date refundTime;
|
||||||
|
|
||||||
|
@TableField(fill = FieldFill.INSERT)
|
||||||
|
private Date createTime;
|
||||||
|
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||||
|
private Date updateTime;
|
||||||
|
|
||||||
|
private String tenantId;
|
||||||
|
private String company;
|
||||||
|
private Integer isDel;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package com.central.order.service;
|
||||||
|
|
||||||
|
import com.central.common.model.PageResult;
|
||||||
|
import com.central.common.service.ISuperService;
|
||||||
|
import com.central.order.model.Refund;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Firmware file information
|
||||||
|
*
|
||||||
|
* @author lsl
|
||||||
|
* @date 2024-12-19 17:52:54
|
||||||
|
*/
|
||||||
|
public interface IRefundService extends ISuperService<Refund> {
|
||||||
|
/**
|
||||||
|
* 列表
|
||||||
|
* @param params
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
PageResult<Refund> findList(Map<String, Object> params);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建订单
|
||||||
|
*
|
||||||
|
* @param refund
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
boolean createRefund(Refund refund) ;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param refundId
|
||||||
|
*/
|
||||||
|
void updateRefund(Refund refundId) ;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
+5
@@ -7,6 +7,7 @@ import com.central.common.model.PageResult;
|
|||||||
import com.central.common.service.impl.SuperServiceImpl;
|
import com.central.common.service.impl.SuperServiceImpl;
|
||||||
import com.central.order.enums.OrderStatus;
|
import com.central.order.enums.OrderStatus;
|
||||||
import com.central.order.mapper.OrderMapper;
|
import com.central.order.mapper.OrderMapper;
|
||||||
|
import com.central.order.mapper.TourismMapper;
|
||||||
import com.central.order.model.Order;
|
import com.central.order.model.Order;
|
||||||
import com.central.order.model.OrderRanking;
|
import com.central.order.model.OrderRanking;
|
||||||
import com.central.order.service.IOrderService;
|
import com.central.order.service.IOrderService;
|
||||||
@@ -53,6 +54,9 @@ public class OrderServiceImpl extends SuperServiceImpl<OrderMapper, Order> imple
|
|||||||
@Autowired
|
@Autowired
|
||||||
private OrderMapper orderMapper;
|
private OrderMapper orderMapper;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private TourismMapper tourismMapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 列表
|
* 列表
|
||||||
* @param params
|
* @param params
|
||||||
@@ -179,6 +183,7 @@ public class OrderServiceImpl extends SuperServiceImpl<OrderMapper, Order> imple
|
|||||||
List<Order> list = baseMapper.findListByUser(page, params);
|
List<Order> list = baseMapper.findListByUser(page, params);
|
||||||
if (list != null && !list.isEmpty()) {
|
if (list != null && !list.isEmpty()) {
|
||||||
for (Order order : list) {
|
for (Order order : list) {
|
||||||
|
order.setTourismName(tourismMapper.getTourismById(order.getTourismId()).getTourismName());
|
||||||
order.setCreatedTime(sdf.format(order.getCreateTime()));
|
order.setCreatedTime(sdf.format(order.getCreateTime()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+76
@@ -0,0 +1,76 @@
|
|||||||
|
package com.central.order.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.central.common.lock.DistributedLock;
|
||||||
|
import com.central.common.model.PageResult;
|
||||||
|
import com.central.common.service.impl.SuperServiceImpl;
|
||||||
|
import com.central.order.mapper.OrderMapper;
|
||||||
|
import com.central.order.mapper.RefundMapper;
|
||||||
|
import com.central.order.mapper.TourismMapper;
|
||||||
|
import com.central.order.model.Refund;
|
||||||
|
import com.central.order.service.IRefundService;
|
||||||
|
import com.wechat.pay.java.service.payments.jsapi.JsapiServiceExtension;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.collections4.MapUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.annotation.Primary;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Order information
|
||||||
|
*
|
||||||
|
* @author lsl
|
||||||
|
* @date 2024-12-19 17:52:54
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
@Primary
|
||||||
|
public class RefundServiceImpl extends SuperServiceImpl<RefundMapper, Refund> implements IRefundService {
|
||||||
|
|
||||||
|
private final static String ORDER_LOCK = "order_lock_";
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private DistributedLock lock;
|
||||||
|
|
||||||
|
private final ExecutorService executorService = Executors.newFixedThreadPool(10); // 线程池,可根据实际并发量调整大小
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private JsapiServiceExtension service;
|
||||||
|
|
||||||
|
private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
||||||
|
@Autowired
|
||||||
|
private OrderMapper orderMapper;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private TourismMapper tourismMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 列表
|
||||||
|
* @param params
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public PageResult<Refund> findList(Map<String, Object> params){
|
||||||
|
Page<Refund> page = new Page<>(MapUtils.getInteger(params, "page"), MapUtils.getInteger(params, "limit"));
|
||||||
|
List<Refund> list = baseMapper.findList(page, params);
|
||||||
|
return PageResult.<Refund>builder().data(list).resp_code(0).count(page.getTotal()).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean createRefund(Refund refund) {
|
||||||
|
|
||||||
|
return baseMapper.insert(refund) > 0 ? true : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateRefund(Refund refund) {
|
||||||
|
baseMapper.updateById(refund);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
<?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="com.central.order.mapper.RefundMapper">
|
||||||
|
|
||||||
|
<select id="findList" resultType="com.central.order.model.Refund">
|
||||||
|
select * from orders_refund t ORDER BY id DESC
|
||||||
|
</select>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</mapper>
|
||||||
@@ -236,6 +236,25 @@ const TableList: React.FC = () => {
|
|||||||
// 添加更多选项...
|
// 添加更多选项...
|
||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
|
<ProFormSelect
|
||||||
|
rules={[
|
||||||
|
{
|
||||||
|
required: true,
|
||||||
|
message: '素材类型不为空',
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
width="md"
|
||||||
|
name="type"
|
||||||
|
label="景区"
|
||||||
|
placeholder="请选择景区"
|
||||||
|
options={[
|
||||||
|
{ label: '展示大图', value: 4 },
|
||||||
|
{ label: '拍照引导图', value: 3 },
|
||||||
|
{ label: '拍照角度展示图', value: 2 },
|
||||||
|
{ label: '活动', value: 1 },
|
||||||
|
// 添加更多选项...
|
||||||
|
]}
|
||||||
|
/>
|
||||||
<ProFormText
|
<ProFormText
|
||||||
width="md"
|
width="md"
|
||||||
name="linkUrl"
|
name="linkUrl"
|
||||||
|
|||||||
Reference in New Issue
Block a user