feat: 退款订单与订单列表整合
This commit is contained in:
@@ -22,7 +22,10 @@
|
||||
"Bash(dir:*)",
|
||||
"Bash(git add:*)",
|
||||
"Bash(git commit -m \"$(cat <<''EOF''\nfix: 修复首页分账计算模块显示问题\n\n- 显示被隐藏的分账计算模块(移除 display: ''none'')\n- 调整 platformSharePercent 状态变量定义顺序\n- 优化 Slider 组件:\n - 设置标记文字颜色为深灰色 (#666),避免看不清\n - 添加 tooltip 提示框,拖动时显示当前百分比\n - 设置 tooltip 背景为深色,文字为白色,确保清晰可见\n- 移除重复的 90% 标记,只保留 0%、50%、100%\n\n🤖 Generated with Claude Code\n\nCo-Authored-By: Claude <noreply@anthropic.com>\nEOF\n)\")",
|
||||
"Bash(git commit:*)"
|
||||
"Bash(git commit:*)",
|
||||
"Read(//f/**)",
|
||||
"Bash(git checkout:*)",
|
||||
"Bash(git diff:*)"
|
||||
],
|
||||
"deny": [],
|
||||
"ask": []
|
||||
|
||||
+3
-3
@@ -661,12 +661,12 @@ public class OrderController {
|
||||
|
||||
for (OrderFile orderFile : orderFiles) {
|
||||
Map<String, String> fileInfo = new HashMap<>();
|
||||
String url = fileCenterService.getViewUrlByPath(orderFile.getFilePath());
|
||||
String url = fileCenterService.getFileViewUrl(orderFile.getFileId());
|
||||
// 去掉URL中的参数并替换域名
|
||||
// String cleanUrl = removeUrlParams(url.replace(cdnOssUrl, cdnUrl));
|
||||
fileInfo.put("url", url.replace(cdnOssUrl, cdnUrl));
|
||||
fileInfo.put("url", url);
|
||||
fileInfo.put("contentType", orderFile.getFileType());
|
||||
fileMap.put("path", orderFile.getFilePath());
|
||||
fileMap.put("fileId", orderFile.getFileId());
|
||||
fileInfo.put("viewUrl", fileCenterService.getViewUrlByPathStyle(fileMap));
|
||||
fileList.add(fileInfo);
|
||||
}
|
||||
|
||||
+98
@@ -9,10 +9,12 @@ import com.central.order.enums.OrderStatus;
|
||||
import com.central.order.enums.RefundState;
|
||||
import com.central.order.model.Order;
|
||||
import com.central.order.model.QrCode;
|
||||
import com.central.order.model.params.ApproveCustomRefundAmountRequest;
|
||||
import com.central.order.service.IOrderService;
|
||||
import com.central.order.service.IQrCodeService;
|
||||
import com.central.order.service.IRefundService;
|
||||
import com.central.order.service.IWxTemplateMessageService;
|
||||
import com.central.order.util.StringUtils;
|
||||
import com.central.wechat.config.WxPayConfigFactory;
|
||||
import com.central.wechat.entity.WechatConfig;
|
||||
import com.central.wechat.feign.WechatConfigService;
|
||||
@@ -26,6 +28,7 @@ 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.apache.poi.util.StringUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -170,6 +173,41 @@ public class RefundController {
|
||||
return Result.failed("处理退款失败");
|
||||
}
|
||||
|
||||
@Operation(summary = "微信支付退款")
|
||||
@PostMapping("/approve/custom")
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Result<com.central.order.model.Refund> approveCustomOrderAmount(@RequestBody ApproveCustomRefundAmountRequest refundRequest) {
|
||||
|
||||
log.info("审批退款单,订单号: {}, 退款单号: {}", refundRequest.getOrderNo(), refundRequest.getRefundNo());
|
||||
// 检查订单是否存在
|
||||
Order order = orderService.getOrderByNumber(refundRequest.getOrderNo());
|
||||
Assert.notNull(order, "ORDER DATA不存在");
|
||||
com.central.order.model.Refund refundorder = refundService.getRefundByNo(refundRequest.getRefundNo());
|
||||
Assert.notNull(order, "退款订单不存在");
|
||||
if (!order.getOrderStatus().equals(OrderStatus.REFUNDING.getId())){
|
||||
return Result.failed("订单状态不支持退款");
|
||||
}
|
||||
if (! refundRequest.getStatus().equals(OrderStatus.REFUNDING.getId())){
|
||||
return Result.failed("该状态不支持审核");
|
||||
}
|
||||
if (refundRequest.getState().equals(RefundState.APPROVED.getId())){
|
||||
dealCustomRefundAmountRequest(order,refundRequest.getRefundAmount());
|
||||
refundorder.setRefundReason(refundRequest.getApproveReason());
|
||||
if(refundRequest.getRefundAmount()!=null){
|
||||
refundorder.setRefundAmount(refundRequest.getRefundAmount());
|
||||
}
|
||||
refundService.updateById(refundorder);
|
||||
return Result.succeed("已处理退款");
|
||||
}
|
||||
if (refundRequest.getState().equals(RefundState.REFUSED.getId())){
|
||||
order.setOrderStatus(OrderStatus.REFUND_FAILED.getId());
|
||||
refundorder.setStatus(OrderStatus.REFUND_FAILED.getId());
|
||||
orderService.updateOrder(order);
|
||||
refundService.updateById(refundorder);
|
||||
return Result.succeed("处理成功");
|
||||
}
|
||||
return Result.failed("处理退款失败");
|
||||
}
|
||||
|
||||
@PutMapping("/auto")
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@@ -312,4 +350,64 @@ public class RefundController {
|
||||
throw new RuntimeException("退款失败: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 微信退款申请
|
||||
* @param order
|
||||
*/
|
||||
private void dealCustomRefundAmountRequest(Order order,String refundAmount) {
|
||||
try {
|
||||
// 获取二维码信息
|
||||
QrCode qrCode = qrCodeService.getByCodeId(order.getCodeId());
|
||||
if (qrCode == null) {
|
||||
log.error("二维码不存在,订单号: {}", order.getOrderNo());
|
||||
throw new RuntimeException("二维码不存在");
|
||||
}
|
||||
// 获取微信支付配置
|
||||
WechatConfig wechatConfig = wechatConfigService.getConfig("PAY", qrCode.getTenantId());
|
||||
if (wechatConfig == null) {
|
||||
log.error("微信支付配置不存在,租户ID: {}", qrCode.getTenantId());
|
||||
throw new RuntimeException("微信支付配置不存在");
|
||||
}
|
||||
// 创建微信退款请求
|
||||
CreateRequest request = new CreateRequest();
|
||||
request.setOutTradeNo(order.getOrderNo());
|
||||
request.setOutRefundNo("RF" + order.getOrderNo());
|
||||
request.setReason("用户申请退款");
|
||||
request.setNotifyUrl(refundNotifyUrl);
|
||||
// 设置退款金额
|
||||
AmountReq amount = new AmountReq();
|
||||
amount.setTotal(Long.valueOf(order.getOrderAmount()));
|
||||
if(refundAmount!=null ){
|
||||
amount.setRefund(Long.valueOf(refundAmount));
|
||||
}else{
|
||||
amount.setRefund(Long.valueOf(order.getOrderAmount())) ;
|
||||
}
|
||||
amount.setCurrency("CNY");
|
||||
request.setAmount(amount);
|
||||
// 根据是否为服务商模式设置不同的参数
|
||||
RefundService refundService;
|
||||
if (Boolean.TRUE.equals(wechatConfig.getIsServiceMode())) {
|
||||
// 服务商模式:需要设置子商户号
|
||||
request.setSubMchid(wechatConfig.getSubMchId());
|
||||
log.info("服务商模式退款,子商户号: {}, 订单号: {}", wechatConfig.getSubMchId(), order.getOrderNo());
|
||||
|
||||
// 创建服务商模式的退款服务
|
||||
refundService = wxPayConfigFactory.createRefundServiceBySubMchId(wechatConfig.getSubMchId());
|
||||
} else {
|
||||
// 普通商户模式
|
||||
log.info("普通商户模式退款,商户号: {}, 订单号: {}", wechatConfig.getMerchantId(), order.getOrderNo());
|
||||
refundService = wxPayConfigFactory.createRefundService(qrCode.getTenantId());
|
||||
}
|
||||
|
||||
// 发起退款请求
|
||||
Refund response = refundService.create(request);
|
||||
Assert.notNull(response, "退款失败");
|
||||
|
||||
log.info("退款请求成功,退款单号: {}, 订单号: {}", response.getRefundId(), order.getOrderNo());
|
||||
} catch (Exception e) {
|
||||
log.error("退款请求失败,订单号: {}, 异常: {}", order.getOrderNo(), e.getMessage(), e);
|
||||
throw new RuntimeException("退款失败: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -382,9 +382,10 @@ public interface DashboardMapper {
|
||||
|
||||
@Select({
|
||||
"<script>",
|
||||
"SELECT COALESCE(SUM(o.order_amount), 0) as amount",
|
||||
"SELECT COALESCE(SUM(r.refund_amount), 0) as amount",
|
||||
"FROM orders o",
|
||||
"JOIN qrcodes q ON o.code_id = q.code_id",
|
||||
"JOIN orders_refund r ON o.order_no = r.order_no",
|
||||
"WHERE 1=1",
|
||||
"<if test='p.includeTestQrcodes == null or p.includeTestQrcodes == false'>",
|
||||
" AND q.is_test = 0",
|
||||
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
package com.central.order.model.params;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ApproveCustomRefundAmountRequest {
|
||||
|
||||
private String orderNo;
|
||||
|
||||
private String refundNo;
|
||||
|
||||
private String refundAmount;
|
||||
|
||||
private Integer status;
|
||||
|
||||
private Integer state;
|
||||
|
||||
private String approveReason;
|
||||
}
|
||||
-1
@@ -95,7 +95,6 @@ public class RefundServiceImpl extends SuperServiceImpl<RefundMapper, Refund> im
|
||||
result.put("refundReason", refund.getRefundReason());
|
||||
result.put("createTime", refund.getCreateTime());
|
||||
result.put("applyTime", refund.getCreateTime());
|
||||
result.put("orderStatus", "退款中");
|
||||
|
||||
// 处理图片列表 - refundImgs 可能是逗号分隔的字符串或JSON
|
||||
List<String> images = new ArrayList<>();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// UTF-8: 退款审核弹框组件
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { Modal, Form, Select, Input, message, Empty, Image, Space, Row, Col, Divider } from 'antd';
|
||||
import { Modal, Form, Select, Input, message, Empty, Image, Space, Row, Col, Divider, InputNumber, Button } from 'antd';
|
||||
import { ordersApi } from '@/services/orders';
|
||||
|
||||
interface RefundReviewModalProps {
|
||||
@@ -22,6 +22,8 @@ const RefundReviewModal: React.FC<RefundReviewModalProps> = ({
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [refundData, setRefundData] = useState<any>(null);
|
||||
const [fetching, setFetching] = useState(false);
|
||||
const [editingAmount, setEditingAmount] = useState(false);
|
||||
const [customRefundAmount, setCustomRefundAmount] = useState<number | null>(null);
|
||||
|
||||
// 审核结果选项
|
||||
const reviewResults = [
|
||||
@@ -54,10 +56,23 @@ const RefundReviewModal: React.FC<RefundReviewModalProps> = ({
|
||||
}
|
||||
};
|
||||
|
||||
// 根据status获取退款状态的文案和颜色
|
||||
const getRefundStatusInfo = (status: number) => {
|
||||
const statusMap: Record<number, { text: string; bgColor: string; textColor: string }> = {
|
||||
7: { text: '退款中', bgColor: '#fff7e6', textColor: '#d46b08' }, // orange
|
||||
8: { text: '退款成功', bgColor: '#f6ffed', textColor: '#52c41a' }, // lime
|
||||
9: { text: '退款失败', bgColor: '#fff1f0', textColor: '#f5222d' }, // red
|
||||
};
|
||||
return statusMap[status] || { text: '未知状态', bgColor: '#f5f5f5', textColor: '#666' };
|
||||
};
|
||||
|
||||
// 获取退款订单详情
|
||||
useEffect(() => {
|
||||
if (visible && orderNo) {
|
||||
fetchRefundDetail();
|
||||
// 打开弹窗时清空编辑状态
|
||||
setEditingAmount(false);
|
||||
setCustomRefundAmount(null);
|
||||
}
|
||||
}, [visible, orderNo]);
|
||||
|
||||
@@ -92,13 +107,20 @@ const RefundReviewModal: React.FC<RefundReviewModalProps> = ({
|
||||
const values = await form.validateFields();
|
||||
setLoading(true);
|
||||
|
||||
// 调用审核接口(需要与后端 RefundController.approveOrder 的参数匹配)
|
||||
const res = await ordersApi.updateRefund({
|
||||
orderNo: refundData?.orderNo, // 订单号(后端需要校验订单状态)
|
||||
refundNo: refundData?.refundNo, // 退款单号
|
||||
status: refundData?.status, // 退款状态(应保持为 REFUNDING)
|
||||
state: values.reviewResult, // 审核状态:1=通过(APPROVED),0=拒绝(REFUSED)
|
||||
approveReason: values.reviewComment, // 审核意见
|
||||
// 计算实际退款金额(分)
|
||||
// 如果用户编辑了退款金额,就用编辑的,否则用原始退款金额
|
||||
const actualRefundAmount = customRefundAmount !== null
|
||||
? Math.round(customRefundAmount * 100) // 元转分
|
||||
: refundData?.refundAmount;
|
||||
|
||||
// 调用自定义金额的退款审核接口
|
||||
const res = await ordersApi.approveRefundWithCustomAmount({
|
||||
orderNo: refundData?.orderNo,
|
||||
refundNo: refundData?.refundNo,
|
||||
refundAmount: String(actualRefundAmount), // 后端期望字符串格式
|
||||
status: 7, // 退款中状态码
|
||||
state: values.reviewResult, // 审核状态:1=通过(APPROVED),0=拒绝(REFUSED)
|
||||
approveReason: values.reviewComment, // 审核意见
|
||||
});
|
||||
|
||||
// 显示后端返回的实际消息
|
||||
@@ -161,7 +183,63 @@ const RefundReviewModal: React.FC<RefundReviewModalProps> = ({
|
||||
<Col span={12}>
|
||||
<div>
|
||||
<span style={{ fontWeight: 'bold' }}>退款金额</span>
|
||||
<div style={{ marginTop: 4 }}>¥ {formatAmount(refundData?.refundAmount)}</div>
|
||||
{editingAmount ? (
|
||||
<div style={{ marginTop: 4, display: 'flex', gap: 8, alignItems: 'center' }}>
|
||||
<InputNumber
|
||||
style={{ flex: 1 }}
|
||||
value={customRefundAmount}
|
||||
onChange={setCustomRefundAmount}
|
||||
min={0.01}
|
||||
max={parseFloat(formatAmount(refundData?.orderAmount))}
|
||||
step={0.01}
|
||||
precision={2}
|
||||
prefix="¥"
|
||||
/>
|
||||
<Button
|
||||
size="small"
|
||||
type="primary"
|
||||
onClick={() => {
|
||||
if (customRefundAmount === null || customRefundAmount <= 0) {
|
||||
message.error('请输入大于0的退款金额');
|
||||
return;
|
||||
}
|
||||
// 校验通过,关闭编辑模式
|
||||
setEditingAmount(false);
|
||||
}}
|
||||
>
|
||||
确定
|
||||
</Button>
|
||||
<Button
|
||||
size="small"
|
||||
onClick={() => {
|
||||
// 取消编辑,恢复原值
|
||||
setEditingAmount(false);
|
||||
setCustomRefundAmount(null);
|
||||
message.info('已取消编辑');
|
||||
}}
|
||||
>
|
||||
取消
|
||||
</Button>
|
||||
</div>
|
||||
) : (
|
||||
<div style={{ marginTop: 4, display: 'flex', gap: 8, alignItems: 'center' }}>
|
||||
<span>¥ {customRefundAmount !== null ? customRefundAmount.toFixed(2) : formatAmount(refundData?.refundAmount)}</span>
|
||||
{isReviewMode && (
|
||||
<Button
|
||||
size="small"
|
||||
onClick={() => {
|
||||
// 编辑时,如果还没有自定义金额,则使用接口返回的原始金额
|
||||
if (customRefundAmount === null) {
|
||||
setCustomRefundAmount(parseFloat(formatAmount(refundData?.refundAmount)));
|
||||
}
|
||||
setEditingAmount(true);
|
||||
}}
|
||||
>
|
||||
编辑
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</Col>
|
||||
</Row>
|
||||
@@ -172,20 +250,30 @@ const RefundReviewModal: React.FC<RefundReviewModalProps> = ({
|
||||
<Row gutter={[16, 16]}>
|
||||
<Col span={12}>
|
||||
<div>
|
||||
<span style={{ fontWeight: 'bold' }}>订单状态</span>
|
||||
<span style={{ fontWeight: 'bold' }}>退款状态</span>
|
||||
<div style={{ marginTop: 4 }}>
|
||||
<span style={{ padding: '2px 8px', backgroundColor: '#fff7e6', color: '#d46b08', borderRadius: 2 }}>
|
||||
{refundData?.orderStatus || '退款中'}
|
||||
</span>
|
||||
{(() => {
|
||||
const statusInfo = getRefundStatusInfo(refundData?.status);
|
||||
return (
|
||||
<span style={{
|
||||
padding: '2px 8px',
|
||||
backgroundColor: statusInfo.bgColor,
|
||||
color: statusInfo.textColor,
|
||||
borderRadius: 2
|
||||
}}>
|
||||
{statusInfo.text}
|
||||
</span>
|
||||
);
|
||||
})()}
|
||||
</div>
|
||||
</div>
|
||||
</Col>
|
||||
<Col span={12}>
|
||||
<div>
|
||||
<span style={{ fontWeight: 'bold' }}>退款状态</span>
|
||||
<span style={{ fontWeight: 'bold' }}>订单状态</span>
|
||||
<div style={{ marginTop: 4 }}>
|
||||
<span style={{ padding: '2px 8px', backgroundColor: '#f6f8fb', color: '#000', borderRadius: 2 }}>
|
||||
{refundData?.status === 1 ? '待审核' : refundData?.status === 2 ? '已审核' : '待审核'}
|
||||
{refundData?.orderStatus || '-'}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -155,6 +155,11 @@ export const ordersApi = {
|
||||
const res = await request('/api-order/refund/approve', { method: 'POST', data });
|
||||
return (res as any).data || res;
|
||||
},
|
||||
// 审核退款(支持自定义退款金额)
|
||||
approveRefundWithCustomAmount: async (data: any) => {
|
||||
const res = await request('/api-order/refund/approve/custom', { method: 'POST', data });
|
||||
return (res as any).data || res;
|
||||
},
|
||||
createRefund: async (payload: { orderNo: string }) => {
|
||||
const res = await request('/api-order/refund/auto', { method: 'PUT', data: payload });
|
||||
return (res as any).data || res;
|
||||
|
||||
Reference in New Issue
Block a user