feat: 根据订单号创建退款单功能开发
This commit is contained in:
+4
-1
@@ -142,7 +142,10 @@ public class RefundController {
|
|||||||
}
|
}
|
||||||
Assert.notNull(order, "订单不存在");
|
Assert.notNull(order, "订单不存在");
|
||||||
|
|
||||||
if (!order.getOrderStatus().equals(OrderStatus.DOING.getId())){
|
if (order.getOrderStatus().equals(OrderStatus.UNPAID.getId())
|
||||||
|
|| order.getOrderStatus().equals(OrderStatus.CANCELED.getId())
|
||||||
|
|| order.getOrderStatus().equals(OrderStatus.REFUNDED.getId())
|
||||||
|
|| order.getOrderStatus().equals(OrderStatus.REFUNDING.getId())) {
|
||||||
log.warn("订单状态不支持退款,订单号: {}, 当前状态: {}", orderNo, order.getOrderStatus());
|
log.warn("订单状态不支持退款,订单号: {}, 当前状态: {}", orderNo, order.getOrderStatus());
|
||||||
return Result.succeed("订单状态不支持退款");
|
return Result.succeed("订单状态不支持退款");
|
||||||
}
|
}
|
||||||
|
|||||||
+45
@@ -0,0 +1,45 @@
|
|||||||
|
.createModal {
|
||||||
|
:global {
|
||||||
|
.ant-modal-header {
|
||||||
|
border-bottom: 1px solid #f0f0f0;
|
||||||
|
padding: 16px 24px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ant-modal-body {
|
||||||
|
padding: 24px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ant-form-item-label > label {
|
||||||
|
font-weight: 500;
|
||||||
|
color: #262626;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ant-input {
|
||||||
|
border-radius: 4px;
|
||||||
|
|
||||||
|
&:focus {
|
||||||
|
border-color: #1890ff;
|
||||||
|
box-shadow: 0 0 0 2px rgba(24, 144, 255, 0.2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.tips {
|
||||||
|
margin-top: 16px;
|
||||||
|
padding: 12px 16px;
|
||||||
|
background-color: #f6ffed;
|
||||||
|
border: 1px solid #b7eb8f;
|
||||||
|
border-radius: 4px;
|
||||||
|
|
||||||
|
p {
|
||||||
|
margin: 0 0 4px 0;
|
||||||
|
color: #52c41a;
|
||||||
|
font-size: 13px;
|
||||||
|
line-height: 1.5;
|
||||||
|
|
||||||
|
&:last-child {
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+83
@@ -0,0 +1,83 @@
|
|||||||
|
import {
|
||||||
|
ModalForm,
|
||||||
|
ProForm,
|
||||||
|
ProFormText,
|
||||||
|
} from '@ant-design/pro-components';
|
||||||
|
import { message } from 'antd';
|
||||||
|
import React from 'react';
|
||||||
|
import { createRefund } from '@/services/orders/api';
|
||||||
|
import styles from './CreateRefundForm.less';
|
||||||
|
|
||||||
|
interface CreateRefundFormProps {
|
||||||
|
onSubmit: (values: any) => Promise<void>;
|
||||||
|
onVisibleChange: (visible: boolean) => void;
|
||||||
|
createModalVisible: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
const CreateRefundForm: React.FC<CreateRefundFormProps> = (props) => {
|
||||||
|
return (
|
||||||
|
<ModalForm
|
||||||
|
title="创建退款订单"
|
||||||
|
width={500}
|
||||||
|
visible={props.createModalVisible}
|
||||||
|
onVisibleChange={props.onVisibleChange}
|
||||||
|
onFinish={async (values) => {
|
||||||
|
try {
|
||||||
|
// 检查用户是否已登录
|
||||||
|
const accessToken = sessionStorage.getItem('access_token');
|
||||||
|
if (!accessToken) {
|
||||||
|
message.error('请先登录');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('开始创建退款订单,订单号:', values.orderNo);
|
||||||
|
|
||||||
|
const result = await createRefund(values.orderNo);
|
||||||
|
console.log('创建退款订单结果:', result);
|
||||||
|
|
||||||
|
if (result.resp_code === 0) {
|
||||||
|
message.success('退款订单创建成功');
|
||||||
|
props.onSubmit(values);
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
const errorMsg = result.resp_msg || '创建失败';
|
||||||
|
console.error('创建退款订单失败:', errorMsg);
|
||||||
|
message.error(errorMsg);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('创建退款订单异常:', error);
|
||||||
|
message.error('创建退款订单失败,请检查网络连接或联系管理员');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
modalProps={{
|
||||||
|
destroyOnClose: true,
|
||||||
|
className: styles.createModal
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<ProForm.Group>
|
||||||
|
<ProFormText
|
||||||
|
name="orderNo"
|
||||||
|
label="订单编号"
|
||||||
|
placeholder="请输入订单编号"
|
||||||
|
rules={[
|
||||||
|
{ required: true, message: '请输入订单编号' },
|
||||||
|
{ pattern: /^[A-Za-z0-9]+$/, message: '订单编号只能包含字母和数字' }
|
||||||
|
]}
|
||||||
|
fieldProps={{
|
||||||
|
maxLength: 50,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</ProForm.Group>
|
||||||
|
|
||||||
|
<div className={styles.tips}>
|
||||||
|
<p>• 请输入需要退款的订单编号</p>
|
||||||
|
<p>• 系统将自动创建退款申请</p>
|
||||||
|
<p>• 创建后可在列表中查看退款状态</p>
|
||||||
|
</div>
|
||||||
|
</ModalForm>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default CreateRefundForm;
|
||||||
@@ -59,6 +59,22 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.createButton {
|
||||||
|
margin-bottom: 16px;
|
||||||
|
|
||||||
|
:global {
|
||||||
|
.ant-btn {
|
||||||
|
height: 36px;
|
||||||
|
font-weight: 500;
|
||||||
|
box-shadow: 0 2px 4px rgba(24, 144, 255, 0.2);
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
box-shadow: 0 4px 8px rgba(24, 144, 255, 0.3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.queryFilter {
|
.queryFilter {
|
||||||
:global {
|
:global {
|
||||||
.ant-form-item {
|
.ant-form-item {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { refund, updateRefund } from '@/services/orders/api';
|
import { refund, updateRefund, createRefund } from '@/services/orders/api';
|
||||||
import type { ActionType, ProColumns } from '@ant-design/pro-components';
|
import type { ActionType, ProColumns } from '@ant-design/pro-components';
|
||||||
import {
|
import {
|
||||||
PageContainer,
|
PageContainer,
|
||||||
@@ -7,10 +7,12 @@ import {
|
|||||||
ProTable,
|
ProTable,
|
||||||
QueryFilter,
|
QueryFilter,
|
||||||
} from '@ant-design/pro-components';
|
} from '@ant-design/pro-components';
|
||||||
import { Typography, Tag, Space, message, Card } from 'antd';
|
import { Typography, Tag, Space, message, Card, Button } from 'antd';
|
||||||
|
import { PlusOutlined } from '@ant-design/icons';
|
||||||
import React, { useRef, useState } from 'react';
|
import React, { useRef, useState } from 'react';
|
||||||
import { ORDER_STATUS, REFUND_STATUS, REFUND_ORDER_STATUS } from './constants';
|
import { ORDER_STATUS, REFUND_STATUS, REFUND_ORDER_STATUS } from './constants';
|
||||||
import UpdateForm from './components/UpdateForm';
|
import UpdateForm from './components/UpdateForm';
|
||||||
|
import CreateRefundForm from './components/CreateRefundForm';
|
||||||
import type { RefundItem } from './types';
|
import type { RefundItem } from './types';
|
||||||
import styles from './index.less';
|
import styles from './index.less';
|
||||||
|
|
||||||
@@ -42,8 +44,14 @@ const TableList: React.FC = () => {
|
|||||||
const actionRef = useRef<ActionType>();
|
const actionRef = useRef<ActionType>();
|
||||||
const [params, setParams] = useState<Record<string, string | number>>({});
|
const [params, setParams] = useState<Record<string, string | number>>({});
|
||||||
const [updateModalVisible, setUpdateModalVisible] = useState<boolean>(false);
|
const [updateModalVisible, setUpdateModalVisible] = useState<boolean>(false);
|
||||||
|
const [createModalVisible, setCreateModalVisible] = useState<boolean>(false);
|
||||||
const [currentRow, setCurrentRow] = useState<RefundItem>();
|
const [currentRow, setCurrentRow] = useState<RefundItem>();
|
||||||
|
|
||||||
|
// 检查用户是否已登录
|
||||||
|
const isLoggedIn = () => {
|
||||||
|
return !!sessionStorage.getItem('access_token');
|
||||||
|
};
|
||||||
|
|
||||||
const columns: ProColumns<RefundItem>[] = [
|
const columns: ProColumns<RefundItem>[] = [
|
||||||
{
|
{
|
||||||
dataIndex: 'index',
|
dataIndex: 'index',
|
||||||
@@ -126,7 +134,7 @@ const TableList: React.FC = () => {
|
|||||||
align: 'center',
|
align: 'center',
|
||||||
render: (_, record) => (
|
render: (_, record) => (
|
||||||
<Space size="middle">
|
<Space size="middle">
|
||||||
{record.state === 0 && (
|
{String(record.state) === '0' && (
|
||||||
<Link
|
<Link
|
||||||
className={styles.actionLink}
|
className={styles.actionLink}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
@@ -199,7 +207,14 @@ const TableList: React.FC = () => {
|
|||||||
rowKey="id"
|
rowKey="id"
|
||||||
headerTitle="退款列表"
|
headerTitle="退款列表"
|
||||||
actionRef={actionRef}
|
actionRef={actionRef}
|
||||||
request={refund}
|
request={async (params) => {
|
||||||
|
const result = await refund(params);
|
||||||
|
return {
|
||||||
|
data: result.data as any,
|
||||||
|
total: result.total,
|
||||||
|
success: true,
|
||||||
|
};
|
||||||
|
}}
|
||||||
columns={columns}
|
columns={columns}
|
||||||
search={false}
|
search={false}
|
||||||
params={params}
|
params={params}
|
||||||
@@ -212,27 +227,48 @@ const TableList: React.FC = () => {
|
|||||||
scroll={{ x: 'max-content' }}
|
scroll={{ x: 'max-content' }}
|
||||||
dateFormatter="string"
|
dateFormatter="string"
|
||||||
className={styles.customTable}
|
className={styles.customTable}
|
||||||
|
toolBarRender={() => [
|
||||||
|
<Button
|
||||||
|
key="create"
|
||||||
|
type="primary"
|
||||||
|
icon={<PlusOutlined />}
|
||||||
|
onClick={() => {
|
||||||
|
if (!isLoggedIn()) {
|
||||||
|
message.error('请先登录');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setCreateModalVisible(true);
|
||||||
|
}}
|
||||||
|
disabled={!isLoggedIn()}
|
||||||
|
>
|
||||||
|
创建退款
|
||||||
|
</Button>
|
||||||
|
]}
|
||||||
/>
|
/>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
<UpdateForm
|
<UpdateForm
|
||||||
onSubmit={async (values) => {
|
onSubmit={async (values) => {
|
||||||
if (!currentRow) return false;
|
if (!currentRow) return;
|
||||||
const success = await updateRefund({ ...currentRow, ...values });
|
const success = await updateRefund({ ...currentRow, ...values });
|
||||||
if (success) {
|
if (success) {
|
||||||
setUpdateModalVisible(false);
|
setUpdateModalVisible(false);
|
||||||
actionRef.current?.reload();
|
actionRef.current?.reload();
|
||||||
setCurrentRow(undefined);
|
setCurrentRow(undefined);
|
||||||
}
|
}
|
||||||
return success;
|
|
||||||
}}
|
}}
|
||||||
onVisibleChange={setUpdateModalVisible}
|
onVisibleChange={setUpdateModalVisible}
|
||||||
updateModalVisible={updateModalVisible}
|
updateModalVisible={updateModalVisible}
|
||||||
values={currentRow}
|
values={currentRow}
|
||||||
refundStatusOptions={Object.entries(REFUND_STATUS).map(([key, value]) => ({
|
/>
|
||||||
label: value.text,
|
|
||||||
value: Number(key),
|
<CreateRefundForm
|
||||||
}))}
|
onSubmit={async () => {
|
||||||
|
setCreateModalVisible(false);
|
||||||
|
actionRef.current?.reload();
|
||||||
|
}}
|
||||||
|
onVisibleChange={setCreateModalVisible}
|
||||||
|
createModalVisible={createModalVisible}
|
||||||
/>
|
/>
|
||||||
</PageContainer>
|
</PageContainer>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -154,6 +154,19 @@ export async function updateRefund(data: ORDERS.Refund): Promise<API.Result<ORDE
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 创建退款订单 */
|
||||||
|
export async function createRefund(orderNo: string): Promise<API.Result<ORDERS.Refund>> {
|
||||||
|
console.log('开始创建退款订单,订单号:', orderNo);
|
||||||
|
|
||||||
|
const result = await request<API.Result<ORDERS.Refund>>('/api-order/refund/auto', {
|
||||||
|
method: 'PUT',
|
||||||
|
params: { orderNo },
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log('创建退款订单响应:', result);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/** 获取景区列表 */
|
/** 获取景区列表 */
|
||||||
export async function getTourismList(params: {
|
export async function getTourismList(params: {
|
||||||
page: number;
|
page: number;
|
||||||
|
|||||||
Reference in New Issue
Block a user