-- 检查陪伴员为什么看不到待接单订单

-- 1. 查看最近派单的订单（假设派给了陪伴员ID=10096）
SELECT 
    id,
    order_no,
    teacher_id,
    status,
    pay_status,
    service_date,
    time_slot,
    create_time,
    update_time,
    CASE 
        WHEN teacher_id IS NULL THEN '❌ 未分配陪伴员'
        WHEN status != 1 THEN '❌ 状态不是1（待接单）'
        WHEN pay_status != 1 THEN '❌ 未支付'
        ELSE '✅ 符合条件'
    END as check_result
FROM `order`
WHERE teacher_id = 10096
ORDER BY update_time DESC
LIMIT 10;

-- 2. 查看陪伴员10096应该能看到的待接单订单
-- 条件：teacher_id=10096 AND status=1 AND pay_status=1 AND deleted=0
SELECT 
    id,
    order_no,
    teacher_id,
    status,
    pay_status,
    service_date,
    time_slot,
    create_time,
    update_time
FROM `order`
WHERE teacher_id = 10096
  AND status = 1
  AND pay_status = 1
  AND deleted = 0
ORDER BY create_time DESC;

-- 3. 查看teacher表中ID=10096的陪伴员信息
SELECT 
    id as teacher_id,
    user_id,
    name,
    real_name,
    phone,
    audit_status
FROM teacher
WHERE id = 10096;

-- 4. 检查是否有teacher_id=10096但status不是1的订单
SELECT 
    id,
    order_no,
    teacher_id,
    status,
    pay_status,
    CASE 
        WHEN status = 0 THEN '待派单'
        WHEN status = 1 THEN '待接单'
        WHEN status = 2 THEN '待服务'
        WHEN status = 3 THEN '服务中'
        WHEN status = 4 THEN '已完成'
        WHEN status = 5 THEN '已取消'
        ELSE '未知状态'
    END as status_name,
    update_time
FROM `order`
WHERE teacher_id = 10096
  AND status != 1
ORDER BY update_time DESC
LIMIT 10;

-- 5. 统计陪伴员10096的订单状态分布
SELECT 
    status,
    COUNT(*) as count,
    CASE 
        WHEN status = 0 THEN '待派单'
        WHEN status = 1 THEN '待接单'
        WHEN status = 2 THEN '待服务'
        WHEN status = 3 THEN '服务中'
        WHEN status = 4 THEN '已完成'
        WHEN status = 5 THEN '已取消'
        ELSE '未知状态'
    END as status_name
FROM `order`
WHERE teacher_id = 10096
  AND deleted = 0
GROUP BY status
ORDER BY status;

-- 6. 查看最近派单的订单（订单306）
SELECT 
    id,
    order_no,
    teacher_id,
    status,
    pay_status,
    service_date,
    time_slot,
    create_time,
    update_time
FROM `order`
WHERE id = 306;
