fix(统计管理):新增二维码、设备、景区分账统计前后端功能
This commit is contained in:
@@ -49,9 +49,11 @@
|
||||
"@ant-design/icons": "^4.7.0",
|
||||
"@ant-design/pro-components": "1.1.1",
|
||||
"@babel/runtime": "^7.27.0",
|
||||
"@types/file-saver": "^2.0.7",
|
||||
"@umijs/route-utils": "^2.0.0",
|
||||
"antd": "^4.20.0",
|
||||
"classnames": "^2.3.0",
|
||||
"file-saver": "^2.0.5",
|
||||
"lodash": "^4.17.21",
|
||||
"moment": "^2.29.0",
|
||||
"omit.js": "^2.0.2",
|
||||
@@ -67,7 +69,8 @@
|
||||
"spark-md5": "^3.0.2",
|
||||
"treeify-js": "^1.0.8",
|
||||
"umi": "^3.5.0",
|
||||
"uuid": "^9.0.0"
|
||||
"uuid": "^9.0.0",
|
||||
"xlsx": "^0.18.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@ant-design/pro-cli": "^2.1.0",
|
||||
|
||||
@@ -28,7 +28,7 @@ const statusColorMap = {
|
||||
};
|
||||
|
||||
// 提取常量
|
||||
const WORKSPACE_OPTIONS: DefaultOptionType[] = [
|
||||
export const WORKSPACE_OPTIONS: DefaultOptionType[] = [
|
||||
{ label: '工作区1', value: '1' },
|
||||
{ label: '工作区2', value: '2' },
|
||||
// ... 根据实际需求添加更多选项
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
.statistics-filter-card {
|
||||
.ant-form {
|
||||
.ant-row {
|
||||
align-items: flex-end;
|
||||
}
|
||||
}
|
||||
|
||||
.ant-radio-group {
|
||||
margin-bottom: 24px;
|
||||
|
||||
.ant-radio-button-wrapper {
|
||||
min-width: 100px;
|
||||
text-align: center;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.ant-tabs-card {
|
||||
.ant-tabs-content {
|
||||
margin-top: -16px;
|
||||
}
|
||||
|
||||
.ant-tabs-tab {
|
||||
border-radius: 4px 4px 0 0;
|
||||
background: #fafafa;
|
||||
border-color: #f0f0f0;
|
||||
|
||||
&.ant-tabs-tab-active {
|
||||
background: #fff;
|
||||
}
|
||||
}
|
||||
|
||||
.ant-card {
|
||||
border-radius: 0 4px 4px 4px;
|
||||
}
|
||||
}
|
||||
|
||||
.ant-card {
|
||||
.ant-statistic {
|
||||
.ant-statistic-title {
|
||||
font-size: 14px;
|
||||
color: rgba(0, 0, 0, 0.45);
|
||||
}
|
||||
|
||||
.ant-statistic-content {
|
||||
font-size: 24px;
|
||||
font-weight: 500;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.ant-pro-table {
|
||||
.ant-table {
|
||||
.ant-table-thead {
|
||||
> tr > th {
|
||||
background: #fafafa;
|
||||
font-weight: 500;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,387 @@
|
||||
import React, { useState, useEffect, useRef } from 'react';
|
||||
import { PageContainer, ProForm, ProFormDateRangePicker, ProFormSelect, ProTable } from '@ant-design/pro-components';
|
||||
import { Card, Radio, Space, message, Tabs, Row, Col, Statistic, Button } from 'antd';
|
||||
import { Line } from '@ant-design/plots';
|
||||
import { ReloadOutlined, DownloadOutlined } from '@ant-design/icons';
|
||||
import moment from 'moment';
|
||||
import { getTimeStatistics, getQrcodeList } from '@/services/statistics/api';
|
||||
import { exportExcel } from '@/utils/export';
|
||||
|
||||
// 定义数据结构接口
|
||||
interface StatisticsItem {
|
||||
groupKey: string;
|
||||
totalOrders: number;
|
||||
paidOrders: number;
|
||||
completedOrders: number;
|
||||
canceledOrders: number;
|
||||
totalAmount: number;
|
||||
totalAmountYuan: string;
|
||||
paidAmount: number;
|
||||
paidAmountYuan: string;
|
||||
refundAmount: number;
|
||||
refundAmountYuan: string;
|
||||
completionRate: string;
|
||||
}
|
||||
|
||||
const Statistics: React.FC = () => {
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [qrcodeOptions, setQrcodeOptions] = useState<{ label: string; value: string; }[]>([]);
|
||||
const [qrcodeId, setQrcodeId] = useState<string>();
|
||||
const [timeType, setTimeType] = useState<'hour' | 'day' | 'month'>('day');
|
||||
const [timeRange, setTimeRange] = useState<[moment.Moment, moment.Moment]>([
|
||||
moment().startOf('month'),
|
||||
moment().endOf('month')
|
||||
]);
|
||||
const [statisticsData, setStatisticsData] = useState<StatisticsItem[]>([]);
|
||||
const [refreshKey, setRefreshKey] = useState(0); // 用于触发数据刷新
|
||||
|
||||
// 自动刷新定时器
|
||||
const refreshTimer = useRef<NodeJS.Timeout>();
|
||||
|
||||
// 获取二维码列表
|
||||
const fetchQrcodeList = async () => {
|
||||
try {
|
||||
const res = await getQrcodeList({ page: 1, limit: 100 });
|
||||
if (res.resp_code === 0 && res.data) {
|
||||
const options = res.data.map((item: any) => ({
|
||||
label: `${item.name || item.qrcode} | ${item.deviceSn || '无设备'} | ${((item.price || 0) / 100).toFixed(2)}元`,
|
||||
value: item.codeId,
|
||||
}));
|
||||
setQrcodeOptions(options);
|
||||
if (options.length > 0) {
|
||||
setQrcodeId(options[0].value);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
message.error('获取二维码列表失败');
|
||||
}
|
||||
};
|
||||
|
||||
// 获取统计数据
|
||||
const fetchStatisticsData = async () => {
|
||||
if (!qrcodeId) return;
|
||||
|
||||
setLoading(true);
|
||||
try {
|
||||
const params = {
|
||||
qrcodeId,
|
||||
startTime: timeRange[0].format('YYYY-MM-DD HH:mm:ss'),
|
||||
endTime: timeRange[1].format('YYYY-MM-DD HH:mm:ss'),
|
||||
timeType,
|
||||
};
|
||||
|
||||
const res = await getTimeStatistics(params);
|
||||
if (res.resp_code === 0) {
|
||||
setStatisticsData(res.data || []);
|
||||
}
|
||||
} catch (error) {
|
||||
message.error('获取统计数据失败');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
// 处理数据导出
|
||||
const handleExport = () => {
|
||||
const header = [
|
||||
{ title: '统计时间', dataIndex: 'groupKey' },
|
||||
{ title: '订单总数', dataIndex: 'totalOrders' },
|
||||
{ title: '已支付订单数', dataIndex: 'paidOrders' },
|
||||
{ title: '已完成订单数', dataIndex: 'completedOrders' },
|
||||
{ title: '已取消订单数', dataIndex: 'canceledOrders' },
|
||||
{ title: '订单总金额(元)', dataIndex: 'totalAmountYuan' },
|
||||
{ title: '已支付金额(元)', dataIndex: 'paidAmountYuan' },
|
||||
{ title: '退款金额(元)', dataIndex: 'refundAmountYuan' },
|
||||
{ title: '完成率', dataIndex: 'completionRate' },
|
||||
];
|
||||
|
||||
exportExcel({
|
||||
data: statisticsData,
|
||||
header,
|
||||
fileName: `订单统计数据_${moment().format('YYYY-MM-DD')}`,
|
||||
});
|
||||
};
|
||||
|
||||
// 图表配置
|
||||
const chartConfig = {
|
||||
data: statisticsData,
|
||||
loading,
|
||||
xField: 'groupKey',
|
||||
yField: 'value',
|
||||
seriesField: 'type',
|
||||
smooth: true,
|
||||
meta: {
|
||||
value: {
|
||||
alias: '数量/金额',
|
||||
},
|
||||
},
|
||||
tooltip: {
|
||||
formatter: (datum: any) => ({
|
||||
name: datum.type,
|
||||
value: datum.type.includes('金额') ? `¥${datum.value}` : datum.value,
|
||||
}),
|
||||
},
|
||||
};
|
||||
|
||||
// 处理图表数据
|
||||
const getChartData = () => {
|
||||
const result: any[] = [];
|
||||
statisticsData.forEach(item => {
|
||||
result.push(
|
||||
{
|
||||
groupKey: item.groupKey,
|
||||
type: '订单总数',
|
||||
value: item.totalOrders,
|
||||
},
|
||||
{
|
||||
groupKey: item.groupKey,
|
||||
type: '总金额(元)',
|
||||
value: Number(item.totalAmountYuan),
|
||||
},
|
||||
);
|
||||
});
|
||||
return result;
|
||||
};
|
||||
|
||||
// 表格列定义
|
||||
const columns = [
|
||||
{
|
||||
title: '统计时间',
|
||||
dataIndex: 'groupKey',
|
||||
width: 180,
|
||||
fixed: 'left',
|
||||
},
|
||||
{
|
||||
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),
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
// 计算总览数据
|
||||
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 + parseFloat(cur.totalAmountYuan),
|
||||
avgCompletionRate: (acc.avgCompletionRate + parseFloat(cur.completionRate)) / 2,
|
||||
}), {
|
||||
totalOrders: 0,
|
||||
paidOrders: 0,
|
||||
totalAmount: 0,
|
||||
avgCompletionRate: 0,
|
||||
});
|
||||
};
|
||||
|
||||
// 自动刷新
|
||||
useEffect(() => {
|
||||
refreshTimer.current = setInterval(() => {
|
||||
setRefreshKey(prev => prev + 1);
|
||||
}, 300000); // 每5分钟刷新一次
|
||||
|
||||
return () => {
|
||||
if (refreshTimer.current) {
|
||||
clearInterval(refreshTimer.current);
|
||||
}
|
||||
};
|
||||
}, []);
|
||||
|
||||
// 添加初始化加载二维码列表
|
||||
useEffect(() => {
|
||||
fetchQrcodeList();
|
||||
}, []);
|
||||
|
||||
// 数据刷新
|
||||
useEffect(() => {
|
||||
fetchStatisticsData();
|
||||
}, [qrcodeId, timeType, timeRange, refreshKey]);
|
||||
|
||||
return (
|
||||
<PageContainer
|
||||
extra={[
|
||||
<Button
|
||||
key="refresh"
|
||||
icon={<ReloadOutlined />}
|
||||
onClick={() => setRefreshKey(prev => prev + 1)}
|
||||
>
|
||||
刷新
|
||||
</Button>,
|
||||
<Button
|
||||
key="export"
|
||||
type="primary"
|
||||
icon={<DownloadOutlined />}
|
||||
onClick={handleExport}
|
||||
>
|
||||
导出数据
|
||||
</Button>,
|
||||
]}
|
||||
>
|
||||
{/* 筛选条件 */}
|
||||
<Card bordered={false} className="statistics-filter-card" style={{ marginBottom: 24 }}>
|
||||
<ProForm
|
||||
layout="horizontal"
|
||||
submitter={false}
|
||||
initialValues={{ timeRange, qrcodeId }}
|
||||
>
|
||||
<Row gutter={24}>
|
||||
<Col span={8}>
|
||||
<ProFormSelect
|
||||
name="qrcodeId"
|
||||
label="二维码"
|
||||
width="xl"
|
||||
options={qrcodeOptions}
|
||||
placeholder="请选择二维码"
|
||||
rules={[{ required: true, message: '请选择二维码' }]}
|
||||
fieldProps={{
|
||||
value: qrcodeId,
|
||||
onChange: setQrcodeId,
|
||||
showSearch: true,
|
||||
filterOption: (input, option) =>
|
||||
(option?.label ?? '').toLowerCase().includes(input.toLowerCase()),
|
||||
optionLabelProp: "label",
|
||||
}}
|
||||
/>
|
||||
</Col>
|
||||
<Col span={8}>
|
||||
<ProFormDateRangePicker
|
||||
name="timeRange"
|
||||
label="统计时间"
|
||||
fieldProps={{
|
||||
value: timeRange,
|
||||
onChange: setTimeRange,
|
||||
}}
|
||||
/>
|
||||
</Col>
|
||||
<Col span={8}>
|
||||
<Radio.Group
|
||||
value={timeType}
|
||||
onChange={e => setTimeType(e.target.value)}
|
||||
optionType="button"
|
||||
buttonStyle="solid"
|
||||
>
|
||||
<Radio.Button value="hour">按小时</Radio.Button>
|
||||
<Radio.Button value="day">按天</Radio.Button>
|
||||
<Radio.Button value="month">按月</Radio.Button>
|
||||
</Radio.Group>
|
||||
</Col>
|
||||
</Row>
|
||||
</ProForm>
|
||||
</Card>
|
||||
|
||||
{/* 数据概览 */}
|
||||
<Card bordered={false} style={{ marginBottom: 24 }}>
|
||||
<Row gutter={24}>
|
||||
<Col span={6}>
|
||||
<Statistic
|
||||
title="总订单数"
|
||||
value={getOverviewData()?.totalOrders || 0}
|
||||
suffix="笔"
|
||||
/>
|
||||
</Col>
|
||||
<Col span={6}>
|
||||
<Statistic
|
||||
title="已支付订单"
|
||||
value={getOverviewData()?.paidOrders || 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 }}>
|
||||
<Line {...chartConfig} data={getChartData()} />
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
{/* 详细数据表格 */}
|
||||
<Card bordered={false}>
|
||||
<ProTable
|
||||
dataSource={statisticsData}
|
||||
columns={columns}
|
||||
loading={loading}
|
||||
search={false}
|
||||
options={false}
|
||||
pagination={false}
|
||||
scroll={{ x: 1500 }}
|
||||
size="small"
|
||||
/>
|
||||
</Card>
|
||||
</PageContainer>
|
||||
);
|
||||
};
|
||||
|
||||
export default Statistics;
|
||||
-80
@@ -1,80 +0,0 @@
|
||||
import React from 'react';
|
||||
import { ProTable } from '@ant-design/pro-components';
|
||||
import type { ProColumns } from '@ant-design/pro-components';
|
||||
|
||||
interface StatisticsTableProps {
|
||||
data: STATISTICS.OrderStatistics[];
|
||||
loading?: boolean;
|
||||
}
|
||||
|
||||
const StatisticsTable: React.FC<StatisticsTableProps> = ({ data, loading }) => {
|
||||
const columns: ProColumns<STATISTICS.OrderStatistics>[] = [
|
||||
{
|
||||
title: '统计日期',
|
||||
dataIndex: 'statisticsDate',
|
||||
valueType: 'date',
|
||||
},
|
||||
{
|
||||
title: '景区名称',
|
||||
dataIndex: 'tourismName',
|
||||
},
|
||||
{
|
||||
title: '设备编号',
|
||||
dataIndex: 'deviceSn',
|
||||
},
|
||||
{
|
||||
title: '总订单数',
|
||||
dataIndex: 'totalOrders',
|
||||
},
|
||||
{
|
||||
title: '已支付订单数',
|
||||
dataIndex: 'paidOrders',
|
||||
},
|
||||
{
|
||||
title: '已完成订单数',
|
||||
dataIndex: 'completedOrders',
|
||||
},
|
||||
{
|
||||
title: '已取消订单数',
|
||||
dataIndex: 'canceledOrders',
|
||||
},
|
||||
{
|
||||
title: '总金额(元)',
|
||||
dataIndex: 'totalAmount',
|
||||
render: (val) => (val as number / 100).toFixed(2),
|
||||
},
|
||||
{
|
||||
title: '已支付金额(元)',
|
||||
dataIndex: 'paidAmount',
|
||||
render: (val) => (val as number / 100).toFixed(2),
|
||||
},
|
||||
{
|
||||
title: '退款金额(元)',
|
||||
dataIndex: 'refundAmount',
|
||||
render: (val) => (val as number / 100).toFixed(2),
|
||||
},
|
||||
{
|
||||
title: '平台分成(元)',
|
||||
dataIndex: 'platformAmount',
|
||||
render: (val) => (val as number / 100).toFixed(2),
|
||||
},
|
||||
{
|
||||
title: '景区分成(元)',
|
||||
dataIndex: 'tourismAmount',
|
||||
render: (val) => (val as number / 100).toFixed(2),
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<ProTable<STATISTICS.OrderStatistics>
|
||||
columns={columns}
|
||||
dataSource={data}
|
||||
loading={loading}
|
||||
search={false}
|
||||
options={false}
|
||||
pagination={false}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export default StatisticsTable;
|
||||
@@ -1,144 +0,0 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import {
|
||||
PageContainer,
|
||||
ProCard,
|
||||
ProForm,
|
||||
ProFormDateTimeRangePicker,
|
||||
ProFormSelect,
|
||||
} from '@ant-design/pro-components';
|
||||
import { Card, Tabs, message } from 'antd';
|
||||
import { Line, Column, Pie } from '@ant-design/plots';
|
||||
import {
|
||||
generateStatistics,
|
||||
getTimeStatistics,
|
||||
getTourismStatistics,
|
||||
getDeviceStatistics,
|
||||
} from '@/services/statistics/api';
|
||||
|
||||
const Statistics: React.FC = () => {
|
||||
const [timeData, setTimeData] = useState<STATISTICS.OrderStatistics[]>([]);
|
||||
const [tourismData, setTourismData] = useState<STATISTICS.OrderStatistics[]>([]);
|
||||
const [deviceData, setDeviceData] = useState<STATISTICS.OrderStatistics[]>([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
// 获取统计数据
|
||||
const fetchStatistics = async (params: STATISTICS.StatisticsParams) => {
|
||||
setLoading(true);
|
||||
try {
|
||||
// 生成统计数据
|
||||
await generateStatistics(params);
|
||||
|
||||
// 获取各维度统计数据
|
||||
const [timeRes, tourismRes, deviceRes] = await Promise.all([
|
||||
getTimeStatistics(params),
|
||||
getTourismStatistics(params),
|
||||
getDeviceStatistics(params),
|
||||
]);
|
||||
|
||||
if (timeRes.resp_code === 0) setTimeData(timeRes.data);
|
||||
if (tourismRes.resp_code === 0) setTourismData(tourismRes.data);
|
||||
if (deviceRes.resp_code === 0) setDeviceData(deviceRes.data);
|
||||
} catch (error) {
|
||||
message.error('获取统计数据失败');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
// 时间维度图表配置
|
||||
const timeChartConfig = {
|
||||
data: timeData,
|
||||
xField: 'statisticsDate',
|
||||
yField: 'totalAmount',
|
||||
seriesField: 'type',
|
||||
legend: { position: 'top' },
|
||||
};
|
||||
|
||||
// 景区维度图表配置
|
||||
const tourismChartConfig = {
|
||||
data: tourismData.map(item => ({
|
||||
type: '订单总额',
|
||||
value: item.totalAmount / 100,
|
||||
tourism: item.tourismName,
|
||||
})),
|
||||
angleField: 'value',
|
||||
colorField: 'tourism',
|
||||
};
|
||||
|
||||
return (
|
||||
<PageContainer>
|
||||
<ProCard>
|
||||
<ProForm
|
||||
onFinish={async (values) => {
|
||||
const [startTime, endTime] = values.timeRange || [];
|
||||
await fetchStatistics({
|
||||
startTime,
|
||||
endTime,
|
||||
timeType: values.timeType,
|
||||
});
|
||||
}}
|
||||
>
|
||||
<ProFormDateTimeRangePicker
|
||||
name="timeRange"
|
||||
label="统计时间范围"
|
||||
required
|
||||
/>
|
||||
<ProFormSelect
|
||||
name="timeType"
|
||||
label="统计维度"
|
||||
options={[
|
||||
{ label: '按小时', value: 'hour' },
|
||||
{ label: '按天', value: 'day' },
|
||||
{ label: '按月', value: 'month' },
|
||||
]}
|
||||
required
|
||||
/>
|
||||
</ProForm>
|
||||
</ProCard>
|
||||
|
||||
<Tabs
|
||||
items={[
|
||||
{
|
||||
key: 'time',
|
||||
label: '时间维度统计',
|
||||
children: (
|
||||
<Card loading={loading}>
|
||||
<Line {...timeChartConfig} />
|
||||
</Card>
|
||||
),
|
||||
},
|
||||
{
|
||||
key: 'tourism',
|
||||
label: '景区维度统计',
|
||||
children: (
|
||||
<Card loading={loading}>
|
||||
<Pie {...tourismChartConfig} />
|
||||
</Card>
|
||||
),
|
||||
},
|
||||
{
|
||||
key: 'device',
|
||||
label: '设备维度统计',
|
||||
children: (
|
||||
<Card loading={loading}>
|
||||
<Column
|
||||
data={deviceData}
|
||||
xField="deviceSn"
|
||||
yField="totalAmount"
|
||||
label={{
|
||||
position: 'middle',
|
||||
style: {
|
||||
fill: '#FFFFFF',
|
||||
},
|
||||
}}
|
||||
/>
|
||||
</Card>
|
||||
),
|
||||
},
|
||||
]}
|
||||
/>
|
||||
</PageContainer>
|
||||
);
|
||||
};
|
||||
|
||||
export default Statistics;
|
||||
@@ -1,97 +1,43 @@
|
||||
import { request } from '@/utils/request';
|
||||
import moment from 'moment';
|
||||
import { request } from 'umi';
|
||||
|
||||
/** 生成统计数据 */
|
||||
export async function generateStatistics(params: {
|
||||
startTime: string;
|
||||
endTime: string;
|
||||
}) {
|
||||
return request('/api-order/statistics/generate', {
|
||||
method: 'POST',
|
||||
data: params,
|
||||
});
|
||||
/** 获取二维码列表参数 */
|
||||
interface QrcodeListParams {
|
||||
page: number;
|
||||
limit: number;
|
||||
}
|
||||
|
||||
/** 获取二维码维度统计数据 */
|
||||
export async function getQrcodeStatistics(params: {
|
||||
startTime?: string;
|
||||
endTime?: string;
|
||||
}) {
|
||||
const response = await request('/api-order/statistics/qrcode', {
|
||||
method: 'GET',
|
||||
params,
|
||||
});
|
||||
return {
|
||||
...response,
|
||||
data: processChartData(response.data || []),
|
||||
};
|
||||
}
|
||||
|
||||
/** 获取景区维度统计数据 */
|
||||
export async function getTourismStatistics(params: {
|
||||
startTime?: string;
|
||||
endTime?: string;
|
||||
}) {
|
||||
const response = await request('/api-order/statistics/tourism', {
|
||||
method: 'GET',
|
||||
params,
|
||||
});
|
||||
return {
|
||||
...response,
|
||||
data: processChartData(response.data || []),
|
||||
};
|
||||
}
|
||||
|
||||
/** 获取设备维度统计数据 */
|
||||
export async function getDeviceStatistics(params: {
|
||||
startTime: string;
|
||||
endTime: string;
|
||||
}) {
|
||||
return request('/api-order/statistics/device', {
|
||||
/** 获取二维码列表 */
|
||||
export async function getQrcodeList(params: QrcodeListParams = { page: 1, limit: 100 }) {
|
||||
return request('/api-order/qrcode', {
|
||||
method: 'GET',
|
||||
params,
|
||||
});
|
||||
}
|
||||
|
||||
// 获取二维码时间维度统计数据
|
||||
export async function getQrcodeTimeStatistics(params: {
|
||||
/** 时间维度类型 */
|
||||
type TimeType = 'hour' | 'day' | 'month';
|
||||
|
||||
/** 获取时间统计数据参数 */
|
||||
export interface TimeStatisticsParams {
|
||||
/** 二维码ID */
|
||||
qrcodeId: string;
|
||||
/** 开始时间 (格式:yyyy-MM-dd HH:mm:ss) */
|
||||
startTime: string;
|
||||
/** 结束时间 (格式:yyyy-MM-dd HH:mm:ss) */
|
||||
endTime: string;
|
||||
timeType?: 'hour' | 'day' | 'month';
|
||||
}) {
|
||||
/** 时间维度类型(hour/day/month) */
|
||||
timeType?: TimeType;
|
||||
}
|
||||
|
||||
/** 获取时间统计数据 */
|
||||
export async function getTimeStatistics(params: TimeStatisticsParams) {
|
||||
return request('/api-order/statistics/time', {
|
||||
method: 'GET',
|
||||
params,
|
||||
params: {
|
||||
qrcodeId: params.qrcodeId,
|
||||
startTime: params.startTime,
|
||||
endTime: params.endTime,
|
||||
timeType: params.timeType || 'day',
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// 获取时间维度统计数据
|
||||
export async function getTimeStatistics(params: {
|
||||
qrcodeId: string;
|
||||
startTime: string;
|
||||
endTime: string;
|
||||
timeType: 'hour' | 'day' | 'month';
|
||||
}) {
|
||||
return request('/api-order/statistics/time', {
|
||||
method: 'GET',
|
||||
params,
|
||||
});
|
||||
}
|
||||
|
||||
// 获取二维码列表
|
||||
export async function getQrcodeList() {
|
||||
return request('/api-order/qrcode/list', {
|
||||
method: 'GET',
|
||||
});
|
||||
}
|
||||
|
||||
// 处理图表数据的辅助函数
|
||||
const processChartData = (data: any[]) => {
|
||||
return data.map(item => ({
|
||||
...item,
|
||||
date: item.statisticsTime || moment().format('YYYY-MM-DD'),
|
||||
value: item.amount || 0,
|
||||
count: item.count || 0,
|
||||
}));
|
||||
};
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
declare namespace STATISTICS {
|
||||
interface OrderStatistics {
|
||||
id: number;
|
||||
qrcodeId: string;
|
||||
tourismId: number;
|
||||
tourismName: string;
|
||||
deviceSn: string;
|
||||
tenantId: string;
|
||||
|
||||
totalOrders: number;
|
||||
paidOrders: number;
|
||||
completedOrders: number;
|
||||
canceledOrders: number;
|
||||
|
||||
totalAmount: number;
|
||||
paidAmount: number;
|
||||
refundAmount: number;
|
||||
|
||||
platformRate: number;
|
||||
tourismRate: number;
|
||||
platformAmount: number;
|
||||
tourismAmount: number;
|
||||
|
||||
startTime: string;
|
||||
endTime: string;
|
||||
statisticsDate: string;
|
||||
statisticsHour: number;
|
||||
createTime: string;
|
||||
}
|
||||
|
||||
interface StatisticsParams {
|
||||
qrcodeId: string;
|
||||
startTime: string;
|
||||
endTime: string;
|
||||
timeType: 'hour' | 'day' | 'month';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
import { saveAs } from 'file-saver';
|
||||
import * as XLSX from 'xlsx';
|
||||
|
||||
interface ExportExcelParams {
|
||||
data: any[];
|
||||
header: {
|
||||
title: string;
|
||||
dataIndex: string;
|
||||
}[];
|
||||
fileName: string;
|
||||
}
|
||||
|
||||
export const exportExcel = ({ data, header, fileName }: ExportExcelParams) => {
|
||||
try {
|
||||
// 转换数据格式
|
||||
const excelData = data.map(item => {
|
||||
const row: any = {};
|
||||
header.forEach(h => {
|
||||
row[h.title] = item[h.dataIndex];
|
||||
});
|
||||
return row;
|
||||
});
|
||||
|
||||
// 创建工作簿
|
||||
const wb = XLSX.utils.book_new();
|
||||
// 创建工作表
|
||||
const ws = XLSX.utils.json_to_sheet(excelData, {
|
||||
header: header.map(h => h.title),
|
||||
});
|
||||
|
||||
// 将工作表添加到工作簿
|
||||
XLSX.utils.book_append_sheet(wb, ws, 'Sheet1');
|
||||
|
||||
// 生成excel文件
|
||||
const excelBuffer = XLSX.write(wb, { bookType: 'xlsx', type: 'array' });
|
||||
const blob = new Blob([excelBuffer], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });
|
||||
|
||||
// 下载文件
|
||||
saveAs(blob, `${fileName}.xlsx`);
|
||||
} catch (error) {
|
||||
console.error('导出Excel失败:', error);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user