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
@@ -94,16 +94,10 @@ public interface DashboardMapper {
"SELECT COALESCE(SUM(order_amount), 0)", "SELECT COALESCE(SUM(order_amount), 0)",
"FROM orders", "FROM orders",
"WHERE is_del = 0", "WHERE is_del = 0",
"AND order_status IN (1, 3, 4, 5, 6)", // 已支付排队中、设备执行完成、正在服务中、素材上传中、素材上传完成 "AND (order_status = 3 OR order_status = 8)",
"<if test='p.tourismId != null'>", "<if test='p.tourismId != null'>",
" AND tourism_id = #{p.tourismId}", " AND tourism_id = #{p.tourismId}",
"</if>", "</if>",
"<if test='p.qrcodeId != null and p.qrcodeId != \"\"'>",
" AND code_id = #{p.qrcodeId}",
"</if>",
"<if test='p.deviceSn != null and p.deviceSn != \"\"'>",
" AND device_sn = #{p.deviceSn}",
"</if>",
"<if test='p.startTime != null and p.startTime != \"\"'>", "<if test='p.startTime != null and p.startTime != \"\"'>",
" AND create_time >= #{p.startTime}", " AND create_time >= #{p.startTime}",
"</if>", "</if>",
@@ -164,23 +158,18 @@ public interface DashboardMapper {
@Select({ @Select({
"<script>", "<script>",
"SELECT COALESCE(SUM(refund_amount), 0)", "SELECT COALESCE(SUM(CAST(r.refund_amount AS SIGNED)), 0)",
"FROM order_statistics", "FROM orders_refund r",
"WHERE 1=1", "JOIN orders o ON r.order_no = o.order_no",
"WHERE r.status = 8",
"<if test='p.tourismId != null'>", "<if test='p.tourismId != null'>",
" AND tourism_id = #{p.tourismId}", " AND o.tourism_id = #{p.tourismId}",
"</if>",
"<if test='p.qrcodeId != null and p.qrcodeId != \"\"'>",
" AND qrcode_id = #{p.qrcodeId}",
"</if>",
"<if test='p.deviceSn != null and p.deviceSn != \"\"'>",
" AND device_sn = #{p.deviceSn}",
"</if>", "</if>",
"<if test='p.startTime != null and p.startTime != \"\"'>", "<if test='p.startTime != null and p.startTime != \"\"'>",
" AND create_time >= #{p.startTime}", " AND r.create_time >= #{p.startTime}",
"</if>", "</if>",
"<if test='p.endTime != null and p.endTime != \"\"'>", "<if test='p.endTime != null and p.endTime != \"\"'>",
" AND create_time &lt;= #{p.endTime}", " AND r.create_time &lt;= #{p.endTime}",
"</if>", "</if>",
"</script>" "</script>"
}) })
@@ -72,13 +72,10 @@ public class DashboardServiceImpl implements IDashboardService {
// 获取对账相关数据 // 获取对账相关数据
stats.setTotalAmount(dashboardMapper.getTotalAmount(params)); stats.setTotalAmount(dashboardMapper.getTotalAmount(params));
stats.setPlatformAmount(dashboardMapper.getPlatformAmount(params));
stats.setTourismAmount(dashboardMapper.getTourismAmount(params));
stats.setRefundAmount(dashboardMapper.getRefundAmount(params)); stats.setRefundAmount(dashboardMapper.getRefundAmount(params));
// 景区收入 = 总订单金额 - 退款金额
// 计算净收入 = 景区分账金额 - 退款金额 Long netIncome = (stats.getTotalAmount() != null ? stats.getTotalAmount() : 0)
Long netIncome = (stats.getTourismAmount() != null ? stats.getTourismAmount() : 0) - - (stats.getRefundAmount() != null ? stats.getRefundAmount() : 0);
(stats.getRefundAmount() != null ? stats.getRefundAmount() : 0);
stats.setNetIncome(netIncome); stats.setNetIncome(netIncome);
return stats; return stats;
@@ -55,11 +55,11 @@ interface Statistics {
const Welcome: React.FC = () => { const Welcome: React.FC = () => {
const [loading, setLoading] = useState<boolean>(true); const [loading, setLoading] = useState<boolean>(true);
const [statistics, setStatistics] = useState<any>({}); const [statistics, setStatistics] = useState<any>({});
// 只保留景区筛选
// 筛选条件
const [selectedTourism, setSelectedTourism] = useState<number | undefined>(); const [selectedTourism, setSelectedTourism] = useState<number | undefined>();
const [selectedQrcode, setSelectedQrcode] = useState<string | undefined>(); // 新增平台分账比例,默认70%
const [selectedDevice, setSelectedDevice] = useState<string | undefined>(); const [platformRate, setPlatformRate] = useState<number>(0.7);
// 新增时间区间筛选
const [timeRange, setTimeRange] = useState<[string, string]>(['', '']); const [timeRange, setTimeRange] = useState<[string, string]>(['', '']);
const fetchData = async () => { const fetchData = async () => {
@@ -67,8 +67,6 @@ const Welcome: React.FC = () => {
setLoading(true); setLoading(true);
const params = { const params = {
tourismId: selectedTourism, tourismId: selectedTourism,
qrcodeId: selectedQrcode,
deviceSn: selectedDevice,
startTime: timeRange[0], startTime: timeRange[0],
endTime: timeRange[1], endTime: timeRange[1],
}; };
@@ -85,13 +83,18 @@ const Welcome: React.FC = () => {
useEffect(() => { useEffect(() => {
fetchData(); fetchData();
}, [selectedTourism, selectedQrcode, selectedDevice, timeRange]); }, [selectedTourism, timeRange]);
// 更新数据访问方式 // 更新数据访问方式
const orderStats = statistics.orderStats || {}; const orderStats = statistics.orderStats || {};
const chartStats = statistics.chartStats || {}; const chartStats = statistics.chartStats || {};
const filterOptions = statistics.filterOptions || {}; const filterOptions = statistics.filterOptions || {};
// 动态分账金额计算
const netIncome = orderStats.netIncome || 0;
const platformAmount = Math.round(netIncome * platformRate);
const tourismAmount = netIncome - platformAmount;
// 订单趋势配置 // 订单趋势配置
const orderTrendConfig = { const orderTrendConfig = {
data: chartStats.orderTrend || [], data: chartStats.orderTrend || [],
@@ -120,9 +123,13 @@ const Welcome: React.FC = () => {
}, },
}; };
// 收入构成配置 // 收入构成图表数据
const incomeConfig = { const incomeConfig = {
data: chartStats.incomeBreakdown || [], data: [
{ type: '平台分账', value: platformAmount / 100 },
{ type: '景区分账', value: tourismAmount / 100 },
{ type: '退款金额', value: (orderStats.refundAmount || 0) / 100 },
],
xField: 'type', xField: 'type',
yField: 'value', yField: 'value',
label: { label: {
@@ -148,22 +155,19 @@ const Welcome: React.FC = () => {
value={selectedTourism} value={selectedTourism}
onChange={setSelectedTourism} onChange={setSelectedTourism}
/> />
{/* 新增平台分账比例选择 */}
<span>平台分账比例:</span>
<Select <Select
placeholder="选择二维码/点位" style={{ width: 120 }}
style={{ width: 200 }} value={platformRate}
allowClear onChange={setPlatformRate}
options={filterOptions.qrcodeList || []} options={[
value={selectedQrcode} { label: '70%', value: 0.7 },
onChange={setSelectedQrcode} { label: '60%', value: 0.6 },
/> { label: '50%', value: 0.5 },
<Select ]}
placeholder="选择设备"
style={{ width: 200 }}
allowClear
options={filterOptions.deviceList || []}
value={selectedDevice}
onChange={setSelectedDevice}
/> />
{/* 新增时间区间筛选 */}
<RangePicker <RangePicker
placeholder={['开始时间', '结束时间']} placeholder={['开始时间', '结束时间']}
onChange={(dates) => { onChange={(dates) => {
@@ -172,8 +176,12 @@ const Welcome: React.FC = () => {
dates[0]?.format('YYYY-MM-DD HH:mm:ss') || '', dates[0]?.format('YYYY-MM-DD HH:mm:ss') || '',
dates[1]?.format('YYYY-MM-DD HH:mm:ss') || '' dates[1]?.format('YYYY-MM-DD HH:mm:ss') || ''
]); ]);
} else {
setTimeRange(['', '']);
} }
}} }}
showTime
style={{ width: 300 }}
/> />
<Button <Button
icon={<ReloadOutlined />} icon={<ReloadOutlined />}
@@ -228,7 +236,7 @@ const Welcome: React.FC = () => {
<div className={styles.subStats}> <div className={styles.subStats}>
<Statistic <Statistic
title="景区净收入" title="景区净收入"
value={(orderStats.netIncome || 0) / 100} value={netIncome / 100}
precision={2} precision={2}
prefix="¥" prefix="¥"
/> />
@@ -250,20 +258,19 @@ const Welcome: React.FC = () => {
</div> </div>
<Statistic <Statistic
title="平台分账" title="平台分账"
value={(orderStats.platformAmount || 0) / 100} value={platformAmount / 100}
precision={2} precision={2}
prefix="¥" prefix="¥"
/> />
<div className={styles.subStats}> <div className={styles.subStats}>
<Statistic <Statistic
title="景区分账" title="景区分账"
value={(orderStats.tourismAmount || 0) / 100} value={tourismAmount / 100}
precision={2} precision={2}
prefix="¥" prefix="¥"
/> />
<Progress <Progress
percent={orderStats.totalAmount > 0 ? percent={netIncome > 0 ? (tourismAmount / netIncome * 100) : 0}
((orderStats.tourismAmount || 0) / orderStats.totalAmount * 100) : 0}
size="small" size="small"
status="active" status="active"
format={(percent) => `分账率 ${percent?.toFixed(1)}%`} format={(percent) => `分账率 ${percent?.toFixed(1)}%`}