fix(统计管理):新增二维码、设备、景区分账统计前后端功能
This commit is contained in:
+80
@@ -0,0 +1,80 @@
|
|||||||
|
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;
|
||||||
@@ -0,0 +1,144 @@
|
|||||||
|
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;
|
||||||
@@ -0,0 +1,97 @@
|
|||||||
|
import { request } from '@/utils/request';
|
||||||
|
import moment from 'moment';
|
||||||
|
|
||||||
|
/** 生成统计数据 */
|
||||||
|
export async function generateStatistics(params: {
|
||||||
|
startTime: string;
|
||||||
|
endTime: string;
|
||||||
|
}) {
|
||||||
|
return request('/api-order/statistics/generate', {
|
||||||
|
method: 'POST',
|
||||||
|
data: params,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 获取二维码维度统计数据 */
|
||||||
|
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', {
|
||||||
|
method: 'GET',
|
||||||
|
params,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取二维码时间维度统计数据
|
||||||
|
export async function getQrcodeTimeStatistics(params: {
|
||||||
|
qrcodeId: string;
|
||||||
|
startTime: string;
|
||||||
|
endTime: string;
|
||||||
|
timeType?: 'hour' | 'day' | 'month';
|
||||||
|
}) {
|
||||||
|
return request('/api-order/statistics/time', {
|
||||||
|
method: 'GET',
|
||||||
|
params,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取时间维度统计数据
|
||||||
|
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,
|
||||||
|
}));
|
||||||
|
};
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
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';
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user