-- 添加礼物打赏菜单到数据库

-- 1. 查看当前最大的菜单ID
SELECT MAX(id) as max_id FROM eb_system_menu;

-- 2. 删除旧的礼物菜单（如果存在）
DELETE FROM eb_system_menu WHERE path LIKE '/gift%' OR path LIKE '/giftManage%';

-- 3. 添加礼物打赏主菜单
INSERT INTO eb_system_menu (pid, menu_name, path, component, is_show, sort, icon, create_time, update_time) 
VALUES (0, '礼物打赏', '/gift', 'Layout', 1, 50, 'el-icon-present', NOW(), NOW());

-- 获取刚插入的主菜单ID
SET @gift_menu_id = LAST_INSERT_ID();

-- 4. 添加子菜单 - 礼物列表
INSERT INTO eb_system_menu (pid, menu_name, path, component, is_show, sort, icon, create_time, update_time)
VALUES (@gift_menu_id, '礼物列表', 'config', 'gift/config/index', 1, 1, 'el-icon-goods', NOW(), NOW());

-- 5. 添加子菜单 - 打赏记录
INSERT INTO eb_system_menu (pid, menu_name, path, component, is_show, sort, icon, create_time, update_time)
VALUES (@gift_menu_id, '打赏记录', 'records', 'gift/records/index', 1, 2, 'el-icon-document', NOW(), NOW());

-- 6. 添加子菜单 - 充值套餐
INSERT INTO eb_system_menu (pid, menu_name, path, component, is_show, sort, icon, create_time, update_time)
VALUES (@gift_menu_id, '充值套餐', 'recharge', 'gift/recharge/index', 1, 3, 'el-icon-coin', NOW(), NOW());

-- 7. 验证插入结果
SELECT 
    m1.id,
    m1.menu_name as '主菜单',
    m2.id as '子菜单ID',
    m2.menu_name as '子菜单',
    m2.path as '路径',
    m2.component as '组件'
FROM eb_system_menu m1
LEFT JOIN eb_system_menu m2 ON m1.id = m2.pid
WHERE m1.path = '/gift'
ORDER BY m2.sort;

-- 8. 查看所有礼物相关菜单
SELECT * FROM eb_system_menu WHERE path LIKE '/gift%' OR pid IN (SELECT id FROM eb_system_menu WHERE path = '/gift');
