-- 提成结算：核对/确定业绩接口权限（挂在 fans/commission-settlement 页面菜单下）

SET @commission_cs_pid := (
    SELECT id FROM `zyt_system_menu` WHERE component = 'fans/commission-settlement' ORDER BY id DESC LIMIT 1
);

INSERT INTO `zyt_system_menu`
(`pid`, `type`, `name`, `icon`, `sort`, `perms`, `paths`, `component`, `selected`, `params`, `is_show`, `is_disable`, `create_time`, `update_time`)
SELECT
    @commission_cs_pid,
    'A',
    '提成结算-核对明细',
    '',
    11,
    'stats.commissionSettlement/orderLines',
    '',
    '',
    '',
    '',
    1,
    0,
    UNIX_TIMESTAMP(),
    UNIX_TIMESTAMP()
FROM (SELECT 1 AS `_`) AS `_exec`
WHERE @commission_cs_pid IS NOT NULL
  AND NOT EXISTS (
      SELECT 1 FROM `zyt_system_menu` m
      WHERE m.pid = @commission_cs_pid AND m.perms = 'stats.commissionSettlement/orderLines'
  );

INSERT INTO `zyt_system_menu`
(`pid`, `type`, `name`, `icon`, `sort`, `perms`, `paths`, `component`, `selected`, `params`, `is_show`, `is_disable`, `create_time`, `update_time`)
SELECT
    @commission_cs_pid,
    'A',
    '提成结算-确认状态',
    '',
    12,
    'stats.commissionSettlement/confirmStatus',
    '',
    '',
    '',
    '',
    1,
    0,
    UNIX_TIMESTAMP(),
    UNIX_TIMESTAMP()
FROM (SELECT 1 AS `_`) AS `_exec`
WHERE @commission_cs_pid IS NOT NULL
  AND NOT EXISTS (
      SELECT 1 FROM `zyt_system_menu` m
      WHERE m.pid = @commission_cs_pid AND m.perms = 'stats.commissionSettlement/confirmStatus'
  );

INSERT INTO `zyt_system_menu`
(`pid`, `type`, `name`, `icon`, `sort`, `perms`, `paths`, `component`, `selected`, `params`, `is_show`, `is_disable`, `create_time`, `update_time`)
SELECT
    @commission_cs_pid,
    'A',
    '提成结算-保存核对',
    '',
    13,
    'stats.commissionSettlement/saveReconcile',
    '',
    '',
    '',
    '',
    1,
    0,
    UNIX_TIMESTAMP(),
    UNIX_TIMESTAMP()
FROM (SELECT 1 AS `_`) AS `_exec`
WHERE @commission_cs_pid IS NOT NULL
  AND NOT EXISTS (
      SELECT 1 FROM `zyt_system_menu` m
      WHERE m.pid = @commission_cs_pid AND m.perms = 'stats.commissionSettlement/saveReconcile'
  );

INSERT INTO `zyt_system_menu`
(`pid`, `type`, `name`, `icon`, `sort`, `perms`, `paths`, `component`, `selected`, `params`, `is_show`, `is_disable`, `create_time`, `update_time`)
SELECT
    @commission_cs_pid,
    'A',
    '提成结算-确定业绩',
    '',
    14,
    'stats.commissionSettlement/confirmFinalize',
    '',
    '',
    '',
    '',
    1,
    0,
    UNIX_TIMESTAMP(),
    UNIX_TIMESTAMP()
FROM (SELECT 1 AS `_`) AS `_exec`
WHERE @commission_cs_pid IS NOT NULL
  AND NOT EXISTS (
      SELECT 1 FROM `zyt_system_menu` m
      WHERE m.pid = @commission_cs_pid AND m.perms = 'stats.commissionSettlement/confirmFinalize'
  );
