-- 检查日历数据 - 2026-01-24

-- 1. 检查当前登录用户的订单数据
SELECT 
    id,
    order_no,
    user_id,
    student_id,
    teacher_id,
    service_date,
    time_slot,
    service_name,
    status,
    CASE status
        WHEN 0 THEN '待支付'
        WHEN 1 THEN '待接单'
        WHEN 2 THEN '待服务'
        WHEN 3 THEN '服务中'
        WHEN 4 THEN '已完成'
        WHEN -1 THEN '已取消'
        ELSE '未知'
    END as status_text,
    deleted,
    create_time
FROM `order`
WHERE deleted = 0
ORDER BY service_date DESC, create_time DESC
LIMIT 20;

-- 2. 检查2026年1月的订单
SELECT 
    id,
    order_no,
    user_id,
    service_date,
    time_slot,
    status,
    CASE status
        WHEN 0 THEN '待支付'
        WHEN 1 THEN '待接单'
        WHEN 2 THEN '待服务'
        WHEN 3 THEN '服务中'
        WHEN 4 THEN '已完成'
        WHEN -1 THEN '已取消'
        ELSE '未知'
    END as status_text
FROM `order`
WHERE service_date >= '2026-01-01' 
  AND service_date <= '2026-01-31'
  AND deleted = 0
ORDER BY service_date, time_slot;

-- 3. 按用户ID统计订单数量
SELECT 
    user_id,
    COUNT(*) as order_count,
    COUNT(CASE WHEN status IN (1,2,3,4) THEN 1 END) as valid_count,
    COUNT(CASE WHEN service_date >= '2026-01-01' AND service_date <= '2026-01-31' THEN 1 END) as jan_count
FROM `order`
WHERE deleted = 0
GROUP BY user_id
ORDER BY order_count DESC;

-- 4. 检查订单状态分布
SELECT 
    status,
    CASE status
        WHEN 0 THEN '待支付'
        WHEN 1 THEN '待接单'
        WHEN 2 THEN '待服务'
        WHEN 3 THEN '服务中'
        WHEN 4 THEN '已完成'
        WHEN -1 THEN '已取消'
        ELSE '未知'
    END as status_text,
    COUNT(*) as count
FROM `order`
WHERE deleted = 0
GROUP BY status
ORDER BY status;

-- 5. 检查用户表中的用户信息
SELECT 
    id,
    username,
    phone,
    user_type,
    CASE user_type
        WHEN 1 THEN '家长'
        WHEN 2 THEN '陪伴员'
        WHEN 3 THEN '管理师'
        WHEN 4 THEN '服务商'
        ELSE '未知'
    END as user_type_text
FROM user
WHERE deleted = 0
ORDER BY id
LIMIT 10;
