-- 批量修复所有订单状态 - 2026-01-23
-- 数据库：peixue

USE peixue;

-- 步骤1: 查看所有可能需要评价的订单
SELECT 
    id,
    order_no,
    status,
    reviewed,
    user_id,
    teacher_id,
    student_id,
    pay_status,
    complete_time
FROM `order` 
WHERE id IN (264, 267, 102)
ORDER BY id;

-- 步骤2: 批量修复订单状态
-- 将所有测试订单改为已完成状态
UPDATE `order` 
SET 
    status = 4,                    -- 已完成
    reviewed = 0,                  -- 未评价
    pay_status = 1,                -- 已支付
    complete_time = NOW(),         -- 完成时间
    service_start_time = DATE_SUB(NOW(), INTERVAL 2 HOUR),  -- 服务开始时间（2小时前）
    verify_time = DATE_SUB(NOW(), INTERVAL 2 HOUR)          -- 核销时间（2小时前）
WHERE id IN (264, 267, 102);

-- 步骤3: 清理所有旧评价记录
DELETE FROM review WHERE order_id IN (264, 267, 102);

-- 步骤4: 验证修复结果
SELECT 
    id,
    order_no,
    status,
    reviewed,
    pay_status,
    complete_time,
    service_start_time,
    verify_time
FROM `order` 
WHERE id IN (264, 267, 102)
ORDER BY id;

-- 步骤5: 确认没有评价记录
SELECT COUNT(*) as review_count 
FROM review 
WHERE order_id IN (264, 267, 102);

-- 预期结果：
-- 所有订单：
-- - status = 4 (已完成)
-- - reviewed = 0 (未评价)
-- - pay_status = 1 (已支付)
-- - complete_time = 当前时间
-- - review_count = 0 (没有评价记录)
