diff --git a/zlt-web/react-web/src/main/frontend/src/pages/orders/statistics/components/TourismStatistics.tsx b/zlt-web/react-web/src/main/frontend/src/pages/orders/statistics/components/TourismStatistics.tsx new file mode 100644 index 00000000..c1c7a118 --- /dev/null +++ b/zlt-web/react-web/src/main/frontend/src/pages/orders/statistics/components/TourismStatistics.tsx @@ -0,0 +1,281 @@ +import React, { useState, useEffect } from 'react'; +import { ProForm, ProFormDateRangePicker, ProTable } from '@ant-design/pro-components'; +import { Card, Row, Col, Statistic, message } from 'antd'; +import { Column } from '@ant-design/plots'; +import moment from 'moment'; +import { getTourismStatistics } from '@/services/statistics/api'; + +interface TourismStatisticsItem { + groupKey: number; // 景区ID + totalOrders: number; // 订单总数 + paidOrders: number; // 已支付订单数 + completedOrders: number; // 已完成订单数 + canceledOrders: number; // 已取消订单数 + totalAmount: number; // 订单总金额(分) + totalAmountYuan: string; // 订单总金额(元) + paidAmount: number; // 已支付金额(分) + paidAmountYuan: string; // 已支付金额(元) + refundAmount: number; // 退款金额(分) + refundAmountYuan: string; // 退款金额(元) + completionRate: string; // 完成率 +} + +const TourismStatistics: React.FC<{ refreshKey: number }> = ({ refreshKey }) => { + const [loading, setLoading] = useState(false); + const [timeRange, setTimeRange] = useState<[moment.Moment, moment.Moment]>([ + moment().startOf('month'), + moment().endOf('month') + ]); + const [statisticsData, setStatisticsData] = useState([]); + + // 获取统计数据 + const fetchStatisticsData = async () => { + setLoading(true); + try { + const params = { + startTime: timeRange[0].format('YYYY-MM-DD HH:mm:ss'), + endTime: timeRange[1].format('YYYY-MM-DD HH:mm:ss'), + }; + + const res = await getTourismStatistics(params); + if (res.resp_code === 0) { + setStatisticsData(res.data || []); + } + } catch (error) { + message.error('获取景区统计数据失败'); + } finally { + setLoading(false); + } + }; + + // 数据刷新 + useEffect(() => { + fetchStatisticsData(); + }, [timeRange, refreshKey]); + + // 处理图表数据 + const getChartData = () => { + const result: any[] = []; + statisticsData.forEach(item => { + result.push( + { + groupKey: `景区${item.groupKey}`, + type: '订单总数', + value: item.totalOrders, + }, + { + groupKey: `景区${item.groupKey}`, + type: '已完成订单', + value: item.completedOrders, + }, + { + groupKey: `景区${item.groupKey}`, + type: '总金额(元)', + value: Number(item.totalAmountYuan), + }, + ); + }); + return result; + }; + + // 计算总览数据 + const getOverviewData = () => { + if (statisticsData.length === 0) return null; + + return statisticsData.reduce((acc, cur) => ({ + totalOrders: acc.totalOrders + cur.totalOrders, + paidOrders: acc.paidOrders + cur.paidOrders, + totalAmount: acc.totalAmount + Number(cur.totalAmountYuan), + avgCompletionRate: (acc.avgCompletionRate * acc.count + parseFloat(cur.completionRate)) / (acc.count + 1), + count: acc.count + 1, + }), { + totalOrders: 0, + paidOrders: 0, + totalAmount: 0, + avgCompletionRate: 0, + count: 0, + }); + }; + + // 表格列定义 + const columns = [ + { + title: '景区ID', + dataIndex: 'groupKey', + width: 100, + fixed: 'left', + render: (val: number) => `景区${val}`, + }, + { + title: '订单数量', + children: [ + { + title: '总订单', + dataIndex: 'totalOrders', + width: 100, + sorter: (a, b) => a.totalOrders - b.totalOrders, + }, + { + title: '已支付', + dataIndex: 'paidOrders', + width: 100, + sorter: (a, b) => a.paidOrders - b.paidOrders, + }, + { + title: '已完成', + dataIndex: 'completedOrders', + width: 100, + sorter: (a, b) => a.completedOrders - b.completedOrders, + }, + { + title: '已取消', + dataIndex: 'canceledOrders', + width: 100, + sorter: (a, b) => a.canceledOrders - b.canceledOrders, + }, + { + title: '完成率', + dataIndex: 'completionRate', + width: 100, + sorter: (a, b) => parseFloat(a.completionRate) - parseFloat(b.completionRate), + } + ], + }, + { + title: '订单金额(元)', + children: [ + { + title: '总金额', + dataIndex: 'totalAmountYuan', + width: 120, + sorter: (a, b) => parseFloat(a.totalAmountYuan) - parseFloat(b.totalAmountYuan), + }, + { + title: '已支付', + dataIndex: 'paidAmountYuan', + width: 120, + sorter: (a, b) => parseFloat(a.paidAmountYuan) - parseFloat(b.paidAmountYuan), + }, + { + title: '退款', + dataIndex: 'refundAmountYuan', + width: 120, + sorter: (a, b) => parseFloat(a.refundAmountYuan) - parseFloat(b.refundAmountYuan), + }, + ], + }, + ]; + + return ( + <> + {/* 筛选条件 */} + + + + + + + + + + + {/* 数据概览 */} + + + + + + + + + + + + + + + + + + {/* 趋势图表 */} + +
+ ({ + name: datum.type, + value: datum.type.includes('金额') ? `¥${datum.value}` : datum.value, + }), + }} + /> +
+
+ + {/* 详细数据表格 */} + + + + + ); +}; + +export default TourismStatistics; \ No newline at end of file diff --git a/zlt-web/react-web/src/main/frontend/src/pages/orders/statistics/index.tsx b/zlt-web/react-web/src/main/frontend/src/pages/orders/statistics/index.tsx index 2d04d5e9..3ef28ed4 100644 --- a/zlt-web/react-web/src/main/frontend/src/pages/orders/statistics/index.tsx +++ b/zlt-web/react-web/src/main/frontend/src/pages/orders/statistics/index.tsx @@ -6,6 +6,7 @@ import type { TabsProps } from 'antd'; import { getQrcodeList } from '@/services/statistics/api'; import QrcodeStatistics from './components/QrcodeStatistics'; import DeviceStatistics from './components/DeviceStatistics'; +import TourismStatistics from './components/TourismStatistics'; const Statistics: React.FC = () => { const [qrcodeOptions, setQrcodeOptions] = useState<{ label: string; value: string; }[]>([]); @@ -58,6 +59,15 @@ const Statistics: React.FC = () => { /> ), }, + { + key: 'tourism', + label: '按景区统计', + children: ( + + ), + }, ]; return ( diff --git a/zlt-web/react-web/src/main/frontend/src/services/statistics/api.ts b/zlt-web/react-web/src/main/frontend/src/services/statistics/api.ts index c877a58a..0b613759 100644 --- a/zlt-web/react-web/src/main/frontend/src/services/statistics/api.ts +++ b/zlt-web/react-web/src/main/frontend/src/services/statistics/api.ts @@ -54,4 +54,15 @@ export async function getDeviceStatistics(params: DeviceStatisticsParams) { method: 'GET', params, }); +} + +/** 获取景区维度统计数据 */ +export async function getTourismStatistics(params: { + startTime: string; + endTime: string; +}) { + return request('/api-order/statistics/tourism', { + method: 'GET', + params, + }); } \ No newline at end of file