fix(订单中心):首页统计优化

This commit is contained in:
2025-08-05 23:38:51 +08:00
parent 47a685f419
commit 6d4fa0f26e
2 changed files with 63 additions and 36 deletions
@@ -172,53 +172,94 @@ public interface DashboardMapper {
@Select({ @Select({
"<script>", "<script>",
"SELECT COUNT(*) as count", "SELECT",
"FROM orders o", " (SELECT COUNT(*) FROM orders o1",
"JOIN qrcodes q ON o.code_id = q.code_id", " JOIN qrcodes q1 ON o1.code_id = q1.code_id",
"WHERE 1=1", " WHERE 1=1",
"<if test='p.includeTestQrcodes == null or p.includeTestQrcodes == false'>", "<if test='p.includeTestQrcodes == null or p.includeTestQrcodes == false'>",
" AND q.is_test = 0", " AND q1.is_test = 0",
"</if>", "</if>",
"AND o.order_status IN (1, 3, 4, 7, 5)", " AND o1.order_status IN (1, 3, 4, 5, 7, 8)",
"<if test='p.tourismId != null'>", "<if test='p.tourismId != null'>",
" AND o.tourism_id = #{p.tourismId}", " AND o1.tourism_id = #{p.tourismId}",
"</if>", "</if>",
"<if test='p.qrcodeId != null and p.qrcodeId != \"\"'>", "<if test='p.qrcodeId != null and p.qrcodeId != \"\"'>",
" AND o.code_id = #{p.qrcodeId}", " AND o1.code_id = #{p.qrcodeId}",
"</if>", "</if>",
"<if test='p.deviceSn != null and p.deviceSn != \"\"'>", "<if test='p.deviceSn != null and p.deviceSn != \"\"'>",
" AND o.device_sn = #{p.deviceSn}", " AND o1.device_sn = #{p.deviceSn}",
"</if>", "</if>",
"<if test='p.startTime != null and p.startTime != \"\"'>", "<if test='p.startTime != null and p.startTime != \"\"'>",
" AND o.create_time >= #{p.startTime}", " AND o1.create_time >= #{p.startTime}",
"</if>", "</if>",
"<if test='p.endTime != null and p.endTime != \"\"'>", "<if test='p.endTime != null and p.endTime != \"\"'>",
" AND o.create_time &lt;= #{p.endTime}", " AND o1.create_time &lt;= #{p.endTime}",
"</if>", "</if>",
" ) - (SELECT COUNT(*) FROM orders o2",
" JOIN qrcodes q2 ON o2.code_id = q2.code_id",
" WHERE 1=1",
"<if test='p.includeTestQrcodes == null or p.includeTestQrcodes == false'>",
" AND q2.is_test = 0",
"</if>",
" AND o2.order_status = 8",
"<if test='p.tourismId != null'>",
" AND o2.tourism_id = #{p.tourismId}",
"</if>",
"<if test='p.qrcodeId != null and p.qrcodeId != \"\"'>",
" AND o2.code_id = #{p.qrcodeId}",
"</if>",
"<if test='p.deviceSn != null and p.deviceSn != \"\"'>",
" AND o2.device_sn = #{p.deviceSn}",
"</if>",
"<if test='p.startTime != null and p.startTime != \"\"'>",
" AND o2.create_time >= #{p.startTime}",
"</if>",
"<if test='p.endTime != null and p.endTime != \"\"'>",
" AND o2.create_time &lt;= #{p.endTime}",
"</if>",
" )) as count",
"</script>" "</script>"
}) })
Long getTotalPaidOrders(@Param("p") Map<String, Object> params); Long getTotalPaidOrders(@Param("p") Map<String, Object> params);
@Select({ @Select({
"<script>", "<script>",
"SELECT COUNT(*) as count", "SELECT",
"FROM orders o", " (SELECT COUNT(*) FROM orders o1",
"JOIN qrcodes q ON o.code_id = q.code_id", " JOIN qrcodes q1 ON o1.code_id = q1.code_id",
"WHERE 1=1", " WHERE 1=1",
"<if test='p.includeTestQrcodes == null or p.includeTestQrcodes == false'>", "<if test='p.includeTestQrcodes == null or p.includeTestQrcodes == false'>",
" AND q.is_test = 0", " AND q1.is_test = 0",
"</if>", "</if>",
"AND o.order_status IN (1, 3, 4, 7, 5)", " AND DATE(o1.create_time) = CURDATE()",
"AND DATE(o.create_time) = CURDATE()", " AND o1.order_status IN (1, 3, 4, 5, 7, 8)",
"<if test='p.tourismId != null'>", "<if test='p.tourismId != null'>",
" AND o.tourism_id = #{p.tourismId}", " AND o1.tourism_id = #{p.tourismId}",
"</if>", "</if>",
"<if test='p.qrcodeId != null and p.qrcodeId != \"\"'>", "<if test='p.qrcodeId != null and p.qrcodeId != \"\"'>",
" AND o.code_id = #{p.qrcodeId}", " AND o1.code_id = #{p.qrcodeId}",
"</if>", "</if>",
"<if test='p.deviceSn != null and p.deviceSn != \"\"'>", "<if test='p.deviceSn != null and p.deviceSn != \"\"'>",
" AND o.device_sn = #{p.deviceSn}", " AND o1.device_sn = #{p.deviceSn}",
"</if>", "</if>",
" ) - (SELECT COUNT(*) FROM orders o2",
" JOIN qrcodes q2 ON o2.code_id = q2.code_id",
" WHERE 1=1",
"<if test='p.includeTestQrcodes == null or p.includeTestQrcodes == false'>",
" AND q2.is_test = 0",
"</if>",
" AND DATE(o2.create_time) = CURDATE()",
" AND o2.order_status = 8",
"<if test='p.tourismId != null'>",
" AND o2.tourism_id = #{p.tourismId}",
"</if>",
"<if test='p.qrcodeId != null and p.qrcodeId != \"\"'>",
" AND o2.code_id = #{p.qrcodeId}",
"</if>",
"<if test='p.deviceSn != null and p.deviceSn != \"\"'>",
" AND o2.device_sn = #{p.deviceSn}",
"</if>",
" )) as count",
"</script>" "</script>"
}) })
Long getTodayPaidOrders(@Param("p") Map<String, Object> params); Long getTodayPaidOrders(@Param("p") Map<String, Object> params);
@@ -553,7 +594,7 @@ public interface DashboardMapper {
" q.code_id as qrcodeId,", " q.code_id as qrcodeId,",
" COUNT(o.id) as orderCount", " COUNT(o.id) as orderCount",
"FROM qrcodes q", "FROM qrcodes q",
"LEFT JOIN orders o ON q.code_id = o.code_id AND o.order_status = 3", "LEFT JOIN orders o ON q.code_id = o.code_id AND o.order_status IN (3, 7)",
"WHERE q.is_del = 0", "WHERE q.is_del = 0",
"<if test='p.includeTestQrcodes == null or p.includeTestQrcodes == false'>", "<if test='p.includeTestQrcodes == null or p.includeTestQrcodes == false'>",
" AND q.is_test = 0", " AND q.is_test = 0",
@@ -212,16 +212,10 @@ const Welcome: React.FC = () => {
// 根据时间筛选状态动态显示标题 // 根据时间筛选状态动态显示标题
const getOrderTitle = () => { const getOrderTitle = () => {
if (hasTimeRange) {
return `订单总数 (${timeRange[0].split(' ')[0]} ~ ${timeRange[1].split(' ')[0]})`;
}
return '总订单数'; return '总订单数';
}; };
const getTodayTitle = () => { const getTodayTitle = () => {
if (hasTimeRange) {
return `区间订单数`;
}
return '今日订单'; return '今日订单';
}; };
@@ -233,9 +227,6 @@ const Welcome: React.FC = () => {
}; };
const getTodayRefundTitle = () => { const getTodayRefundTitle = () => {
if (hasTimeRange) {
return `区间退款订单`;
}
return '今日退款订单'; return '今日退款订单';
}; };
@@ -429,11 +420,6 @@ const Welcome: React.FC = () => {
<Card style={{ marginBottom: 16 }}> <Card style={{ marginBottom: 16 }}>
<Space size="large"> <Space size="large">
<span>筛选条件:</span> <span>筛选条件:</span>
{hasTimeRange && (
<span style={{ color: '#1890ff', fontSize: '12px' }}>
⚠️ 已选择时间区间,统计数据将基于选定时间范围计算
</span>
)}
<Select <Select
placeholder="选择景区" placeholder="选择景区"
style={{ width: 200 }} style={{ width: 200 }}