fix(首页统计):首页订单统计bug修复

This commit is contained in:
2025-07-22 00:48:32 +08:00
parent 33a8bd276e
commit cbe119ac64
3 changed files with 46 additions and 53 deletions
@@ -55,11 +55,11 @@ interface Statistics {
const Welcome: React.FC = () => {
const [loading, setLoading] = useState<boolean>(true);
const [statistics, setStatistics] = useState<any>({});
// 筛选条件
// 只保留景区筛选
const [selectedTourism, setSelectedTourism] = useState<number | undefined>();
const [selectedQrcode, setSelectedQrcode] = useState<string | undefined>();
const [selectedDevice, setSelectedDevice] = useState<string | undefined>();
// 新增平台分账比例,默认70%
const [platformRate, setPlatformRate] = useState<number>(0.7);
// 新增时间区间筛选
const [timeRange, setTimeRange] = useState<[string, string]>(['', '']);
const fetchData = async () => {
@@ -67,8 +67,6 @@ const Welcome: React.FC = () => {
setLoading(true);
const params = {
tourismId: selectedTourism,
qrcodeId: selectedQrcode,
deviceSn: selectedDevice,
startTime: timeRange[0],
endTime: timeRange[1],
};
@@ -85,13 +83,18 @@ const Welcome: React.FC = () => {
useEffect(() => {
fetchData();
}, [selectedTourism, selectedQrcode, selectedDevice, timeRange]);
}, [selectedTourism, timeRange]);
// 更新数据访问方式
const orderStats = statistics.orderStats || {};
const chartStats = statistics.chartStats || {};
const filterOptions = statistics.filterOptions || {};
// 动态分账金额计算
const netIncome = orderStats.netIncome || 0;
const platformAmount = Math.round(netIncome * platformRate);
const tourismAmount = netIncome - platformAmount;
// 订单趋势配置
const orderTrendConfig = {
data: chartStats.orderTrend || [],
@@ -120,9 +123,13 @@ const Welcome: React.FC = () => {
},
};
// 收入构成配置
// 收入构成图表数据
const incomeConfig = {
data: chartStats.incomeBreakdown || [],
data: [
{ type: '平台分账', value: platformAmount / 100 },
{ type: '景区分账', value: tourismAmount / 100 },
{ type: '退款金额', value: (orderStats.refundAmount || 0) / 100 },
],
xField: 'type',
yField: 'value',
label: {
@@ -148,22 +155,19 @@ const Welcome: React.FC = () => {
value={selectedTourism}
onChange={setSelectedTourism}
/>
{/* 新增平台分账比例选择 */}
<span>平台分账比例:</span>
<Select
placeholder="选择二维码/点位"
style={{ width: 200 }}
allowClear
options={filterOptions.qrcodeList || []}
value={selectedQrcode}
onChange={setSelectedQrcode}
/>
<Select
placeholder="选择设备"
style={{ width: 200 }}
allowClear
options={filterOptions.deviceList || []}
value={selectedDevice}
onChange={setSelectedDevice}
style={{ width: 120 }}
value={platformRate}
onChange={setPlatformRate}
options={[
{ label: '70%', value: 0.7 },
{ label: '60%', value: 0.6 },
{ label: '50%', value: 0.5 },
]}
/>
{/* 新增时间区间筛选 */}
<RangePicker
placeholder={['开始时间', '结束时间']}
onChange={(dates) => {
@@ -172,8 +176,12 @@ const Welcome: React.FC = () => {
dates[0]?.format('YYYY-MM-DD HH:mm:ss') || '',
dates[1]?.format('YYYY-MM-DD HH:mm:ss') || ''
]);
} else {
setTimeRange(['', '']);
}
}}
showTime
style={{ width: 300 }}
/>
<Button
icon={<ReloadOutlined />}
@@ -228,7 +236,7 @@ const Welcome: React.FC = () => {
<div className={styles.subStats}>
<Statistic
title="景区净收入"
value={(orderStats.netIncome || 0) / 100}
value={netIncome / 100}
precision={2}
prefix="¥"
/>
@@ -250,20 +258,19 @@ const Welcome: React.FC = () => {
</div>
<Statistic
title="平台分账"
value={(orderStats.platformAmount || 0) / 100}
value={platformAmount / 100}
precision={2}
prefix="¥"
/>
<div className={styles.subStats}>
<Statistic
title="景区分账"
value={(orderStats.tourismAmount || 0) / 100}
value={tourismAmount / 100}
precision={2}
prefix="¥"
/>
<Progress
percent={orderStats.totalAmount > 0 ?
((orderStats.tourismAmount || 0) / orderStats.totalAmount * 100) : 0}
percent={netIncome > 0 ? (tourismAmount / netIncome * 100) : 0}
size="small"
status="active"
format={(percent) => `分账率 ${percent?.toFixed(1)}%`}