-- 检查订单306派单后的实际状态

-- 1. 查看订单306的详细信息
SELECT 
    id,
    order_no,
    user_id,
    teacher_id,
    status,
    pay_status,
    service_date,
    time_slot,
    create_time,
    update_time,
    deleted
FROM `order`
WHERE id = 306;

-- 2. 查看订单306的更新时间是否改变
SELECT 
    id,
    order_no,
    teacher_id,
    status,
    update_time,
    TIMESTAMPDIFF(SECOND, update_time, NOW()) as seconds_since_update
FROM `order`
WHERE id = 306;

-- 3. 查看当前所有待派单的订单（按修复后的条件）
SELECT 
    id,
    order_no,
    user_id,
    teacher_id,
    status,
    pay_status,
    create_time
FROM `order`
WHERE pay_status = 1 
  AND status = 0
  AND teacher_id IS NULL 
  AND deleted = 0
ORDER BY create_time DESC
LIMIT 20;

-- 4. 查看订单306是否在待派单列表中
SELECT 
    CASE 
        WHEN COUNT(*) > 0 THEN '❌ 订单306仍在待派单列表中'
        ELSE '✅ 订单306不在待派单列表中'
    END as check_result
FROM `order`
WHERE id = 306
  AND pay_status = 1 
  AND status = 0
  AND teacher_id IS NULL 
  AND deleted = 0;

-- 5. 检查订单306是否符合已派单条件
SELECT 
    id,
    order_no,
    teacher_id,
    status,
    CASE 
        WHEN teacher_id IS NOT NULL AND status = 1 THEN '✅ 已派单（正常）'
        WHEN teacher_id IS NULL AND status = 0 THEN '⚠️ 待派单（未派单）'
        WHEN teacher_id IS NULL AND status = 1 THEN '❌ 异常：未派单但状态是1'
        WHEN teacher_id IS NOT NULL AND status = 0 THEN '❌ 异常：已派单但状态是0'
        ELSE '❌ 其他异常状态'
    END as check_result
FROM `order`
WHERE id = 306;

-- 6. 统计当前待派单数量（按修复后的条件）
SELECT COUNT(*) as pending_count
FROM `order`
WHERE pay_status = 1 
  AND status = 0
  AND teacher_id IS NULL 
  AND deleted = 0;
