USE youlai_admin;

-- 代理平台菜单初始化
-- 说明：
-- 1. 本脚本只负责后台菜单、按钮权限和系统管理员授权。
-- 2. 页面 component 先按约定路径预留，前端页面接入后直接对齐即可。

-- 一级目录：代理平台
INSERT INTO `sys_menu`
(`id`, `parent_id`, `tree_path`, `name`, `type`, `route_name`, `route_path`, `component`, `perm`,
 `always_show`, `keep_alive`, `visible`, `sort`, `icon`, `redirect`, `create_time`, `update_time`, `params`)
VALUES
(1100, 0, '0', '代理平台', 'C', 'Proxy', '/proxy', 'Layout', NULL,
 1, NULL, 1, 10, 'monitor', '/proxy/product', now(), now(), NULL)
ON DUPLICATE KEY UPDATE
`name` = VALUES(`name`),
`route_path` = VALUES(`route_path`),
`component` = VALUES(`component`),
`always_show` = VALUES(`always_show`),
`visible` = VALUES(`visible`),
`sort` = VALUES(`sort`),
`icon` = VALUES(`icon`),
`redirect` = VALUES(`redirect`),
`update_time` = now();

-- 商品管理
INSERT INTO `sys_menu`
(`id`, `parent_id`, `tree_path`, `name`, `type`, `route_name`, `route_path`, `component`, `perm`,
 `always_show`, `keep_alive`, `visible`, `sort`, `icon`, `redirect`, `create_time`, `update_time`, `params`)
VALUES
(1110, 1100, '0,1100', '商品管理', 'M', 'ProxyProduct', 'product', 'proxy/product/index', NULL,
 0, 1, 1, 1, 'goods', NULL, now(), now(), NULL),
(11101, 1110, '0,1100,1110', '商品查询', 'B', NULL, '', NULL, 'proxy:product:list',
 NULL, NULL, 1, 1, '', NULL, now(), now(), NULL),
(11102, 1110, '0,1100,1110', '商品新增', 'B', NULL, '', NULL, 'proxy:product:create',
 NULL, NULL, 1, 2, '', NULL, now(), now(), NULL),
(11103, 1110, '0,1100,1110', '商品修改', 'B', NULL, '', NULL, 'proxy:product:update',
 NULL, NULL, 1, 3, '', NULL, now(), now(), NULL),
(11104, 1110, '0,1100,1110', '商品删除', 'B', NULL, '', NULL, 'proxy:product:delete',
 NULL, NULL, 1, 4, '', NULL, now(), now(), NULL)
ON DUPLICATE KEY UPDATE
`name` = VALUES(`name`),
`route_name` = VALUES(`route_name`),
`route_path` = VALUES(`route_path`),
`component` = VALUES(`component`),
`perm` = VALUES(`perm`),
`keep_alive` = VALUES(`keep_alive`),
`visible` = VALUES(`visible`),
`sort` = VALUES(`sort`),
`update_time` = now();

-- 静态价格管理
INSERT INTO `sys_menu`
(`id`, `parent_id`, `tree_path`, `name`, `type`, `route_name`, `route_path`, `component`, `perm`,
 `always_show`, `keep_alive`, `visible`, `sort`, `icon`, `redirect`, `create_time`, `update_time`, `params`)
VALUES
(1120, 1100, '0,1100', '静态价格管理', 'M', 'ProxyStaticPrice', 'static-price', 'proxy/static-price/index', NULL,
 0, 1, 1, 2, 'price-tag', NULL, now(), now(), NULL),
(11201, 1120, '0,1100,1120', '静态价格查询', 'B', NULL, '', NULL, 'proxy:static-price:list',
 NULL, NULL, 1, 1, '', NULL, now(), now(), NULL),
(11202, 1120, '0,1100,1120', '静态价格新增', 'B', NULL, '', NULL, 'proxy:static-price:create',
 NULL, NULL, 1, 2, '', NULL, now(), now(), NULL),
(11203, 1120, '0,1100,1120', '静态价格修改', 'B', NULL, '', NULL, 'proxy:static-price:update',
 NULL, NULL, 1, 3, '', NULL, now(), now(), NULL),
(11204, 1120, '0,1100,1120', '静态价格删除', 'B', NULL, '', NULL, 'proxy:static-price:delete',
 NULL, NULL, 1, 4, '', NULL, now(), now(), NULL)
ON DUPLICATE KEY UPDATE
`name` = VALUES(`name`),
`route_name` = VALUES(`route_name`),
`route_path` = VALUES(`route_path`),
`component` = VALUES(`component`),
`perm` = VALUES(`perm`),
`keep_alive` = VALUES(`keep_alive`),
`visible` = VALUES(`visible`),
`sort` = VALUES(`sort`),
`update_time` = now();

-- 动态套餐管理
INSERT INTO `sys_menu`
(`id`, `parent_id`, `tree_path`, `name`, `type`, `route_name`, `route_path`, `component`, `perm`,
 `always_show`, `keep_alive`, `visible`, `sort`, `icon`, `redirect`, `create_time`, `update_time`, `params`)
VALUES
(1130, 1100, '0,1100', '动态套餐管理', 'M', 'ProxyDynamicPlan', 'dynamic-plan', 'proxy/dynamic-plan/index', NULL,
 0, 1, 1, 3, 'set-up', NULL, now(), now(), NULL),
(11301, 1130, '0,1100,1130', '动态套餐查询', 'B', NULL, '', NULL, 'proxy:dynamic-plan:list',
 NULL, NULL, 1, 1, '', NULL, now(), now(), NULL),
(11302, 1130, '0,1100,1130', '动态套餐新增', 'B', NULL, '', NULL, 'proxy:dynamic-plan:create',
 NULL, NULL, 1, 2, '', NULL, now(), now(), NULL),
(11303, 1130, '0,1100,1130', '动态套餐修改', 'B', NULL, '', NULL, 'proxy:dynamic-plan:update',
 NULL, NULL, 1, 3, '', NULL, now(), now(), NULL),
(11304, 1130, '0,1100,1130', '动态套餐删除', 'B', NULL, '', NULL, 'proxy:dynamic-plan:delete',
 NULL, NULL, 1, 4, '', NULL, now(), now(), NULL)
ON DUPLICATE KEY UPDATE
`name` = VALUES(`name`),
`route_name` = VALUES(`route_name`),
`route_path` = VALUES(`route_path`),
`component` = VALUES(`component`),
`perm` = VALUES(`perm`),
`keep_alive` = VALUES(`keep_alive`),
`visible` = VALUES(`visible`),
`sort` = VALUES(`sort`),
`update_time` = now();

-- 时长倍率管理
INSERT INTO `sys_menu`
(`id`, `parent_id`, `tree_path`, `name`, `type`, `route_name`, `route_path`, `component`, `perm`,
 `always_show`, `keep_alive`, `visible`, `sort`, `icon`, `redirect`, `create_time`, `update_time`, `params`)
VALUES
(1140, 1100, '0,1100', '时长倍率管理', 'M', 'ProxyDurationMultiplier', 'duration-multiplier', 'proxy/duration-multiplier/index', NULL,
 0, 1, 1, 4, 'timer', NULL, now(), now(), NULL),
(11401, 1140, '0,1100,1140', '时长倍率查询', 'B', NULL, '', NULL, 'proxy:duration:list',
 NULL, NULL, 1, 1, '', NULL, now(), now(), NULL),
(11402, 1140, '0,1100,1140', '时长倍率新增', 'B', NULL, '', NULL, 'proxy:duration:create',
 NULL, NULL, 1, 2, '', NULL, now(), now(), NULL),
(11403, 1140, '0,1100,1140', '时长倍率修改', 'B', NULL, '', NULL, 'proxy:duration:update',
 NULL, NULL, 1, 3, '', NULL, now(), now(), NULL),
(11404, 1140, '0,1100,1140', '时长倍率删除', 'B', NULL, '', NULL, 'proxy:duration:delete',
 NULL, NULL, 1, 4, '', NULL, now(), now(), NULL)
ON DUPLICATE KEY UPDATE
`name` = VALUES(`name`),
`route_name` = VALUES(`route_name`),
`route_path` = VALUES(`route_path`),
`component` = VALUES(`component`),
`perm` = VALUES(`perm`),
`keep_alive` = VALUES(`keep_alive`),
`visible` = VALUES(`visible`),
`sort` = VALUES(`sort`),
`update_time` = now();

-- 订单管理
INSERT INTO `sys_menu`
(`id`, `parent_id`, `tree_path`, `name`, `type`, `route_name`, `route_path`, `component`, `perm`,
 `always_show`, `keep_alive`, `visible`, `sort`, `icon`, `redirect`, `create_time`, `update_time`, `params`)
VALUES
(1150, 1100, '0,1100', '订单管理', 'M', 'ProxyOrder', 'order', 'proxy/order/index', NULL,
 0, 1, 1, 5, 'tickets', NULL, now(), now(), NULL),
(11501, 1150, '0,1100,1150', '订单查询', 'B', NULL, '', NULL, 'proxy:order:list',
 NULL, NULL, 1, 1, '', NULL, now(), now(), NULL),
(11502, 1150, '0,1100,1150', '订单创建', 'B', NULL, '', NULL, 'proxy:order:create',
 NULL, NULL, 1, 2, '', NULL, now(), now(), NULL),
(11503, 1150, '0,1100,1150', '订单支付', 'B', NULL, '', NULL, 'proxy:order:pay',
 NULL, NULL, 1, 3, '', NULL, now(), now(), NULL),
(11504, 1150, '0,1100,1150', '订单补偿重试', 'B', NULL, '', NULL, 'proxy:order:compensate',
 NULL, NULL, 1, 4, '', NULL, now(), now(), NULL),
(11505, 1150, '0,1100,1150', '订单取消', 'B', NULL, '', NULL, 'proxy:order:cancel',
 NULL, NULL, 1, 5, '', NULL, now(), now(), NULL)
ON DUPLICATE KEY UPDATE
`name` = VALUES(`name`),
`route_name` = VALUES(`route_name`),
`route_path` = VALUES(`route_path`),
`component` = VALUES(`component`),
`perm` = VALUES(`perm`),
`keep_alive` = VALUES(`keep_alive`),
`visible` = VALUES(`visible`),
`sort` = VALUES(`sort`),
`update_time` = now();

-- 静态代理管理
INSERT INTO `sys_menu`
(`id`, `parent_id`, `tree_path`, `name`, `type`, `route_name`, `route_path`, `component`, `perm`,
 `always_show`, `keep_alive`, `visible`, `sort`, `icon`, `redirect`, `create_time`, `update_time`, `params`)
VALUES
(1160, 1100, '0,1100', '静态代理管理', 'M', 'ProxyStaticAsset', 'static-asset', 'proxy/static-asset/index', NULL,
 0, 1, 1, 6, 'connection', NULL, now(), now(), NULL),
(11601, 1160, '0,1100,1160', '静态代理查询', 'B', NULL, '', NULL, 'proxy:static-asset:list',
 NULL, NULL, 1, 1, '', NULL, now(), now(), NULL),
(11602, 1160, '0,1100,1160', '静态代理续费', 'B', NULL, '', NULL, 'proxy:static-asset:renew',
 NULL, NULL, 1, 2, '', NULL, now(), now(), NULL),
(11603, 1160, '0,1100,1160', '静态代理维护', 'B', NULL, '', NULL, 'proxy:static-asset:update',
 NULL, NULL, 1, 3, '', NULL, now(), now(), NULL)
ON DUPLICATE KEY UPDATE
`name` = VALUES(`name`),
`route_name` = VALUES(`route_name`),
`route_path` = VALUES(`route_path`),
`component` = VALUES(`component`),
`perm` = VALUES(`perm`),
`keep_alive` = VALUES(`keep_alive`),
`visible` = VALUES(`visible`),
`sort` = VALUES(`sort`),
`update_time` = now();

-- 动态通道管理
INSERT INTO `sys_menu`
(`id`, `parent_id`, `tree_path`, `name`, `type`, `route_name`, `route_path`, `component`, `perm`,
 `always_show`, `keep_alive`, `visible`, `sort`, `icon`, `redirect`, `create_time`, `update_time`, `params`)
VALUES
(1170, 1100, '0,1100', '动态通道管理', 'M', 'ProxyDynamicChannel', 'dynamic-channel', 'proxy/dynamic-channel/index', NULL,
 0, 1, 1, 7, 'share', NULL, now(), now(), NULL),
(11701, 1170, '0,1100,1170', '动态通道查询', 'B', NULL, '', NULL, 'proxy:dynamic-channel:list',
 NULL, NULL, 1, 1, '', NULL, now(), now(), NULL),
(11702, 1170, '0,1100,1170', '动态通道维护', 'B', NULL, '', NULL, 'proxy:dynamic-channel:update',
 NULL, NULL, 1, 2, '', NULL, now(), now(), NULL)
ON DUPLICATE KEY UPDATE
`name` = VALUES(`name`),
`route_name` = VALUES(`route_name`),
`route_path` = VALUES(`route_path`),
`component` = VALUES(`component`),
`perm` = VALUES(`perm`),
`keep_alive` = VALUES(`keep_alive`),
`visible` = VALUES(`visible`),
`sort` = VALUES(`sort`),
`update_time` = now();

-- 上游供应商管理
INSERT INTO `sys_menu`
(`id`, `parent_id`, `tree_path`, `name`, `type`, `route_name`, `route_path`, `component`, `perm`,
 `always_show`, `keep_alive`, `visible`, `sort`, `icon`, `redirect`, `create_time`, `update_time`, `params`)
VALUES
(1180, 1100, '0,1100', '上游供应商管理', 'M', 'ProxyUpstreamProvider', 'upstream-provider', 'proxy/upstream-provider/index', NULL,
 0, 1, 1, 8, 'cpu', NULL, now(), now(), NULL),
(11801, 1180, '0,1100,1180', '上游供应商查询', 'B', NULL, '', NULL, 'proxy:upstream:list',
 NULL, NULL, 1, 1, '', NULL, now(), now(), NULL),
(11802, 1180, '0,1100,1180', '上游供应商新增', 'B', NULL, '', NULL, 'proxy:upstream:create',
 NULL, NULL, 1, 2, '', NULL, now(), now(), NULL),
(11803, 1180, '0,1100,1180', '上游供应商修改', 'B', NULL, '', NULL, 'proxy:upstream:update',
 NULL, NULL, 1, 3, '', NULL, now(), now(), NULL),
(11804, 1180, '0,1100,1180', '上游供应商删除', 'B', NULL, '', NULL, 'proxy:upstream:delete',
 NULL, NULL, 1, 4, '', NULL, now(), now(), NULL)
ON DUPLICATE KEY UPDATE
`name` = VALUES(`name`),
`route_name` = VALUES(`route_name`),
`route_path` = VALUES(`route_path`),
`component` = VALUES(`component`),
`perm` = VALUES(`perm`),
`keep_alive` = VALUES(`keep_alive`),
`visible` = VALUES(`visible`),
`sort` = VALUES(`sort`),
`update_time` = now();

-- 钱包管理
INSERT INTO `sys_menu`
(`id`, `parent_id`, `tree_path`, `name`, `type`, `route_name`, `route_path`, `component`, `perm`,
 `always_show`, `keep_alive`, `visible`, `sort`, `icon`, `redirect`, `create_time`, `update_time`, `params`)
VALUES
(1190, 1100, '0,1100', '钱包管理', 'M', 'ProxyWallet', 'wallet', 'proxy/wallet/index', NULL,
 0, 1, 1, 9, 'wallet', NULL, now(), now(), NULL),
(11901, 1190, '0,1100,1190', '钱包查询', 'B', NULL, '', NULL, 'proxy:wallet:list',
 NULL, NULL, 1, 1, '', NULL, now(), now(), NULL),
(11902, 1190, '0,1100,1190', '钱包加款', 'B', NULL, '', NULL, 'proxy:wallet:recharge',
 NULL, NULL, 1, 2, '', NULL, now(), now(), NULL),
(11910, 1190, '0,1100,1190', '充值订单', 'C', 'ProxyWalletRecharge', 'wallet-recharge', 'proxy/wallet-recharge/index', NULL,
 0, 1, 1, 3, 'wallet', NULL, now(), now(), NULL),
(11911, 11910, '0,1100,1190,11910', '充值订单查询', 'B', NULL, '', NULL, 'proxy:wallet:recharge-order:list',
 NULL, NULL, 1, 1, '', NULL, now(), now(), NULL)
ON DUPLICATE KEY UPDATE
`name` = VALUES(`name`),
`route_name` = VALUES(`route_name`),
`route_path` = VALUES(`route_path`),
`component` = VALUES(`component`),
`perm` = VALUES(`perm`),
`keep_alive` = VALUES(`keep_alive`),
`visible` = VALUES(`visible`),
`sort` = VALUES(`sort`),
`update_time` = now();

-- 分销管理（页面和接口后续继续补齐）
INSERT INTO `sys_menu`
(`id`, `parent_id`, `tree_path`, `name`, `type`, `route_name`, `route_path`, `component`, `perm`,
 `always_show`, `keep_alive`, `visible`, `sort`, `icon`, `redirect`, `create_time`, `update_time`, `params`)
VALUES
(1200, 1100, '0,1100', '分销管理', 'M', 'ProxyDistribution', 'distribution', 'proxy/distribution/index', NULL,
 0, 1, 1, 10, 'user-filled', NULL, now(), now(), NULL),
(12001, 1200, '0,1100,1200', '分销配置查询', 'B', NULL, '', NULL, 'proxy:distribution:list',
 NULL, NULL, 1, 1, '', NULL, now(), now(), NULL),
(12002, 1200, '0,1100,1200', '分销配置维护', 'B', NULL, '', NULL, 'proxy:distribution:update',
 NULL, NULL, 1, 2, '', NULL, now(), now(), NULL),
(12003, 1200, '0,1100,1200', '佣金流水查询', 'B', NULL, '', NULL, 'proxy:distribution:commission:list',
 NULL, NULL, 1, 3, '', NULL, now(), now(), NULL)
ON DUPLICATE KEY UPDATE
`name` = VALUES(`name`),
`route_name` = VALUES(`route_name`),
`route_path` = VALUES(`route_path`),
`component` = VALUES(`component`),
`perm` = VALUES(`perm`),
`keep_alive` = VALUES(`keep_alive`),
`visible` = VALUES(`visible`),
`sort` = VALUES(`sort`),
`update_time` = now();

-- 系统管理员授权
INSERT IGNORE INTO `sys_role_menu` (`role_id`, `menu_id`) VALUES
(2, 1100),
(2, 1110), (2, 11101), (2, 11102), (2, 11103), (2, 11104),
(2, 1120), (2, 11201), (2, 11202), (2, 11203), (2, 11204),
(2, 1130), (2, 11301), (2, 11302), (2, 11303), (2, 11304),
(2, 1140), (2, 11401), (2, 11402), (2, 11403), (2, 11404),
(2, 1150), (2, 11501), (2, 11502), (2, 11503), (2, 11504), (2, 11505),
(2, 1160), (2, 11601), (2, 11602), (2, 11603),
(2, 1170), (2, 11701), (2, 11702),
(2, 1180), (2, 11801), (2, 11802), (2, 11803), (2, 11804),
(2, 1190), (2, 11901), (2, 11902),
(2, 1200), (2, 12001), (2, 12002), (2, 12003);
