fix(统计管理):新增二维码、设备、景区分账统计前后端功能
This commit is contained in:
+281
@@ -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<TourismStatisticsItem[]>([]);
|
||||||
|
|
||||||
|
// 获取统计数据
|
||||||
|
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 (
|
||||||
|
<>
|
||||||
|
{/* 筛选条件 */}
|
||||||
|
<Card bordered={false} className="statistics-filter-card" style={{ marginBottom: 24 }}>
|
||||||
|
<ProForm
|
||||||
|
layout="horizontal"
|
||||||
|
submitter={false}
|
||||||
|
initialValues={{ timeRange }}
|
||||||
|
>
|
||||||
|
<Row>
|
||||||
|
<Col span={24}>
|
||||||
|
<ProFormDateRangePicker
|
||||||
|
name="timeRange"
|
||||||
|
label="统计时间"
|
||||||
|
fieldProps={{
|
||||||
|
value: timeRange,
|
||||||
|
onChange: setTimeRange,
|
||||||
|
ranges: {
|
||||||
|
'今天': [moment().startOf('day'), moment().endOf('day')],
|
||||||
|
'本周': [moment().startOf('week'), moment().endOf('week')],
|
||||||
|
'本月': [moment().startOf('month'), moment().endOf('month')],
|
||||||
|
'上个月': [moment().subtract(1, 'months').startOf('month'), moment().subtract(1, 'months').endOf('month')],
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Col>
|
||||||
|
</Row>
|
||||||
|
</ProForm>
|
||||||
|
</Card>
|
||||||
|
|
||||||
|
{/* 数据概览 */}
|
||||||
|
<Card bordered={false} style={{ marginBottom: 24 }}>
|
||||||
|
<Row gutter={24}>
|
||||||
|
<Col span={6}>
|
||||||
|
<Statistic
|
||||||
|
title="景区总数"
|
||||||
|
value={statisticsData.length}
|
||||||
|
suffix="个"
|
||||||
|
/>
|
||||||
|
</Col>
|
||||||
|
<Col span={6}>
|
||||||
|
<Statistic
|
||||||
|
title="总订单数"
|
||||||
|
value={getOverviewData()?.totalOrders || 0}
|
||||||
|
suffix="笔"
|
||||||
|
/>
|
||||||
|
</Col>
|
||||||
|
<Col span={6}>
|
||||||
|
<Statistic
|
||||||
|
title="总金额"
|
||||||
|
value={getOverviewData()?.totalAmount || 0}
|
||||||
|
precision={2}
|
||||||
|
prefix="¥"
|
||||||
|
/>
|
||||||
|
</Col>
|
||||||
|
<Col span={6}>
|
||||||
|
<Statistic
|
||||||
|
title="平均完成率"
|
||||||
|
value={getOverviewData()?.avgCompletionRate || 0}
|
||||||
|
precision={2}
|
||||||
|
suffix="%"
|
||||||
|
valueStyle={{ color: '#3f8600' }}
|
||||||
|
/>
|
||||||
|
</Col>
|
||||||
|
</Row>
|
||||||
|
</Card>
|
||||||
|
|
||||||
|
{/* 趋势图表 */}
|
||||||
|
<Card bordered={false} style={{ marginBottom: 24 }}>
|
||||||
|
<div style={{ height: 400 }}>
|
||||||
|
<Column
|
||||||
|
loading={loading}
|
||||||
|
data={getChartData()}
|
||||||
|
xField="groupKey"
|
||||||
|
yField="value"
|
||||||
|
seriesField="type"
|
||||||
|
isGroup={true}
|
||||||
|
columnStyle={{
|
||||||
|
radius: [4, 4, 0, 0],
|
||||||
|
}}
|
||||||
|
meta={{
|
||||||
|
value: {
|
||||||
|
alias: '数量/金额',
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
tooltip={{
|
||||||
|
formatter: (datum) => ({
|
||||||
|
name: datum.type,
|
||||||
|
value: datum.type.includes('金额') ? `¥${datum.value}` : datum.value,
|
||||||
|
}),
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</Card>
|
||||||
|
|
||||||
|
{/* 详细数据表格 */}
|
||||||
|
<Card bordered={false}>
|
||||||
|
<ProTable
|
||||||
|
dataSource={statisticsData}
|
||||||
|
columns={columns}
|
||||||
|
loading={loading}
|
||||||
|
search={false}
|
||||||
|
options={false}
|
||||||
|
pagination={false}
|
||||||
|
scroll={{ x: 1500 }}
|
||||||
|
size="small"
|
||||||
|
/>
|
||||||
|
</Card>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default TourismStatistics;
|
||||||
@@ -6,6 +6,7 @@ import type { TabsProps } from 'antd';
|
|||||||
import { getQrcodeList } from '@/services/statistics/api';
|
import { getQrcodeList } from '@/services/statistics/api';
|
||||||
import QrcodeStatistics from './components/QrcodeStatistics';
|
import QrcodeStatistics from './components/QrcodeStatistics';
|
||||||
import DeviceStatistics from './components/DeviceStatistics';
|
import DeviceStatistics from './components/DeviceStatistics';
|
||||||
|
import TourismStatistics from './components/TourismStatistics';
|
||||||
|
|
||||||
const Statistics: React.FC = () => {
|
const Statistics: React.FC = () => {
|
||||||
const [qrcodeOptions, setQrcodeOptions] = useState<{ label: string; value: string; }[]>([]);
|
const [qrcodeOptions, setQrcodeOptions] = useState<{ label: string; value: string; }[]>([]);
|
||||||
@@ -58,6 +59,15 @@ const Statistics: React.FC = () => {
|
|||||||
/>
|
/>
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
key: 'tourism',
|
||||||
|
label: '按景区统计',
|
||||||
|
children: (
|
||||||
|
<TourismStatistics
|
||||||
|
refreshKey={refreshKey}
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -54,4 +54,15 @@ export async function getDeviceStatistics(params: DeviceStatisticsParams) {
|
|||||||
method: 'GET',
|
method: 'GET',
|
||||||
params,
|
params,
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 获取景区维度统计数据 */
|
||||||
|
export async function getTourismStatistics(params: {
|
||||||
|
startTime: string;
|
||||||
|
endTime: string;
|
||||||
|
}) {
|
||||||
|
return request('/api-order/statistics/tourism', {
|
||||||
|
method: 'GET',
|
||||||
|
params,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user