-- =====================================================
-- 为用户"道玄"（ID: 121）添加测试数据
-- 执行时间: 2026-01-04
-- =====================================================

-- 先检查用户是否存在
SELECT uid, nickname, phone FROM eb_user WHERE uid = 121;

-- 检查现有的直播间
SELECT id, room_title, owner_nickname, status FROM eb_room LIMIT 10;

-- 检查现有的作品
SELECT id, title, user_id FROM eb_works LIMIT 10;

-- 检查现有的主播
SELECT id, uid, nickname FROM eb_streamer LIMIT 10;

-- =====================================================
-- 1. 观看历史记录 (eb_watch_history)
-- =====================================================
INSERT INTO eb_watch_history (uid, target_type, target_id, target_title, target_cover, duration, watch_time, create_time) VALUES
-- 观看直播间
(121, 'room', 1, '欢乐游戏直播', 'https://example.com/cover1.jpg', 1800, '2026-01-03 20:30:00', '2026-01-03 20:30:00'),
(121, 'room', 2, '音乐分享会', 'https://example.com/cover2.jpg', 2400, '2026-01-03 21:00:00', '2026-01-03 21:00:00'),
(121, 'room', 3, '户外探险直播', 'https://example.com/cover3.jpg', 900, '2026-01-02 19:00:00', '2026-01-02 19:00:00'),
(121, 'room', 4, '美食制作教程', 'https://example.com/cover4.jpg', 3600, '2026-01-02 12:00:00', '2026-01-02 12:00:00'),
(121, 'room', 5, '编程技术分享', 'https://example.com/cover5.jpg', 5400, '2026-01-01 14:00:00', '2026-01-01 14:00:00'),
-- 观看作品
(121, 'work', 1, '搞笑短视频合集', 'https://example.com/work1.jpg', 180, '2026-01-03 22:00:00', '2026-01-03 22:00:00'),
(121, 'work', 2, '旅行Vlog-云南之旅', 'https://example.com/work2.jpg', 600, '2026-01-03 18:00:00', '2026-01-03 18:00:00'),
(121, 'work', 3, '美妆教程分享', 'https://example.com/work3.jpg', 420, '2026-01-02 16:00:00', '2026-01-02 16:00:00');

-- =====================================================
-- 2. 直播间点赞记录 (eb_live_room_like)
-- =====================================================
INSERT INTO eb_live_room_like (uid, room_id, like_count, create_time) VALUES
(121, 1, 15, '2026-01-03 20:35:00'),
(121, 2, 28, '2026-01-03 21:15:00'),
(121, 3, 8, '2026-01-02 19:10:00'),
(121, 4, 42, '2026-01-02 12:30:00'),
(121, 5, 20, '2026-01-01 14:30:00');

-- =====================================================
-- 3. 作品关系记录 (eb_works_relation) - 点赞和收藏
-- =====================================================
-- 点赞作品 (type=1)
INSERT INTO eb_works_relation (uid, works_id, type, create_time) VALUES
(121, 1, 1, '2026-01-03 22:05:00'),
(121, 2, 1, '2026-01-03 18:10:00'),
(121, 3, 1, '2026-01-02 16:15:00'),
(121, 4, 1, '2026-01-01 20:00:00'),
(121, 5, 1, '2026-01-01 15:00:00');

-- 收藏作品 (type=2)
INSERT INTO eb_works_relation (uid, works_id, type, create_time) VALUES
(121, 1, 2, '2026-01-03 22:06:00'),
(121, 2, 2, '2026-01-03 18:12:00'),
(121, 6, 2, '2026-01-02 10:00:00'),
(121, 7, 2, '2026-01-01 11:00:00');

-- =====================================================
-- 4. 关注记录 (eb_follow_record)
-- =====================================================
INSERT INTO eb_follow_record (uid, follow_uid, create_time) VALUES
(121, 100, '2026-01-03 20:00:00'),
(121, 101, '2026-01-03 15:00:00'),
(121, 102, '2026-01-02 18:00:00'),
(121, 103, '2026-01-02 12:00:00'),
(121, 104, '2026-01-01 20:00:00'),
(121, 105, '2026-01-01 10:00:00');

-- 被关注记录（其他用户关注道玄）
INSERT INTO eb_follow_record (uid, follow_uid, create_time) VALUES
(100, 121, '2026-01-03 21:00:00'),
(101, 121, '2026-01-03 16:00:00'),
(106, 121, '2026-01-02 20:00:00'),
(107, 121, '2026-01-02 14:00:00');

-- =====================================================
-- 5. 搜索历史 (eb_search_history)
-- =====================================================
INSERT INTO eb_search_history (uid, keyword, search_type, search_count, create_time) VALUES
(121, '游戏直播', 1, 3, '2026-01-03 20:00:00'),
(121, '音乐', 1, 2, '2026-01-03 19:00:00'),
(121, '美食教程', 2, 1, '2026-01-02 11:00:00'),
(121, '旅行Vlog', 2, 2, '2026-01-02 10:00:00'),
(121, '编程学习', 1, 4, '2026-01-01 13:00:00'),
(121, '户外运动', 1, 1, '2026-01-01 09:00:00');

-- =====================================================
-- 6. 礼物打赏记录 (eb_gift_record)
-- =====================================================
INSERT INTO eb_gift_record (uid, streamer_id, room_id, gift_id, gift_name, gift_price, quantity, total_price, create_time) VALUES
(121, 1, 1, 1, '小红心', 1, 10, 10, '2026-01-03 20:40:00'),
(121, 1, 1, 2, '鲜花', 5, 5, 25, '2026-01-03 20:45:00'),
(121, 2, 2, 3, '棒棒糖', 10, 3, 30, '2026-01-03 21:20:00'),
(121, 3, 3, 4, '火箭', 100, 1, 100, '2026-01-02 19:15:00'),
(121, 4, 4, 1, '小红心', 1, 20, 20, '2026-01-02 12:35:00');

-- =====================================================
-- 7. 私聊会话记录 (eb_conversation)
-- =====================================================
INSERT INTO eb_conversation (user1_id, user2_id, last_message, last_message_time, user1_unread, user2_unread, create_time) VALUES
(121, 100, '你好，直播很精彩！', '2026-01-03 21:30:00', 0, 1, '2026-01-03 20:30:00'),
(121, 101, '什么时候再开播？', '2026-01-03 16:00:00', 1, 0, '2026-01-03 15:30:00'),
(102, 121, '感谢关注！', '2026-01-02 18:30:00', 0, 0, '2026-01-02 18:00:00');

-- =====================================================
-- 8. 私聊消息记录 (eb_private_message)
-- =====================================================
INSERT INTO eb_private_message (conversation_id, sender_id, receiver_id, content, msg_type, is_read, create_time) VALUES
-- 与用户100的对话
(1, 121, 100, '你好，直播很精彩！', 'text', 1, '2026-01-03 21:30:00'),
(1, 100, 121, '谢谢支持！', 'text', 1, '2026-01-03 21:31:00'),
-- 与用户101的对话
(2, 101, 121, '什么时候再开播？', 'text', 0, '2026-01-03 16:00:00'),
(2, 121, 101, '明天晚上8点', 'text', 1, '2026-01-03 16:05:00');

-- =====================================================
-- 9. 好友关系 (eb_friend)
-- =====================================================
INSERT INTO eb_friend (uid, friend_uid, remark, create_time) VALUES
(121, 100, '游戏主播', '2026-01-03 21:35:00'),
(121, 101, '音乐达人', '2026-01-03 16:10:00'),
(100, 121, '道玄', '2026-01-03 21:35:00'),
(101, 121, '道玄', '2026-01-03 16:10:00');

-- =====================================================
-- 10. 心愿记录 (eb_wish) - 许愿树功能
-- =====================================================
INSERT INTO eb_wish (uid, festival_id, content, background_id, like_count, comment_count, status, create_time) VALUES
(121, 1, '希望新的一年事业顺利，身体健康！', 1, 15, 3, 1, '2026-01-01 00:05:00'),
(121, 1, '愿家人平安幸福', 2, 8, 1, 1, '2026-01-01 00:10:00');

-- =====================================================
-- 11. 虚拟货币余额更新 (eb_user表)
-- =====================================================
UPDATE eb_user SET 
    now_money = 500.00,
    integral = 1200,
    experience = 350
WHERE uid = 121;

-- =====================================================
-- 12. 充值记录 (eb_recharge_order)
-- =====================================================
INSERT INTO eb_recharge_order (uid, order_no, price, give_price, pay_type, paid, pay_time, create_time) VALUES
(121, 'RC202601030001', 100.00, 10.00, 'alipay', 1, '2026-01-03 10:00:00', '2026-01-03 09:58:00'),
(121, 'RC202601020001', 50.00, 5.00, 'wechat', 1, '2026-01-02 15:00:00', '2026-01-02 14:55:00'),
(121, 'RC202601010001', 200.00, 30.00, 'alipay', 1, '2026-01-01 12:00:00', '2026-01-01 11:50:00');

-- =====================================================
-- 验证插入的数据
-- =====================================================
SELECT '观看历史' as 类型, COUNT(*) as 数量 FROM eb_watch_history WHERE uid = 121
UNION ALL
SELECT '直播间点赞', COUNT(*) FROM eb_live_room_like WHERE uid = 121
UNION ALL
SELECT '作品点赞', COUNT(*) FROM eb_works_relation WHERE uid = 121 AND type = 1
UNION ALL
SELECT '作品收藏', COUNT(*) FROM eb_works_relation WHERE uid = 121 AND type = 2
UNION ALL
SELECT '关注数', COUNT(*) FROM eb_follow_record WHERE uid = 121
UNION ALL
SELECT '粉丝数', COUNT(*) FROM eb_follow_record WHERE follow_uid = 121
UNION ALL
SELECT '搜索历史', COUNT(*) FROM eb_search_history WHERE uid = 121
UNION ALL
SELECT '礼物打赏', COUNT(*) FROM eb_gift_record WHERE uid = 121
UNION ALL
SELECT '好友数', COUNT(*) FROM eb_friend WHERE uid = 121;

SELECT '数据插入完成！用户道玄(ID:121)的测试数据已添加。' as 结果;
