peixue-dev/Archive/[一次性]检查派单后订单状态.sql

78 lines
1.8 KiB
SQL
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- 检查派单后订单状态
-- 1. 查看刚才派单的订单根据控制台日志orderId应该是312或类似
-- 请替换<订单ID>为实际的订单ID
SELECT
id,
order_no,
status,
pay_status,
teacher_id,
user_id,
update_time,
deleted,
CASE
WHEN status = 0 AND teacher_id IS NULL AND pay_status = 1 THEN '待派单'
WHEN status = 1 AND teacher_id IS NOT NULL THEN '已派单'
WHEN status = 0 AND teacher_id IS NOT NULL THEN '异常有陪伴员但status=0'
ELSE '其他状态'
END as status_desc
FROM `order`
WHERE id IN (312, 313, 314, 315) -- 替换为实际的订单ID
ORDER BY id DESC;
-- 2. 查看所有待派单订单(按我们修复后的逻辑)
SELECT
id,
order_no,
status,
pay_status,
teacher_id,
update_time
FROM `order`
WHERE pay_status = 1
AND teacher_id IS NULL
AND deleted = 0
ORDER BY create_time DESC;
-- 3. 查看陪伴员ID=10896的订单
SELECT
id,
order_no,
status,
pay_status,
teacher_id,
update_time
FROM `order`
WHERE teacher_id = 10896
AND deleted = 0
ORDER BY update_time DESC;
-- 4. 检查是否有异常状态的订单有陪伴员但status=0
SELECT
id,
order_no,
status,
pay_status,
teacher_id,
update_time,
'异常已分配陪伴员但status仍为0' as warning
FROM `order`
WHERE teacher_id IS NOT NULL
AND status = 0
AND deleted = 0
ORDER BY update_time DESC;
-- 5. 统计各状态订单数量(用于对比前端显示)
SELECT
CASE
WHEN pay_status = 1 AND teacher_id IS NULL THEN '待派单'
WHEN teacher_id IS NOT NULL THEN '已派单'
WHEN pay_status = 0 THEN '待支付'
ELSE '其他'
END as order_status,
COUNT(*) as count
FROM `order`
WHERE deleted = 0
GROUP BY order_status;