UPDATE `la_system_menu` child
JOIN `la_system_menu` parent
  ON parent.`type` = 'M'
 AND parent.`paths` = 'match'
SET child.`pid` = parent.`id`,
    child.`name` = '赔率列表',
    child.`paths` = 'match_odds',
    child.`component` = 'match/odds/index',
    child.`selected` = '',
    child.`is_show` = 1,
    child.`update_time` = UNIX_TIMESTAMP()
WHERE child.`perms` = 'match.matchOdds/index';

INSERT INTO `la_system_menu` (`pid`, `type`, `name`, `icon`, `sort`, `perms`, `paths`, `component`, `selected`, `params`, `is_cache`, `is_show`, `is_disable`, `create_time`, `update_time`)
SELECT parent.`id`, 'C', '赔率列表', '', 0, 'match.matchOdds/index', 'match_odds', 'match/odds/index', '', '', 0, 1, 0, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()
FROM `la_system_menu` parent
WHERE parent.`type` = 'M'
  AND parent.`paths` = 'match'
  AND NOT EXISTS (
    SELECT 1 FROM `la_system_menu`
    WHERE `perms` = 'match.matchOdds/index'
);

INSERT INTO `la_system_menu` (`pid`, `type`, `name`, `icon`, `sort`, `perms`, `paths`, `component`, `selected`, `params`, `is_cache`, `is_show`, `is_disable`, `create_time`, `update_time`)
SELECT (SELECT `id` FROM `la_system_menu` WHERE `perms` = 'match.matchOdds/index' LIMIT 1), 'A', '赔率列表查询', '', 0, 'match.matchOdds/lists', '', '', '', '', 0, 0, 0, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()
WHERE NOT EXISTS (
    SELECT 1 FROM `la_system_menu`
    WHERE `perms` = 'match.matchOdds/lists'
);

INSERT INTO `la_system_role_menu` (`role_id`, `menu_id`)
SELECT 1, m.`id`
FROM `la_system_menu` m
WHERE m.`perms` IN (
    'match.matchOdds/index',
    'match.matchOdds/lists'
)
AND NOT EXISTS (
    SELECT 1
    FROM `la_system_role_menu` rm
    WHERE rm.`role_id` = 1
      AND rm.`menu_id` = m.`id`
);
