-- 抽奖流程图：两个顶级外链菜单（type=4），点击新窗口打开 public/docs/flowcharts/*.html
-- 挂载位置：与「后台操作指南」同级（parent_id=0），紧挨其下方（sort 略小，列表按 sort 降序）

SET @now = NOW();

-- 移除旧的「抽奖流程说明」内嵌页菜单（若已安装）
SET @old_flow_menu_id = (
  SELECT `id` FROM `sa_system_menu`
  WHERE `path` = 'flowcharts' AND `component` = '/plugin/dice/flowcharts/index/index' AND `type` = 2
  ORDER BY `id` ASC LIMIT 1
);

DELETE FROM `sa_system_role_menu` WHERE `menu_id` = @old_flow_menu_id;
DELETE FROM `sa_system_menu` WHERE `parent_id` = @old_flow_menu_id AND `type` = 3;
DELETE FROM `sa_system_menu` WHERE `id` = @old_flow_menu_id;

-- 1) 为何最终抽到该奖励
INSERT INTO `sa_system_menu`
(`parent_id`,`name`,`code`,`slug`,`type`,`path`,`component`,`method`,`icon`,`sort`,`link_url`,`is_iframe`,`is_keep_alive`,`is_hidden`,`is_fixed_tab`,`is_full_page`,`generate_id`,`generate_key`,`status`,`create_time`,`update_time`)
SELECT 0, '为何最终抽到该奖励', 'DiceFlowWhyReward', NULL, 4, 'dice_flow_why_reward', '', NULL, 'ri:question-answer-line', 4, '/docs/flowcharts/dice-为何抽到该奖励.html', 2, 2, 2, 2, 2, 0, NULL, 1, @now, @now
WHERE NOT EXISTS (
  SELECT 1 FROM `sa_system_menu`
  WHERE `type` = 4 AND `link_url` = '/docs/flowcharts/dice-为何抽到该奖励.html'
);

-- 2) 后台如何配置中奖逻辑
INSERT INTO `sa_system_menu`
(`parent_id`,`name`,`code`,`slug`,`type`,`path`,`component`,`method`,`icon`,`sort`,`link_url`,`is_iframe`,`is_keep_alive`,`is_hidden`,`is_fixed_tab`,`is_full_page`,`generate_id`,`generate_key`,`status`,`create_time`,`update_time`)
SELECT 0, '后台如何配置中奖逻辑', 'DiceFlowAdminConfig', NULL, 4, 'dice_flow_admin_config', '', NULL, 'ri:settings-3-line', 3, '/docs/flowcharts/dice-后台中奖逻辑配置.html', 2, 2, 2, 2, 2, 0, NULL, 1, @now, @now
WHERE NOT EXISTS (
  SELECT 1 FROM `sa_system_menu`
  WHERE `type` = 4 AND `link_url` = '/docs/flowcharts/dice-后台中奖逻辑配置.html'
);
