Files
Mycontent/soul-api/scripts/backfill-vip-orders-preview.sql
卡若 6aa0d27da1 feat: 阅读页与章节预览 API;管理端内容页;book/h5_read;脚本与文档
- miniprogram: read 页与 member-detail/my;SOP 文档
- soul-api: chapter_preview、book/h5_read 调整;VIP 订单回填 SQL
- soul-admin: ContentPage、dist
- scripts: pull_from_baota;content_upload、gitignore、对话规则

Made-with: Cursor
2026-03-27 17:19:21 +08:00

34 lines
1022 B
SQL
Raw Blame History

This file contains ambiguous Unicode characters

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.

-- 预览:将补多少超级个体用户、合计增加多少营收(每人一条 ¥1980 vip 已付订单)
-- 条件:当前仍为 VIPis_vip=1 且未过期或未填过期视为仍有效)且尚无 vip 已付订单
SELECT
COUNT(*) AS users_to_backfill,
COUNT(*) * 1980.00 AS revenue_to_add_yuan
FROM users u
WHERE u.deleted_at IS NULL
AND COALESCE(u.is_vip, 0) = 1
AND (u.vip_expire_date IS NULL OR u.vip_expire_date > NOW())
AND NOT EXISTS (
SELECT 1 FROM orders o
WHERE o.user_id = u.id
AND o.product_type = 'vip'
AND o.status IN ('paid', 'completed', 'success')
);
SELECT
u.id,
u.nickname,
u.vip_activated_at,
u.vip_expire_date
FROM users u
WHERE u.deleted_at IS NULL
AND COALESCE(u.is_vip, 0) = 1
AND (u.vip_expire_date IS NULL OR u.vip_expire_date > NOW())
AND NOT EXISTS (
SELECT 1 FROM orders o
WHERE o.user_id = u.id
AND o.product_type = 'vip'
AND o.status IN ('paid', 'completed', 'success')
)
ORDER BY u.vip_activated_at DESC, u.id;