-- 最终修复礼物菜单 - 确保字段完全匹配

-- 1. 先查看现有的工作菜单示例
SELECT * FROM eb_system_menu WHERE name = '直播管理' LIMIT 1;
SELECT * FROM eb_system_menu WHERE pid = (SELECT id FROM eb_system_menu WHERE name = '直播管理' LIMIT 1) LIMIT 3;

-- 2. 删除旧的礼物菜单
DELETE FROM eb_system_menu WHERE name IN ('礼物打赏', '礼物列表', '打赏记录', '充值套餐', '礼物管理');

-- 3. 添加礼物打赏主菜单
INSERT INTO eb_system_menu (pid, name, icon, perms, component, menu_type, sort, is_show, is_delte) 
VALUES (0, '礼物打赏', 'el-icon-present', '', '/gift', 'M', 50, 1, 0);

SET @gift_pid = LAST_INSERT_ID();

-- 4. 添加子菜单
INSERT INTO eb_system_menu (pid, name, icon, perms, component, menu_type, sort, is_show, is_delte) VALUES
(@gift_pid, '礼物列表', '', 'admin:gift:config', 'gift/config/index', 'C', 1, 1, 0),
(@gift_pid, '打赏记录', '', 'admin:gift:records', 'gift/records/index', 'C', 2, 1, 0),
(@gift_pid, '充值套餐', '', 'admin:gift:recharge', 'gift/recharge/index', 'C', 3, 1, 0);

-- 5. 验证
SELECT 
    m.id,
    m.pid,
    m.name,
    m.component,
    m.menu_type,
    m.sort
FROM eb_system_menu m
WHERE m.name = '礼物打赏' OR m.pid = @gift_pid
ORDER BY m.pid, m.sort;

-- 6. 给管理员分配权限
INSERT IGNORE INTO eb_system_role_menu (rid, menu_id)
SELECT 1, id FROM eb_system_menu WHERE name IN ('礼物打赏', '礼物列表', '打赏记录', '充值套餐');

SELECT '菜单添加完成！请退出登录后重新登录查看' as message;
