peixue-dev/Archive/peidu-temp-files/sql/🔍诊断订单状态-日历预约不一致-2026-01-24.sql

91 lines
2.4 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- 🔍 诊断订单状态 - 日历与预约数据不一致
-- 日期: 2026-01-24
-- 目标: 找出为什么日历显示6个预约显示62个
-- ============================================
-- SQL 1: 检查用户ID=1的所有订单状态分布
-- ============================================
SELECT
status,
CASE status
WHEN 0 THEN '待支付'
WHEN 1 THEN '待服务'
WHEN 2 THEN '进行中'
WHEN 3 THEN '已完成'
WHEN 4 THEN '已取消'
ELSE CONCAT('其他(', status, ')')
END AS status_text,
COUNT(*) AS count
FROM `order`
WHERE user_id = 1
AND deleted = 0
GROUP BY status
ORDER BY status;
-- ============================================
-- SQL 2: 检查"我的预约"页面查询的订单status=1
-- ============================================
SELECT
COUNT(*) AS total_count
FROM `order`
WHERE user_id = 1
AND status = 1
AND deleted = 0;
-- ============================================
-- SQL 3: 检查日历页面查询的订单status IN 1,2,3,4
-- ============================================
SELECT
COUNT(*) AS total_count
FROM `order`
WHERE user_id = 1
AND status IN (1, 2, 3, 4)
AND deleted = 0;
-- ============================================
-- SQL 4: 查看62个订单的详细状态
-- ============================================
SELECT
id,
order_no,
status,
CASE status
WHEN 0 THEN '待支付'
WHEN 1 THEN '待服务'
WHEN 2 THEN '进行中'
WHEN 3 THEN '已完成'
WHEN 4 THEN '已取消'
ELSE CONCAT('其他(', status, ')')
END AS status_text,
service_date,
time_slot,
service_name,
create_time
FROM `order`
WHERE user_id = 1
AND deleted = 0
ORDER BY status, create_time DESC
LIMIT 100;
-- ============================================
-- 执行说明
-- ============================================
/*
请在Navicat中依次执行上面的SQL重点关注
1. SQL 1: 查看订单状态分布
- 如果status=1的订单有62个说明"我的预约"查询正确
- 如果status=1的订单只有2个说明其他60个订单是其他状态
2. SQL 2: 确认"我的预约"查询的订单数
- 应该返回62
3. SQL 3: 确认日历查询的订单数
- 应该返回6
4. SQL 4: 查看所有订单的详细信息
- 确认62个订单的实际状态
执行完成后请告诉我SQL 1的结果
*/