IF NOT EXISTS (SELECT 1 FROM cyhq_sys_Menu WHERE Id = 3001)
BEGIN
    INSERT INTO cyhq_sys_Menu
    (
        Id,
        Name,
        Url,
        ParentId,
        [Type],
        [Order],
        SystemType
    )
    VALUES
    (3001, '品牌设置', '', 100, 0, 1, 'ZB,');
END;

UPDATE cyhq_sys_Menu
SET ParentId = 3001
WHERE Id IN ( 10004 );
IF NOT EXISTS (SELECT 1 FROM cyhq_sys_Menu WHERE Id = 3002)
BEGIN
    INSERT INTO cyhq_sys_Menu
    (
        Id,
        Name,
        Url,
        ParentId,
        [Type],
        [Order],
        SystemType
    )
    VALUES
    (3002, '机构设置', '', 100, 0, 2, 'ZB,');
END;
UPDATE cyhq_sys_Menu
SET ParentId = 3002
WHERE Id IN ( 10000, 10001, 10002, 10003, 10008 );
UPDATE cyhq_sys_Menu
SET Name = '配送机构'
WHERE Id = 10003;
UPDATE cyhq_sys_Menu
SET Name = '会员机构'
WHERE Id = 10008;
IF NOT EXISTS (SELECT 1 FROM cyhq_sys_Menu WHERE Id = 3003)
BEGIN
    INSERT INTO cyhq_sys_Menu
    (
        Id,
        Name,
        Url,
        ParentId,
        [Type],
        [Order],
        SystemType
    )
    VALUES
    (3003, '其他资料', '', 1, 0, 3, 'ZB,');
END;
UPDATE cyhq_sys_Menu
SET ParentId = 3003
WHERE Id IN ( 105, 106, 107, 108, 111 );

IF NOT EXISTS (SELECT 1 FROM cyhq_sys_Menu WHERE Id = 3004)
BEGIN
    INSERT INTO cyhq_sys_Menu
    (
        Id,
        Name,
        Url,
        ParentId,
        [Type],
        [Order],
        SystemType
    )
    VALUES
    (3004, '数据检验', '', 1, 0, 4, 'ZB,');
END;
UPDATE cyhq_sys_Menu
SET ParentId = 3004
WHERE Id IN ( 109 );

IF NOT EXISTS (SELECT 1 FROM cyhq_sys_Menu WHERE Id = 3005)
BEGIN
    INSERT INTO cyhq_sys_Menu
    (
        Id,
        Name,
        Url,
        ParentId,
        [Type],
        [Order],
        SystemType
    )
    VALUES
    (3005, '门店数据', '', 2, 0, 4, 'ZB,');
END;
UPDATE cyhq_sys_Menu
SET ParentId = 3005
WHERE Id IN ( 200, 212, 210, 220 );

UPDATE cyhq_sys_Menu
SET Name = '品项范围'
WHERE Id = 200;
UPDATE cyhq_sys_Menu
SET Name = '物料范围'
WHERE Id = 212;
UPDATE cyhq_sys_Menu
SET Name = '收银范围'
WHERE Id = 210;
UPDATE cyhq_sys_Menu
SET Name = '品项历史价格'
WHERE Id = 20102;
UPDATE cyhq_sys_Menu
SET Name = '品项价格'
WHERE Id = 201;


IF NOT EXISTS (SELECT 1 FROM cyhq_sys_Menu WHERE Id = 3006)
BEGIN
    INSERT INTO cyhq_sys_Menu
    (
        Id,
        Name,
        Url,
        ParentId,
        [Type],
        [Order],
        SystemType
    )
    VALUES
    (3006, '外卖设置', '', 2, 0, 6, 'ZB,');
END;
UPDATE cyhq_sys_Menu
SET ParentId = 3006
WHERE Id IN ( 203, 223 );

UPDATE cyhq_sys_Menu
SET Name = '外卖品项设置'
WHERE Id = 203;
UPDATE cyhq_sys_Menu
SET Name = '外卖配送费'
WHERE Id = 223;

IF NOT EXISTS (SELECT 1 FROM cyhq_sys_Menu WHERE Id = 3007)
BEGIN
    INSERT INTO cyhq_sys_Menu
    (
        Id,
        Name,
        Url,
        ParentId,
        [Type],
        [Order],
        SystemType
    )
    VALUES
    (3007, '促销设置', '', 2, 0, 7, 'ZB,');
END;
UPDATE cyhq_sys_Menu
SET ParentId = 3007
WHERE Id IN ( 202, 20301, 204, 205, 206, 207, 208, 211, 213 );
IF NOT EXISTS (SELECT 1 FROM cyhq_sys_Menu WHERE Id = 3008)
BEGIN
    INSERT INTO cyhq_sys_Menu
    (
        Id,
        Name,
        Url,
        ParentId,
        [Type],
        [Order],
        SystemType
    )
    VALUES
    (3008, '其他数据', '', 2, 0, 8, 'ZB,');
END;
UPDATE cyhq_sys_Menu
SET ParentId = 3008
WHERE Id IN ( 221, 224 );

UPDATE cyhq_sys_Menu
SET Name = '熟客资料'
WHERE Id = 221;

IF NOT EXISTS (SELECT 1 FROM cyhq_sys_Menu WHERE Id = 3009)
BEGIN
    INSERT INTO cyhq_sys_Menu
    (
        Id,
        Name,
        Url,
        ParentId,
        [Type],
        [Order],
        SystemType
    )
    VALUES
    (3009, '美广设置', '', 18, 0, 9, 'ZB,');
END;
UPDATE cyhq_sys_Menu
SET ParentId = 3009
WHERE Id IN ( 1801 );
UPDATE cyhq_sys_Menu
SET Name = '美广管理'
WHERE Id = 1802;

UPDATE cyhq_sys_Menu
SET ParentId = 89201
WHERE Id IN ( 8920425, 8920639 );

UPDATE cyhq_sys_Menu
SET Name = '品项做法查询'
WHERE Id = 8920210;
UPDATE cyhq_sys_Menu
SET Name = '品项加料查询'
WHERE Id = 8920211;

UPDATE cyhq_sys_Menu
SET Name = '门店移动支付开通统计'
WHERE Id = 8920610;
UPDATE cyhq_sys_Menu
SET Name = '门店升级监控'
WHERE Id = 8920640;

IF NOT EXISTS (SELECT 1 FROM cyhq_sys_Menu WHERE Id = 3010)
BEGIN
    INSERT INTO cyhq_sys_Menu
    (
        Id,
        Name,
        Url,
        ParentId,
        [Type],
        [Order],
        SystemType
    )
    VALUES
    (3010, '营业额分析', '', 9, 0, 10, 'ZB,');
END;
UPDATE cyhq_sys_Menu
SET ParentId = 3010
WHERE Id IN ( 900, 901, 908, 909 );

IF NOT EXISTS (SELECT 1 FROM cyhq_sys_Menu WHERE Id = 3011)
BEGIN
    INSERT INTO cyhq_sys_Menu
    (
        Id,
        Name,
        Url,
        ParentId,
        [Type],
        [Order],
        SystemType
    )
    VALUES
    (3011, '消费额分析', '', 9, 0, 11, 'ZB,');
END;
UPDATE cyhq_sys_Menu
SET ParentId = 3011
WHERE Id IN ( 904, 905, 911 );

IF NOT EXISTS (SELECT 1 FROM cyhq_sys_Menu WHERE Id = 3012)
BEGIN
    INSERT INTO cyhq_sys_Menu
    (
        Id,
        Name,
        Url,
        ParentId,
        [Type],
        [Order],
        SystemType
    )
    VALUES
    (3012, '数量分析', '', 9, 0, 12, 'ZB,');
END;
UPDATE cyhq_sys_Menu
SET ParentId = 3012
WHERE Id IN ( 902, 903, 906, 907, 910 );

IF NOT EXISTS (SELECT 1 FROM cyhq_sys_Menu WHERE Id = 3013)
BEGIN
    INSERT INTO cyhq_sys_Menu
    (
        Id,
        Name,
        Url,
        ParentId,
        [Type],
        [Order],
        SystemType
    )
    VALUES
    (3013, '人员管理', '', 99, 0, 13, 'ZB,');
END;
UPDATE cyhq_sys_Menu
SET ParentId = 3013
WHERE Id IN ( 9900, 990100, 990101, 990202 );

UPDATE cyhq_sys_Menu
SET ParentId = 3013333
WHERE Id IN ( 9902, 9901 );

IF NOT EXISTS (SELECT 1 FROM cyhq_sys_Menu WHERE Id = 3014)
BEGIN
    INSERT INTO cyhq_sys_Menu
    (
        Id,
        Name,
        Url,
        ParentId,
        [Type],
        [Order],
        SystemType
    )
    VALUES
    (3014, '权限管理', '', 99, 0, 14, 'ZB,');
END;
UPDATE cyhq_sys_Menu
SET ParentId = 3014
WHERE Id IN ( 990104, 990102, 990103 );


UPDATE cyhq_sys_Menu
SET Name = '权限角色设置'
WHERE Id = 990104;

UPDATE cyhq_sys_Menu
SET Name = '操作员及权限设置'
WHERE Id = 990102;


IF NOT EXISTS (SELECT 1 FROM cyhq_sys_Menu WHERE Id = 3015)
BEGIN
    INSERT INTO cyhq_sys_Menu
    (
        Id,
        Name,
        Url,
        ParentId,
        [Type],
        [Order],
        SystemType
    )
    VALUES
    (3015, '系统管理', '', 99, 0, 15, 'ZB,');
END;
UPDATE cyhq_sys_Menu
SET ParentId = 3015
WHERE Id IN ( 9907, 9905, 9906, 9908, 9910, 9909, 990106, 990107 );


UPDATE cyhq_sys_Menu
SET Name = '操作员在线列表'
WHERE Id = 9910;

UPDATE cyhq_sys_Menu
SET Name = '软件下载管理'
WHERE Id = 9909;
UPDATE cyhq_sys_Menu
SET Name = '移动POS3直连总部服务'
WHERE Id = 990106;

IF NOT EXISTS (SELECT 1 FROM cyhq_sys_Menu WHERE Id = 3016)
BEGIN
    INSERT INTO cyhq_sys_Menu
    (
        Id,
        Name,
        Url,
        ParentId,
        [Type],
        [Order],
        SystemType
    )
    VALUES
    (3016, '其它管理', '', 99, 0, 16, 'ZB,');
END;
UPDATE cyhq_sys_Menu
SET ParentId = 3016
WHERE Id IN ( 9914, 9915 );

UPDATE cyhq_sys_Menu
SET IconCls = 'icon-report2'
WHERE Id = 10;

UPDATE cyhq_sys_Menu
SET IconCls = 'icon-cog2'
WHERE Id = 99;

IF NOT EXISTS (SELECT 1 FROM cyhq_sys_Menu WHERE Id = 3017)
BEGIN
    INSERT INTO cyhq_sys_Menu
    (
        Id,
        Name,
        Url,
        ParentId,
        [Type],
        [Order],
        SystemType
    )
    VALUES
    (3017, '仓库基础数据', '', 1, 0, 17, 'GYL,');
END;

UPDATE cyhq_sys_Menu
SET ParentId = 3017
WHERE Id IN ( 10204, 60000 );

UPDATE cyhq_sys_Menu
SET Name = '账务报表'
WHERE Id = 40003;
UPDATE cyhq_sys_Menu
SET Name = '预付款管理'
WHERE Id = 40004;
UPDATE cyhq_sys_Menu
SET Name = '历史价查询'
WHERE Id = 40101;

IF NOT EXISTS (SELECT 1 FROM cyhq_sys_Menu WHERE Id = 3018)
BEGIN
    INSERT INTO cyhq_sys_Menu
    (
        Id,
        Name,
        Url,
        ParentId,
        [Type],
        [Order],
        SystemType
    )
    VALUES
    (3018, '采购单据', '', 4, 0, 18, 'GYL,');
END;

UPDATE cyhq_sys_Menu
SET ParentId = 3018
WHERE Id IN ( 40201, 40202, 403, 404, 405 );

UPDATE cyhq_sys_Menu
SET ParentId = 3013333
WHERE Id IN ( 402 );

UPDATE cyhq_sys_Menu
SET Name = '申购单处理'
WHERE Id = 40201;
UPDATE cyhq_sys_Menu
SET Name = '退货申请单处理'
WHERE Id = 40202;
UPDATE cyhq_sys_Menu
SET Name = '采购订单'
WHERE Id = 403;
UPDATE cyhq_sys_Menu
SET Name = '采购入库单'
WHERE Id = 404;
UPDATE cyhq_sys_Menu
SET Name = '采购退货单'
WHERE Id = 405;

IF NOT EXISTS (SELECT 1 FROM cyhq_sys_Menu WHERE Id = 3019)
BEGIN
    INSERT INTO cyhq_sys_Menu
    (
        Id,
        Name,
        Url,
        ParentId,
        [Type],
        [Order],
        SystemType
    )
    VALUES
    (3019, '采购报表', '', 4, 0, 19, 'GYL,');
END;

UPDATE cyhq_sys_Menu
SET ParentId = 3019
WHERE Id IN ( 100100, 100101, 100102, 100103 );

UPDATE cyhq_sys_Menu
SET ParentId = 3013333
WHERE Id IN ( 402 );

UPDATE cyhq_sys_Menu
SET Name = '批次库存查询'
WHERE Id = 100102;

UPDATE cyhq_sys_Menu
SET Name = '订单状态报表'
WHERE Id = 100103;

IF NOT EXISTS (SELECT 1 FROM cyhq_sys_Menu WHERE Id = 3020)
BEGIN
    INSERT INTO cyhq_sys_Menu
    (
        Id,
        Name,
        Url,
        ParentId,
        [Type],
        [Order],
        SystemType
    )
    VALUES
    (3020, '加工品管理', '', 5, 0, 20, 'GYL,');
END;

UPDATE cyhq_sys_Menu
SET ParentId = 3020
WHERE Id IN ( 500, 501 );



UPDATE cyhq_sys_Menu
SET Name = '配方管理'
WHERE Id = 500;
UPDATE cyhq_sys_Menu
SET Name = '入库价管理'
WHERE Id = 501;

IF NOT EXISTS (SELECT 1 FROM cyhq_sys_Menu WHERE Id = 3021)
BEGIN
    INSERT INTO cyhq_sys_Menu
    (
        Id,
        Name,
        Url,
        ParentId,
        [Type],
        [Order],
        SystemType
    )
    VALUES
    (3021, '加工单据', '', 5, 0, 21, 'GYL,');
END;

UPDATE cyhq_sys_Menu
SET ParentId = 3020
WHERE Id IN ( 502, 503, 504 );



UPDATE cyhq_sys_Menu
SET Name = '加工领料单'
WHERE Id = 502;
UPDATE cyhq_sys_Menu
SET Name = '加工退料单'
WHERE Id = 503;
UPDATE cyhq_sys_Menu
SET Name = '加工入库单'
WHERE Id = 504;

IF NOT EXISTS (SELECT 1 FROM cyhq_sys_Menu WHERE Id = 3022)
BEGIN
    INSERT INTO cyhq_sys_Menu
    (
        Id,
        Name,
        Url,
        ParentId,
        [Type],
        [Order],
        SystemType
    )
    VALUES
    (3022, '加工报表', '', 5, 0, 22, 'GYL,');
END;

UPDATE cyhq_sys_Menu
SET ParentId = 3022
WHERE Id IN ( 100300, 100301 );



UPDATE cyhq_sys_Menu
SET Name = '单据查询'
WHERE Id = 100300;

IF NOT EXISTS (SELECT 1 FROM cyhq_sys_Menu WHERE Id = 3023)
BEGIN
    INSERT INTO cyhq_sys_Menu
    (
        Id,
        Name,
        Url,
        ParentId,
        [Type],
        [Order],
        SystemType
    )
    VALUES
    (3023, '库存初始化管理', '', 6, 0, 23, 'GYL,');
END;

UPDATE cyhq_sys_Menu
SET ParentId = 3023
WHERE Id IN ( 60001 );

IF NOT EXISTS (SELECT 1 FROM cyhq_sys_Menu WHERE Id = 3024)
BEGIN
    INSERT INTO cyhq_sys_Menu
    (
        Id,
        Name,
        Url,
        ParentId,
        [Type],
        [Order],
        SystemType
    )
    VALUES
    (3024, '仓库申请', '', 6, 0, 24, 'GYL,');
END;

UPDATE cyhq_sys_Menu
SET ParentId = 3024
WHERE Id IN ( 601 );

UPDATE cyhq_sys_Menu
SET Name = '库存单据'
WHERE Id = 602;

IF NOT EXISTS (SELECT 1 FROM cyhq_sys_Menu WHERE Id = 3025)
BEGIN
    INSERT INTO cyhq_sys_Menu
    (
        Id,
        Name,
        Url,
        ParentId,
        [Type],
        [Order],
        SystemType
    )
    VALUES
    (3025, '库存报表', '', 6, 0, 25, 'GYL,');
END;

UPDATE cyhq_sys_Menu
SET ParentId = 3025
WHERE Id IN ( 608, 100200, 100201, 100202 );

UPDATE cyhq_sys_Menu
SET Name = '物料库存告警分析'
WHERE Id = 608;

UPDATE cyhq_sys_Menu
SET ParentId = 708
WHERE Id IN ( 70801, 70802, 709, 70105, 707 );


UPDATE cyhq_sys_Menu
SET ParentId = 3013333
WHERE Id IN ( 7010000 );

UPDATE cyhq_sys_Menu
SET Name = '配送池'
WHERE Id = 708;
UPDATE cyhq_sys_Menu
SET Name = '要货按单处理'
WHERE Id = 70801;
UPDATE cyhq_sys_Menu
SET Name = '要货批量处理'
WHERE Id = 70802;
UPDATE cyhq_sys_Menu
SET Name = '要货单追踪查询'
WHERE Id = 707;

IF NOT EXISTS (SELECT 1 FROM cyhq_sys_Menu WHERE Id = 3026)
BEGIN
    INSERT INTO cyhq_sys_Menu
    (
        Id,
        Name,
        Url,
        ParentId,
        [Type],
        [Order],
        SystemType
    )
    VALUES
    (3026, '配送单据', '', 7, 0, 26, 'GYL,');
END;

UPDATE cyhq_sys_Menu
SET ParentId = 3026
WHERE Id IN ( 70102, 70103, 70104, 70202 );

IF NOT EXISTS (SELECT 1 FROM cyhq_sys_Menu WHERE Id = 3027)
BEGIN
    INSERT INTO cyhq_sys_Menu
    (
        Id,
        Name,
        Url,
        ParentId,
        [Type],
        [Order],
        SystemType
    )
    VALUES
    (3027, '配送报表', '', 7, 0, 27, 'GYL,');
END;

UPDATE cyhq_sys_Menu
SET ParentId = 3027
WHERE Id IN ( 100400, 100401, 100402 );

IF NOT EXISTS (SELECT 1 FROM cyhq_sys_Menu WHERE Id = 3028)
BEGIN
    INSERT INTO cyhq_sys_Menu
    (
        Id,
        Name,
        Url,
        ParentId,
        [Type],
        [Order],
        SystemType
    )
    VALUES
    (3028, '调拨报表', '', 11, 0, 28, 'GYL,');
END;

UPDATE cyhq_sys_Menu
SET ParentId = 3028
WHERE Id IN ( 111060, 111070 );


UPDATE cyhq_sys_Menu
SET Name = '调入管理'
WHERE Id = 1109;
UPDATE cyhq_sys_Menu
SET Name = '调出管理'
WHERE Id = 1110;
UPDATE cyhq_sys_Menu
SET Name = '调拨结算'
WHERE Id = 111040;
UPDATE cyhq_sys_Menu
SET Name = '调拨结算报表'
WHERE Id = 111050;
UPDATE cyhq_sys_Menu
SET Name = '调拨报表'
WHERE Id = 111060;
UPDATE cyhq_sys_Menu
SET Name = '调拨差异分析'
WHERE Id = 111070;

UPDATE cyhq_sys_Menu
SET ParentId = 111071
WHERE Id IN ( 111030 );

UPDATE cyhq_sys_Menu
SET Name = '调拨差异处理'
WHERE Id = 111030;

IF NOT EXISTS (SELECT 1 FROM cyhq_sys_Menu WHERE Id = 3029)
BEGIN
    INSERT INTO cyhq_sys_Menu
    (
        Id,
        Name,
        Url,
        ParentId,
        [Type],
        [Order],
        SystemType
    )
    VALUES
    (3029, '参数设置', '', 3, 0, 29, 'HY,');
END;

UPDATE cyhq_sys_Menu
SET ParentId = 3029
WHERE Id IN ( 300 );

IF NOT EXISTS (SELECT 1 FROM cyhq_sys_Menu WHERE Id = 3030)
BEGIN
    INSERT INTO cyhq_sys_Menu
    (
        Id,
        Name,
        Url,
        ParentId,
        [Type],
        [Order],
        SystemType
    )
    VALUES
    (3030, '资料管理', '', 3, 0, 30, 'HY,');
END;

UPDATE cyhq_sys_Menu
SET ParentId = 3030
WHERE Id IN ( 30100, 30101, 30102, 306 );

IF NOT EXISTS (SELECT 1 FROM cyhq_sys_Menu WHERE Id = 3031)
BEGIN
    INSERT INTO cyhq_sys_Menu
    (
        Id,
        Name,
        Url,
        ParentId,
        [Type],
        [Order],
        SystemType
    )
    VALUES
    (3031, '营销数据', '', 12, 0, 31, 'HY,');
END;

UPDATE cyhq_sys_Menu
SET ParentId = 3031
WHERE Id IN ( 1202, 1210 );

IF NOT EXISTS (SELECT 1 FROM cyhq_sys_Menu WHERE Id = 3032)
BEGIN
    INSERT INTO cyhq_sys_Menu
    (
        Id,
        Name,
        Url,
        ParentId,
        [Type],
        [Order],
        SystemType
    )
    VALUES
    (3032, '营销业务', '', 12, 0, 32, 'HY,');
END;

UPDATE cyhq_sys_Menu
SET ParentId = 3032
WHERE Id IN ( 1217, 1218, 1219, 1222, 1223, 1220 );

UPDATE cyhq_sys_Menu
SET Name = '会员拉新营销'
WHERE Id = 1219;
UPDATE cyhq_sys_Menu
SET Name = '会员分销'
WHERE Id = 1222;

UPDATE cyhq_sys_Menu
SET Name = '老带新提现报表'
WHERE Id = 121409;

IF NOT EXISTS (SELECT 1 FROM cyhq_sys_Menu WHERE Id = 3033)
BEGIN
    INSERT INTO cyhq_sys_Menu
    (
        Id,
        Name,
        Url,
        ParentId,
        [Type],
        [Order],
        SystemType
    )
    VALUES
    (3033, 'Plus设置', '', 17, 0, 33, 'HY,');
END;

UPDATE cyhq_sys_Menu
SET ParentId = 3033
WHERE Id IN ( 1701, 1703 );

IF NOT EXISTS (SELECT 1 FROM cyhq_sys_Menu WHERE Id = 3034)
BEGIN
    INSERT INTO cyhq_sys_Menu
    (
        Id,
        Name,
        Url,
        ParentId,
        [Type],
        [Order],
        SystemType
    )
    VALUES
    (3034, 'Plus营销', '', 17, 0, 34, 'HY,');
END;

UPDATE cyhq_sys_Menu
SET ParentId = 3034
WHERE Id IN ( 1704, 1705 );

IF NOT EXISTS (SELECT 1 FROM cyhq_sys_Menu WHERE Id = 3035)
BEGIN
    INSERT INTO cyhq_sys_Menu
    (
        Id,
        Name,
        Url,
        ParentId,
        [Type],
        [Order],
        SystemType
    )
    VALUES
    (3035, '规则设置', '', 304, 0, 35, 'HY,');
END;

UPDATE cyhq_sys_Menu
SET ParentId = 3035
WHERE Id IN ( 30411, 304123 );

IF NOT EXISTS (SELECT 1 FROM cyhq_sys_Menu WHERE Id = 3036)
BEGIN
    INSERT INTO cyhq_sys_Menu
    (
        Id,
        Name,
        Url,
        ParentId,
        [Type],
        [Order],
        SystemType
    )
    VALUES
    (3036, '积分管理', '', 304, 0, 36, 'HY,');
END;

UPDATE cyhq_sys_Menu
SET ParentId = 3036
WHERE Id IN ( 30400, 30412 );

UPDATE cyhq_sys_Menu
SET Name = '积分报表'
WHERE Id = 30412;

IF NOT EXISTS (SELECT 1 FROM cyhq_sys_Menu WHERE Id = 3037)
BEGIN
    INSERT INTO cyhq_sys_Menu
    (
        Id,
        Name,
        Url,
        ParentId,
        [Type],
        [Order],
        SystemType
    )
    VALUES
    (3037, '商城业务', '', 314, 0, 37, 'HY,');
END;

UPDATE cyhq_sys_Menu
SET ParentId = 3037
WHERE Id IN ( 31403, 31404 );

IF NOT EXISTS (SELECT 1 FROM cyhq_sys_Menu WHERE Id = 3038)
BEGIN
    INSERT INTO cyhq_sys_Menu
    (
        Id,
        Name,
        Url,
        ParentId,
        [Type],
        [Order],
        SystemType
    )
    VALUES
    (3038, '充值额度', '', 303, 0, 38, 'HY,');
END;

UPDATE cyhq_sys_Menu
SET ParentId = 3038
WHERE Id IN ( 30302 );

IF NOT EXISTS (SELECT 1 FROM cyhq_sys_Menu WHERE Id = 3039)
BEGIN
    INSERT INTO cyhq_sys_Menu
    (
        Id,
        Name,
        Url,
        ParentId,
        [Type],
        [Order],
        SystemType
    )
    VALUES
    (3039, '充值业务', '', 303, 0, 39, 'HY,');
END;

UPDATE cyhq_sys_Menu
SET ParentId = 3039
WHERE Id IN ( 30300, 30303, 30315, 30316, 30317 );

IF NOT EXISTS (SELECT 1 FROM cyhq_sys_Menu WHERE Id = 3040)
BEGIN
    INSERT INTO cyhq_sys_Menu
    (
        Id,
        Name,
        Url,
        ParentId,
        [Type],
        [Order],
        SystemType
    )
    VALUES
    (3040, '计量（计次）管理', '', 0, 0, 40, 'HY,');
END;

UPDATE cyhq_sys_Menu
SET ParentId = 3040
WHERE Id IN ( 311, 305 );

IF NOT EXISTS (SELECT 1 FROM cyhq_sys_Menu WHERE Id = 3041)
BEGIN
    INSERT INTO cyhq_sys_Menu
    (
        Id,
        Name,
        Url,
        ParentId,
        [Type],
        [Order],
        SystemType
    )
    VALUES
    (3041, '挂账管理设置', '', 302, 0, 41, 'HY,');
END;

UPDATE cyhq_sys_Menu
SET ParentId = 3041
WHERE Id IN ( 30200, 30201, 30202, 30203 );

IF NOT EXISTS (SELECT 1 FROM cyhq_sys_Menu WHERE Id = 3042)
BEGIN
    INSERT INTO cyhq_sys_Menu
    (
        Id,
        Name,
        Url,
        ParentId,
        [Type],
        [Order],
        SystemType
    )
    VALUES
    (3042, '会员业务报表', '', 313, 0, 42, 'HY,');
END;

UPDATE cyhq_sys_Menu
SET ParentId = 3042
WHERE Id IN ( 309, 310, 31311, 31312, 31313, 31314 );

UPDATE cyhq_sys_Menu
SET Name = '计量/次管理'
WHERE Id = 3040;

UPDATE cyhq_sys_Menu
SET IconCls = 'ic_hyplus'
WHERE Id = 17;

UPDATE cyhq_sys_Menu
SET IconCls = 'ic_jfsc'
WHERE Id = 314;

UPDATE cyhq_sys_Menu
SET IconCls = 'ic_jlgl'
WHERE Id = 3040;
UPDATE cyhq_sys_Menu
SET IconCls = 'icon-report2'
WHERE Id = 1000;

IF NOT EXISTS (SELECT 1 FROM cyhq_sys_Menu WHERE Id = 3043)
BEGIN
    INSERT INTO cyhq_sys_Menu
    (
        Id,
        Name,
        Url,
        ParentId,
        [Type],
        [Order],
        SystemType
    )
    VALUES
    (3043, '基础资料', '', 2, 0, 43, 'MDHT,');
END;

UPDATE cyhq_sys_Menu
SET ParentId = 3043
WHERE Id IN ( 214, 215, 216 );

IF NOT EXISTS (SELECT 1 FROM cyhq_sys_Menu WHERE Id = 3044)
BEGIN
    INSERT INTO cyhq_sys_Menu
    (
        Id,
        Name,
        Url,
        ParentId,
        [Type],
        [Order],
        SystemType
    )
    VALUES
    (3044, '价格设置', '', 2, 0, 44, 'MDHT,');
END;

UPDATE cyhq_sys_Menu
SET ParentId = 3044
WHERE Id IN ( 217, 222 );

IF NOT EXISTS (SELECT 1 FROM cyhq_sys_Menu WHERE Id = 3045)
BEGIN
    INSERT INTO cyhq_sys_Menu
    (
        Id,
        Name,
        Url,
        ParentId,
        [Type],
        [Order],
        SystemType
    )
    VALUES
    (3045, '微餐厅设置', '', 2, 0, 45, 'MDHT,');
END;

UPDATE cyhq_sys_Menu
SET ParentId = 3045
WHERE Id IN ( 218, 219, 225 );

UPDATE cyhq_sys_Menu
SET SystemType = 'ZB,MDHT,'
WHERE Id IN ( 3010, 3011, 3012 );

IF NOT EXISTS (SELECT 1 FROM cyhq_sys_Menu WHERE Id = 3046)
BEGIN
    INSERT INTO cyhq_sys_Menu
    (
        Id,
        Name,
        Url,
        ParentId,
        [Type],
        [Order],
        SystemType
    )
    VALUES
    (3046, '门店物料报表', '', 1000, 0, 46, 'MDHT,');
END;

UPDATE cyhq_sys_Menu
SET ParentId = 3046
WHERE Id IN ( 100000, 100001, 100002, 100003, 100004, 100005, 100006, 100007 );

UPDATE cyhq_sys_Menu
SET ParentId = 3003
WHERE Id IN ( 10009 );

UPDATE cyhq_sys_Menu
SET ParentId = 101
WHERE Id IN ( 104 );

UPDATE cyhq_sys_Menu
SET Name = '门店供应商'
WHERE Id = 10203;

UPDATE cyhq_sys_Menu
SET Name = '反结账记录查询'
WHERE Id = 8920639;
UPDATE cyhq_sys_Menu
SET Name = '宴席数据查询'
WHERE Id = 8920121;

UPDATE cyhq_sys_Menu
SET Name = '门店移动支付开通记录'
WHERE Id = 8920610;

UPDATE cyhq_sys_Menu
SET Name = '数据分析'
WHERE Id = 9;

UPDATE cyhq_sys_Menu
SET Name = '单均/人均消费趋势图'
WHERE Id = 904;

UPDATE cyhq_sys_Menu
SET Name = '市别单均消费趋势图'
WHERE Id = 911;

UPDATE cyhq_sys_Menu
SET Name = '交易/来客数量趋势图'
WHERE Id = 902;

UPDATE cyhq_sys_Menu
SET Name = '系统管理'
WHERE Id = 99;

UPDATE cyhq_sys_Menu
SET Name = '系统设置'
WHERE Id = 3015;

UPDATE cyhq_sys_Menu
SET ParentId = 99,
    Name = '供应商平台管理',
    [Order] = 17
WHERE Id IN ( 14 );

UPDATE cyhq_sys_Menu
SET [Order] = 10003
WHERE Id = 10003;
UPDATE cyhq_sys_Menu
SET [Order] = 103.3
WHERE Id = 3003;

UPDATE cyhq_sys_Menu
SET [Order] = 103.4
WHERE Id = 3004;

UPDATE cyhq_sys_Menu
SET ParentId = 101,
    Name = '品项配方'
WHERE Id IN ( 104 );

UPDATE cyhq_sys_Menu
SET [Order] = 10104.00
WHERE Id = 104;
UPDATE cyhq_sys_Menu
SET [Order] = 10101.1
WHERE Id = 10100;

UPDATE cyhq_sys_Menu
SET [Order] = 10201.1
WHERE Id = 10200;

UPDATE cyhq_sys_Menu
SET [Order] = 106.1
WHERE Id = 105;

UPDATE cyhq_sys_Menu
SET [Order] = 5
WHERE Id = 201;

UPDATE cyhq_sys_Menu
SET [Order] = 3
WHERE Id = 18;

UPDATE cyhq_sys_Menu
SET ParentId = 3017,
    Name = '物料默认仓库'
WHERE Id = 10204;

UPDATE cyhq_sys_Menu
SET Name = '供应商预付款'
WHERE Id = 40004;

UPDATE cyhq_sys_Menu
SET [Order] = 402
WHERE Id = 3018;
UPDATE cyhq_sys_Menu
SET [Order] = 403
WHERE Id = 3019;

UPDATE cyhq_sys_Menu
SET Name = '基础数据'
WHERE Id = 3020;
UPDATE cyhq_sys_Menu
SET Name = '加工品配方'
WHERE Id = 500;
UPDATE cyhq_sys_Menu
SET Name = '加工品价格设置'
WHERE Id = 501;

UPDATE cyhq_sys_Menu
SET ParentId = 3021
WHERE Id IN ( 502, 503, 504 );

UPDATE cyhq_sys_Menu
SET Name = '采购/退货申请'
WHERE Id = 601;

UPDATE cyhq_sys_Menu
SET [Order] = 605
WHERE Id = 3025;

UPDATE cyhq_sys_Menu
SET Name = '价格管理'
WHERE Id = 700;

UPDATE cyhq_sys_Menu
SET [Order] = 700.02
WHERE Id = 3026;
UPDATE cyhq_sys_Menu
SET [Order] = 700.03
WHERE Id = 3027;



UPDATE cyhq_sys_Menu
SET Name = '老带新返佣统计'
WHERE Id = 121405;

UPDATE cyhq_sys_Menu
SET Name = 'Plus基础设置'
WHERE Id = 1701;
UPDATE cyhq_sys_Menu
SET Name = 'Plus会员资料'
WHERE Id = 1703;

UPDATE cyhq_sys_Menu
SET Name = '积分规则'
WHERE Id = 30411;
UPDATE cyhq_sys_Menu
SET Name = '累计积分升级设置',
    ParentId = 3035
WHERE Id = 304124;

UPDATE cyhq_sys_Menu
SET Name = '门店充值额度'
WHERE Id = 30302;

UPDATE cyhq_sys_Menu
SET Name = '会员充值对账表'
WHERE Id = 30317;

UPDATE cyhq_sys_Menu
SET Name = '计量规则'
WHERE Id = 30511;

UPDATE cyhq_sys_Menu
SET Name = '挂账类型'
WHERE Id = 30200;
UPDATE cyhq_sys_Menu
SET Name = '挂账资料'
WHERE Id = 30201;
UPDATE cyhq_sys_Menu
SET Name = '挂账结算单'
WHERE Id = 30202;
UPDATE cyhq_sys_Menu
SET Name = '挂账账务'
WHERE Id = 30203;

UPDATE cyhq_sys_Menu
SET Name = '分析报表'
WHERE Id = 309;
UPDATE cyhq_sys_Menu
SET Name = '门店账务报表'
WHERE Id = 310;
UPDATE cyhq_sys_Menu
SET Name = '消费交易报表'
WHERE Id = 31311;
UPDATE cyhq_sys_Menu
SET Name = '当前余额积分查询'
WHERE Id = 31312;
UPDATE cyhq_sys_Menu
SET Name = '卡库存统计'
WHERE Id = 31313;
UPDATE cyhq_sys_Menu
SET Name = '购券使用报表'
WHERE Id = 31314;

UPDATE cyhq_sys_Menu
SET [Order] = 36
WHERE Id = 31402;

UPDATE cyhq_sys_Menu
SET [Order] = 3.31
WHERE Id = 3040;

DELETE FROM fast_Entrance_setting;

DELETE FROM cyhq_sys_Menu
WHERE Id = '990105';

UPDATE cybr_sys_parameter
SET vch_value = 0
WHERE vch_parameter = 'sys_login_background';

UPDATE cyhq_sys_Menu
SET Name = '消费交易报表'
WHERE Id = 31311;

UPDATE cyhq_sys_Menu
SET Name = '物料报表'
WHERE Id = 1000;

UPDATE cyhq_sys_Menu
SET Name = '会员报表',
    ParentId = 3047
WHERE Id = 89208;

IF NOT EXISTS (SELECT 1 FROM cyhq_sys_Menu WHERE Id = 3047)
BEGIN
    INSERT INTO cyhq_sys_Menu
    (
        Id,
        Name,
        Url,
        ParentId,
        [Type],
        [Order],
        SystemType
    )
    VALUES
    (3047, '会员报表', '', 0, 0, 47, 'MDHT,');
END;

UPDATE cyhq_sys_Menu
SET [Order] = 10
WHERE Id = 1000;

UPDATE cyhq_sys_Menu
SET IconCls = 'icon-m-report',
    [Order] = 11
WHERE Id = 3047;
UPDATE cyhq_sys_Menu
SET [Order] = 12
WHERE Id = 99;



UPDATE cyhq_sys_Menu
SET Name = '门店品项新增'
WHERE Id = 220;

UPDATE cyhq_sys_Menu
SET SystemType = 'ZB,MDHT,'
WHERE Id = 3005;

UPDATE cyhq_sys_Menu
SET SystemType = 'ZB,MDHT,'
WHERE Id = 3007;

go

--//给总部新增菜单 添加操作员权限
INSERT INTO cyhq_sys_Permission (UserId,MenuId,Type)
SELECT c.Userid,c.id,c.Type
FROM
(
    SELECT a.Userid,
           b.Id,
           a.Type
    FROM
    (
        SELECT vch_operID AS Userid,
               'U' AS Type,
               1 AS MenuId
        FROM dbo.cybr_sys_operator
    ) AS a
        LEFT JOIN
        (
            SELECT 1 AS MenuId,
                   Id
            FROM cyhq_sys_Menu
            WHERE Id LIKE '30%'
                  AND LEN(Id) = 4
                  AND SystemType LIKE '%ZB%'
        ) AS b
            ON a.MenuId = b.MenuId
) c
    LEFT JOIN cyhq_sys_Permission d
        ON c.Userid = d.UserId
           AND c.Id = d.MenuId
           AND c.Type = d.Type
WHERE d.UserId IS NULL

GO

-- //给供应链新增菜单 添加操作员权限
INSERT INTO cyhq_sys_Permission (UserId,MenuId,Type)
SELECT c.Userid,c.id,c.Type
FROM
(
    SELECT a.Userid,
           b.Id,
           a.Type
    FROM
    (
        SELECT vch_operID AS Userid,
               'UG' AS Type,
               1 AS MenuId
        FROM dbo.cybr_sys_operator
    ) AS a
        LEFT JOIN
        (
            SELECT 1 AS MenuId,
                   Id
            FROM cyhq_sys_Menu
            WHERE Id LIKE '30%'
                  AND LEN(Id) = 4
                  AND SystemType LIKE '%GYL%'
        ) AS b
            ON a.MenuId = b.MenuId
) c
    LEFT JOIN cyhq_sys_Permission d
        ON c.Userid = d.UserId
           AND c.Id = d.MenuId
           AND c.Type = d.Type
WHERE d.UserId IS NULL
GO
--//给会员新增菜单 添加操作员权限
INSERT INTO cyhq_sys_Permission (UserId,MenuId,Type)
SELECT c.Userid,c.id,c.Type
FROM
(
    SELECT a.Userid,
           b.Id,
           a.Type
    FROM
    (
        SELECT vch_operID AS Userid,
               'UH' AS Type,
               1 AS MenuId
        FROM dbo.cybr_sys_operator
    ) AS a
        LEFT JOIN
        (
            SELECT 1 AS MenuId,
                   Id
            FROM cyhq_sys_Menu
            WHERE Id LIKE '30%'
                  AND LEN(Id) = 4
                  AND SystemType LIKE '%HY%'
        ) AS b
            ON a.MenuId = b.MenuId
) c
    LEFT JOIN cyhq_sys_Permission d
        ON c.Userid = d.UserId
           AND c.Id = d.MenuId
           AND c.Type = d.Type
WHERE d.UserId IS NULL
go

-- //给门店后台新增菜单 添加操作员权限
INSERT INTO cyhq_sys_Permission (UserId,MenuId,Type)
SELECT c.Userid,c.id,c.Type
FROM
(
    SELECT a.Userid,
           b.Id,
           a.Type
    FROM
    (
        SELECT vch_operID AS Userid,
               'UM' AS Type,
               1 AS MenuId
        FROM dbo.cybr_sys_operator
    ) AS a
        LEFT JOIN
        (
            SELECT 1 AS MenuId,
                   Id
            FROM cyhq_sys_Menu
            WHERE Id LIKE '30%'
                  AND LEN(Id) = 4
                  AND SystemType LIKE '%MDHT%'
        ) AS b
            ON a.MenuId = b.MenuId
) c
    LEFT JOIN cyhq_sys_Permission d
        ON c.Userid = d.UserId
           AND c.Id = d.MenuId
           AND c.Type = d.Type
WHERE d.UserId IS NULL
GO
DELETE FROM t_hq_m_parameter WHERE vch_parameter = 'DataBaseName'
go