feat: 1:二维码统计明细 2:航线规划

This commit is contained in:
2026-01-08 23:12:25 +08:00
parent a9f1e1f4d4
commit 2b61492b15
61 changed files with 7639 additions and 1065 deletions
@@ -0,0 +1,166 @@
import React, { useRef } from 'react';
import { Drawer, Tag } from 'antd';
import { ProTable, type ActionType } from '@ant-design/pro-components';
import { ordersApi, type OrderItem } from '@/services/orders';
interface QrcodeData {
id: number;
qrcodeId: string;
qrcodeName: string;
qrcodeCode: string;
orderCount: number;
todayOrderCount: number;
viewUrl: string;
status: number;
price: string;
deviceSn: string;
}
interface OrderListDrawerProps {
open: boolean;
onClose: () => void;
qrcode: QrcodeData | null;
queryParams?: Record<string, any>;
}
const OrderListDrawer: React.FC<OrderListDrawerProps> = ({ open, onClose, qrcode, queryParams }) => {
const actionRef = useRef<ActionType>();
const columns: any[] = [
{ dataIndex: 'index', valueType: 'indexBorder', width: 48, fixed: 'left' },
{
title: '订单号',
dataIndex: 'orderNo',
width: 180,
fixed: 'left',
ellipsis: true,
},
{
title: '用户手机',
dataIndex: 'userPhone',
width: 120,
render: (phone: string) => phone || '-',
},
{
title: '金额',
dataIndex: 'orderAmount',
width: 100,
render: (amount: string | number) => {
if (!amount && amount !== 0) return '-';
const amountNum = typeof amount === 'string' ? parseFloat(amount) : amount;
if (Number.isNaN(amountNum)) return '-';
return `¥${(amountNum / 100).toFixed(2)}`;
},
},
{
title: '支付方式',
dataIndex: 'payType',
width: 100,
render: (type: number) => {
const typeMap: Record<number, { text: string; color: string }> = {
1: { text: '微信支付', color: 'green' },
2: { text: '优惠券', color: 'blue' },
3: { text: '第三方', color: 'orange' },
};
const info = typeMap[type] || { text: '未知', color: 'default' };
return <Tag color={info.color}>{info.text}</Tag>;
},
},
{
title: '订单状态',
dataIndex: 'orderStatus',
width: 120,
render: (status: number) => {
const statusMap: Record<number, { text: string; color: string }> = {
0: { text: '未支付', color: 'default' },
1: { text: '已支付', color: 'blue' },
2: { text: '已取消', color: 'red' },
3: { text: '任务完成', color: 'success' },
4: { text: '执行中', color: 'processing' },
5: { text: '素材上传中', color: 'cyan' },
6: { text: '素材上传完成', color: 'success' },
7: { text: '退款中', color: 'orange' },
8: { text: '已退款', color: 'orange' },
9: { text: '退款失败', color: 'red' },
10: { text: '部分退款', color: 'orange' },
};
const info = statusMap[status] || { text: '未知', color: 'default' };
return <Tag color={info.color}>{info.text}</Tag>;
},
},
{
title: '支付时间',
dataIndex: 'payTime',
width: 160,
valueType: 'dateTime',
render: (time: string) => time || '-',
},
{
title: '创建时间',
dataIndex: 'createTime',
width: 160,
valueType: 'dateTime',
},
];
return (
<Drawer
title={`订单列表 - ${qrcode?.qrcodeName || '未命名'}`}
placement="right"
width={1200}
open={open}
onClose={onClose}
destroyOnClose
className="order-list-drawer"
>
{qrcode && (
<>
<div className="drawer-summary">
<div className="summary-item">
<span className="label">二维码名称:</span>
<span className="value">{qrcode.qrcodeName || '未命名'}</span>
</div>
<div className="summary-item">
<span className="label">二维码Code:</span>
<span className="value" style={{ fontSize: 14, fontFamily: 'Courier New' }}>
{qrcode.qrcodeCode}
</span>
</div>
<div className="summary-item">
<span className="label">订单总数:</span>
<span className="value">{qrcode.orderCount}</span>
</div>
<div className="summary-item">
<span className="label">今日订单:</span>
<span className="value" style={{ color: '#52c41a' }}>
{qrcode.todayOrderCount}
</span>
</div>
</div>
<ProTable<OrderItem>
rowKey="id"
actionRef={actionRef}
request={(p) => ordersApi.ordersByCodeId({
...(p as any),
codeId: qrcode.qrcodeId,
payTimeStart: queryParams?.payTimeStart,
payTimeEnd: queryParams?.payTimeEnd,
})}
columns={columns}
search={false}
pagination={{
showSizeChanger: true,
showQuickJumper: true,
defaultPageSize: 10,
}}
toolBarRender={false}
scroll={{ x: 1200 }}
/>
</>
)}
</Drawer>
);
};
export default OrderListDrawer;
@@ -0,0 +1,110 @@
import React from 'react';
import { Card, Row, Col, Tag } from 'antd';
import { ShoppingOutlined, QrcodeOutlined } from '@ant-design/icons';
interface QrcodeData {
id: number;
qrcodeId: string;
qrcodeName: string;
qrcodeCode: string;
orderCount: number;
todayOrderCount: number;
viewUrl: string;
status: number;
price: string;
deviceSn: string;
}
interface TourismData {
tourismId: number;
tourismName: string;
tourismAddress: string;
orderCount: number;
qrcodeCount: number;
qrcodeList: QrcodeData[];
}
interface TourismSectionProps {
tourism: TourismData;
onQrcodeClick: (qrcode: QrcodeData) => void;
}
const TourismSection: React.FC<TourismSectionProps> = ({ tourism, onQrcodeClick }) => {
return (
<div className="tourism-section">
<div className="tourism-header">
<h3 className="tourism-title">
{tourism.tourismName}
{tourism.tourismAddress && (
<span style={{ fontSize: 14, fontWeight: 400, marginLeft: 12, opacity: 0.9 }}>
{tourism.tourismAddress}
</span>
)}
</h3>
<div className="tourism-stats">
<div className="stat-item">
<QrcodeOutlined />
<span className="stat-label">二维码:</span>
<span className="stat-value">{tourism.qrcodeCount}</span>
</div>
<div className="stat-item">
<ShoppingOutlined />
<span className="stat-label">订单总数:</span>
<span className="stat-value">{tourism.orderCount}</span>
</div>
</div>
</div>
<div className="qrcode-grid">
<Row gutter={[16, 16]}>
{tourism.qrcodeList.map((qrcode) => (
<Col xs={24} sm={12} md={8} lg={6} xl={4} key={qrcode.id}>
<Card
className="qrcode-card"
onClick={() => onQrcodeClick(qrcode)}
hoverable
bodyStyle={{ padding: 0 }}
>
<div className="qrcode-image-wrapper">
<img
src={qrcode.viewUrl}
alt={qrcode.qrcodeName}
className="qrcode-image"
/>
<div className={`status-badge ${qrcode.status === 0 ? 'status-active' : 'status-inactive'}`}>
{qrcode.status === 0 ? '启用' : '禁用'}
</div>
</div>
<div className="qrcode-info">
<div className="qrcode-name" title={qrcode.qrcodeName}>
{qrcode.qrcodeName || '未命名'}
</div>
<div className="qrcode-stats">
<div className="stat-item">
<div className="stat-value">{qrcode.orderCount}</div>
<div className="stat-label">总订单</div>
</div>
<div className="stat-item">
<div className="stat-value" style={{ color: '#52c41a' }}>
{qrcode.todayOrderCount}
</div>
<div className="stat-label">今日</div>
</div>
</div>
<div className="qrcode-code" title={qrcode.qrcodeCode}>
Code: {qrcode.qrcodeCode}
</div>
</div>
</Card>
</Col>
))}
</Row>
</div>
</div>
);
};
export default TourismSection;
@@ -0,0 +1,247 @@
.qrcode-order-page {
.stat-card {
border-radius: 12px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
transition: all 0.3s ease;
border: none;
background: linear-gradient(135deg, #ffffff 0%, #f5f5f5 100%);
&:hover {
transform: translateY(-4px);
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
}
&.stat-card-blue {
background: linear-gradient(135deg, #e6f7ff 0%, #bae7ff 100%);
}
&.stat-card-purple {
background: linear-gradient(135deg, #f9f0ff 0%, #efdbff 100%);
}
&.stat-card-green {
background: linear-gradient(135deg, #f6ffed 0%, #d9f7be 100%);
}
&.stat-card-orange {
background: linear-gradient(135deg, #fff7e6 0%, #ffd591 100%);
}
.ant-statistic-title {
font-size: 14px;
font-weight: 500;
color: rgba(0, 0, 0, 0.65);
}
.ant-statistic-content {
font-size: 28px;
font-weight: 600;
font-family: 'Roboto Mono', monospace;
}
}
}
.tourism-section {
margin-bottom: 24px;
.tourism-header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 16px 24px;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
border-radius: 12px 12px 0 0;
color: white;
.tourism-title {
font-size: 18px;
font-weight: 600;
margin: 0;
}
.tourism-stats {
display: flex;
gap: 24px;
font-size: 14px;
.stat-item {
display: flex;
align-items: center;
gap: 6px;
.stat-label {
opacity: 0.9;
}
.stat-value {
font-weight: 600;
font-size: 16px;
}
}
}
}
.qrcode-grid {
padding: 24px;
background: white;
border-radius: 0 0 12px 12px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}
}
.qrcode-card {
border-radius: 12px;
overflow: hidden;
transition: all 0.3s ease;
cursor: pointer;
border: 2px solid transparent;
background: white;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
&:hover {
transform: translateY(-8px) scale(1.02);
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
border-color: #1890ff;
}
.qrcode-image-wrapper {
position: relative;
padding: 16px;
background: linear-gradient(135deg, #f5f5f5 0%, #e8e8e8 100%);
display: flex;
justify-content: center;
align-items: center;
height: 180px;
.qrcode-image {
width: 140px;
height: 140px;
object-fit: contain;
border-radius: 8px;
background: white;
padding: 8px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}
.status-badge {
position: absolute;
top: 12px;
right: 12px;
padding: 4px 12px;
border-radius: 12px;
font-size: 12px;
font-weight: 500;
background: rgba(255, 255, 255, 0.9);
backdrop-filter: blur(4px);
&.status-active {
color: #52c41a;
border: 1px solid #52c41a;
}
&.status-inactive {
color: #ff4d4f;
border: 1px solid #ff4d4f;
}
}
}
.qrcode-info {
padding: 16px;
.qrcode-name {
font-size: 16px;
font-weight: 600;
color: #262626;
margin-bottom: 12px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.qrcode-stats {
display: flex;
justify-content: space-between;
margin-bottom: 12px;
.stat-item {
text-align: center;
.stat-value {
font-size: 20px;
font-weight: 600;
color: #1890ff;
font-family: 'Roboto Mono', monospace;
}
.stat-label {
font-size: 12px;
color: #8c8c8c;
margin-top: 4px;
}
}
}
.qrcode-code {
font-size: 12px;
color: #8c8c8c;
padding: 8px;
background: #f5f5f5;
border-radius: 6px;
font-family: 'Courier New', monospace;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
}
}
.order-list-drawer {
.ant-drawer-header {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
border-bottom: none;
.ant-drawer-title {
color: white;
font-size: 18px;
font-weight: 600;
}
.ant-drawer-close {
color: white;
&:hover {
color: rgba(255, 255, 255, 0.8);
}
}
}
.drawer-summary {
padding: 16px;
background: linear-gradient(135deg, #e6f7ff 0%, #bae7ff 100%);
border-radius: 8px;
margin-bottom: 16px;
.summary-item {
display: flex;
justify-content: space-between;
margin-bottom: 8px;
&:last-child {
margin-bottom: 0;
}
.label {
color: #595959;
font-size: 14px;
}
.value {
font-weight: 600;
font-size: 16px;
color: #1890ff;
font-family: 'Roboto Mono', monospace;
}
}
}
}
@@ -0,0 +1,285 @@
import React, { useEffect, useState } from 'react';
import { PageContainer } from '@ant-design/pro-components';
import { Card, Row, Col, Statistic, Empty, Spin, Drawer, message } from 'antd';
import { QrcodeOutlined, ShopOutlined, ShoppingOutlined, ClockCircleOutlined } from '@ant-design/icons';
import { ordersApi } from '@/services/orders';
import { tenantApi } from '@/services/tenant';
import { SearchBarPlus, GradientButton } from '@/components/ui';
import { ProFormText, ProFormDateRangePicker } from '@ant-design/pro-components';
import TourismSection from './components/TourismSection';
import OrderListDrawer from './components/OrderListDrawer';
import './index.less';
import moment from 'moment';
interface QrcodeData {
id: number;
qrcodeId: string;
qrcodeName: string;
qrcodeCode: string;
orderCount: number;
todayOrderCount: number;
viewUrl: string;
status: number;
price: string;
deviceSn: string;
}
interface TourismData {
tourismId: number;
tourismName: string;
tourismAddress: string;
orderCount: number;
qrcodeCount: number;
qrcodeList: QrcodeData[];
}
interface StatisticsData {
tourismList: TourismData[];
totalTourismCount: number;
totalQrcodeCount: number;
totalOrderCount: number;
todayOrderCount: number;
}
const QrcodeOrderPage: React.FC = () => {
const [loading, setLoading] = useState(false);
const [loadingMore, setLoadingMore] = useState(false);
const [statistics, setStatistics] = useState<StatisticsData | null>(null);
const [params, setParams] = useState<Record<string, any>>({});
const [drawerOpen, setDrawerOpen] = useState(false);
const [selectedQrcode, setSelectedQrcode] = useState<QrcodeData | null>(null);
const [page, setPage] = useState(1);
const [hasMore, setHasMore] = useState(false);
// 首次进入时,默认按"当前租户 + 包含下级租户 + 当天支付时间"查询
useEffect(() => {
(async () => {
try {
let tenantId: string | undefined;
const cur: any = await tenantApi.getCurrentTenant();
tenantId = cur?.data?.tenantId ?? cur?.tenantId;
if (!tenantId) {
const stats: any = await tenantApi.getScopeStats();
tenantId = stats?.data?.currentTenantId ?? stats?.currentTenantId;
}
if (tenantId) {
// 默认查询当天
const initialParams = {
tenantId,
includeChildren: true,
payTimeStart: moment().startOf('day').valueOf(), // 传时间戳
payTimeEnd: moment().endOf('day').valueOf(), // 传时间戳
};
setParams(initialParams);
setPage(1);
fetchStatistics(initialParams, 1, false);
}
} catch {
// 忽略错误,保留手动查询能力
}
})();
}, []);
const fetchStatistics = async (queryParams: Record<string, any>, currentPage: number, isLoadMore: boolean) => {
if (isLoadMore) {
setLoadingMore(true);
} else {
setLoading(true);
}
try {
const res = await ordersApi.qrcodeOrderStatistics({ ...queryParams, page: currentPage, limit: 10 });
console.log('二维码订单统计返回数据:', res);
// 确保返回的数据结构正确
const safeRes = {
...res,
tourismList: res?.tourismList || [],
totalTourismCount: res?.totalTourismCount || 0,
totalQrcodeCount: res?.totalQrcodeCount || 0,
totalOrderCount: res?.totalOrderCount || 0,
todayOrderCount: res?.todayOrderCount || 0,
hasMore: res?.hasMore || false,
};
if (isLoadMore) {
// 加载更多:追加数据
setStatistics((prev) => {
if (!prev) return safeRes;
return {
...safeRes,
tourismList: [...(prev.tourismList || []), ...(safeRes.tourismList || [])],
};
});
} else {
// 首次查询或重新查询:替换数据
setStatistics(safeRes);
}
setHasMore(safeRes.hasMore);
setPage(currentPage);
} catch (error) {
console.error('二维码订单统计查询失败:', error);
message.error('查询失败');
// 出错时设置空数据
setStatistics({
tourismList: [],
totalTourismCount: 0,
totalQrcodeCount: 0,
totalOrderCount: 0,
todayOrderCount: 0,
});
} finally {
if (isLoadMore) {
setLoadingMore(false);
} else {
setLoading(false);
}
}
};
const handleQrcodeClick = (qrcode: QrcodeData) => {
setSelectedQrcode(qrcode);
setDrawerOpen(true);
};
const handleLoadMore = () => {
const nextPage = page + 1;
fetchStatistics(params, nextPage, true);
};
return (
<PageContainer
header={{ title: '二维码统计管理' }}
className="qrcode-order-page"
>
{/* 顶部筛选栏 */}
<SearchBarPlus
defaultCollapsed={false}
split
span={8}
hideReset
onTenantChanged={(tenantId, includeChildren) => {
const newParams = { ...(params || {}), tenantId, includeChildren };
setParams(newParams);
setPage(1);
fetchStatistics(newParams, 1, false);
}}
onFinish={async (values) => {
// 处理支付时间范围 - 保留用户选择的具体时间点
let processedValues = { ...values };
if (values.payTimeRange && values.payTimeRange.length === 2) {
processedValues.payTimeStart = moment(values.payTimeRange[0]).valueOf();
processedValues.payTimeEnd = moment(values.payTimeRange[1]).valueOf();
delete processedValues.payTimeRange;
}
const newParams = { ...(params || {}), ...processedValues };
setParams(newParams);
setPage(1);
fetchStatistics(newParams, 1, false);
}}
>
<ProFormDateRangePicker
name="payTimeRange"
label="支付时间"
placeholder={['开始时间', '结束时间']}
initialValue={[moment().startOf('day'), moment().endOf('day')]}
fieldProps={{
showTime: { format: 'HH:mm:ss' },
format: 'YYYY-MM-DD HH:mm:ss',
}}
/>
<ProFormText name="qrcodeName" label="二维码名称" placeholder="请输入二维码名称" />
<ProFormText name="codeId" label="二维码Code" placeholder="请输入二维码Code" />
</SearchBarPlus>
{/* 统计概览卡片 */}
{statistics && (
<Row gutter={16} style={{ marginBottom: 24 }}>
<Col xs={24} sm={12} md={6}>
<Card className="stat-card stat-card-blue">
<Statistic
title="景区总数"
value={statistics.totalTourismCount}
prefix={<ShopOutlined />}
valueStyle={{ color: '#1890ff' }}
/>
</Card>
</Col>
<Col xs={24} sm={12} md={6}>
<Card className="stat-card stat-card-purple">
<Statistic
title="二维码总数"
value={statistics.totalQrcodeCount}
prefix={<QrcodeOutlined />}
valueStyle={{ color: '#722ed1' }}
/>
</Card>
</Col>
<Col xs={24} sm={12} md={6}>
<Card className="stat-card stat-card-green">
<Statistic
title="订单总数"
value={statistics.totalOrderCount}
prefix={<ShoppingOutlined />}
valueStyle={{ color: '#52c41a' }}
/>
</Card>
</Col>
<Col xs={24} sm={12} md={6}>
<Card className="stat-card stat-card-orange">
<Statistic
title="今日订单"
value={statistics.todayOrderCount}
prefix={<ClockCircleOutlined />}
valueStyle={{ color: '#fa8c16' }}
/>
</Card>
</Col>
</Row>
)}
{/* 景区二维码卡片网格 */}
<Spin spinning={loading}>
{statistics && statistics.tourismList.length > 0 ? (
<>
{statistics.tourismList.map((tourism) => (
<TourismSection
key={tourism.tourismId}
tourism={tourism}
onQrcodeClick={handleQrcodeClick}
/>
))}
{/* 加载更多按钮 */}
{hasMore && (
<div style={{ textAlign: 'center', marginTop: 24, marginBottom: 24 }}>
<GradientButton
size="large"
onClick={handleLoadMore}
loading={loadingMore}
style={{ minWidth: 200 }}
>
{loadingMore ? '加载中...' : '加载更多'}
</GradientButton>
</div>
)}
</>
) : (
<Card>
<Empty description="暂无数据" />
</Card>
)}
</Spin>
{/* 订单列表抽屉 */}
<OrderListDrawer
open={drawerOpen}
onClose={() => setDrawerOpen(false)}
qrcode={selectedQrcode}
queryParams={params}
/>
</PageContainer>
);
};
export default QrcodeOrderPage;
@@ -456,4 +456,17 @@ export const ordersApi = {
throw error;
}
},
// 二维码订单统计查询
qrcodeOrderStatistics: async (params?: { tenantId?: string; includeChildren?: boolean; qrcodeName?: string; codeId?: string; tourismId?: number; page?: number; limit?: number; payTimeStart?: number; payTimeEnd?: number }) => {
const res = await request('/api-order/qrcode/order/statistics', { method: 'GET', params });
return (res as any).data || res;
},
// 根据二维码ID查询订单列表
ordersByCodeId: async (params: { current?: number; pageSize?: number; codeId: string; [k: string]: any }) => {
const { current, pageSize, codeId, ...rest } = params || {};
const res = await request(`/api-order/qrcode/${codeId}/orders`, { method: 'GET', params: { page: current, limit: pageSize, ...rest } });
return { data: (res as any).data, total: (res as any).count } as { data: OrderItem[]; total: number };
},
};