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)",
"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 &lt;= #{p.endTime}",
" AND r.create_time &lt;= #{p.endTime}",
"</if>",
"</script>"
})
@@ -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;