-- 修复评价提交问题 - 2026-01-23
-- 数据库：peixue

USE peixue;

-- 步骤1: 检查订单状态
SELECT 
    id,
    order_no,
    status,
    reviewed,
    user_id,
    teacher_id,
    student_id,
    tenant_id
FROM `order` 
WHERE id = 102;

-- 步骤2: 检查是否已有评价记录
SELECT * FROM review WHERE order_id = 102;

-- 步骤3: 清理旧评价记录（如果存在）
DELETE FROM review WHERE order_id = 102;

-- 步骤4: 修复订单状态
-- 确保订单状态为4（已完成），reviewed为0（未评价）
UPDATE `order` 
SET 
    status = 4,
    reviewed = 0,
    user_id = 1,  -- 确保user_id与登录用户匹配
    teacher_id = 1,  -- 确保有陪伴员ID
    student_id = 1   -- 确保有学生ID
WHERE id = 102;

-- 步骤5: 验证修复结果
SELECT 
    id,
    order_no,
    status,
    reviewed,
    user_id,
    teacher_id,
    student_id
FROM `order` 
WHERE id = 102;

-- 预期结果：
-- status = 4
-- reviewed = 0
-- user_id = 1
-- teacher_id = 1
-- student_id = 1

-- 步骤6: 确认review表为空
SELECT COUNT(*) as review_count FROM review WHERE order_id = 102;
-- 预期结果：review_count = 0
