fix(首页统计):首页订单统计bug修复
This commit is contained in:
+8
-19
@@ -94,16 +94,10 @@ public interface DashboardMapper {
|
||||
"SELECT COALESCE(SUM(order_amount), 0)",
|
||||
"FROM orders",
|
||||
"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'>",
|
||||
" AND tourism_id = #{p.tourismId}",
|
||||
"</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 != \"\"'>",
|
||||
" AND create_time >= #{p.startTime}",
|
||||
"</if>",
|
||||
@@ -164,23 +158,18 @@ public interface DashboardMapper {
|
||||
|
||||
@Select({
|
||||
"<script>",
|
||||
"SELECT COALESCE(SUM(refund_amount), 0)",
|
||||
"FROM order_statistics",
|
||||
"WHERE 1=1",
|
||||
"SELECT COALESCE(SUM(CAST(r.refund_amount AS SIGNED)), 0)",
|
||||
"FROM orders_refund r",
|
||||
"JOIN orders o ON r.order_no = o.order_no",
|
||||
"WHERE r.status = 8",
|
||||
"<if test='p.tourismId != null'>",
|
||||
" AND 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}",
|
||||
" AND o.tourism_id = #{p.tourismId}",
|
||||
"</if>",
|
||||
"<if test='p.startTime != null and p.startTime != \"\"'>",
|
||||
" AND create_time >= #{p.startTime}",
|
||||
" AND r.create_time >= #{p.startTime}",
|
||||
"</if>",
|
||||
"<if test='p.endTime != null and p.endTime != \"\"'>",
|
||||
" AND create_time <= #{p.endTime}",
|
||||
" AND r.create_time <= #{p.endTime}",
|
||||
"</if>",
|
||||
"</script>"
|
||||
})
|
||||
|
||||
+3
-6
@@ -72,13 +72,10 @@ public class DashboardServiceImpl implements IDashboardService {
|
||||
|
||||
// 获取对账相关数据
|
||||
stats.setTotalAmount(dashboardMapper.getTotalAmount(params));
|
||||
stats.setPlatformAmount(dashboardMapper.getPlatformAmount(params));
|
||||
stats.setTourismAmount(dashboardMapper.getTourismAmount(params));
|
||||
stats.setRefundAmount(dashboardMapper.getRefundAmount(params));
|
||||
|
||||
// 计算净收入 = 景区分账金额 - 退款金额
|
||||
Long netIncome = (stats.getTourismAmount() != null ? stats.getTourismAmount() : 0) -
|
||||
(stats.getRefundAmount() != null ? stats.getRefundAmount() : 0);
|
||||
// 景区收入 = 总订单金额 - 退款金额
|
||||
Long netIncome = (stats.getTotalAmount() != null ? stats.getTotalAmount() : 0)
|
||||
- (stats.getRefundAmount() != null ? stats.getRefundAmount() : 0);
|
||||
stats.setNetIncome(netIncome);
|
||||
|
||||
return stats;
|
||||
|
||||
@@ -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)}%`}
|
||||
|
||||
Reference in New Issue
Block a user