fix(订单中心):首页统计数据规则修改,时间筛选无效bug修复,退款订单显示问题修复
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { PageContainer } from '@ant-design/pro-components';
|
||||
import { Card, Row, Col, Statistic, Progress, Typography, Select, DatePicker, Space, Button, Switch } from 'antd';
|
||||
import { Card, Row, Col, Statistic, Progress, Typography, Select, DatePicker, Space, Button, Switch, Pagination } from 'antd';
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { dashboard, getQrcodeOptions } from '@/services/orders/api';
|
||||
import { dashboard, getQrcodeOptions, getDashboardOrders } from '@/services/orders/api';
|
||||
import { Line, Column, Pie } from '@ant-design/plots';
|
||||
import {
|
||||
ShoppingCartOutlined,
|
||||
@@ -43,6 +43,7 @@ interface Statistics {
|
||||
todayOrders: number;
|
||||
orderGrowth: number;
|
||||
completionRate: number;
|
||||
refundedOrders: number; // 退款订单数
|
||||
// 对账相关字段
|
||||
totalAmount: number; // 订单总金额(分)
|
||||
refundAmount: number; // 退款金额(分)
|
||||
@@ -85,6 +86,13 @@ const Welcome: React.FC = () => {
|
||||
const [timeRange, setTimeRange] = useState<[string, string]>(['', '']);
|
||||
// 新增是否包含测试二维码筛选,默认不包含
|
||||
const [includeTestQrcodes, setIncludeTestQrcodes] = useState<boolean>(false);
|
||||
// 订单列表数据
|
||||
const [orderList, setOrderList] = useState<any[]>([]);
|
||||
const [orderPagination, setOrderPagination] = useState({
|
||||
current: 1,
|
||||
pageSize: 10,
|
||||
total: 0,
|
||||
});
|
||||
|
||||
const fetchData = async () => {
|
||||
try {
|
||||
@@ -107,8 +115,34 @@ const Welcome: React.FC = () => {
|
||||
}
|
||||
};
|
||||
|
||||
const fetchOrderList = async (page = 1) => {
|
||||
try {
|
||||
const params = {
|
||||
tourismId: selectedTourism,
|
||||
qrcodeId: selectedQrcode,
|
||||
startTime: timeRange[0],
|
||||
endTime: timeRange[1],
|
||||
includeTestQrcodes: includeTestQrcodes,
|
||||
page: page,
|
||||
limit: orderPagination.pageSize,
|
||||
};
|
||||
const result = await getDashboardOrders(params);
|
||||
if (result.resp_code === 0) {
|
||||
setOrderList(result.data?.data || []);
|
||||
setOrderPagination(prev => ({
|
||||
...prev,
|
||||
current: page,
|
||||
total: result.data?.count || 0,
|
||||
}));
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取订单列表失败:', error);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
fetchData();
|
||||
fetchOrderList(1); // 重置到第一页
|
||||
}, [selectedTourism, selectedQrcode, timeRange, includeTestQrcodes]);
|
||||
|
||||
// 处理景区选择变化
|
||||
@@ -164,6 +198,62 @@ const Welcome: React.FC = () => {
|
||||
const refundAmount = orderStats.refundAmount || 0;
|
||||
const netIncome = orderStats.netIncome || 0;
|
||||
|
||||
// 判断是否选择了时间区间
|
||||
const hasTimeRange = timeRange[0] && timeRange[1];
|
||||
|
||||
// 根据时间筛选状态动态显示标题
|
||||
const getOrderTitle = () => {
|
||||
if (hasTimeRange) {
|
||||
return `订单总数 (${timeRange[0].split(' ')[0]} ~ ${timeRange[1].split(' ')[0]})`;
|
||||
}
|
||||
return '总订单数';
|
||||
};
|
||||
|
||||
const getTodayTitle = () => {
|
||||
if (hasTimeRange) {
|
||||
return `区间订单数`;
|
||||
}
|
||||
return '今日订单';
|
||||
};
|
||||
|
||||
const getTodayValue = () => {
|
||||
if (hasTimeRange) {
|
||||
return orderStats.totalOrders || 0; // 时间筛选时显示区间总订单数
|
||||
}
|
||||
return orderStats.todayOrders || 0; // 无时间筛选时显示今日订单数
|
||||
};
|
||||
|
||||
const getTodayRefundTitle = () => {
|
||||
if (hasTimeRange) {
|
||||
return `区间退款订单`;
|
||||
}
|
||||
return '今日退款订单';
|
||||
};
|
||||
|
||||
const getTodayRefundValue = () => {
|
||||
if (hasTimeRange) {
|
||||
return orderStats.refundedOrders || 0; // 时间筛选时显示区间退款订单数
|
||||
}
|
||||
return orderStats.todayRefundedOrders || 0; // 无时间筛选时显示今日退款订单数
|
||||
};
|
||||
|
||||
// 获取订单状态文本
|
||||
const getOrderStatusText = (status: number) => {
|
||||
const statusMap: { [key: number]: string } = {
|
||||
0: '待支付',
|
||||
1: '已支付排队中',
|
||||
2: '已取消',
|
||||
3: '设备执行完成',
|
||||
4: '正在服务中',
|
||||
5: '素材上传中',
|
||||
6: '素材上传完成',
|
||||
7: '退款中',
|
||||
8: '已退款',
|
||||
9: '退款失败',
|
||||
};
|
||||
return statusMap[status] || '未知状态';
|
||||
};
|
||||
|
||||
// 动态分账金额计算(基于净收入和分账比例)
|
||||
const platformAmount = Math.round(netIncome * platformRate);
|
||||
const tourismAmount = netIncome - platformAmount;
|
||||
@@ -218,23 +308,7 @@ const Welcome: React.FC = () => {
|
||||
},
|
||||
};
|
||||
|
||||
// 收入构成图表数据
|
||||
const incomeConfig = {
|
||||
data: [
|
||||
{ type: '平台分账', value: platformAmount / 100 },
|
||||
{ type: '景区分账', value: tourismAmount / 100 },
|
||||
{ type: '退款金额', value: refundAmount / 100 },
|
||||
],
|
||||
xField: 'type',
|
||||
yField: 'value',
|
||||
label: {
|
||||
position: 'middle' as const,
|
||||
style: {
|
||||
fill: '#FFFFFF',
|
||||
opacity: 0.6,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
return (
|
||||
<PageContainer className={styles.container}>
|
||||
@@ -244,6 +318,11 @@ const Welcome: React.FC = () => {
|
||||
<Card style={{ marginBottom: 16 }}>
|
||||
<Space size="large">
|
||||
<span>筛选条件:</span>
|
||||
{hasTimeRange && (
|
||||
<span style={{ color: '#1890ff', fontSize: '12px' }}>
|
||||
⚠️ 已选择时间区间,统计数据将基于选定时间范围计算
|
||||
</span>
|
||||
)}
|
||||
<Select
|
||||
placeholder="选择景区"
|
||||
style={{ width: 200 }}
|
||||
@@ -337,22 +416,34 @@ const Welcome: React.FC = () => {
|
||||
<ShoppingCartOutlined className={styles.iconOrders} />
|
||||
<span>订单总览</span>
|
||||
</div>
|
||||
<Statistic
|
||||
title="总订单数"
|
||||
value={orderStats.totalOrders || 0}
|
||||
suffix={
|
||||
<span className={styles.trend}>
|
||||
<RiseOutlined /> {orderStats.orderGrowth || 0}%
|
||||
</span>
|
||||
}
|
||||
/>
|
||||
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: '16px' }}>
|
||||
<Statistic
|
||||
title={getOrderTitle()}
|
||||
value={orderStats.totalOrders || 0}
|
||||
suffix={
|
||||
!hasTimeRange && (
|
||||
<span className={styles.trend}>
|
||||
<RiseOutlined /> {orderStats.orderGrowth || 0}%
|
||||
</span>
|
||||
)
|
||||
}
|
||||
/>
|
||||
<Statistic
|
||||
title="退款订单"
|
||||
value={orderStats.refundedOrders || 0}
|
||||
/>
|
||||
</div>
|
||||
<div className={styles.subStats}>
|
||||
<Statistic title="今日订单" value={orderStats.todayOrders || 0} />
|
||||
<Statistic title={getTodayTitle()} value={getTodayValue()} />
|
||||
<Statistic
|
||||
title="完成率"
|
||||
value={orderStats.completionRate || 0}
|
||||
suffix="%"
|
||||
/>
|
||||
<Statistic
|
||||
title={getTodayRefundTitle()}
|
||||
value={getTodayRefundValue()}
|
||||
/>
|
||||
</div>
|
||||
</Card>
|
||||
</Col>
|
||||
@@ -431,11 +522,70 @@ const Welcome: React.FC = () => {
|
||||
</Col>
|
||||
</Row>
|
||||
|
||||
{/* 收入构成 */}
|
||||
{/* 订单列表 */}
|
||||
<Row gutter={[16, 16]}>
|
||||
<Col xs={24}>
|
||||
<Card title="收入构成分析" loading={loading}>
|
||||
<Column {...incomeConfig} height={300} />
|
||||
<Card title="最新订单列表" loading={loading}>
|
||||
<div style={{ maxHeight: '400px', overflowY: 'auto' }}>
|
||||
{orderList.length > 0 ? (
|
||||
<div>
|
||||
{orderList.map((order, index) => (
|
||||
<div
|
||||
key={order.id || index}
|
||||
style={{
|
||||
padding: '12px',
|
||||
borderBottom: '1px solid #f0f0f0',
|
||||
display: 'flex',
|
||||
justifyContent: 'space-between',
|
||||
alignItems: 'center',
|
||||
}}
|
||||
>
|
||||
<div style={{ flex: 1 }}>
|
||||
<div style={{ fontWeight: 'bold', marginBottom: '4px' }}>
|
||||
订单号: {order.orderNo}
|
||||
</div>
|
||||
<div style={{ fontSize: '12px', color: '#666' }}>
|
||||
创建时间: {order.createTime}
|
||||
</div>
|
||||
<div style={{ fontSize: '12px', color: '#666' }}>
|
||||
状态: {getOrderStatusText(order.orderStatus)}
|
||||
</div>
|
||||
</div>
|
||||
<div style={{ textAlign: 'right' }}>
|
||||
<div style={{ fontWeight: 'bold', color: '#1890ff' }}>
|
||||
¥{(order.orderAmount / 100).toFixed(2)}
|
||||
</div>
|
||||
<div style={{ fontSize: '12px', color: '#666' }}>
|
||||
用户ID: {order.userId}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<div style={{ textAlign: 'center', padding: '40px', color: '#999' }}>
|
||||
暂无订单数据
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
{/* 分页组件 */}
|
||||
{orderPagination.total > 0 && (
|
||||
<div style={{ textAlign: 'center', marginTop: '16px' }}>
|
||||
<Pagination
|
||||
current={orderPagination.current}
|
||||
pageSize={orderPagination.pageSize}
|
||||
total={orderPagination.total}
|
||||
showSizeChanger={false}
|
||||
showQuickJumper
|
||||
showTotal={(total, range) =>
|
||||
`第 ${range[0]}-${range[1]} 条,共 ${total} 条`
|
||||
}
|
||||
onChange={(page) => {
|
||||
fetchOrderList(page);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</Card>
|
||||
</Col>
|
||||
</Row>
|
||||
|
||||
@@ -198,6 +198,23 @@ export async function dashboard(params?: {
|
||||
});
|
||||
}
|
||||
|
||||
/** 获取首页订单列表 GET /api-order/dashboard/orders */
|
||||
export async function getDashboardOrders(params?: {
|
||||
tourismId?: number;
|
||||
qrcodeId?: string;
|
||||
deviceSn?: string;
|
||||
startTime?: string;
|
||||
endTime?: string;
|
||||
includeTestQrcodes?: boolean;
|
||||
page?: number;
|
||||
limit?: number;
|
||||
}) {
|
||||
return request('/api-order/dashboard/orders', {
|
||||
method: 'GET',
|
||||
params,
|
||||
});
|
||||
}
|
||||
|
||||
/** 获取二维码列表 GET /api-order/qrcode/options */
|
||||
export async function getQrcodeOptions(params?: {
|
||||
tourismId?: number;
|
||||
|
||||
Reference in New Issue
Block a user