//
//  HomeViewController.m
//  Open
//
//  Created by 雷俊博 on 2020/9/28.
//  Copyright © 2020 黄江涛 . All rights reserved.
//

#import "HomeViewController.h"

//tableviewcell/header,footer
#import "HomeCollectionCell.h"
#import "Home3MiddleBannerCell.h"
#import "socialAssistant.h"
#import "MyTableViewCell_d.h"
#import "HomeSectionHeaderView.h"
#import "HomeFooterView.h"
//#import "SDCycleScrollView.h"
#import "HomeMiddleNewsCell.h"
#import "HomeNewAuthResultCell.h"
#import "HomeServiceTableViewCell.h"
#import "HomeService2TableViewCell.h"
#import "HomeVideoContentCell.h"
#import "HomeHelperHeaderView.h"


//天气
#import "GovWeatherModel.h"
#import "CTAPIBaseManager.h"
#import "TimerProxy.h"


//model
#import "ButtonModel.h"


//版本更新
#import "VersionUpdateTool.h"

//百度
#import <BMKLocationKit/BMKLocationComponent.h>



//个数统计
#import "GTCountSDK.h"
#import "WXApi.h"

//授权弹框
#import "AiDaAlertView.h"

//登录
#import "LoginVC.h"

//合伙人
#import "JoinPartnerResultViewController.h"
#import "PartnerCenterViewController.h"
#import "JoinPartnerViewController.h"
#import "JoinPartGuideViewController.h"
#import "PartnerModel.h"


//电子社保卡
#import "SSTerminationViewController.h"

//社保缴费
#import "SSPaymenyViewController.h"

//优抚认证
#import "DistrictAuthenticationPersonalInfoController.h"
//社保认证
#import "KKUserIdentifyViewController.h"
//卫健查询
#import "WeiJianQueryViewController.h"

#import "ApplyStateQueryViewController.h"


//政务便民
#import "GovInfoViewController.h"
//社保缴费
#import "SSPaymenyViewController.h"
//新闻
#import "NewsViewController.h"
#import "NewsWebViewController.h"
//喜马拉雅
#import "KKLisenViewController.h"
//看病买药
#import "SmartInterrogationViewController.h"

//存钱罐
#import "StatisticsViewController.h"
#import "SaveTabBarController.h"
#import "SaveProductListController.h"
#import "MyAssetsController.h"
#import "LittleGoldHouseWebVC.h"
#import "ProductDetailController.h"
#import "KKActivityRedPackageBaseView.h"


#import "KKAuthHelperViewController.h"

//抢红包
#import "RewardPackageViewController.h"
#import "DDActiveModel.h"


//电子社保卡
#import "DDSBCardViewController.h"
#import "DDSBCardListVC.h"
#import "DDBindCardModel.h"

#import "CTAPIBaseManager.h"
#import "KKSocialAuthSuccessController.h"
#import "PayHistoryController.h"
#import "KKSaveActivityPackageView.h"
#import "BCNewActivityShareView.h"
#import "PasswordLoginViewController.h"
#import "KKAlertView.h"
#import "SearchCollectionViewController.h"
#import "CollectionAddressSelectedViewController.h"

#import "KKAuthWhiteAlertView.h"
#import "KKUserAuthViewController.h"
#import "KKUserAuthSuccessViewController.h"
#import "TBCycleView.h"

//极光小视频
#import "KKTabBarViewController.h"
#import "KKTVViewController.h"
#import "LittleVideoViewController.h"
#import "KKVideoViewController.h"


//快手
#import "KKSVideoViewController.h"
#import "KKSFeedPageViewController.h"
#import <KSAdSDK/KSCUFeedPageScrollViewDelegate.h>
#import "UIViewController+KSCUFeedPageExtend.h"

#import"SuppleSignAlertView.h"
#import"FtCjhxDialog.h"

//云蜻SDK
//#import <YXLaunchAds/YXLaunchAds.h>
//#import "YQTVViewController.h"
//新闻
#import "JHNewsModel.h"

#import "KKNewMsgResultInfoModel.h"


#import "CoinCenterCoinRewardAlertView.h"

#import "CoinsCenterViewController.h"

#import "PrizeInfoCommitSuccessAlertView.h"
#import "PayAttention2ToWXAlertView.h"
#import "KKGoldHouseActivityView.h"
#import "KKSaveBankRedPackageOPenedView.h"



#import "KKInsuranceModel.h"
#import "KKInsuranceTabBarController.h"
#import "KKInsuranceViewController.h"
#import "KKInsuranceContainerController.h"

#import "KKPrivateAlertView.h"

//变现猫广告
#import "DHCWNativeRenderAd.h"


#import "LocalPlayerVideoManager.h"

#import "KKShareView.h"
#import "HomeTableView.h"


//抢红包点击事件model
#import "KKRedPackageClickEventModel.h"
#import <objc/runtime.h>

#import "PreDeceptionAlertView.h"

#import "LivenessViewController.h"
#import "TestViewController.h"
#import "FaceImageModel.h"

#import "ClickOnForCoinsAlertView.h"

#import "GovLineView.h"



#import "KKFiveRedPackage.h"

#import "HeadLineViewController.h"

#import "RedPackageOpenedView.h"

//小满
#import <BXMediaSDK/BXMediaMaterialManager.h>
#import "KKActivityViewController.h"
#import "MyFruitViewController.h"

#import "GuideONLineFindJobAlertView.h"
#import "KKSelectNewsTypeAlertView.h"

#import "KKCLFundViewController.h"

#import "PasswordAlertView.h"

#import "KKTodayProfitViewController.h"

#import "TLMenuButtonView.h"
#import "TLHomeButton.h"

#import "MiniPaySocial.h"

#import "GuideMyWalletAlertView.h"

//理财
#import "KKFinancialViewController.h"

//新首页
#import "HometTopView.h"
//电子社保卡导包

#import "GuideView.h"
#import "WETianqiController.h"
#import "AuthenticationButieFinishVC.h"
//凡泰
#import <FinApplet/FinApplet.h>
#import<AdSupport/AdSupport.h>
#import"ChooseAddressController.h"
#import "GoodCommentDialog.h"
#import"AuthSuccessEss.h"
#import <CXHAdSDK-Core/CXHAdSDKServiceAdView.h>
#import "GiveChanceDialog.h"
#import "KKDealIdPhotoVC.h"
#import "SbPayMini.h"
#import "FtCjhxInfoDialog.h"
@interface HomeViewController ()<UITableViewDelegate,UITableViewDataSource,UIScrollViewDelegate,HomeCollectionCellDelegate,BMKLocationManagerDelegate,MiddleBannerViewCellDelegate,HomeServiceTableViewCellDelegate,HomeService2TableViewCellDelegate,HomeMiddleNewsCellDelegate,DHCWNativeRenderAdDelegate,DHCWNativeAdViewDelegate,KSCUFeedPageScrollViewDelegate,HomeHelperHeaderViewDelegate,HomeItemDelegate,HometTopViewDelegate,CXHSDKServiceAdViewDelegate,ChooseAddressDelegate>
{
    //检测定位是否是河北,黑龙江,就业采集 。修改
    BOOL showJYCaiji;
    
    BOOL isAPPLogined;//APP是否已经默认登录更新数据;
    
    NSInteger index;
    
    CGFloat _currentPostion;
    
    CGFloat _lastPostion;
    
    CGFloat _lastPostion2;
    
    BOOL superCanScroll;
    BOOL childCanScroll;
    
    NSInteger currentCount;
    
    BOOL _ISShowMenuButton;
    
    BOOL firstShow;
    
}
@property (nonatomic, strong)HomeTableView* tableView;
@property (nonatomic, strong) HometTopView *TopView;
@property (nonatomic, assign)BOOL validateTime;//隐藏参数



//@property (nonatomic, strong)SDCycleScrollView* headerView;

//@property (nonatomic, strong)HomeFooterView* footerView;

@property (nonatomic, strong)NSMutableArray *newsDataArray;//中部banner数组

//@property(nonatomic,strong)NSMutableArray *arrayT;//顶部banner数组


@property(nonatomic,strong)socialResultModel* resultModel;

@property (nonatomic, strong)AiDaAlertView* aiDaView;

@property (nonatomic, strong)NSMutableArray <ButtonModel *> *buttonArray;

//百度
@property (nonatomic, strong)BMKLocationManager *locationManager;

@property (nonatomic, strong)NSArray *newsArray;

@property (nonatomic, strong)NSTimer* timer;

@property (nonatomic, strong)YYLabel* lb_content1;

@property (nonatomic, strong)YYLabel* lb_content2;

@property (nonatomic, strong)KKNewMsgResultInfoModel *msgModel;

@property (nonatomic, assign)NSInteger unreadCount;

@property (nonatomic, assign)BOOL locationTarget;//定位廊坊

//变现猫
@property (nonatomic, strong) DHCWNativeRenderAd *nativeAd;
@property (nonatomic, strong) NSMutableArray *adDataArray;


@property (nonatomic, strong)HomeVideoContentCell *videoCell;

@property (nonatomic, strong)UIView* footerView;

@property (nonatomic, strong)UIView *topWhiteView;


//抢红包点击事件数组
@property (nonatomic, strong)NSMutableArray *redPackageClickEventsArray;

@property (nonatomic, strong)UIButton* TopBtn;



//@property (nonatomic, strong)GovWeatherModel *weatherModel;
@property (nonatomic, strong)NSDictionary *weatherDic;
@property (nonatomic, assign)BOOL showWeather;

@property (nonatomic, assign)BOOL coinSigned;

@property (nonatomic, strong)HomeHelperHeaderView *newsHeaderView;
@property (nonatomic, strong)NSTimer *helperTimer;

@property (nonatomic, strong) TLMenuButtonView *tlMenuView ;

@property (nonatomic, strong) UIView *bgView;

@property (nonatomic, strong)UIButton *button;


@property (nonatomic, strong)NSArray *btnItemsArray;

@property (nonatomic, strong)YYLabel *lb_msg;

//首页按钮
@property (nonatomic, strong) NSMutableArray *DataArr;

@property (nonatomic, strong) UILabel *titleLabel;

@property (nonatomic, strong) GuideView *GuideView;

@property (nonatomic, assign) int GuideViewTapCount;

@property (nonatomic, strong) UILabel *cityLab;

@property (nonatomic, strong) UILabel *weatherLab;

@property (nonatomic, strong)UIScrollView *scrollView;

@property(nonatomic,strong)CXHAdSDKServiceAdView *serviceAdView;
@property(nonatomic,strong)UIView *topBkgView;
@property(nonatomic,strong)KKRedPackageClickEventModel *topBkgModel;
@end

@implementation HomeViewController

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    NSLog(@"🎁 HomeViewController viewWillAppear - 首页即将显示");
    [self.navigationController.navigationBar navBarBackGroundColor:K_MainColor image:nil isOpaque:YES];//颜色
    [self.navigationController.navigationBar navBarBottomLineHidden:YES];
    [self.navigationController setNavigationBarHidden:YES animated:animated];
    NSString *good=[[NSUserDefaults standardUserDefaults]objectForKey:@"good_comment_dialog"];
    if(good!=nil&&[good isEqualToString:@"1"]){
        long time= [Tools getNowTimeTimesLong];
        float good_comment_dialog_time=[[NSUserDefaults standardUserDefaults] floatForKey:@"good_comment_dialog_time"];
        if(time-good_comment_dialog_time>1000L*60*60*24*30){
            [GoodCommentDialog showWithTitle:self :@"" btnYes:^{
                NSString *appid = @"1507076734";
                NSString *str = [NSString stringWithFormat:@"itms-apps://itunes.apple.com/app/viewContentsUserReviews?id=%@", appid];
                NSURL *url = [NSURL URLWithString:str];
                [[UIApplication sharedApplication] openURL:url];
            } btnNo:^{
                [[clickEvent instance] clickEventRooterVC:self Content:@"mineFeebBack" menuName:@"mineFeebBack"];
            } ];
            [[NSUserDefaults standardUserDefaults]setFloat:time forKey:@"good_comment_dialog_time"];
        }
        [[NSUserDefaults standardUserDefaults]setObject:@"0" forKey:@"good_comment_dialog"];
    }
    //获取未读消息数
    if (isAPPLogined) {
        [self getUnreadState];
    }
    [self scanPasteboard];
    self.edgesForExtendedLayout = UIRectEdgeNone;// 推荐使用

    
    NSLog(@"闪屏:http://www.baidu.com");
}
- (void)ChooseAddressBack:(NSString*)pro:(NSString*)city{
    if (city==nil||[city isEqualToString:@""]||[city isEqualToString:@"null"]||[city isEqualToString:@"<null>"]) {
        self.cityLab.text=@"上海";
        pro=@"上海";
        city=@"上海";
    }else{
        self.cityLab.text=city;
    }
    //self.cityLab.text=city;
    //腾讯天气
    NSString *url = [NSString stringWithFormat:@"https://wis.qq.com/weather/common?source=pc&weather_type=observe&province=%@&city=%@",pro,city];
    NSString * encodingString = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    [NetworkRequest Get4:encodingString Params:param Success:^(id _Nonnull responseObject) {
        NSLog(@"responseObject:%@",responseObject);
        NSDictionary *dic = responseObject;
        NSString *status=dic[@"status"];
        if([status isEqualToString:@"200"]){
            NSDictionary *data=dic[@"data"];
            if(data!=nil){
                NSDictionary *observe= data[@"observe"];
                if(observe!=nil){
                    NSString *weather_short=observe[@"weather_short"];
                    NSString *degree=observe[@"degree"];//@"晴18℃"
                    if(weather_short!=nil){
                        NSString *weather = [NSString stringWithFormat:@"%@%@℃",weather_short,degree];
                        self.weatherLab.text=weather;
                    }
                }
            }
        }
    } Failure:^(NSError * _Nonnull error) {
        NSLog(@"error:%@",error);
    }];
}
- (UIScrollView *)scrollView{
    if (!_scrollView) {
        _scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
        _scrollView.backgroundColor = [UIColor whiteColor];
        _scrollView.contentSize = CGSizeMake(ScreenWidth, ScreenHeight+TAB_BAR_HEIGHT);
        _scrollView.showsHorizontalScrollIndicator = NO;
        _scrollView.scrollEnabled=YES;
        _scrollView.showsVerticalScrollIndicator = NO;
        //[self setupUI];
    }
    return _scrollView;
}

-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:YES];
    if (_ISShowMenuButton) {
        [self clickAddButton:self.button];
    }
}

- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    BOOL pushVC = [UserDefault boolForKey:@"pushVC"];
    if (pushVC) {
        [UserDefault setBool:NO forKey:@"pushVC"];
        [self checkTapPushMessage];
    }
}

#pragma mark - 观察闪屏点击
- (void)splashClickEvent{
    NSString *eventFlag=[[NSUserDefaults standardUserDefaults]objectForKey:@"eventFlag_spalsh"];
    if (eventFlag!=nil&&![eventFlag isEqualToString:@""]&&![eventFlag isEqualToString:@"null"]) {
        [[NSUserDefaults standardUserDefaults]setObject:@"" forKey:@"eventFlag_spalsh"];
        NSString *eventParam=[[NSUserDefaults standardUserDefaults]objectForKey:@"eventParam_spalsh"];
        if ([eventFlag isEqualToString:@"101"]) {//原生
            [[clickEvent instance] clickEventRooterVC:self Content:eventParam menuName:@""];
        }else if ([eventFlag isEqualToString:@"104"]){//H5

            WebVC *webvc = [[WebVC alloc]init];
            webvc.url = eventParam;
            webvc.title = @"";
            webvc.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:webvc animated:YES];
        }else if ([eventFlag isEqualToString:@"106"]){//联合登录
            if([[NSUserDefaults standardUserDefaults] boolForKey:@"firstlog"]){
                [[clickEvent instance] clickEventRooterVC:self getFederatedLoginRequestWithUrl:eventParam menuName:@"看看生活"];
            }else{
                [self unLoginTap];
            }
            
        }
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    NSLog(@"🎁 HomeViewController viewDidLoad - 首页已加载");
    [self configNav];
    //init初始化
    superCanScroll = YES;
    childCanScroll = NO;
    self.validateTime = NO;
    self.newsDataArray = [[NSMutableArray alloc]init];
//    self.arrayT = [[NSMutableArray alloc]init];
    self.buttonArray = [NSMutableArray array];
    //add
    //[self.view addSubview:self.scrollView];
    [self.view addSubview:self.tableView];
    //self.tableView.scrollEnabled=NO;
    if (@available(iOS 11.0, *)) {
        self.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }else {
        self.automaticallyAdjustsScrollViewInsets = NO;
    };
    //configData
//    [self creatTable];
//    [self queryButton];
//    [self sortMyButton];

    //观察闪屏点击
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(splashClickEvent) name:@"splashClickEvent" object:nil];
    
    //观察认证成功后刷新
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshKankanAssistant) name:@"ZLAuthenticationAssistant" object:nil];
    //从后端获取最大认证人数限制
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getAuthPersonNumberRequest) name:KKSBLoginGetMaxAuthNumberNotificationName object:nil];
    //登录成功通知
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loginUpdateDataAction) name:KKSBLoginSuccessNotificationName object:nil];
    NSLog(@"闪屏111111:http://www.baidu.com");
    //社保认证成功弹窗
    //[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showFiveRedPackageNotic:) name:KKSBFiveRedPackageNotificationName object:nil];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeToHomeVC) name:KKSBChangeToHomeVCNotificationName object:nil];

    // 注册消息监听者
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(listeneropenLink:) name:@"openLinkNoti" object:nil];
    
    // 注册mobpush消息
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(dealMobPush) name:KKSBGTPushNotificationName object:nil];
    
    //认证人数初始化
    [self authNumberInitConfig];
    
    //获取中部banner请求
    [self loadMiddleBannerApiRequest];
    
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        //百度定位
        //[self locationDisplay];
    });
    
    [self essCardProvicne];
    
    //默认更新登录
    [self defaultLogin];
    
    //新闻
    [self loadData];
    
    //助手
    [self getNewNotcieMsgRequest];

    //悬浮样式
    //[self showBtns];
    //广告
    [self getJSQAd];
    
    //获取抢红包事件
    [self requestRedPackageIconsAndTargetEvent];
    
    //检测环境
    [self checkRuntimeEnvironment];
    
    //版本更新检测
    [[VersionUpdateTool sharedInstance]VersionUpdate];
    
    // [ 参考代码，开发者注意根据实际需求自行修改 ] 注册远程通知
    //[GeTuiSdk registerRemoteNotification: (UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge)];
        
    [self loadBXMADViews];

    //获取首页按钮
    [self requestIconsAndTargetEvent];
    
    //首页直播弹窗
    //[self ShowLiveAlert];
    [self appOpen];
}
#pragma mark - mobpush 处理
-(void)dealMobPush{
    // 以 firstlog 为准；若 firstlog 为 NO 但已有用户 ID，视为已登录，避免误判（如启动时未再清除 firstlog 后的兜底）
    BOOL hasFirstLog = [[NSUserDefaults standardUserDefaults] boolForKey:@"firstlog"];
    BOOL hasUserId = [getPeopleID PeopleID] > 0;
    if (!hasFirstLog && !hasUserId){
        [[NSNotificationCenter defaultCenter]postNotificationName:KKSBJumpLoginVCNotificationName object:nil];
    } else {
        [self loginMobPush];
    }
}

#pragma mark - 开平统计
- (void)appOpen{
    NSInteger factoryIndex = [[NSUserDefaults standardUserDefaults]integerForKey:@"adType"];
    NSString *adTag=nil;
    if (factoryIndex == 1001004){
        adTag=@"1001004";
    }else if (factoryIndex == 1001005){
        adTag=@"1001005";
    }else if (factoryIndex == 1001007){
        adTag=@"1001007";
    }else if (factoryIndex == 1001001){
        adTag=@"1001001";
    }
    long time=[[NSUserDefaults standardUserDefaults]integerForKey:@"app_open_time"];
    long openTime=[Tools getNowTimeTimesLong]-time;
    NSString *adSuccess=[[NSUserDefaults standardUserDefaults]stringForKey:@"ad_tag_success"];
    int success=0;
    if (adSuccess==nil||[adSuccess isEqualToString:@"0"]) {
        success=0;
    }else {
        success=1;
    }
    NSLog(@"开屏时间:%lld",openTime);
    //[[NSUserDefaults standardUserDefaults]setInteger:factoryIndex.integerValue forKey:@"adType"];
    
    [NetworkRequest appOpen:adTag adSuccess:success openTime:openTime];
}

- (void)listeneropenLink:(NSNotification *)notification{
    NSDictionary *dataDictionary = notification.userInfo;
    NSString *push_type = dataDictionary[@"push_type"];
    NSString *push_url = dataDictionary[@"push_url"];
    NSLog(@"开屏时间push_url:%@",push_url);
    UIViewController *rootVC = [self getCurrentVC];
    if (![[NSUserDefaults standardUserDefaults]boolForKey:@"firstlog"]){
        LoginVC *loginVC = [[LoginVC alloc]init];
        loginVC.block = ^(BOOL show) {
            if([push_type isEqualToString:@"0"]){//url
                WebVC *webvc = [[WebVC alloc]init];
                webvc.url = push_url;
                webvc.title = @"";
                webvc.hidesBottomBarWhenPushed = YES;
                [rootVC.navigationController pushViewController:webvc animated:YES];
            }else if([push_type isEqualToString:@"2"]){//原生
                [[clickEvent instance] clickEventRooterVC:rootVC Content:push_url menuName:@""];
            }else if([push_type isEqualToString:@"3"]){//联合登录
                [[clickEvent instance]clickEventRooterVC:rootVC getFederatedLoginRequestWithUrl:push_url menuName:@"看看生活"];
            }
        };
        UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:loginVC];
        [rootVC presentViewController:nav animated:YES completion:nil];
    }else{
        if([push_type isEqualToString:@"0"]){//url
            WebVC *webvc = [[WebVC alloc]init];
            webvc.url = push_url;
            webvc.title = @"";
            webvc.hidesBottomBarWhenPushed = YES;
            [rootVC.navigationController pushViewController:webvc animated:YES];
        }else if([push_type isEqualToString:@"2"]){//原生
            [[clickEvent instance] clickEventRooterVC:rootVC Content:push_url menuName:@""];
        }else if([push_type isEqualToString:@"3"]){//联合登录
            [[clickEvent instance]clickEventRooterVC:rootVC getFederatedLoginRequestWithUrl:push_url menuName:@"看看生活"];
        }
    }
    
//    if ([push_type intValue] == 2) {
//        //原生
//        if (![[NSUserDefaults standardUserDefaults]boolForKey:@"firstlog"]){
//            LoginVC *loginVC = [[LoginVC alloc]init];
//            loginVC.block = ^(BOOL show) {
//                [[clickEvent instance] clickEventRooterVC:self Content:push_url menuName:@""];
//            };
//            UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:loginVC];
//            [rootVC presentViewController:nav animated:YES completion:nil];
//        }else{
//            [self.navigationController popToRootViewControllerAnimated:NO];
//            
//            [[clickEvent instance] clickEventRooterVC:rootVC Content:push_url menuName:@""];
//        }
//    }else{
//        [self.navigationController popToRootViewControllerAnimated:NO];
//        
//        WebVC *webvc = [[WebVC alloc]init];
//        webvc.url = push_url;
//        webvc.hidesBottomBarWhenPushed = YES;
//        [rootVC.navigationController pushViewController:webvc animated:YES];
//    }
}
//当前显示的控制器

- (UIViewController *)getCurrentVC

{
    UIViewController *result =nil;

    UIWindow * window = [[UIApplication sharedApplication] keyWindow];

    if (window.windowLevel != UIWindowLevelNormal)

    {

        NSArray*windows = [[UIApplication sharedApplication]windows];

        for(UIWindow* tmpWin in windows)

        {

            if (tmpWin.windowLevel == UIWindowLevelNormal)

            {

                window = tmpWin;

                break;

            }

        }

    }

    //从根控制器开始查找

    UIViewController*rootVC = window.rootViewController;

    id nextResponder = [rootVC.view nextResponder];

      if([nextResponder isKindOfClass:[UINavigationController class]]) {

          result = ((UINavigationController*)nextResponder).topViewController;

          if([result isKindOfClass:[UITabBarController class]]) {

              result = ((UITabBarController*)result).selectedViewController;

          }

       }else if([nextResponder isKindOfClass:[UITabBarController class]]) {

           result = ((UITabBarController*)nextResponder).selectedViewController;

           if([result isKindOfClass:[UINavigationController class]]) {

               result = ((UINavigationController*)result).topViewController;

           }

       }else if([nextResponder isKindOfClass:[UIViewController class]]) {

           result = nextResponder;

       }else{

           result = window.rootViewController;

           if([result isKindOfClass:[UINavigationController class]]) {

               result = ((UINavigationController*)result).topViewController;

               if([result isKindOfClass:[UITabBarController  class]]) {

                   result = ((UITabBarController*)result).selectedViewController;

               }

           }else if([result isKindOfClass:[UIViewController class]]) {

               result = nextResponder;

           }

      }

    return result;

}
//#pragma mark - 第一次进入引导指示
//- (void)firstShowHome{
//    self.GuideViewTapCount = 0;
//
//    self.GuideView = [[[NSBundle mainBundle] loadNibNamed:@"GuideView" owner:nil options:nil] firstObject];
//    self.GuideView.TopHight.constant = cl_kNavigationBarHeight;
//    self.GuideView.leftWidth.constant = ScreenWidth / 4;
//    self.GuideView.frame = CGRectMake(0, 0, ScreenWidth, ScreenHeight);
//    self.GuideView.BaseView.backgroundColor = [UIColor colorWithWhite:0.f alpha:0.8];
//    [XYKEYWINDOW addSubview:self.GuideView];
//    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(GuideViewTap)];
//    [self.GuideView addGestureRecognizer:tap];
//}
//- (void)GuideViewTap{
//    self.GuideViewTapCount++;
//    if (self.GuideViewTapCount == 1) {
//        self.GuideView.leftWidth.constant = ScreenWidth / 4 * 2;
//        self.GuideView.itemImg.image = [UIImage imageNamed:@"Guide_Subsidies"];
//        self.GuideView.GuideImg.image = [UIImage imageNamed:@"Guide_second"];
//    }else{
//        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"firstShowHome"];
//        [[NSUserDefaults standardUserDefaults] synchronize];
//        [self.GuideView removeFromSuperview];
//    }
//}

-(void)topbkgClick:(UITapGestureRecognizer *)recognizer{
    if(![[NSUserDefaults standardUserDefaults] boolForKey:@"firstlog"]){
        [self unLoginTap];
        return;
      }
    //https://web.kanface.com:444/common/forward/KK_MEMBER
    //[[clickEvent instance] clickEventRooterVC:self getFederatedLoginRequestWithUrl:@"https://web.kanface.com:444/common/forward/KK_MEMBER" menuName:@"会员"];
    if(self.topBkgModel !=nil){
        [[clickEvent instance] clickEventNative:self model:self.topBkgModel];
    }
    NSLog(@"error:%@",@"topbkgClick");
}
- (void)configNav{
    
    UIImageView *topBkg=[[UIImageView alloc] init];
    topBkg.image=[UIImage imageNamed:@"home_top_bkg"];
    topBkg.contentMode=UIViewContentModeScaleAspectFill;
    
    int imageHight=cl_kNavigationBarHeight + 220*WIDTHRADIU;
    self.topBkgView = [[UIView alloc]initWithFrame:CGRectMake(0, 0,ScreenWidth, imageHight)];
    topBkg.userInteractionEnabled = YES;
    UITapGestureRecognizer *topBkgGes = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(topbkgClick:)];
    [topBkg addGestureRecognizer:topBkgGes];
    [self.topBkgView addSubview:topBkg];
    [topBkg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.offset(ScreenWidth);
        make.height.offset(imageHight);
    }];
    [self.view addSubview:_topBkgView];
    
    _TopView = [[HometTopView alloc]initWithFrame:CGRectMake(0, cl_kNavigationBarHeight, ScreenWidth, 100*WIDTHRADIU)];
    _TopView.delegate = self;
    _TopView.hiddenButton = NO;
    [self.topBkgView addSubview:_TopView];
    
    
    NSString*version = [Tools getVersionCode];

    NSString *url1 = [NSString stringWithFormat:@"%@dynamic/menu/get",[NetworkConfig ipYinShuConfig]];
    NSString *chooseCity=[[NSUserDefaults standardUserDefaults]objectForKey:@"chooseCity"];
    NSString *chooseProvince=[[NSUserDefaults standardUserDefaults]objectForKey:@"chooseProvince"];
    NSDictionary *params1 = @{
        @"configName":@"HomeActivityMenu",
        @"appName":@"kksh",
        @"version":version,
        @"systemType":@"iOS",
        @"uid":[NSString stringWithFormat:@"%ld",(long)[getPeopleID PeopleID]],
        @"city":chooseCity,
        @"province":chooseProvince
    };
    [NetworkRequest Post15:url1 Params:params1 Success:^(id _Nonnull objc) {
        NSLog(@"首页顶部背景===objc:%@",objc);
        if ([objc isKindOfClass:[NSDictionary class]]) {
            NSString *state = [NSString stringWithFormat:@"%@",objc[@"state"]];
            if ([state isEqualToString:@"200"]) {
                if ([objc[@"result"] isKindOfClass:[NSArray class]]) {
                    NSMutableArray *homeBkgArray= [NSMutableArray array];
                    for (NSDictionary *dic in objc[@"result"]) {
                        KKRedPackageClickEventModel *model = [KKRedPackageClickEventModel mj_objectWithKeyValues:dic];
                        [homeBkgArray addObject:model];
                    }
                    int randomNumber = arc4random_uniform(homeBkgArray.count);
                    KKRedPackageClickEventModel *model=homeBkgArray[randomNumber];//获得背景实体类
                
                    NSString *iconUrl=[NSString stringWithFormat:@"%@%@",KKFindPackageIP,model.menuIcon];//地址
                
                    NSString *content=model.content;
                    int imageHight;
//                    if(content==nil||[content isEqualToString:@""]||[content isEqualToString:@"默认"]){
//                        self.topBkgModel=nil;
//                        imageHight=cl_kNavigationBarHeight + 100*WIDTHRADIU;
//                        _topBkgView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, imageHight)];
//                    }else{
//                        self.topBkgModel=model;
//                        imageHight=cl_kNavigationBarHeight + 200*WIDTHRADIU;
//                        _topBkgView = [[UIView alloc]initWithFrame:CGRectMake(0, 0,ScreenWidth, imageHight)];
//                    }
                    //UIView *nav = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, height/2)];
                    //[[SetGradient instance] setViewBackground:nav fromColor:@"#0e76d4" toColor:@"#2591f3" fromCGPoint:CGPointMake(0, 0) toCGPoint:CGPointMake(0, 1)];

                    //nav.backgroundColor= [UIColorcolorWithPatternImage:[UIImageimageNamed:@"home_top_bkg"]];
                    //[self.view addSubview:_topBkgView];

                    //UIImageView *topBkg=[[UIImageView alloc] init];
                    //topBkg.image=[UIImage imageNamed:@"home_top_bkg"];
                    self.topBkgModel=model;
                    [topBkg sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",KKFindPackageIP,model.menuIcon]]];
//                    topBkg.userInteractionEnabled = YES;
//                    UITapGestureRecognizer *topBkgGes = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(topbkgClick:)];
//                    [topBkg addGestureRecognizer:topBkgGes];
//                    [self.topBkgView addSubview:topBkg];
//                    [topBkg mas_makeConstraints:^(MASConstraintMaker *make) {
//                        make.width.offset(ScreenWidth);
//                        make.height.offset(imageHight);
//                    }];


                    UILabel*titleLabel = [[UILabel alloc]init];
                    titleLabel.textColor = [UIColor whiteColor];
                    titleLabel.textAlignment = NSTextAlignmentCenter;
                    titleLabel.text = @"看看生活";
                    titleLabel.font = [UIFont boldSystemFontOfSize:20];
                    self.titleLabel = titleLabel;
                    [self.topBkgView addSubview:titleLabel];

                    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                        make.centerX.offset(0);
                        make.top.offset(cl_kStatusBarHeight);
                        make.width.offset(150);
                        make.height.offset(30);
                    }];

                    UIButton *RightBtn = [[UIButton alloc]init];
                    [RightBtn setTitle:@" 客服" forState:UIControlStateNormal];
                    [RightBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
                    [RightBtn setImage:[UIImage imageNamed:@"客服"] forState:UIControlStateNormal];
                    [RightBtn setImage:[UIImage imageNamed:@"客服"] forState:UIControlStateHighlighted];
                    RightBtn.titleLabel.font = [UIFont systemFontOfSize:14.0];
                    RightBtn.imageEdgeInsets = UIEdgeInsetsMake(7.5, 0, 7.5, 0);
                    [RightBtn addTarget:self action:@selector(kefu) forControlEvents:UIControlEventTouchUpInside];
                    [self.topBkgView addSubview:RightBtn];
                    [RightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
                        make.right.offset(-15);
                        make.centerY.equalTo(titleLabel);
                        make.width.offset(60);
                        make.height.offset(30);
                    }];

                    _cityLab = [[UILabel alloc]init];
                    _cityLab.textColor = [UIColor whiteColor];
                    _cityLab.textAlignment = NSTextAlignmentLeft;
                    _cityLab.text = @"上海";
                    _cityLab.font = [UIFont systemFontOfSize:14];


                    [self.topBkgView addSubview:_cityLab];
                    [_cityLab mas_makeConstraints:^(MASConstraintMaker *make) {
                        make.top.offset(cl_kStatusBarHeight);
                        make.left.offset(15);
                        make.width.offset(80);
                        make.height.offset(15);
                    }];

                    UIImageView *image=[[UIImageView alloc] init];
                    image.image=[UIImage imageNamed:@"choose_address"];
                    [self.topBkgView addSubview:image];
                    [image mas_makeConstraints:^(MASConstraintMaker *make) {
                        make.top.offset(cl_kStatusBarHeight+2);
                        make.left.equalTo(_cityLab.mas_right).offset(-20);
                        make.width.offset(10);
                        make.height.offset(7);
                    }];

                    _weatherLab = [[UILabel alloc]init];
                    _weatherLab.textColor = [UIColor whiteColor];
                    _weatherLab.textAlignment = NSTextAlignmentLeft;
                    _weatherLab.text = @"晴18℃";
                    _weatherLab.font = [UIFont systemFontOfSize:10];
                    [self.topBkgView addSubview:_weatherLab];
                    typeof(self) wSelf = self;
                    [_weatherLab mas_makeConstraints:^(MASConstraintMaker *make) {
                        make.top.equalTo(wSelf.cityLab.mas_bottom);
                        make.left.offset(15);
                        make.width.offset(100);
                        make.height.offset(15);
                    }];

                    UIButton *weatherBtn = [[UIButton alloc]init];
                    weatherBtn.backgroundColor = [UIColor clearColor];
                    [weatherBtn addTarget:self action:@selector(weatherTapClick) forControlEvents:UIControlEventTouchUpInside];
                    [self.topBkgView addSubview:weatherBtn];
                    [weatherBtn mas_makeConstraints:^(MASConstraintMaker *make) {
                        make.top.offset(cl_kStatusBarHeight);
                        make.left.offset(15);
                        make.width.offset(100);
                        make.height.offset(30);
                    }];

//                    _TopView = [[HometTopView alloc]initWithFrame:CGRectMake(0, cl_kNavigationBarHeight, ScreenWidth, 100*WIDTHRADIU)];
//                    _TopView.delegate = self;
//                    _TopView.hiddenButton = NO;
//                    [self.topBkgView addSubview:_TopView];
                    
//                    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
//                        //百度定位
//
//                    });
                    [self locationDisplay];
                }
            }
        }

    } Failure:^(NSError *error) {
        NSLog(@"首页顶部背景error:%@",error);
    }];
    
    
    
    
//    UIView *nav = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, cl_kNavigationBarHeight + 93)];
//    //[[SetGradient instance] setViewBackground:nav fromColor:@"#0e76d4" toColor:@"#2591f3" fromCGPoint:CGPointMake(0, 0) toCGPoint:CGPointMake(0, 1)];
//
//    //nav.backgroundColor= [UIColorcolorWithPatternImage:[UIImageimageNamed:@"home_top_bkg"]];
//    [self.view addSubview:nav];
//
//    UIImageView *topBkg=[[UIImageView alloc] init];
//    topBkg.image=[UIImage imageNamed:@"home_top_bkg"];
//    [nav addSubview:topBkg];
//    [topBkg mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.width.offset(ScreenWidth);
//        make.height.offset(cl_kNavigationBarHeight + 93);
//    }];
//
//
//    UILabel*titleLabel = [[UILabel alloc]init];
//    titleLabel.textColor = [UIColor whiteColor];
//    titleLabel.textAlignment = NSTextAlignmentCenter;
//    titleLabel.text = @"看看生活";
//    titleLabel.font = [UIFont boldSystemFontOfSize:20];
//    self.titleLabel = titleLabel;
//    [nav addSubview:titleLabel];
//
//    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.centerX.offset(0);
//        make.top.offset(cl_kStatusBarHeight);
//        make.width.offset(150);
//        make.height.offset(30);
//    }];
//
//    UIButton *RightBtn = [[UIButton alloc]init];
//    [RightBtn setTitle:@" 客服" forState:UIControlStateNormal];
//    [RightBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
//    [RightBtn setImage:[UIImage imageNamed:@"客服"] forState:UIControlStateNormal];
//    [RightBtn setImage:[UIImage imageNamed:@"客服"] forState:UIControlStateHighlighted];
//    RightBtn.titleLabel.font = [UIFont systemFontOfSize:14.0];
//    RightBtn.imageEdgeInsets = UIEdgeInsetsMake(7.5, 0, 7.5, 0);
//    [RightBtn addTarget:self action:@selector(kefu) forControlEvents:UIControlEventTouchUpInside];
//    [nav addSubview:RightBtn];
//    [RightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.right.offset(-15);
//        make.centerY.equalTo(titleLabel);
//        make.width.offset(60);
//        make.height.offset(30);
//    }];
//
//    _cityLab = [[UILabel alloc]init];
//    _cityLab.textColor = [UIColor whiteColor];
//    _cityLab.textAlignment = NSTextAlignmentLeft;
//    _cityLab.text = @"上海";
//    _cityLab.font = [UIFont systemFontOfSize:14];
//
//
//    [nav addSubview:_cityLab];
//    [_cityLab mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.offset(cl_kStatusBarHeight);
//        make.left.offset(15);
//        make.width.offset(80);
//        make.height.offset(15);
//    }];
//
//    UIImageView *image=[[UIImageView alloc] init];
//    image.image=[UIImage imageNamed:@"choose_address"];
//    [nav addSubview:image];
//    [image mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.offset(cl_kStatusBarHeight+2);
//        make.left.equalTo(_cityLab.mas_right).offset(-20);
//        make.width.offset(10);
//        make.height.offset(7);
//    }];
//
//    _weatherLab = [[UILabel alloc]init];
//    _weatherLab.textColor = [UIColor whiteColor];
//    _weatherLab.textAlignment = NSTextAlignmentLeft;
//    _weatherLab.text = @"晴18℃";
//    _weatherLab.font = [UIFont systemFontOfSize:10];
//    [nav addSubview:_weatherLab];
//    typeof(self) wSelf = self;
//    [_weatherLab mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(wSelf.cityLab.mas_bottom);
//        make.left.offset(15);
//        make.width.offset(100);
//        make.height.offset(15);
//    }];
//
//    UIButton *weatherBtn = [[UIButton alloc]init];
//    weatherBtn.backgroundColor = [UIColor clearColor];
//    [weatherBtn addTarget:self action:@selector(weatherTapClick) forControlEvents:UIControlEventTouchUpInside];
//    [nav addSubview:weatherBtn];
//    [weatherBtn mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.offset(cl_kStatusBarHeight);
//        make.left.offset(15);
//        make.width.offset(100);
//        make.height.offset(30);
//    }];
//
//    _TopView = [[HometTopView alloc]initWithFrame:CGRectMake(0, cl_kNavigationBarHeight, ScreenWidth, 93)];
//    _TopView.delegate = self;
//    _TopView.hiddenButton = YES;
//    [nav addSubview:_TopView];
}



#pragma mark - 天气
- (void)weatherTapClick
{
//    WebVC *webvc = [[WebVC alloc]init];
//    webvc.url=@"https://m.tianqi.com/docking.html";
//    //webvc.url=@"http://172.16.10.126:8848/myweb/index.html";
//    webvc.title=@"天气";
//    [self.navigationController pushViewController:webvc animated:YES];
    ChooseAddressController *choose=[[ChooseAddressController alloc] init];
    choose.title=@"地区选择";
    choose.delegate=self;
    [self.navigationController pushViewController:choose animated:YES];
}
#pragma mark - 智能客服
- (void)kefu{
    [self jumpToHTML5:@"https://nginx.weface.com.cn/appH5/appoutlink/#/customer" andJAnalytics:@"智能客服"];
}
- (void)dealloc
{
    NSLog(@"首页被销毁了");
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"ZLAuthenticationAssistant" object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:KKSBLoginGetMaxAuthNumberNotificationName object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:KKSBLoginSuccessNotificationName object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:KKSBFiveRedPackageNotificationName object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:KKSBChangeToHomeVCNotificationName object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"openLinkNoti" object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"mobpush_msg" object:nil];
}


#pragma mark - 检测是否有点击推送消息
- (void)checkTapPushMessage{
    
    NSDictionary* dict = [UserDefault objectForKey:@"pushInfo"];
    NSNumber *needLogin = dict[@"needLogin"];
    if (needLogin && needLogin.boolValue) {
        
        if (![[NSUserDefaults standardUserDefaults]boolForKey:@"firstlog"]) {
            [self unLoginTap];
            return;
        }else{
            [self kkHandelPushNoticationVCWithInfo:dict];
        }
        
    }else{
        [self kkHandelPushNoticationVCWithInfo:dict];
    }
   
}

- (void)kkHandelPushNoticationVCWithInfo:(NSDictionary *)dict
{
    
    [UserDefault setObject:nil forKey:@"pushInfo"];

    // 根据字典字段反射出我们想要的类，并初始化控制器
    Class class = NSClassFromString(dict[@"className"]);
    UIViewController *vc = [[class alloc] init];
    vc.title = dict[@"classTitle"];
    // 获取参数列表，使用枚举的方式，对控制器属性进行KVC赋值
    NSDictionary *parameter = dict[@"propertys"];
    [parameter enumerateKeysAndObjectsUsingBlock:^(id  _Nonnull key, id  _Nonnull obj, BOOL * _Nonnull stop) {
        // 在属性赋值时，做容错处理，防止因为后台数据导致的异常
        if ([vc respondsToSelector:NSSelectorFromString(key)]) {
            [vc setValue:obj forKey:key];
        }
    }];
    
    
    UINavigationController* nav = self.navigationController;
    
    if (nav) {
        vc.hidesBottomBarWhenPushed = YES;
        [nav pushViewController:vc animated:YES];
    }
    // 从字典中获取方法名，并调用对应的方法
    NSString* methods = [NSString stringWithFormat:@"%@",dict[@"method"]];
    if (![Tools isBlankString:methods]) {
        SEL selector = NSSelectorFromString(methods);
        
        ((void (*)(id, SEL))[vc methodForSelector:selector])(vc, selector);
    }
}

#pragma mark - 检索是否点击宣传页
- (void)scanPasteboard
{
    NSString *jsonStr = [UserDefault objectForKey:@"MyADJsonStr"];
    if (![Tools isBlankString:jsonStr]) {
        NSDictionary*dict = [self dictionaryWithJsonString:jsonStr];
        NSString* type = [NSString stringWithFormat:@"%@",dict[@"type"]];
        if ([type isEqualToString:@"ad"]) {
            [self jumpToHTML5:dict[@"targetUrl"] andJAnalytics:dict[@"title"]];
            [UserDefault setObject:nil forKey:@"MyADJsonStr"];
        }
    }
}

- (NSDictionary *)dictionaryWithJsonString:(NSString *)jsonString
{
    if (jsonString == nil) {
        return nil;
    }

    NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
    NSError *err;
    NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData
                                                        options:NSJSONReadingMutableContainers
                                                          error:&err];
    if(err)
    {
        NSLog(@"json解析失败：%@",err);
        return nil;
    }
    return dic;
}


#pragma mark - APP环境检测
- (BOOL)isJailBreak {
    if ([[NSFileManager defaultManager] fileExistsAtPath:@"User/Applications/"]) {
        NSLog(@"The device is jail broken!");
        NSArray *appList = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:@"User/Applications/" error:nil];
        NSLog(@"appList = %@", appList);
        return YES;
    }
    NSLog(@"The device is NOT jail broken!");
    return NO;
}

- (void)checkRuntimeEnvironment {
    NSString *message = nil;
    if (TARGET_IPHONE_SIMULATOR) {
        // 模拟器环境
      message = @"模拟器环境";
       
    } else if ([self isJailBreak]) {
        message = @"越狱环境";
    }
    if (message.length > 0) {
       
        [self showRunInSimulatorAlertView:message];
    }
    
}

- (void)showRunInSimulatorAlertView:(NSString *)message {
    if (@available(iOS 9.0,*)) {
        
        UIAlertController * alertV = [UIAlertController alertControllerWithTitle:@"提示" message:[NSString stringWithFormat:@"APP目前在%@上运行",message] preferredStyle:UIAlertControllerStyleAlert];
        
        UIAlertAction *confirm = [UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            [self exitApplication];
        }];
        
        [alertV addAction:confirm];
        
        [self presentViewController:alertV animated:YES completion:nil];
        
    }
}
- (void)exitApplication {
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    [UIView animateWithDuration:0.5f animations:^{
        window.alpha = 0;
        window.frame = CGRectMake(0, window.bounds.size.height / 2, window.bounds.size.width, 0.5);
    } completion:^(BOOL finished) {
        exit(0);
    }];
}
#pragma mark - 认证人数初始化
- (void)authNumberInitConfig {
    
    //初始化认证人数
    [UserDefault setObject:@"0" forKey:@"alreadyCount"];
    
    BOOL auth =  [getPeopleID getpeopleLimited];
    if (auth) {
        [UserDefault setObject:@"10" forKey:@"maxcount"];
    }else{
        [UserDefault setObject:@"5" forKey:@"maxcount"];
    }
    [UserDefault synchronize];
    
}

#pragma mark - 默认登录
- (void)defaultLogin {
    NSString *accountStr = [getPeopleID getDefaultLoginAccount];
    NSString *passwordStr = [getPeopleID getDefaultLoginPassword];
    if(accountStr==nil||passwordStr==nil){
        NSString *url=[[NSUserDefaults standardUserDefaults]objectForKey:@"mob_pushUrl"];
        NSString *type=[[NSUserDefaults standardUserDefaults]objectForKey:@"mob_pushType"];
        if(url!=nil&&type!=nil){
            [[NSNotificationCenter defaultCenter]postNotificationName:KKSBJumpLoginVCNotificationName object:nil];
        }
    }else{
        WeakSelf
        [self judgeLoginTimeInvalid:^(bool success) {
            __strong __typeof(self) strongSelf = weakSelf;
            strongSelf->isAPPLogined = YES;
            if (success) {
                NSString *url=[[NSUserDefaults standardUserDefaults]objectForKey:@"mob_pushUrl"];
                NSString *type=[[NSUserDefaults standardUserDefaults]objectForKey:@"mob_pushType"];
                if(url!=nil&&type!=nil){
                    if([type isEqualToString:@"0"]){//url
                        WebVC *webvc = [[WebVC alloc]init];
                        webvc.url = url;
                        webvc.title = @"看看生活";
                        webvc.hidesBottomBarWhenPushed = YES;
                        [self.navigationController pushViewController:webvc animated:YES];
                    }else if([type isEqualToString:@"2"]){//原生
                        [[clickEvent instance] clickEventRooterVC:self Content:url menuName:url];
                    }else if([type isEqualToString:@"3"]){//联合登录
                        [[clickEvent instance]clickEventRooterVC:self getFederatedLoginRequestWithUrl:url menuName:@"看看生活"];
                    }
                    [[NSUserDefaults standardUserDefaults]setObject:nil forKey:@"mob_pushUrl"];
                    [[NSUserDefaults standardUserDefaults]setObject:nil forKey:@"mob_pushType"];
                }
                NSLog(@"自动登录成功");
            }else {
                NSLog(@"自动登录失败");
                //[self logOut];
            }
        }];
    }
    
}

#pragma mark - 通知绑定方法
- (void)changeToHomeVC
{
    if (firstShow) {
        return;
    }
    firstShow = YES;
    
    [self showBtns];
}
#pragma mark - 认证结果更新
- (void)refreshKankanAssistant
{
    //[self updateMyAuthResultRequest];
    
    [self getNewNotcieMsgRequest];
}
#pragma mark - 登录成功通知绑定方法
- (void)loginUpdateDataAction {
    
//    //获取后台返回数据
//    [self getCertlistReq];
    
    //更新最新认证结果
   // [self updateMyAuthResultRequest];
    [self getNewNotcieMsgRequest];
    //获取认证人数限制
    [self getAuthPersonNumberRequest];
    //获取未读消息数
    [self getUnreadState];
    //获取实名状态
    [self judgeAccountAuthStateRequest];
    //获取新闻
    [self loadData];
    
//    //刷新天气
//    [self requestWeatherData];
//    //判断是否今日签到
//    [self judgeSignOrNorSignRequest];
    
    //新注册用户弹窗，老用户弹窗
    [self ShowActivityAlert];
    
    //获取应用列表
    [self getappinfo];
    
    //登录成功后mob推送判断跳转
    //[self loginMobPush];
}
#pragma mark-登陆成功mobpush处理
-(void) loginMobPush{
    NSString *url=[[NSUserDefaults standardUserDefaults]objectForKey:@"mob_pushUrl"];
    NSString *type=[[NSUserDefaults standardUserDefaults]objectForKey:@"mob_pushType"];
    if(url!=nil&&type!=nil){
        if([type isEqualToString:@"0"]){//url
            WebVC *webvc = [[WebVC alloc]init];
            webvc.url = url;
            webvc.title = @"看看生活";
            webvc.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:webvc animated:YES];
        }else if([type isEqualToString:@"2"]){//原生
            [[clickEvent instance] clickEventRooterVC:self Content:url menuName:url];
        }else if([type isEqualToString:@"3"]){//联合登录
            [[clickEvent instance]clickEventRooterVC:self getFederatedLoginRequestWithUrl:url menuName:@"看看生活"];
        }
        [[NSUserDefaults standardUserDefaults]setObject:nil forKey:@"mob_pushUrl"];
        [[NSUserDefaults standardUserDefaults]setObject:nil forKey:@"mob_pushType"];
    }
}

#pragma mark - 获取应用列表
- (void)getappinfo{
    NSDate *oldTime = [[NSUserDefaults standardUserDefaults]objectForKey:@"getappinfo"];
    if (oldTime && [self isSameDay:[NSDate date] date2:oldTime]) {
        return;
    }
    NSDate *oldDate = [NSDate date];
    [[NSUserDefaults standardUserDefaults]setObject:oldDate forKey:@"getappinfo"];
    [[NSUserDefaults standardUserDefaults]synchronize];
    
    
    NSString *url = [NSString stringWithFormat:@"%@20200228/appinfo/getappinfo",[NetworkConfig ipAdDaConfig]];
//    NSString *url = [NSString stringWithFormat:@"%@appinfo/getappinfo",@"http://172.16.10.102:8080/20200228/"];
    NSDictionary *params = @{
        @"userid":@([getPeopleID PeopleID]),
        @"fromMobile":@(2),
    };
    WeakSelf
    [NetworkRequest PostNomal:url Params:params Success:^(id _Nonnull objc) {
        if ([objc isKindOfClass:[NSDictionary class]]) {
            NSString *state = [NSString stringWithFormat:@"%@",objc[@"state"]];
            NSString* describe = [NSString stringWithFormat:@"%@",objc[@"describe"]];
            if ([state isEqualToString:@"200"]) {
                NSArray *listInfo = objc[@"result"];
                if (listInfo.count > 0) {
                    NSMutableArray *muArr = [NSMutableArray array];
                    for (NSDictionary *dic in listInfo) {
                        NSMutableDictionary *muDic = [[NSMutableDictionary alloc]initWithDictionary:dic];
                
                        NSURL * app_url = [NSURL URLWithString:[NSString stringWithFormat:@"%@://",dic[@"appextend"]]];
                        BOOL isopen = [[UIApplication sharedApplication] canOpenURL:app_url];
                        if (isopen) {
                            [muDic setValue:@(1) forKey:@"isInstall"];
                        }else{
                            [muDic setValue:@(0) forKey:@"isInstall"];
                        }
                        [muArr addObject:muDic];
                    }
                    
                    [weakSelf UpdateappinfoWithArr:muArr];
                }
            }else{
                [weakSelf alertShow:describe];
            }
        }
    } Failure:^(NSError *error) {
        NSLog(@"error:%@",error);
    }];
}
- (void)UpdateappinfoWithArr:(NSArray *)arr{
    NSString *url = [NSString stringWithFormat:@"%@20200228/appinfo/setappinfo",[NetworkConfig ipAdDaConfig]];
//    NSString *url = [NSString stringWithFormat:@"%@appinfo/setappinfo",@"http://172.16.10.102:8080/20200228/"];
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setValue:@([getPeopleID PeopleID]) forKey:@"userid"];
    [params setValue:@(2) forKey:@"fromMobile"];
    [params setObject:arr forKey:@"list"];
    [NetworkRequest PostNomal:url Params:params Success:^(id _Nonnull objc) {
    
    } Failure:^(NSError *error) {
        NSLog(@"error:%@",error);
    }];
}
#pragma mark - 首页直播弹窗
- (void)ShowLiveAlert{
    NSDate *oldTime = [[NSUserDefaults standardUserDefaults]objectForKey:@"homeLive"];
    if (oldTime && [self isSameDay:[NSDate date] date2:oldTime]) {
        return;
    }
    NSDate *oldDate = [NSDate date];
    [[NSUserDefaults standardUserDefaults]setObject:oldDate forKey:@"homeLive"];
    [[NSUserDefaults standardUserDefaults]synchronize];
    
    
    NSString*version = nil;
    NSString*v = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
    NSArray*vArr = [v componentsSeparatedByString:@"."];
    for (int i = 0; i < vArr.count; i++) {
        if (version == nil) {
            version = [NSString stringWithFormat:@"%@",vArr[i]];
        }else{
            version = [version stringByAppendingFormat:@"%@",vArr[i]];
        }
    }
    NSString *url = [NSString stringWithFormat:@"%@socialsecurity/popupservice/tcform",[NetworkConfig ipKKSBConfig]];
//    NSString *url = [NSString stringWithFormat:@"%@socialsecurity/popupservice/tcform",@"http://172.16.10.215:8081/"];
    NSDictionary *params1 = @{
        @"activeType":@(2001),
        @"fromModel":@(2),
        @"temerInfo":@"kksh",
        @"version":[version stringByReplacingOccurrencesOfString:@"." withString:@""]
    };
    typeof(self) wSelf = self;
    [NetworkRequest Post11:url Params:params1 Success:^(id _Nonnull objc) {
        if ([objc isKindOfClass:[NSDictionary class]]) {
           NSString *state = [NSString stringWithFormat:@"%@",objc[@"code"]];
            if ([state isEqualToString:@"0"]) {
                NSDictionary *resultDic = objc[@"result"];
                if (resultDic.count > 0) {
                    [NetworkRequest statisticsWithEventName:@"show_home_live"];
                    [GuideAlertView showInWindowWithImageName:resultDic[@"callImage"] VC:[[[UIApplication sharedApplication] keyWindow] rootViewController] Block:^(BOOL success) {
                        [NetworkRequest statisticsWithEventName:@"dialog_home_live"];
                        if (![[NSUserDefaults standardUserDefaults]boolForKey:@"firstlog"]){
                            UIWindow *keywindow = [[UIApplication sharedApplication] keyWindow];
                            __block KKNavViewController *nav1 = (KKNavViewController *)keywindow.rootViewController;
                            LoginVC *loginVC = [[LoginVC alloc]init];
                           
                            loginVC.block = ^(BOOL show) {
                                if ([resultDic[@"urlType"] intValue] == 101) {
                                    [[clickEvent instance] clickEventRooterVC:wSelf Content:resultDic[@"eventParam"] menuName:resultDic[@"eventTitle"]];
                                }else if([resultDic[@"urlType"] intValue] == 102){
                                    WebVC *webvc = [[WebVC alloc]init];
                                    webvc.url = resultDic[@"eventParam"];
                                    webvc.title = resultDic[@"eventTitle"];
                                    webvc.hidesBottomBarWhenPushed = YES;
                                    [wSelf.navigationController pushViewController:webvc animated:YES];
                                }else if([resultDic[@"urlType"] intValue] == 103){//小程序
                                    NSDictionary *json=resultDic[@"eventParam"];
                                    NSString *name= json[@"userName"];
                                    NSString *path=json[@"path"];
                                    WXLaunchMiniProgramReq *launchMiniProgramReq = [WXLaunchMiniProgramReq object];
                                    launchMiniProgramReq.userName = name; //拉起的小程序的username
                                    launchMiniProgramReq.path = path; //拉起小程序页面的可带参路径，不填默认拉起小程序首页
                                    launchMiniProgramReq.miniProgramType = WXMiniProgramTypeRelease; //拉起小程序的类型
                                    [WXApi sendReq:launchMiniProgramReq completion:^(BOOL success) {
                                    
                                    }];
                                }
                                
                            };
                            UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:loginVC];
                            [nav1 presentViewController:nav animated:YES completion:nil];
                        }else{
                            if ([resultDic[@"urlType"] intValue] == 101) {
                                [[clickEvent instance] clickEventRooterVC:wSelf Content:resultDic[@"eventParam"] menuName:resultDic[@"eventTitle"]];
                            }else if([resultDic[@"urlType"] intValue] == 102){
                                WebVC *webvc = [[WebVC alloc]init];
                                webvc.url = resultDic[@"eventParam"];
                                webvc.title = resultDic[@"eventTitle"];
                                webvc.hidesBottomBarWhenPushed = YES;
                                [wSelf.navigationController pushViewController:webvc animated:YES];
                            }else if([resultDic[@"urlType"] intValue] == 103){//小程序
                                NSDictionary *json=resultDic[@"eventParam"];
                                NSString *name= json[@"userName"];
                                NSString *path=json[@"path"];
                                WXLaunchMiniProgramReq *launchMiniProgramReq = [WXLaunchMiniProgramReq object];
                                launchMiniProgramReq.userName = name; //拉起的小程序的username
                                launchMiniProgramReq.path = path; //拉起小程序页面的可带参路径，不填默认拉起小程序首页
                                launchMiniProgramReq.miniProgramType = WXMiniProgramTypeRelease; //拉起小程序的类型
                                [WXApi sendReq:launchMiniProgramReq completion:^(BOOL success) {
                                
                                }];
                            }
                        }
                    } close:^(BOOL success) {
                        
                    }];
                }
            }
       }
    } Failure:^(NSError *error) {
        NSLog(@"error:%@",error);
    }];
}
#pragma mark - 新注册用户弹窗，老用户弹窗
- (void)ShowActivityAlert{
     NSDate *oldTime = [[NSUserDefaults standardUserDefaults]objectForKey:@"homeActivitye"];
     if (oldTime && [self isSameDay:[NSDate date] date2:oldTime]) {
         return;
     }
     NSDate *oldDate = [NSDate date];
     [[NSUserDefaults standardUserDefaults]setObject:oldDate forKey:@"homeActivitye"];
     [[NSUserDefaults standardUserDefaults]synchronize];
    
    NSString*version = nil;
    NSString*v = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
    NSArray*vArr = [v componentsSeparatedByString:@"."];
    
    for (int i = 0; i < vArr.count; i++) {
        if (version == nil) {
            version = [NSString stringWithFormat:@"%@",vArr[i]];
        }else{
            version = [version stringByAppendingFormat:@"%@",vArr[i]];
        }
    }
    NSString *url = [NSString stringWithFormat:@"%@socialsecurity/popupservice/tcform",[NetworkConfig ipKKSBConfig]];
    //NSString *url = [NSString stringWithFormat:@"%@socialsecurity/popupservice/tcform",@"http://172.16.10.215:8081/"];
    NSDictionary *params1 = @{
        @"activeType":@(2002),
        @"fromModel":@(2),
        @"temerInfo":@"kksh",
        @"version":[version stringByReplacingOccurrencesOfString:@"." withString:@""],
        @"userId":@([getPeopleID PeopleID]),
        @"telephone":[EnercryTool encryptUseDES:[getPeopleID PeopleIphoneNmber] key:DESKEY]
    };
    typeof(self) wSelf = self;
    [NetworkRequest Post11:url Params:params1 Success:^(id _Nonnull objc) {
        if ([objc isKindOfClass:[NSDictionary class]]) {
           NSString *state = [NSString stringWithFormat:@"%@",objc[@"code"]];
            if ([state isEqualToString:@"0"]) {
                NSDictionary *resultDic = objc[@"result"];
                if (resultDic.count > 0) {
                    [NetworkRequest statisticsWithEventName:[NSString stringWithFormat:@"show_home_%@",resultDic[@"eventType"]]];
                    [GuideAlertView showInWindowWithImageName:resultDic[@"callImage"] VC:[[[UIApplication sharedApplication] keyWindow] rootViewController] Block:^(BOOL success) {
                        [NetworkRequest statisticsWithEventName:[NSString stringWithFormat:@"dialog_home_%@",resultDic[@"eventType"]]];
                        [wSelf popupserviceTcrecordWithDic:resultDic];
                        if ([resultDic[@"urlType"] intValue] == 101) {
                            [[clickEvent instance] clickEventRooterVC:wSelf Content:resultDic[@"eventParam"] menuName:resultDic[@"eventTitle"]];
                        }else if([resultDic[@"urlType"] intValue] == 102){
                            WebVC *webvc = [[WebVC alloc]init];
                            webvc.url = resultDic[@"eventParam"];
                            webvc.title = resultDic[@"eventTitle"];
                            webvc.hidesBottomBarWhenPushed = YES;
                            [wSelf.navigationController pushViewController:webvc animated:YES];
                        }else if([resultDic[@"urlType"] intValue] == 103){//小程序
                            NSString *json=resultDic[@"eventParam"];
                            NSData *jsonData = [json dataUsingEncoding:NSUTF8StringEncoding];
                            NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData
                            options:NSJSONReadingMutableContainers
                            error:nil];
                            NSString *name=[dic[@"userName"] stringValue];
                            NSString *path=[dic[@"path"] stringValue];
                            WXLaunchMiniProgramReq *launchMiniProgramReq = [WXLaunchMiniProgramReq object];
                            launchMiniProgramReq.userName = name; //拉起的小程序的username
                            launchMiniProgramReq.path = path; //拉起小程序页面的可带参路径，不填默认拉起小程序首页
                            launchMiniProgramReq.miniProgramType = WXMiniProgramTypeRelease; //拉起小程序的类型
                            [WXApi sendReq:launchMiniProgramReq completion:^(BOOL success) {
                            
                            }];
                        }
                    } close:^(BOOL success) {

                    }];
                }
            }
       }
    } Failure:^(NSError *error) {
        NSLog(@"error:%@",error);
    }];
}
#pragma mark - 领取优惠卷
- (void)popupserviceTcrecordWithDic:(NSDictionary *)dic{
        NSString *url = [NSString stringWithFormat:@"%@socialsecurity/popupservice/tcrecord",[NetworkConfig ipKKSBConfig]];
//        NSString *url = [NSString stringWithFormat:@"%@socialsecurity/popupservice/tcrecord",@"http://172.16.10.215:8081/"];
        NSDictionary *params1 = @{
            @"eventType":dic[@"eventType"],
            @"userId":@([getPeopleID PeopleID]),
            @"telephone":[EnercryTool encryptUseDES:[getPeopleID PeopleIphoneNmber] key:DESKEY]
        };
        [NetworkRequest Post11:url Params:params1 Success:^(id _Nonnull objc) {
           
            NSLog(@"领取优惠卷===========%@",objc);
        } Failure:^(NSError *error) {
            NSLog(@"error:%@",error);
        }];
}
//社保认证成功弹窗
- (void)showFiveRedPackageNotic:(NSNotification *)notic
{
    NSDate *oldTime = [[NSUserDefaults standardUserDefaults]objectForKey:@"InternetCommerceBank"];
    if (oldTime && [self isSameDay:[NSDate date] date2:oldTime]) {
       
        
    }else{
        NSDate *oldDate = [NSDate date];
        [[NSUserDefaults standardUserDefaults] setObject:oldDate forKey:@"InternetCommerceBank"];
        [[NSUserDefaults standardUserDefaults] synchronize];
        
        [self AlertInternetCommerceBank];
        return;
    }
    
    NSInteger x = (arc4random() % 2) + 1;
    switch (x) {
        case 1:
        {
            [self AlertMoreCredit];
        }
            break;
        case 2:
        {
            [self AlertGasStation];
        }
            break;
            
        default:
            break;
    }
}
#pragma mark - 网商银行弹窗
- (void)AlertInternetCommerceBank{
    NSString *url = [NSString stringWithFormat:@"%@sys/popup/isPopUpBank",[NetworkConfig ipYinShuConfig]];
//    NSString *url = [NSString stringWithFormat:@"%@sys/popup/isPopUpBank",@"http://172.16.10.102:8081/"];
    NSDictionary *params1 = @{
        @"uid":@([getPeopleID PeopleID]),
    };
    typeof(self) wSelf = self;
    [NetworkRequest PostNo:url Params:params1 Success:^(id _Nonnull objc) {
        NSLog(@"%@",objc);
        NSDictionary *resultDic = objc[@"result"];
        if (resultDic.count > 0) {
            NSString *popUp = [NSString stringWithFormat:@"%@",resultDic[@"popUp"]];
            if ([popUp intValue] == 1) {
                [NetworkRequest statisticsWithEventName:@"show_home_InternetCommerceBank"];
                [GuideAlertView showInWindowWithImageName:resultDic[@"imgurl"] VC:[[[UIApplication sharedApplication] keyWindow] rootViewController] Block:^(BOOL success) {
                    [NetworkRequest statisticsWithEventName:@"dialog_home_InternetCommerceBank"];
                    //网商银行
                    NSURL * alipay_app_url = [NSURL URLWithString:@"alipay://"];
                    BOOL ali = [[UIApplication sharedApplication] canOpenURL:alipay_app_url];
                    if (ali) {
                        NSString *url = resultDic[@"bankurl"];
                        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url] options:nil completionHandler:nil];
                    }else{
                        //未安装支付宝
                        [[clickEvent instance] clickEventRooterVC:wSelf Content:@"homeThree4" menuName:@"存钱罐"];
                    }
                } close:^(BOOL success) {
            
                }];
            }
        }
    } Failure:^(NSError *error) {
        NSLog(@"error:%@",error);
    }];
}
#pragma mark - 5元话费
- (void)AlertMoreCredit{
    NSDate *oldTime = [[NSUserDefaults standardUserDefaults]objectForKey:@"homeMoreCredit"];
    if (oldTime && [self isSameDay:[NSDate date] date2:oldTime]) {
        return;
    }
    NSDate *oldDate = [NSDate date];
    [[NSUserDefaults standardUserDefaults]setObject:oldDate forKey:@"homeMoreCredit"];
    [[NSUserDefaults standardUserDefaults]synchronize];
    WeakSelf
    [KKFiveRedPackage showWithBlock:^(BOOL success) {
        [[clickEvent instance] clickEventRooterVC:weakSelf getFederatedLoginRequestWithUrl:@"https://web.kanface.com:444/common/forward/FamilyChargeForwardUrl" menuName:@"话费充值"];
//        WebVC *webvc = [[WebVC alloc]init];
//        NSString  *phone = [getPeopleID PeopleIphoneNmber];
//        if (phone.length > 0) {
//            webvc.url = [NSString stringWithFormat:@"http://www.qld02.com/t/blackcard/callFee/callFeeForH5.html?channel=shebao&mobile=%@",[getPeopleID PeopleIphoneNmber]];
//        }else{
//            webvc.url = @"http://www.qld02.com/t/blackcard/callFee/callFeeForH5.html?channel=shebao";
//        }
//        webvc.title = @"话费劵";
//        webvc.hidesBottomBarWhenPushed = YES;
//        [self.navigationController pushViewController:webvc animated:YES];
    }];
}
#pragma mark - 团油
- (void)AlertGasStation{
    NSDate *oldTime = [[NSUserDefaults standardUserDefaults]objectForKey:@"HomeGasStation"];

    if (oldTime && [self isSameDay:[NSDate date] date2:oldTime]) {
        return;
    }

    NSDate *oldDate = [NSDate date];
    [[NSUserDefaults standardUserDefaults]setObject:oldDate forKey:@"HomeGasStation"];
    [[NSUserDefaults standardUserDefaults]synchronize];

    [NetworkRequest statisticsWithEventName:@"show_Certification_GasStation"];
    [GuideAlertView showInWindowWithImageName:@"CertificationGasStation" Block:^(BOOL success) {
        [[clickEvent instance] clickEventRooterVC:self Content:@"homeTwoOil" menuName:@"团油"];
        [NetworkRequest statisticsWithEventName:@"dialog_Certification_GasStation"];
    }];
}
//判断是否同一天
- (BOOL)isSameDay:(NSDate*)date1 date2:(NSDate*)date2
{
    NSCalendar* calendar = [NSCalendar currentCalendar];
    unsigned unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit;
    NSDateComponents* comp1 = [calendar components:unitFlags fromDate:date1];
    NSDateComponents* comp2 = [calendar components:unitFlags fromDate:date2];
    return [comp1 day] == [comp2 day] &&
    [comp1 month] == [comp2 month] &&
    [comp1 year] == [comp2 year];
}
//获取认证限制人数
- (void)getAuthPersonNumberRequest {
    NSString*url = [NSString stringWithFormat:@"%@/socialsecurity/verify/getAlreadyCount",IPDIZHI];
     BOOL auth =  [getPeopleID getpeopleLimited];
    BOOL cert =  [getPeopleID accountState];
    NSDictionary* params = @{
        @"userId":@([getPeopleID PeopleID]),
        @"telephone":[EnercryTool encryptUseDES:[getPeopleID PeopleIphoneNmber] key:DESKEY],
        @"accountType":auth ? @"0" : @"1",
        @"iscert": cert ? @"2" : @"1"
    };
    
    [NetworkRequest SBAuthPost:url Params:params Success:^(id _Nonnull responseObject) {
        NSLog(@"当前认证限制信息responseObject:%@",responseObject);
        if ([responseObject isKindOfClass:[NSDictionary class]]) {
            NSString*code = [NSString stringWithFormat:@"%@",responseObject[@"code"]];
            if ([code isEqualToString:@"0"]) {
                if ([responseObject[@"result"] isKindOfClass:[NSDictionary class]]) {
                    NSString*alreadyCount = [NSString stringWithFormat:@"%@",responseObject[@"result"][@"alreadyCount"]];
                    NSString*maxcount = [NSString stringWithFormat:@"%@",responseObject[@"result"][@"maxcount"]];
                    NSString*certRealNameCount = [NSString stringWithFormat:@"%@",responseObject[@"result"][@"certRealNameCount"]];
                    [UserDefault setObject:alreadyCount forKey:@"alreadyCount"];
                    [UserDefault setObject:maxcount forKey:@"maxcount"];
                    [UserDefault setObject:certRealNameCount forKey:@"certRealNameCount"];
                    [UserDefault synchronize];
                }
                
            }
        }
       
    } Failure:^(NSError* _Nonnull error) {
        NSLog(@"error:%@",error);
    }];
 
}

#pragma mark - 判断是否处在登录时间内,或者是否有登陆过
- (void)judgeLoginTimeInvalid:(void (^)(bool success))complete
{
    
    NSString* accountStr = [getPeopleID getDefaultLoginAccount];
    NSString* passwordStr = [getPeopleID getDefaultLoginPassword];
    
    if (![NSString blankString:accountStr] && ![NSString blankString:passwordStr]) {
        [[PasswordLoginViewController new]defaultLogin:^(bool success) {
            complete(success);
            
        }];
    }else{
       
       // [self logOut];
        
    }
}

#pragma mark - 退出登录
- (void)logOut
{
    [UserDefault setBool:NO forKey:@"firstlog"];
    [UserDefault setBool:NO forKey:@"secondImage"];
    
    //清除分享时间
    [UserDefault setObject:nil forKey:@"shareLastTime"];
    //清除最近认证记录
    [UserDefault setObject:nil forKey:@"ValidationDic"];
    //清除认证成功弹框时间
    [UserDefault setObject:nil forKey:@"coinsauthenticationLastTime"];
    
    //清除走路赚金币领取时间
    [UserDefault setObject:nil forKey:@"onFootCoinsDate"];
    
    [getPeopleID getpeopleLimitedAuthority:NO];
    [getPeopleID socialSate:0];
    
    //雷俊博退出时清除登录类型和账号密码
    [getPeopleID getLoginType:nil];
    [getPeopleID getLoginAccount:nil];
    [getPeopleID getLoginPassword:nil];
    [getPeopleID saveDefaultLoginAccount:nil];
    [getPeopleID saveDefaultLoginPassword:nil];
    [getPeopleID getTotalCoins:nil];
    [getPeopleID clearTotalCoins];
    [getPeopleID clearDefaultProvince];
    
    [getPeopleID saveAccountAuthWithState:NO];
    
    //清除登录时间
    [getPeopleID saveLoginTime:nil];

    [UserDefault setInteger:0 forKey:@"appleLoginState"];
    //
//    NSString *giUid = [UserDefault valueForKey:@"giUid"];
    
    [UserDefault synchronize];
    

    NSIndexSet *indexSet = [[NSIndexSet alloc] initWithIndex:1];
    [self.tableView reloadSections:indexSet withRowAnimation:UITableViewRowAnimationAutomatic];
}


//#pragma mark - 获取用户列表请求
//- (NSDictionary *)getCertlistRequestParam
//{
//    NSDictionary *params = @{
//        @"userId":[NSNumber numberWithInteger:[getPeopleID PeopleID]],
//        @"telephone":[EnercryTool encryptUseDES:[getPeopleID PeopleIphoneNmber] key:DESKEY],
////        @"userId":@3618036,
////        @"telephone":@"bFx4t3dqQjILZvmonLp1lg==",
//        @"fromModel":@"2"
//    };
//    return params;
//}
//
//- (void)getCertlistReq
//{
//    NSString *url = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipKKSBConfig],getCertlistRequest];
//    NSLog(@"获取用户列表url:%@",url);
//    NSLog(@"params:%@",[self getCertlistRequestParam]);
//    WeakSelf
//    [NetworkRequest SBAuthPost:url Params:[self getCertlistRequestParam] Success:^(id _Nonnull responseObject) {
//        NSLog(@"responseObject:%@",responseObject);
//        if ([responseObject isKindOfClass:[NSDictionary class]]) {
//            NSString* code = [NSString stringWithFormat:@"%@",responseObject[@"code"]];
//            if ([code isEqualToString:@"0"]) {
//                NSArray *listArray = responseObject[@"result"];
//                if ([listArray isKindOfClass:[NSArray class]] && listArray.count > 0) {
//                     [weakSelf creatTable2:listArray];
//                }
//
//            }
//        }
//    } Failure:^(NSError* error) {
//        NSLog(@"error:%@",error);
//    }];
//}
#pragma mark - 判断是否有理财
- (void)GetyeepayUrl
{
    [[clickEvent instance] clickEventRooterVC:self Content:@"homeThree4" menuName:@"存钱罐"];
}

//金丝雀广告

-(void) getJSQAd{
    NSString *url=@"https://web.kanface.com:444/navigate/get/config";
    NSDictionary *params = @{@"configName":@"HomeFloat_kksh"};
    [NetworkRequest PostNo:url Params:params Success:^(id _Nonnull obj) {
        NSString* state = [NSString stringWithFormat:@"%@",obj[@"state"]];
        if([state isEqualToString:@"200"]){
            NSString* result = [NSString stringWithFormat:@"%@",obj[@"result"]];
            if([result isEqualToString:@"1001"]){//金丝雀
                _serviceAdView = [[CXHAdSDKServiceAdView alloc] initWithFrame:CGRectMake(0, 0, 60*WIDTHRADIU,
                                                                                         80*WIDTHRADIU)];
                _serviceAdView.delegate = self;
                _serviceAdView.controller = self;
                _serviceAdView.refershTime = 35;
                _serviceAdView.posId = @"42625192";
                // _serviceAdView.showCloseView = YES;
                //_serviceAdView.backgroundColor = [UIColor whiteColor];
                
                [_serviceAdView sendWinNotice:100];
                // 2 添加到⽗视图上
                _serviceAdView.frame = CGRectMake([UIScreen mainScreen].bounds.size.width -90, [UIScreen mainScreen].bounds.size.height -170*WIDTHRADIU, 60*WIDTHRADIU, 80*WIDTHRADIU);
                [self.view addSubview:_serviceAdView];
                // 3 加载并显示⼴告
                [_serviceAdView loadAndShow];
            }else{
                //获取homeBtns
                [self getHomeBtnItemsRequest];
            }
        }else{
            //获取homeBtns
            [self getHomeBtnItemsRequest];
        }
        
    } Failure:^(NSError* error) {
        
    }];
    
}

// 4 代理回调
#pragma mark - CXHSDKServiceAdViewDelegate
/**
⼴告获取成功
@param serviceAdView ⼴告实例
*/
- (void)CXH_serviceAdViewDidReceived:(CXHAdSDKServiceAdView *)serviceAdView{
    [NetworkRequest statisticsWithEventName:@"jsq_adReceived"];
}
/**
⼴告拉取失败
@param serviceAdView ⼴告实例
@param error 错误描述
*/
- (void)CXH_serviceAdViewFailToReceived:(CXHAdSDKServiceAdView *)serviceAdView error: (NSError *)error{
 [_serviceAdView removeFromSuperview];
_serviceAdView = nil;
    [NetworkRequest statisticsWithEventName:@"jsq_adFail"];
}
/**
⼴告点击
@param serviceAdView ⼴告实例
@param loadingPageURL ⼴告落地⻚地址，当渠道为bwt，并且customLoadingPage为YES时有值
*/
- (void)CXH_serviceAdViewClicked:(CXHAdSDKServiceAdView *)serviceAdView loadingPageURL: (NSString *)loadingPageURL{
    NSLog(@"🎁 首页广告按钮被点击 - 广告实例: %@", serviceAdView);
    NSLog(@"🎁 广告落地页URL: %@", loadingPageURL);
    NSLog(@"🎁 广告点击时间: %@", [NSDate date]);
    [NetworkRequest statisticsWithEventName:@"jsq_adClicked"];
}
/**
⼴告关闭
@param serviceAdView ⼴告实例
*/
- (void)CXH_serviceAdViewClose:(CXHAdSDKServiceAdView *)serviceAdView{
dispatch_async(dispatch_get_main_queue(), ^{
_serviceAdView = nil;
    [NetworkRequest statisticsWithEventName:@"jsq_adViewClose"];
 });
}
/**
⼴告展示
@param serviceAdView ⼴告实例
*/
- (void)CXH_serviceAdViewExposure:(CXHAdSDKServiceAdView *)serviceAdView{
    [NetworkRequest statisticsWithEventName:@"jsq_adExposure"];
}
/**
关闭落地⻚
@param serviceAdView ⼴告实例
*/
- (void)CXH_serviceAdViewCloseLandingPage:(CXHAdSDKServiceAdView *)serviceAdView{
    [NetworkRequest statisticsWithEventName:@"jsq_adCloseLanding"];
}

#pragma mark - 获取悬浮框显示图片
- (void)getHomeBtnItemsRequest
{
    NSString*version = nil;
    NSString*v = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
    NSArray*vArr = [v componentsSeparatedByString:@"."];
    
    for (int i = 0; i < vArr.count; i++) {
        if (version == nil) {
            version = [NSString stringWithFormat:@"%@",vArr[i]];
        }else{
            version = [version stringByAppendingFormat:@"%@",vArr[i]];
        }
    }
    
    NSString *url = [NSString stringWithFormat:@"%@dynamic/menu/get",[NetworkConfig ipYinShuConfig]];
    //NSString *url = @"http://172.16.10.18:8017/dynamic/menu/get";
    
    NSDictionary *params = @{
        @"configName":@"ShouYeXuanFuKuang",
        @"appName":@"kksh",
        @"version":version,
        @"systemType":@"iOS"
    };
    WeakSelf
    [NetworkRequest Post15:url Params:params Success:^(id _Nonnull objc) {
        
        NSLog(@"ShouYeXuanFuKuangobjc:%@",objc);
        if ([objc isKindOfClass:[NSDictionary class]]) {
            NSString *state = [NSString stringWithFormat:@"%@",objc[@"state"]];
            
            if ([state isEqualToString:@"200"]) {
                if ([objc[@"result"] isKindOfClass:[NSArray class]]) {
                    weakSelf.btnItemsArray = [KKRedPackageClickEventModel mj_objectArrayWithKeyValuesArray:objc[@"result"]];
                    NSLog(@"🎁 网络请求返回数据 - btnItemsArray数量: %lu", (unsigned long)weakSelf.btnItemsArray.count);

                    if (weakSelf.btnItemsArray.count == 4) {
                        self.button.hidden=NO;
                        NSLog(@"🎁 悬浮按钮显示条件满足 - btnItemsArray.count == 4");
                        KKRedPackageClickEventModel *model = weakSelf.btnItemsArray[0];
                        [weakSelf.button sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",KKFindPackageIP,model.menuIcon]] forState:UIControlStateNormal completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
                            UIImage *refined = [UIImage imageWithCGImage:image.CGImage scale:2.0 orientation:image.imageOrientation];
                            [weakSelf.button setImage:refined forState:UIControlStateNormal];
                        }];
                    }

                }
            }

        }

    } Failure:^(NSError *error) {
        NSLog(@"🎁 网络请求失败 - 无法获取悬浮按钮数据: %@", error);
        NSLog(@"🎁 悬浮按钮将保持隐藏状态");

    }];
}
#pragma mark - 创建本地数据库
- (void)creatTable2:(NSArray *)listArray
{
    //1.获得数据库文件的路径
    NSLog(@"表格路径:%@",[self getDBPath2]);
     //2.获得数据库
    FMDatabase *db=[FMDatabase databaseWithPath:[self getDBPath2]];
    if ([db open]) {
         //4.创表
        NSString* sql = @"CREATE TABLE IF NOT EXISTS t_rzUser (id integer PRIMARY KEY AUTOINCREMENT, name text NOT NULL, idNumber text NOT NULL, userid text NOT NULL,timeSp text);";
         BOOL result=[db executeUpdate:sql];
        if (result) {
            NSLog(@"创表成功");
            
            [self removeLocalUserList:listArray];
            
        }else{
            NSLog(@"创表失败");
        }
        
        [db close];
    }
}

#pragma mark - 添加用户列表
- (void)insertUserList:(NSArray *)listArray
{
    
    FMDatabase *db = [FMDatabase databaseWithPath:[self getDBPath2]];
    if ([db open]) {
        for (NSDictionary* dic in listArray) {
            NSString*name = dic[@"idname"];
            NSString*idNumber = dic[@"idcard"];
            if (![NSString blankString:name] && ![NSString blankString:idNumber]) {
                
                NSString * sql = [NSString stringWithFormat:@"INSERT INTO t_rzUser (name,idNumber,userid) VALUES (?, ?,?);"];
                NSString *userid = [NSString stringWithFormat:@"%ld",[getPeopleID PeopleID]];
                
                BOOL res =  [db executeUpdate:sql,name,idNumber,userid];
                 if (res) {
                     NSLog(@"数据添加成功");
                    
                 }else{
                     NSLog(@"数据添加失败");
                 }
                
            }
   
        };
        
        [db close];
    }
    
}

#pragma mark - 移除本地用户
- (void)removeLocalUserList:(NSArray *)listArray
{
    FMDatabase *db = [FMDatabase databaseWithPath:[self getDBPath2]];
    
    if ([db open]) {
        NSString *sql = [NSString stringWithFormat:@"delete from t_rzUser where userid = '%ld'",[getPeopleID PeopleID]];
        BOOL reslut =   [db executeUpdate:sql];
        if (reslut) {
            NSLog(@"本地数据删除成功");
            [self insertUserList:listArray];
        }else{
            NSLog(@"本地数据删除失败");
        }
        [db close];
    }
}

- (NSString *)getDBPath2
{
     NSString *doc= [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
        return [doc stringByAppendingPathComponent:@"rzUserlist.sqlite"];

}
#pragma mark - 添加认证记录统计
- (void)addAuthPersonNumberRequest {
    NSString*url = [NSString stringWithFormat:@"%@/socialsecurity/verify/insertCerRecord",IPDIZHI];
    
   NSString* NameEnerypt =  [EnercryTool A:@"雷俊博"];
    //身份证号AES加密
    NSString* IdentiftyEnerypt = [EnercryTool A:@"411522199109276910"];
    
    NSDictionary* params = @{
        @"userId":@([getPeopleID PeopleID]),
        @"telephone":[EnercryTool encryptUseDES:[getPeopleID PeopleIphoneNmber] key:DESKEY],
        @"certificationStatus": @"0",
        @"personName":NameEnerypt,
        @"identityNumber":IdentiftyEnerypt
    };
    
    [NetworkRequest SBAuthPost:url Params:params Success:^(id _Nonnull responseObject) {
        
        NSLog(@"添加认证记录统计responseObject:%@",responseObject);
        
    } Failure:^(NSError* _Nonnull error) {
        
        NSLog(@"error:%@",error);
        
    }];
    
    [CTAPIBaseManager POST:url params:params completionHandler:^(id  _Nonnull responseObject, NSError * _Nonnull error) {
        
        NSLog(@"添加认证记录统计responseObject:%@",responseObject);
        
    }];
    
    
}

#pragma mark - 判断账户是否已实名
- (NSDictionary *)judgeAccountAuthRequestParams {
    NSString*tel =  [getPeopleID PeopleIphoneNmber];
    
    tel = [EnercryTool AES256Encrypt:tel key:DESKEY];
    NSDictionary *dic = @{
           @"tel":tel
       };
    
    return dic;
}

- (void)judgeAccountAuthStateRequest {
    
    NSString *urlString = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipESSCConfig],KKCheckAccountStateRequest];
    NSLog(@"判断账户是否已实名url:%@",urlString);
    NSLog(@"params:%@",[self judgeAccountAuthRequestParams]);
    
    [NetworkRequest SBAuthPost:urlString Params:[self judgeAccountAuthRequestParams] Success:^(id _Nonnull objc) {
        NSLog(@"objc:%@",objc);
        if ([objc isKindOfClass:[NSDictionary class]]) {
            NSString* code = [NSString stringWithFormat:@"%@",objc[@"state"]];
            //NSString* describe = [NSString stringWithFormat:@"%@",objc[@"describe"]];
            if ([code isEqualToString:@"200"]) {
                
                //[self alertShow:@"该账户当天认证人数已达上限"];
                
                [getPeopleID saveAccountAuthWithState:YES];
                
            }else if ([code isEqualToString:@"204"]) {
                
                //[self goToAuthVC];
                [getPeopleID saveAccountAuthWithState:NO];
            }
        }
        
        
    } Failure:^(NSError* error) {
       
        
    }];
}


#pragma mark - 中部banner新闻
- (NSDictionary *)requestParams
{
    NSString* province = [UserDefault objectForKey:@"locationProvince"];
    
    NSString* provinceValue = [self getLocationAddressKeyWithProvinceName:province];
    
    NSDictionary *param = @{
        @"news_type":@"hot",
        @"address":provinceValue
    };
    
    return param;
}

- (void)loadData
{
    NSString *urlString = JUHEUrlString;
    NSLog(@"新闻列表:url:%@",urlString);
    NSLog(@"🌐 开始请求新闻数据...");
    NSLog(@"📡 接口URL: %@", urlString);
    NSLog(@"📋 请求参数: %@", [self requestParams]);
    NSLog(@"⏰ 请求时间: %@", [NSDate date]);
    
    [NetworkRequest NewsPost:urlString Params:[self requestParams] Success:^(id _Nonnull objc) {
       
        NSLog(@"📥 原始响应数据: %@", objc);
        
        if ([objc isKindOfClass:[NSDictionary class]]) {
            NSString *status = [NSString stringWithFormat:@"%@",objc[@"status"]];
            NSString *msg = [NSString stringWithFormat:@"%@",objc[@"msg"] ?: @""];
            
            NSLog(@"📊 响应状态码: %@", status);
            NSLog(@"📢 响应消息: %@", msg);
            
            if ([status isEqualToString:@"0"]) {
                NSLog(@"✅ 新闻请求成功 - 渲染时间: %@", [NSDate date]);

                if (self.timer) {
                    [self.timer invalidate];
                }
                
                // 获取新闻列表数组
                NSArray *newsList = objc[@"news_list"];
                NSLog(@"📰 原始新闻列表数组: %@", newsList);
                
                if (newsList && [newsList isKindOfClass:[NSArray class]]) {
                    NSLog(@"📊 原始新闻数量: %lu", (unsigned long)newsList.count);
                    
                    // 打印前几条新闻的详细信息
                    for (NSInteger i = 0; i < MIN(3, newsList.count); i++) {
                        NSDictionary *newsDict = newsList[i];
                        if ([newsDict isKindOfClass:[NSDictionary class]]) {
                            NSLog(@"📰 新闻[%ld]: title=%@, url=%@, pic=%@", 
                                  (long)i, 
                                  newsDict[@"title"] ?: @"无标题",
                                  newsDict[@"url"] ?: @"无链接",
                                  newsDict[@"pic"] ?: @"无图片");
                        }
                    }
                }
                
                self.newsArray = [JHNewsModel mj_objectArrayWithKeyValuesArray:newsList];
                self->index = 0;
                
                // 添加log打印解析后的新闻数量
                NSLog(@"📊 解析后新闻数量: %lu", (unsigned long)self.newsArray.count);
                
                // 打印解析后的新闻模型
                for (NSInteger i = 0; i < MIN(3, self.newsArray.count); i++) {
                    JHNewsModel *model = self.newsArray[i];
                    if ([model isKindOfClass:[JHNewsModel class]]) {
                        NSLog(@"📄 新闻模型[%ld]: title=%@, news_url=%@", 
                              (long)i, 
                              model.title ?: @"无标题",
                              model.news_url ?: @"无链接");
                    }
                }
                
                if (self.newsArray.count >= 10) {
                    NSLog(@"📈 新闻数量≥10，启动定时滚动");
                    [self scrollNewsTime];
                } else {
                    NSLog(@"📉 新闻数量<10，不启动定时滚动");
                }
                
                NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:1];
                [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone];
                
                NSLog(@"🔄 已刷新section 1的cell");
                
            } else {
                NSLog(@"❌ 新闻请求失败 - 状态码: %@, 消息: %@", status, msg);
            }
        } else {
            NSLog(@"⚠️ 响应数据格式异常: %@", [objc class]);
        }
        
        
    } Failure:^(NSError* error) {
       
        NSLog(@"❌ 新闻请求失败: %@", error);
        NSLog(@"❌ 错误详情: %@", error.localizedDescription);
    }];
}


#pragma mark - 消息拉取
- (void)getNewNotcieMsgRequest
{
    NSString *url = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipYouFuVerityConfig],KKHomeHelperAuthResultRequest];
    
    NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
    NSString *app_Version = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
    app_Version = [app_Version stringByReplacingOccurrencesOfString:@"." withString:@""];
    
    NSDictionary *params = @{
        @"telphone":[EnercryTool encryptUseDES:[getPeopleID PeopleIphoneNmber] key:DESKEY],
        @"userid":@([getPeopleID PeopleID]),
        @"fromapp":@"kksh",
        @"version":app_Version,
        @"frommodel":@(2)
    };
    
    
    [NetworkRequest Post15:url Params:params Success:^(id _Nonnull objc) {
        
        NSLog(@"objc:%@",objc);
        if ([objc isKindOfClass:[NSDictionary class]]) {
            NSString *state = [NSString stringWithFormat:@"%@",objc[@"state"]];
            
            if ([state isEqualToString:@"200"]) {
                NSArray *msgArray = [KKNewMsgResultInfoModel mj_objectArrayWithKeyValuesArray:objc[@"result"]];
                
                if (msgArray.count > 0) {
                    self.msgModel = msgArray[0];
                  
                    NSDictionary *dic = [Tools dictionaryWithJsonString:objc[@"describe"]];
                    if ([dic isKindOfClass:[NSDictionary class]]) {
                        NSString *count = [NSString stringWithFormat:@"%@",dic[@"all"]];
                        self.unreadCount = count.integerValue ;
                    }
                    
                    [self.tableView reloadData];
                    
                    
                }
            }
            
        }
        
        
    } Failure:^(NSError* error) {
        
        NSLog(@"error:%@",error);
        
    }];
 
}

#pragma mark - 获取定位省份的key
- (NSString *)getLocationAddressKeyWithProvinceName:(NSString *)province
{
    NSString* str = @"bj";
    
    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"newProvince" ofType:@"plist"];
    //其次通过这个文件路径获得字典文件(因为Info.plist内容本身就是个字典集)
    NSArray *provinceArr = [NSArray arrayWithContentsOfFile:filePath];
    
    for (NSDictionary* dic in provinceArr) {
        if ([dic[@"provinceName"] isEqualToString:province]) {
            str = dic[@"provinceValue"];
            break;
        }
    }
    
    
    return str;
}


#pragma mark - 定时刷新新闻
- (void)scrollNewsTime {
    self.timer = [NSTimer timerWithTimeInterval:10.0 target:self selector:@selector(timerMethod1) userInfo:nil repeats:YES];
    [[NSRunLoop currentRunLoop] addTimer:self.timer forMode:NSRunLoopCommonModes];
}

#pragma mark - 定时器绑定方法
- (void)timerMethod1 {
    if (self.msgModel && [[NSUserDefaults standardUserDefaults] boolForKey:@"firstlog"] && [self compareCurrentTime:self.msgModel.noticeTime] && self.newsArray.count > 10){
        
        NSInteger m = self.newsArray.count;
        
        if (index > (m - 1)) {
            index = 0;
        }
        
        __block JHNewsModel* model1 = self.newsArray[index];
        
        NSDictionary *attributes = @{NSFontAttributeName:[UIFont systemFontOfSize:15], NSForegroundColorAttributeName: [UIColor colorWithHex:0x4d4d4d]};
           
        NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString:model1.title attributes:attributes];
      
        [text yy_setTextHighlightRange:NSMakeRange(0, model1.title.length) color:[UIColor colorWithHex:0x4d4d4d] backgroundColor:[UIColor colorWithHex:0xcccccc] userInfo:nil tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
            containerView.backgroundColor = [UIColor colorWithHex:0xcccccc];
            [self goToNewsDetaiVCWithModel:model1];
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                    //3秒后 执行block内的代码
                containerView.backgroundColor = [UIColor clearColor];
            });
        } longPressAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
            
            [self goToNewsDetaiVCWithModel:model1];
        }];
        
        self.lb_msg.attributedText = text;
        
    }else{
        NSInteger m = self.newsArray.count / 2;
        
        if (index > (m - 1)) {
            index = 0;
        }
        
        __block JHNewsModel* model1 = self.newsArray[index*2];
        __block JHNewsModel* model2 = self.newsArray[index*2 + 1];
        
        
        NSDictionary *attributes = @{NSFontAttributeName:[UIFont fontWithName:@"PingFangSC-Regular" size:15], NSForegroundColorAttributeName: [UIColor colorWithHex:0x808080]};
           
        NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString:model1.title attributes:attributes];
        NSMutableAttributedString *text2 = [[NSMutableAttributedString alloc] initWithString:model2.title attributes:attributes];
           //设置高亮色和点击事件
    //    [text yy_setTextHighlightRange:NSMakeRange(0, model1.title.length) color:[UIColor colorWithHex:0x808080] backgroundColor:[UIColor colorWithHex:0xcccccc] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
    //        [self goToNewsDetaiVCWithModel:model1];
    //    }];
        
        [text yy_setTextHighlightRange:NSMakeRange(0, model1.title.length) color:[UIColor colorWithHex:0x4d4d4d] backgroundColor:[UIColor colorWithHex:0xcccccc] userInfo:nil tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
            containerView.backgroundColor = [UIColor colorWithHex:0xcccccc];
            [self goToNewsDetaiVCWithModel:model1];
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                    //3秒后 执行block内的代码
                containerView.backgroundColor = [UIColor clearColor];
            });
        } longPressAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
            
            [self goToNewsDetaiVCWithModel:model1];
        }];
        
    //    [text2 yy_setTextHighlightRange:NSMakeRange(0, model2.title.length) color:[UIColor colorWithHex:0x808080] backgroundColor:[UIColor colorWithHex:0xcccccc] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
    //        [self goToNewsDetaiVCWithModel:model2];
    //    }];
        
        [text2 yy_setTextHighlightRange:NSMakeRange(0, model2.title.length ) color:[UIColor colorWithHex:0x4d4d4d] backgroundColor:[UIColor colorWithHex:0xcccccc] userInfo:nil tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
            containerView.backgroundColor = [UIColor colorWithHex:0xcccccc];
            [self goToNewsDetaiVCWithModel:model2];
            
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                    //3秒后 执行block内的代码
                containerView.backgroundColor = [UIColor clearColor];
            });
        
            
            
        } longPressAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
            [self goToNewsDetaiVCWithModel:model2];
        }];
        
        self.lb_content1.attributedText = text;
        self.lb_content2.attributedText = text2;
        
    }
    index++;
}

#pragma mark - 定位
//定位
-(void)locationDisplay
{
    //天气url
//    NSString *url = WeatherUrl;
//    typeof(self) wSelf = self;
//    NSMutableDictionary *param = [NSMutableDictionary dictionary];
//    [NetworkRequest Get4:url Params:param Success:^(id _Nonnull responseObject) {
//        NSLog(@"responseObject:%@",responseObject);
//        NSDictionary *dic = responseObject;
//        if (dic.count > 0) {
//            NSMutableDictionary *tqData =  [[NSMutableDictionary alloc]initWithDictionary:dic];
//            NSString *chooseCity=[[NSUserDefaults standardUserDefaults]objectForKey:@"chooseCity"];
//            NSString *city=tqData[@"city"];
//            if(chooseCity==nil){
//                self.cityLab.text = tqData[@"city"];
//                NSString *temp = tqData[@"today"][@"temp"];
//                self.weatherLab.text = [NSString stringWithFormat:@"%@ %@℃",tqData[@"today"][@"weather"],temp];
//            }else{
//                NSString *chooseProvince=[[NSUserDefaults standardUserDefaults]objectForKey:@"chooseProvince"];
//                [self ChooseAddressBack:chooseProvince :chooseCity];
//            }
//        }
//    } Failure:^(NSError * _Nonnull error) {
//        NSLog(@"error:%@",error);
//
//    }];
    NSString *chooseCity=[[NSUserDefaults standardUserDefaults]objectForKey:@"chooseCity"];
    NSString *chooseProvince=[[NSUserDefaults standardUserDefaults]objectForKey:@"chooseProvince"];
    if(chooseCity!=nil){
        [self ChooseAddressBack:chooseProvince :chooseCity];
    }else{
        NSString *locationCity=[[NSUserDefaults standardUserDefaults]objectForKey:@"locationCity"];
        NSString *locationProvince=[[NSUserDefaults standardUserDefaults]objectForKey:@"locationProvince"];
        [self ChooseAddressBack:locationProvince :locationCity];
    }
    
    //ip定位
    NSMutableDictionary *paramW = [NSMutableDictionary dictionary];
    [NetworkRequest Get4:@"https://h5.weface.com.cn/20200228/ws/address/ip" Params:paramW Success:^(id _Nonnull responseObject) {
        NSLog(@"responseObject:%@",responseObject);
        NSString* state = [NSString stringWithFormat:@"%@",responseObject[@"state"]];
        if([state isEqualToString:@"200"]){
            if ([responseObject[@"result"] isKindOfClass:[NSDictionary class]]){
                NSDictionary *result=responseObject[@"result"];
                
                [[NSUserDefaults standardUserDefaults]setObject:[NSString stringWithFormat:@"%@",result[@"province"]] forKey:@"locationProvince"];
               [[NSUserDefaults standardUserDefaults]setObject:[NSString stringWithFormat:@"%@",result[@"city"]] forKey:@"locationCity"];
               [[NSUserDefaults standardUserDefaults]setObject:[NSString stringWithFormat:@"%@",result[@"district"]] forKey:@"locationCounty"];
                //[[NSUserDefaults standardUserDefaults]setObject:[NSString stringWithFormat:@"%@",result[@"province"]] forKey:@"chooseProvince"];
               //[[NSUserDefaults standardUserDefaults]setObject:[NSString stringWithFormat:@"%@",result[@"city"]] forKey:@"chooseCity"];
            }
        }
    } Failure:^(NSError * _Nonnull error) {
        NSLog(@"error:%@",error);
      
    }];
    
//
////    [self acquirePicture:nil andL:0];
//      //初始化实例
//
//    _locationManager = [[BMKLocationManager alloc] init];
//     //设置delegate
//    _locationManager.delegate = self;
//     //设置返回位置的坐标系类型
//    _locationManager.coordinateType = BMKLocationCoordinateTypeBMK09LL;
//     //设置距离过滤参数
//    _locationManager.distanceFilter = kCLDistanceFilterNone;
//     //设置预期精度参数
//    _locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
//     //设置应用位置类型
//    _locationManager.activityType = CLActivityTypeAutomotiveNavigation;
//     //设置是否自动停止位置更新
//    _locationManager.pausesLocationUpdatesAutomatically = NO;
//     //设置是否允许后台定位
//     //_locationManager.allowsBackgroundLocationUpdates = YES;
//     //设置位置获取超时时间
//    _locationManager.locationTimeout = 10;
//     //设置获取地址信息超时时间
//    _locationManager.reGeocodeTimeout = 10;
//
//    //[_locationManager startUpdatingLocation];
//     [_locationManager requestLocationWithReGeocode:YES withNetworkState:YES completionBlock:^(BMKLocation * _Nullable location, BMKLocationNetworkState state, NSError * _Nullable error) {
//        [self->_locationManager stopUpdatingLocation]; //停止定位
//        if (error)
//        {
//            NSLog(@"locError:{%ld - %@};", (long)error.code, error.localizedDescription);
//        }
//
//        if (location) { //得到定位信息，添加annotation
//            if (location.location) {
//                NSLog(@"LOC = %@",location.location);
//            }
//            if (location.rgcData) {
//                NSLog(@"rgc = %@",[location.rgcData description]);
//            }
//
//            if (location.rgcData.poiList) {
//                for (BMKLocationPoi * poi in location.rgcData.poiList) {
//                    NSLog(@"poi = %@", poi.name);
//                }
//            }
//
//
//            if (location.rgcData) {
//                NSLog(@"定位信息:%@%@%@%@%@",location.rgcData.province,location.rgcData.city,location.rgcData.district,location.rgcData.street,location.rgcData.streetNumber);
//                NSString *address = [NSString stringWithFormat:@"%@%@%@%@%@%@(%@)",[NSString validBlankStr:location.rgcData.province],[NSString validBlankStr:location.rgcData.city],[NSString validBlankStr:location.rgcData.district],[NSString validBlankStr:location.rgcData.town],[NSString validBlankStr:location.rgcData.street],[NSString validBlankStr:location.rgcData.streetNumber],[NSString validBlankStr:location.rgcData.locationDescribe]];
//
//                 [[NSUserDefaults standardUserDefaults]setObject:location.rgcData.province forKey:@"locationProvince"];
//                [[NSUserDefaults standardUserDefaults]setObject:location.rgcData.city forKey:@"locationCity"];
//                [[NSUserDefaults standardUserDefaults]setObject:location.rgcData.district forKey:@"locationCounty"];
//                [[NSUserDefaults standardUserDefaults]setObject:address forKey:@"locationAddress"];
//                [UserDefault setObject:[NSString stringWithFormat:@"%f,%f",location.location.coordinate.longitude,location.location.coordinate.latitude] forKey:@"locationCoordinate"];
//                [[NSUserDefaults standardUserDefaults]synchronize];
//
//
//                NSString*city = [UserDefault objectForKey:@"locationCity"];
//                NSString*county = [UserDefault objectForKey:@"locationCounty"];
//                BOOL isNeedRefresh = NO;
//                if ([Tools isBlankString:city] || [Tools isBlankString:county]) {
//                    isNeedRefresh = YES;
//                }
//
//                if (isNeedRefresh) {
//                    [ self loadMiddleBannerApiRequest];
////                    [self acquirePicture:nil andL:0];
//                }
//
//                if ([city isEqualToString:@"廊坊市"]) {
//                    self.locationTarget = YES;
//                    NSIndexSet *indexSet = [[NSIndexSet alloc] initWithIndex:0];
//                    [self.tableView reloadSections:indexSet withRowAnimation:UITableViewRowAnimationFade];
//                }
//
//            }
//
//            AppDelegate *delegate=(AppDelegate*)[[UIApplication sharedApplication]delegate];
//            delegate.jin =[NSString stringWithFormat:@"%f",location.location.coordinate.latitude];
//            delegate.wei =[NSString stringWithFormat:@"%f",location.location.coordinate.longitude];
//        NSString *url = WeatherUrl;
//        NSMutableDictionary *param = [NSMutableDictionary dictionary];
//        if (location.rgcData.province.length > 0 && location.rgcData.city.length > 0) {
//            [param setValue:location.rgcData.province forKey:@"province"];
//            [param setValue:location.rgcData.city forKey:@"city"];
//        }
//        typeof(self) wSelf = self;
//        [NetworkRequest Get4:url Params:param Success:^(id _Nonnull responseObject) {
//            NSLog(@"responseObject:%@",responseObject);
//            NSDictionary *dic = responseObject;
//            if (dic.count > 0) {
//                NSMutableDictionary *tqData =  [[NSMutableDictionary alloc]initWithDictionary:dic];
//                [tqData setObject:![NSString blankString:location.rgcData.city] ? location.rgcData.city :@"" forKey:@"cityname"];
//                [tqData setObject:delegate.jin ? delegate.jin :@"" forKey:@"lat"];
//                [tqData setObject:delegate.wei ? delegate.wei :@"" forKey:@"lng"];
//                [[NSUserDefaults standardUserDefaults]setObject:tqData forKey:@"TQData"];
//                [[NSUserDefaults standardUserDefaults]synchronize];
//
//                wSelf.cityLab.text = tqData[@"city"];
////                NSString *low_temp = tqData[@"today"][@"low_temp"];
////                NSString *high_temp = tqData[@"today"][@"high_temp"];
//                NSString *temp = tqData[@"today"][@"temp"];
//                self.weatherLab.text = [NSString stringWithFormat:@"%@ %@℃",tqData[@"today"][@"weather"],temp];
////                self.weatherLab.text = [NSString stringWithFormat:@"%@ %@~%@",tqData[@"today"][@"weather"],[low_temp substringFromIndex:2],[high_temp substringFromIndex:2]];
//            }
//        } Failure:^(NSError * _Nonnull error) {
//            NSLog(@"error:%@",error);
//
//        }];
//           NSString *city=location.rgcData.city;
//           AppDelegate *dele=(AppDelegate*)[[UIApplication sharedApplication]delegate];
//           [getPeopleID getAppleyPay:MHSafeStrings(city)];
//           if ([getPeopleID applePaycity]) {
//               dele.isLogin=YES;
//           }else{
//               dele.isLogin=NO;
//           }
//
//            NSString*province = location.rgcData.province;
//            if ([province isEqualToString:@"黑龙江省"] || [province isEqualToString:@"河北省"] || [province isEqualToString:@"贵州省"] ) {
//                [[NSUserDefaults standardUserDefaults]setBool:YES forKey:@"jiuyecaiji"];
//                [[NSUserDefaults standardUserDefaults]synchronize];
//
//                //[self showSBDataCollect];
//            }
//
//        }
//
//    }];
}


- (void)BMKLocationManager:(BMKLocationManager * _Nonnull)manager doRequestAlwaysAuthorization:(CLLocationManager * _Nonnull)locationManager
{
    
    [locationManager requestAlwaysAuthorization];
}
//#pragma mark - creatTable
//- (void)creatTable
//{
//    NSArray *imageNameArray =  @[@"home_daka",@"home_askLawer",@"万年历2",@"快递查询2",@"home_Train",@"home_busTicket",@"home_airPlane",@"home_Hotel",@"home_Menu",@"home_radiostation",@"home_Travel",@"home_sport"];
//    NSArray *buttonTitleArray = @[@"打卡",@"问律师",@"万年历",@"快递查询",@"火车票",@"汽车票",@"飞机票",@"酒店",@"菜谱",@"FM电台",@"周边游",@"运动"];
//    NSArray *urlArray = @[@"",@"https://www.ilaw66.com/jasmine/?channel=kkss",
//                          @"https://m.wannianli.tianqi.com",
//                          @"https://m.kuaidi100.com/index_all.html",
//                      @"https://m.ctrip.com/webapp/train/?allianceid=452800&sid=949980&sourceid=2055&popup=close&autoawaken=close&hiderecommapp=1",
//                      @"https://m.ctrip.com/webapp/bus/?allianceid=452800&sid=949980&sourceid=2055&popup=close&autoawaken=close",
//                      @"https://m.ctrip.com/html5/Flight/?allianceid=452800&sid=949980&sourceid=2055&popup=close&autoawaken=close",
//                      @"http://m.ctrip.com/webapp/Hotel/?allianceid=452800&sid=949980&sourceid=xx&popup=close&autoawaken=close",
//                          @"https://www.xinshipu.com/",
//                          @"http://m.ximalaya.com/",
//                      @"http://m.ctrip.com/webapp/weekend?allianceid=452800&sid=949980&sourceid=2055&popup=close&autoawaken=close",
//                      @"http://m.ctrip.com/webapp/sport/?allianceid=1630&sid=436793&sourceid=2056&popup=close&autoawaken=close"];
//
//    if ([[VisitCountManager shareInstance]creatTable]) {
//        for (int i = 0; i < buttonTitleArray.count; i++) {
//            if (![[VisitCountManager shareInstance]queryButtonWithTitle:buttonTitleArray[i] imageName:imageNameArray[i] url:urlArray[i]]) {
//                [[VisitCountManager shareInstance]insertButtonWithimage:imageNameArray[i] title:buttonTitleArray[i] url:urlArray[i]];
//            }
//        }
//    }
//}

- (void)queryButton
{
    FMDatabase *db = [FMDatabase databaseWithPath:[self getDBPath]];
       if ([db open]){
           NSString *sql = [NSString stringWithFormat:@"SELECT * FROM t_button1 WHERE id > 0 ORDER BY count DESC limit 3 ;"];
           FMResultSet *resultSet = [db executeQuery:sql];

           while (resultSet.next) {
               ButtonModel *model = [[ButtonModel alloc]init];
               
               model.imageName = [resultSet stringForColumn:@"imageName"];
               model.buttonTitle = [resultSet stringForColumn:@"buttonTitle"];
               model.url = [resultSet stringForColumn:@"url"];
               model.count = [resultSet intForColumn:@"count"];
               
               if (self.buttonArray.count < 1) {
                       [self.buttonArray addObject:model];
                   
               }
  
           }
       }
       
       [db close];
}

- (NSString *)getDBPath
{
    NSString *doc= [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
    return [doc stringByAppendingPathComponent:@"visitCount.sqlite"];
}

//对按钮重新排序
- (void)sortMyButton{
    //button1
    NSIndexPath *indexPath1 = [NSIndexPath indexPathForRow:0 inSection:0];
    [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath1, nil] withRowAnimation:UITableViewRowAnimationNone];
}

#pragma mark - 中部banner数据请求
- (void)loadMiddleBannerApiRequest
{   __block BOOL requestSuccess = NO;
    __block BOOL show = NO;
    typeof(self) wSelf = self;
   dispatch_group_t group = dispatch_group_create();

   dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
    
    dispatch_group_async(group, queue, ^{
        dispatch_group_enter(group);
        NSString*version = nil;
        NSString*v = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
        NSArray*vArr = [v componentsSeparatedByString:@"."];

        for (int i = 0; i < vArr.count; i++) {
            if (version == nil) {
                version = [NSString stringWithFormat:@"%@",vArr[i]];
            }else{
                version = [version stringByAppendingFormat:@"%@",vArr[i]];
            }
        }
        NSString *url1 = [NSString stringWithFormat:@"%@dynamic/menu/get",[NetworkConfig ipYinShuConfig]];
        NSDictionary *params1 = @{
            @"configName":@"ShouYeBanner",
            @"appName":@"kksh",
            @"version":version,
            @"systemType":@"iOS",
            @"uid":[NSString stringWithFormat:@"%ld",(long)[getPeopleID PeopleID]]
        };
        [NetworkRequest Post15:url1 Params:params1 Success:^(id _Nonnull objc) {
            NSLog(@"objc:%@",objc);
            if ([objc isKindOfClass:[NSDictionary class]]) {
                NSString *state = [NSString stringWithFormat:@"%@",objc[@"state"]];
                if ([state isEqualToString:@"200"]) {
                    if ([objc[@"result"] isKindOfClass:[NSArray class]]) {
                        for (NSDictionary *dic in objc[@"result"]) {
                            KKRedPackageClickEventModel *model = [KKRedPackageClickEventModel mj_objectWithKeyValues:dic];

                            [wSelf.newsDataArray addObject:model];
                            requestSuccess = YES;
                        }
//                        [wSelf.tableView reloadData];
                        //[wSelf.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:0 inSection:2]] withRowAnimation:UITableViewRowAnimationNone];
                    }
                }
            }
            dispatch_group_leave(group);

        } Failure:^(NSError *error) {
            NSLog(@"error:%@",error);
            dispatch_group_leave(group);
        }];
    });
    
    dispatch_group_async(group, queue, ^{
        NSString * url =[NSString stringWithFormat:@"%@%@",[NetworkConfig ipSwitchConfig],SwitchRequest];
        
        NSString*version = nil;
               NSString*v = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
               NSArray*vArr = [v componentsSeparatedByString:@"."];
               
               for (int i = 0; i < vArr.count; i++) {
                   if (version == nil) {
                       version = [NSString stringWithFormat:@"kklife%@",vArr[i]];
                   }else{
                       version = [version stringByAppendingFormat:@"%@",vArr[i]];
                   }
               }
               
               NSDictionary*params = @{
                   @"version":version
               };
        dispatch_group_enter(group);
        [NetworkRequest Get:url Params:params Success:^(id _Nonnull responseObject) {
            
            NSString* state = [NSString stringWithFormat:@"%@",responseObject[@"state"]];
            if ([state isEqualToString:@"200"]) {
                NSString* result = responseObject[@"result"];
                if ([result isEqualToString:@"0"]) {
                    show = YES;
//                    [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"showSuspension"];
//                    //悬浮按钮
//                    [[clickEvent instance] SuspensionBtnRooterVC:self];
                }
//                else{
//                    [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"showSuspension"];
//                    [[clickEvent instance]  dissSuspensionBtn];
//                }
            }
            //show = YES;
            dispatch_group_leave(group);
            
        } Failure:^(NSError* error) {
            dispatch_group_leave(group);
        }];
        
    });
    
    dispatch_group_notify(group, dispatch_get_main_queue(), ^{
        if (show) {
            
        }
        wSelf.validateTime = NO;
        //[self sortMyButton];
        //wSelf.button.hidden = NO;
        wSelf.titleLabel.text = @"让领钱更简单";
        
        //顶部视图
        wSelf.TopView.hiddenButton = NO;
        [wSelf.TopView reloadData];
        [wSelf.tableView reloadData];
        if (requestSuccess) {
            [wSelf.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:0 inSection:2]] withRowAnimation:UITableViewRowAnimationNone];
        }
    });
    
}

//#pragma mark - 爱达api请求
//- (NSDictionary *)aiDaTokenRequestPara
//{
//    NSDictionary* params = @{
//        @"loginId":[NSNumber numberWithInteger:[getPeopleID PeopleID]].stringValue,
//        @"telephone":[getPeopleID PeopleIphoneNmber]
//    };
//    return params;
//}
//
//- (void)aiDaTokenRequest:(void (^)(bool success, NSString*token))response
//{
//    NSString*url = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipAdDaConfig],AiDaTokenRequest];
//    NSLog(@"爱达token的url:%@",url);
//
//    NSLog(@"params:%@",[self aiDaTokenRequestPara]);
//
//    [NetworkRequest Get3:url Params:[self aiDaTokenRequestPara] Success:^(id _Nonnull responseObject) {
//
//        NSLog(@"responseObject:%@",responseObject);
//
//        if ([responseObject isKindOfClass:[NSDictionary class]]) {
//            NSString*state = [NSString stringWithFormat:@"%@",responseObject[@"state"]];
//            NSString*describe = [NSString stringWithFormat:@"%@",responseObject[@"describe"]];
//            if ([state isEqualToString:@"200"]) {
//
//                NSString*token = [NSString stringWithFormat:@"%@",responseObject[@"result"]];
//
//                response(YES,token);
//
//            }else{
//                [SVProgressHUD showErrorWithStatus:describe];
//            }
//
//        }else{
//            [SVProgressHUD showErrorWithStatus:@"服务器异常"];
//        }
//
//    } Failure:^(NSError * _Nonnull error) {
//        NSLog(@"error:%@",error);
//        [SVProgressHUD showErrorWithStatus:@"网络异常"];
//    }];
//}

//- (NSDictionary *)aidaUrlRequestPara
//{
//    NSDictionary* params = @{
//        @"deviceid":[[[[UIDevice currentDevice] identifierForVendor] UUIDString]stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]],
//        @"mobile":[[getPeopleID PeopleIphoneNmber] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]],
//        @"uid":[NSNumber numberWithInteger:[getPeopleID PeopleID]].stringValue
//    };
//
//    return params;
//}
//
//- (void)aidaUrlRequestWithToken:(NSString *)token
//{
//    NSString*url = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipAdDaUrlConfig],AiDaUrlRequest];
//    NSLog(@"爱达url的url:%@",url);
//
//    NSLog(@"params:%@",[self aidaUrlRequestPara]);
//
//    [NetworkRequest Post5:url Params:[self aidaUrlRequestPara] Token:token Success:^(id  _Nonnull responseObject) {
//
//         NSLog(@"responseObject:%@",responseObject);
//
//        if ([responseObject isKindOfClass:[NSDictionary class]]) {
//            NSString*state = [NSString stringWithFormat:@"%@",responseObject[@"state"]];
//            NSString*describe = [NSString stringWithFormat:@"%@",responseObject[@"describe"]];
//            if ([state isEqualToString:@"200"]) {
//
//                NSString*url = [NSString stringWithFormat:@"%@",responseObject[@"result"]];
//
////                NSMutableCharacterSet *lastSet = [[NSMutableCharacterSet alloc] init];
////                   [lastSet formUnionWithCharacterSet:[NSCharacterSet characterSetWithCharactersInString:@"-_.!~*;/?:@&=$,#"]];
////                   [lastSet formUnionWithCharacterSet:[NSCharacterSet letterCharacterSet]];
////                   [lastSet formUnionWithCharacterSet:[NSCharacterSet alphanumericCharacterSet]];
////
////                url = [url stringByAddingPercentEncodingWithAllowedCharacters:lastSet];
//
//                if ([self.navigationController.visibleViewController isKindOfClass:[HomeViewController class]]) {
//                    Web2ViewController * vc = [Web2ViewController new];
//                    vc.title= @"智能问诊";
//                    vc.skipUrl = [NSURL URLWithString:url];
//                    vc.hidesBottomBarWhenPushed = YES;
//                    [self.navigationController pushViewController:vc animated:YES];
//                }
//
//            }else{
//                [SVProgressHUD showErrorWithStatus:describe];
//            }
//
//        }else{
//            [SVProgressHUD showErrorWithStatus:@"服务器异常"];
//        }
//
//    } Failure:^(NSError * _Nonnull error) {
//
//        NSLog(@"error:%@",error);
//        [SVProgressHUD showErrorWithStatus:@"网络异常"];
//
//    }];
//}


#pragma mark - 医疗服务
- (void)getHaoDaifuUrlRequest {
    
    
    if (![[NSUserDefaults standardUserDefaults]boolForKey:@"firstlog"]) {
        [self unLoginTap];
        return;
    }
    
    NSString*url = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipAdDaUrlConfig],HaoDaiFuUrlRequest];
    
    NSDictionary* params = @{
        @"userId":@([getPeopleID PeopleID]),
        @"telphone": [EnercryTool encryptUseDES:[getPeopleID PeopleIphoneNmber] key:DESKEY]
    };
    
    [KKLoadingAnimationView show];
    [NetworkRequest Post:url Params:params Success:^(id _Nonnull responseObject) {
        [KKLoadingAnimationView dismiss];
        NSLog(@"objc:%@",responseObject);
        if ([responseObject isKindOfClass:[NSDictionary class]]) {
            NSString*state = [NSString stringWithFormat:@"%@",responseObject[@"state"]];
            NSString*describe = [NSString stringWithFormat:@"%@",responseObject[@"describe"]];
            if ([state isEqualToString:@"200"]) {
                
                NSString*url = [NSString stringWithFormat:@"%@",responseObject[@"result"]];
                
//                NSMutableCharacterSet *lastSet = [[NSMutableCharacterSet alloc] init];
//                   [lastSet formUnionWithCharacterSet:[NSCharacterSet characterSetWithCharactersInString:@"-_.!~*;/?:@&=$,#"]];
//                   [lastSet formUnionWithCharacterSet:[NSCharacterSet letterCharacterSet]];
//                   [lastSet formUnionWithCharacterSet:[NSCharacterSet alphanumericCharacterSet]];
//
//                url = [url stringByAddingPercentEncodingWithAllowedCharacters:lastSet];
                
                if ([self.navigationController.visibleViewController isKindOfClass:[HomeViewController class]]) {
                    Web2ViewController * vc = [Web2ViewController new];
                    vc.title= @"医疗服务";
                    vc.skipUrl = [NSURL URLWithString:url];
                    vc.hidesBottomBarWhenPushed = YES;
                    [self.navigationController pushViewController:vc animated:YES];
                }
                
              
                
                
            }else{
                [SVProgressHUD showErrorWithStatus:describe];
            }
            
        }else{
            [SVProgressHUD showErrorWithStatus:@"服务器异常"];
        }
        
    } Failure:^(NSError* error) {
        [KKLoadingAnimationView dismiss];
        NSLog(@"error:%@",error);
        
    }];
    
}
//#pragma mark - 康爱多
//- (void)getKangAiDuoUrlRequest {
//
//
//    if (![[NSUserDefaults standardUserDefaults]boolForKey:@"firstlog"]) {
//        [self unLoginTap];
//        return;
//    }
//
//    NSString*url = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipAdDaUrlConfig],KADURLRequest];
//
//    NSDictionary* params = @{
//        @"mobile": [getPeopleID PeopleIphoneNmber]
//    };
//
//    [KKLoadingAnimationView show];
//    [NetworkRequest Post:url Params:params Success:^(id _Nonnull responseObject) {
//        [KKLoadingAnimationView dismiss];
//        NSLog(@"objc:%@",responseObject);
//        if ([responseObject isKindOfClass:[NSDictionary class]]) {
//            NSString*state = [NSString stringWithFormat:@"%@",responseObject[@"state"]];
//            NSString*describe = [NSString stringWithFormat:@"%@",responseObject[@"describe"]];
//            if ([state isEqualToString:@"200"]) {
//
//                NSString*url = [NSString stringWithFormat:@"%@",responseObject[@"result"]];
//
////                NSMutableCharacterSet *lastSet = [[NSMutableCharacterSet alloc] init];
////                   [lastSet formUnionWithCharacterSet:[NSCharacterSet characterSetWithCharactersInString:@"-_.!~*;/?:@&=$,#"]];
////                   [lastSet formUnionWithCharacterSet:[NSCharacterSet letterCharacterSet]];
////                   [lastSet formUnionWithCharacterSet:[NSCharacterSet alphanumericCharacterSet]];
////
////                url = [url stringByAddingPercentEncodingWithAllowedCharacters:lastSet];
//
//                if ([self.navigationController.visibleViewController isKindOfClass:[HomeViewController class]]) {
//                    Web2ViewController * vc = [Web2ViewController new];
//                    vc.title= @"便民药房";
//                    vc.skipUrl = [NSURL URLWithString:url];
//                    vc.hidesBottomBarWhenPushed = YES;
//                    [self.navigationController pushViewController:vc animated:YES];
//                }
//
//            }else{
//                [SVProgressHUD showErrorWithStatus:describe];
//            }
//
//        }else{
//            [SVProgressHUD showErrorWithStatus:@"服务器异常"];
//        }
//
//    } Failure:^(NSError* error) {
//        [KKLoadingAnimationView dismiss];
//        NSLog(@"error:%@",error);
//
//    }];
//
//}
//#pragma mark -合伙人查询
//- (NSDictionary *)getPartnerQueryRequestPara
//{
//    NSDictionary*params = @{
//         @"tel":[EnercryTool encryptUseDES:[getPeopleID PeopleIphoneNmber] key:DESKEY]
//    };
//    return params;
//}
//
//- (void)getPartnerQuery
//{
//    WeakSelf
//    NSString *urlString = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipPartnerConfig],PartnetQueryRequest];
//    NSLog(@"合伙人查询url:%@",urlString);
//    NSLog(@"params:%@",[self getPartnerQueryRequestPara]);
//
//
//    [NetworkRequest Get3:urlString Params:[self getPartnerQueryRequestPara] Success:^(id _Nonnull responseObject) {
//        NSLog(@"responseObject:%@",responseObject);
//        if ([responseObject isKindOfClass:[NSDictionary class]]) {
//             NSString*state = [NSString stringWithFormat:@"%@",responseObject[@"state"]];
//             NSString*describe = [NSString stringWithFormat:@"%@",responseObject[@"describe"]];
//            if ([state isEqualToString:@"202"]) {
//                JoinPartnerResultViewController* vc = [JoinPartnerResultViewController new];
//                vc.type = @"loading";
//                vc.hidesBottomBarWhenPushed = YES;
//                [self.navigationController pushViewController:vc animated:YES];
//            }else if ([state isEqualToString:@"200"]){
//                    PartnerModel*model = [PartnerModel mj_objectWithKeyValues:responseObject[@"result"]];
//                    PartnerCenterViewController*vc = [PartnerCenterViewController new];
//                    vc.title = @"合伙人中心";
//                    vc.model = model;
//                vc.hidesBottomBarWhenPushed = YES;
//                    [self.navigationController pushViewController:vc animated:YES];
//
//                    return;
//            }else if ([state isEqualToString:@"203"]){
//                JoinPartnerResultViewController* vc = [JoinPartnerResultViewController new];
//                vc.type = @"fail";
//                vc.hidesBottomBarWhenPushed = YES;
//                [self.navigationController pushViewController:vc animated:YES];
//            }else if ([state isEqualToString:@"201"]){
//
//                JoinPartGuideViewController *vc = [JoinPartGuideViewController new];
//                vc.title = @"加入合伙人";
//                vc.hidesBottomBarWhenPushed = YES;
//                [self.navigationController pushViewController:vc animated:YES];
//            }else{
//                [SVProgressHUD showErrorWithStatus:describe];
//            }
//        }else{
//            [SVProgressHUD showErrorWithStatus:@"服务器异常"];
//        }
//
//    } Failure:^(NSError * _Nonnull error) {
//        NSLog(@"error:%@",error);
//        [SVProgressHUD showErrorWithStatus:@"网络异常"];
//    }];
//}

#pragma mark - 电子社保卡绑定列表请求
-(NSDictionary *)kkBindESSCCardListRequestPara
{
    NSString*phone = [getPeopleID PeopleIphoneNmber];
    phone = [EnercryTool encryptUseDES:phone key:DESKEY];
    phone = [phone stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet characterSetWithCharactersInString:@"#%<>[\\]^`{|}\"]+"].invertedSet];
    phone = [phone stringByReplacingOccurrencesOfString:@" " withString:@""];
//    phone = [EnercryTool decryptUseDES:phone key:DESKEY];
    
    NSDictionary*params = @{
        @"phone":phone
    };
    
    return params;
}

- (void)kkBindESSCCardListRequest
{
//    WeakSelf
       NSString *urlString = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipKKSBConfig],KKESSCBindCardListRequest];
       NSLog(@"绑定电子社保卡列表url:%@",urlString);
       NSLog(@"params:%@",[self kkBindESSCCardListRequestPara]);
    [KKLoadingAnimationView show];
    [NetworkRequest baseGet:urlString Params:[self kkBindESSCCardListRequestPara] Success:^(id _Nonnull responseObject) {
        [KKLoadingAnimationView dismiss];
        
        NSLog(@"responseObject:%@",responseObject);
        NSString*state = [NSString stringWithFormat:@"%@",responseObject[@"state"]];
        NSString*describe = [NSString stringWithFormat:@"%@",responseObject[@"describe"]];
        if ([state isEqualToString:@"200"]) {
            
            NSArray*result = [DDBindCardModel mj_objectArrayWithKeyValuesArray:responseObject[@"result"]];
            
            if (result.count == 0) {
                DDSBCardViewController*ddVC = [DDSBCardViewController new];
                ddVC.title = @"电子社保卡";
                ddVC.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:ddVC animated:YES];
                
                return;
            }else{
                DDSBCardListVC* listVC = [DDSBCardListVC new];
                listVC.title = @"电子社保卡";
                listVC.hidesBottomBarWhenPushed = YES;
                listVC.dataArray = result;
                [self.navigationController pushViewController:listVC animated:YES];
            }
            
        }else{
            [SVProgressHUD showErrorWithStatus:describe];
        }
        
        
    } Failure:^(NSError* error) {
        [KKLoadingAnimationView dismiss];
        NSLog(@"error:%@",error);
         [SVProgressHUD showErrorWithStatus:@"网络异常"];
    }];
}

#pragma mark - 更新认证结果
- (void)updateMyAuthResultRequest {
    
    __block  NSString *address = nil;
   [CityNetManager phonenumberAndCompletionHandle:^(resulTModel *model, NSError *error) {
       if (model.result  != nil) {
           address = model.result;
             NSLog(@"%@",address);
           
           //rengzhi
           //我改动的地方
           NSString *       path = [IPDIZHI stringByAppendingString:@"/socialsecurity/kankan/myCertificationRecord"];
           NSString *  cityAddressResult = @"";
       NSString *CityAddress=    [[NSUserDefaults standardUserDefaults]objectForKey:@"provinceAABBCC"];

           if([MHSafeStrings(CityAddress) isEqualToString:@""] || !CityAddress ){
               cityAddressResult = MHSafeStrings(model.result);
           }else{
               cityAddressResult =MHSafeStrings(CityAddress);
           }
           
           [CityNetManager myCertificationUserID:[getPeopleID PeopleID] andPage:1 province:MHSafeStrings(cityAddressResult) andPath:path completionHandle:^(socialModelRecord *model, NSError *error) {
               if (error) {
                   return;
               }
               if (!model.result) {
               }else{
                   //

                   if (model.result.count > 0) {
                       socialResultModel *models =(socialResultModel*)model.result[0];
                       
                       self.resultModel = models;
                       NSLog(@"%@",models.createTime);
                       
                       NSIndexSet *indexSet = [[NSIndexSet alloc] initWithIndex:1];
                       [self.tableView reloadSections:indexSet withRowAnimation:UITableViewRowAnimationAutomatic];
                   }



               }


           }];
       }
       
   }];
    
}


#pragma mark - 获取未读消息接口
- (void)getUnreadState
{
    
//    WeakSelf
    if ([getPeopleID PeopleID])
    {
        NSDictionary *params = @{
                                 @"userId":[NSNumber numberWithInteger:[getPeopleID PeopleID]],
                                 @"appType":FeedAppType
                                 };
        NSString *url =[NSString stringWithFormat:@"%@/socialsecurity/kankan/getUnreadState",IPDIZHI];
        
        [NetworkRequest SBAuthPost:url Params:params Success:^(id _Nonnull responseObj) {
            NSLog(@"responseObj:%@",responseObj);
            if (responseObj) {
                NSString *code = [responseObj[@"code"] stringValue];
                if ([code isEqualToString:@"0"]) {
                    NSDictionary *dic = responseObj[@"result"];
                    if ([dic[@"newUnread"] isKindOfClass:[NSNumber class]] ) {
                        NSNumber *newUnread = dic[@"newUnread"];
                        
                        
                        if (newUnread.integerValue) {
                            [self.tabBarController.tabBar showBadgeOnItemIndex:3];
                        }else{
                            [self.tabBarController.tabBar hideBadgeOnItemIndex:3];
                        }
                        
                        
                    }

                    return ;
                }
            }
        } Failure:^(NSError *error) {
            NSLog(@"error:%@",error);
        }];
    }
}
//#pragma mark - 云闪付拉新记录
//- (void)recordCheckChinaPayRequest:(NSString*)title url:(NSString*)urlString {
//    NSString* url = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipYinShuConfig],GETChinaPayRecordRequest];
//    NSDictionary*params = @{
//        @"phone":[EnercryTool encryptUseDES:[getPeopleID PeopleIphoneNmber] key:DESKEY]
//
//    };
//
//    NSLog(@"云闪付拉新记录url:%@",url);
//    NSLog(@"params:%@",params);
//    [KKLoadingAnimationView show];
//    [NetworkRequest Get:url Params:params Success:^(id _Nonnull objc) {
//        [KKLoadingAnimationView dismiss];
//        NSLog(@"objc:%@",objc);
//        NSString* state = [NSString stringWithFormat:@"%@",objc[@"state"]];
//        NSString* describe = [NSString stringWithFormat:@"%@",objc[@"describe"]];
//        if ([state isEqualToString:@"200"]) {
//            NSString* respCode = [NSString stringWithFormat:@"%@",objc[@"result"][@"respCode"]];
//            NSString* respMsg = [NSString stringWithFormat:@"%@",objc[@"result"][@"respMsg"]];
//            if ([respCode isEqualToString:@"0000"]) {
//                WebVC * vc = [WebVC new];
//                vc.title= title;
//                vc.url = urlString;
//                vc.hidesBottomBarWhenPushed = YES;
//                [self.navigationController pushViewController:vc animated:YES];
//            }else{
//                [self alertShow:respMsg];
//            }
//
//        }else{
//            [self alertShow:describe];
//        }
//
//
//    } Failure:^(NSError* error) {
//        [KKLoadingAnimationView dismiss];
//        NSLog(@"error:%@",error);
//        [self alertShow:@"网络异常"];
//    }];
//}
//#pragma mark - 0元领
//- (void)getZeroInsuranceRequestWithType:(NSString *)type
//{
//
//    if(![[NSUserDefaults standardUserDefaults] boolForKey:@"firstlog"]){
//
//        [self unLoginTap];
//        return;
//
//      }
//
//    NSString *url = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipYinShuConfig],KKInsuranceForwardRequest];
//
//    NSLog(@"获取0元领url:%@",url);
//
//    NSString *province = [Tools isBlankString:[UserDefault objectForKey:@"locationProvince"]] ? @"" : [UserDefault objectForKey:@"locationProvince"];
//    NSString *city = [Tools isBlankString:[UserDefault objectForKey:@"locationCity"]] ? @"" : [UserDefault objectForKey:@"locationCity"];
//    NSString *county = [Tools isBlankString:[UserDefault objectForKey:@"locationCounty"]] ? @"" : [UserDefault objectForKey:@"locationCounty"];
//
//    NSMutableDictionary *params = [NetworkPublicParams getBCPublicParams];
//
//
//    [params setObject:[EnercryTool encryptUseDES:[getPeopleID PeopleIphoneNmber] key:DESKEY] forKey:@"tel"];
//    [params setObject:@([getPeopleID PeopleID]) forKey:@"uid"];
//    [params setObject:province forKey:@"province"];
//    [params setObject:city forKey:@"city"];
//    [params setObject:county forKey:@"county"];
//    [params setObject:@"kksh" forKey:@"fromApp"];
//    [params setObject:type forKey:@"type"];
//
//
//    NSLog(@"params:%@",params);
//    WeakSelf
//    [KKLoadingAnimationView show];
//    [NetworkRequest Post15:url Params:params Success:^(id _Nonnull objc) {
//        [KKLoadingAnimationView dismiss];
//        NSLog(@"objc:%@",objc);
//        NSString *state = [NSString stringWithFormat:@"%@",objc[@"state"]];
//        NSString *describe = [NSString stringWithFormat:@"%@",objc[@"describe"]];
//        if ([state isEqualToString:@"200"]) {
//            NSString *result = objc[@"result"];
//            if ([result isKindOfClass:[NSArray class]]) {
//
//                NSArray *array = [KKInsuranceModel mj_objectArrayWithKeyValuesArray:result];
//
//                if (array.count == 1) {
//                    KKInsuranceModel* model = array[0];
//                    [self jump2ToHTML5:model.path andJAnalytics:model.title];
//
//                    if ([model.pageName isEqualToString:@"重疾险"]) {
//                    }else if ([model.pageName isEqualToString:@"综合险"]){
//                    }
//
//                }else if (array.count == 2){
//                    [self goToInsurnceVC:array];
//                }
//            }
//
//        }else{
//            [Tools showMessage:describe];
//        }
//
//    } Failure:^(NSError* error) {
//        [KKLoadingAnimationView dismiss];
//        NSLog(@"error:%@",error);
//
//        [Tools showMessage:@"网络出小差了,请稍后重试"];
//
//    }];
//
//}
//#pragma mark - 保险统计
///**
// * 请求类型
// * 100101保险_banner入口
// * 100102保险_菜单入口
// * 100103保险_任务入口
// * 100104保险_重疾险
// * 100105保险_综合险
// */
//- (void)makeInsuranceStatisticsRequestWithType:(NSString *)type
//{
//    NSString *url = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipYinShuConfig],KKInsuranceStatisticsRequest];
//
//    NSString *province = [Tools isBlankString:[UserDefault objectForKey:@"locationProvince"]] ? @"" : [UserDefault objectForKey:@"locationProvince"];
//    NSString *city = [Tools isBlankString:[UserDefault objectForKey:@"locationCity"]] ? @"" : [UserDefault objectForKey:@"locationCity"];
//    NSString *county = [Tools isBlankString:[UserDefault objectForKey:@"locationCounty"]] ? @"" : [UserDefault objectForKey:@"locationCounty"];
//
//    NSMutableDictionary *params = [NetworkPublicParams getBCPublicParams];
//
//
//    [params setObject:[EnercryTool encryptUseDES:[getPeopleID PeopleIphoneNmber] key:DESKEY] forKey:@"tel"];
//    [params setObject:@([getPeopleID PeopleID]) forKey:@"uid"];
//    [params setObject:province forKey:@"province"];
//    [params setObject:city forKey:@"city"];
//    [params setObject:county forKey:@"county"];
//    [params setObject:@"kksh" forKey:@"fromApp"];
//    [params setObject:type forKey:@"type"];
//
//
//    NSLog(@"params:%@",params);
//
//
//    [NetworkRequest Post15:url Params:params Success:^(id _Nonnull objc) {
//
//        NSLog(@"objc:%@",objc);
//
//
//    } Failure:^(NSError* error) {
//
//        NSLog(@"error:%@",error);
//
//    }];
//
//}

#pragma mark - 后台获取抢红包的icon和点击事件关键字
- (void)requestRedPackageIconsAndTargetEvent
{
    
    NSString*version = nil;
    NSString*v = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
    NSArray*vArr = [v componentsSeparatedByString:@"."];
    
    for (int i = 0; i < vArr.count; i++) {
        if (version == nil) {
            version = [NSString stringWithFormat:@"%@",vArr[i]];
        }else{
            version = [version stringByAppendingFormat:@"%@",vArr[i]];
        }
    }
    
    NSString *url = [NSString stringWithFormat:@"%@dynamic/menu/get",[NetworkConfig ipYinShuConfig]];
    
    //NSString *url = @"http://172.16.10.18:8017/dynamic/menu/get";
    
    NSDictionary *params = @{
        @"configName":@"QiangHongBao",
        @"appName":@"kksh",
        @"version":version,
        @"systemType":@"iOS"
    };
    
    [NetworkRequest Post15:url Params:params Success:^(id _Nonnull objc) {
        
        NSLog(@"objc:%@",objc);
        if ([objc isKindOfClass:[NSDictionary class]]) {
            NSString *state = [NSString stringWithFormat:@"%@",objc[@"state"]];
            
            if ([state isEqualToString:@"200"]) {
                if ([objc[@"result"] isKindOfClass:[NSArray class]]) {
                    self.redPackageClickEventsArray = [KKRedPackageClickEventModel mj_objectArrayWithKeyValuesArray:objc[@"result"]];
                    
                    if (self.redPackageClickEventsArray.count > 0) {
                        NSIndexSet *indexSet=[[NSIndexSet alloc]initWithIndex:0];
                        [self.tableView reloadSections:indexSet withRowAnimation:UITableViewRowAnimationNone];
                    }
                }
            }
            
           
        }

    } Failure:^(NSError *error) {
        NSLog(@"error:%@",error);
        
        
    }];
    
}

//#pragma mark - 获取天气
//- (void)requestWeatherData
//{
//     WeakSelf
//     NSString *url = WeatherUrl;
//     NSMutableDictionary *param = [NSMutableDictionary dictionary];
//     [NetworkRequest Get4:url Params:param Success:^(id _Nonnull responseObject) {
//
//         NSLog(@"responseObject:%@",responseObject);
//         NSDictionary *dic = responseObject;
//         if (dic.count > 0) {
//             weakSelf.weatherDic  = dic;
//
//             if (weakSelf.weatherDic) {
//                 [weakSelf creatTimer];
//             }
//
//             [weakSelf timerMethod2];
//         }
//
//     } Failure:^(NSError * _Nonnull error) {
//         NSLog(@"error:%@",error);
//
//     }];
//}
//#pragma mark - 长量基金
//- (void)getChangLiangUrlRequest
//{
//    NSString*version = nil;
//    NSString*v = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
//    NSArray*vArr = [v componentsSeparatedByString:@"."];
//
//    for (int i = 0; i < vArr.count; i++) {
//        if (version == nil) {
//            version = [NSString stringWithFormat:@"%@",vArr[i]];
//        }else{
//            version = [version stringByAppendingFormat:@"%@",vArr[i]];
//        }
//    }
//
//    NSString *url = [NSString stringWithFormat:@"%@dynamic/menu/get",[NetworkConfig ipYinShuConfig]];
//    //NSString *url = @"http://172.16.10.18:8017/dynamic/menu/get";
//
//    NSDictionary *params = @{
//        @"configName":@"ChangLiangJiJin",
//        @"appName":@"kksh",
//        @"version":@"150",
//        @"systemType":@"Android"
//    };
//
//    [KKLoadingAnimationView show];
//
//    [NetworkRequest Post15:url Params:params Success:^(id _Nonnull objc) {
//
//        [KKLoadingAnimationView dismiss];
//
//        NSLog(@"objc:%@",objc);
//        if ([objc isKindOfClass:[NSDictionary class]]) {
//            NSString *state = [NSString stringWithFormat:@"%@",objc[@"state"]];
//
//            if ([state isEqualToString:@"200"]) {
//
//
//                NSArray *array = objc[@"result"];
//                if ([array isKindOfClass:[NSArray class]] && array.count > 0) {
//                    NSDictionary *dic = (NSDictionary *)array[0];
//                    if ([dic isKindOfClass:[NSDictionary class]]) {
//                        KKCLFundViewController *vc = [[KKCLFundViewController alloc]init];
//                        vc.title = @"长量基金";
//                        vc.url = dic[@"content"];
//                        vc.hidesBottomBarWhenPushed = YES;
//                        [self.navigationController pushViewController:vc animated:YES];
//                    }
//
//                }
//
//            }
//
//        }
//
//    } Failure:^(NSError *error) {
//        NSLog(@"error:%@",error);
//        [KKLoadingAnimationView dismiss];
//
//    }];
//
//}

#pragma mark - 获取是否已签到
- (void)judgeSignOrNorSignRequest
{
    
    WeakSelf
    NSString *url = [NSString stringWithFormat:@"%@score/getuserTaskStatus",[NetworkConfig ipCoinsConfig]];
    
    NSDictionary *dic = @{
                             @"userId":[NSNumber numberWithInteger:[getPeopleID PeopleID]],
                             @"telephone":[EnercryTool encryptUseDES:[getPeopleID PeopleIphoneNmber] key:DESKEY],
                             @"fromModel":@"2"
                             };
    
    
    NSArray *result = [dic.allKeys sortedArrayUsingComparator:^NSComparisonResult(id  _Nonnull obj1, id  _Nonnull obj2) {
        
        NSLog(@"%@~%@",obj1,obj2); //3~4 2~1 3~1 3~2
        
        return [obj1 compare:obj2]; //升序
        
    }];
    NSString *sign = nil;
    for (int i = 0; i < result.count; i++) {
        NSString *key = result[i];
        if (i==0) {
            sign = [NSString stringWithFormat:@"%@=%@",key,dic[key]];
        }else{
            
            sign = [NSString stringWithFormat:@"%@&%@=%@",sign,key,dic[key]];
        }
    }
    
    sign = [NSString stringWithFormat:@"%@&Kanwf574",sign];
    
    NSMutableDictionary *params = [[NSMutableDictionary alloc]initWithDictionary:dic];
    
    NSString *signString = [[MyMD5 md5:sign] lowercaseString];
    [params setObject:signString forKey:@"sign"];
   
    [params setObject:[NSNumber numberWithInt:172] forKey:@"verflag"];
    
    [CTAPIBaseManager POST:url params:params completionHandler:^(id  _Nonnull responseObject, NSError * _Nonnull error) {
        
       
        if (responseObject) {
            NSNumber *code = responseObject[@"code"];
            if (code.integerValue == 0) {
                
                
               
                NSArray* dateArray = [[NSMutableArray alloc]initWithArray:responseObject[@"result"][@"dateTaskStatus"]];
                //self.dataArray = [KKTaskModel mj_objectArrayWithKeyValuesArray:responseObject[@"result"][@"taskstatus"]];
                
                //获取今天是周几
                
                NSNumber *index = responseObject[@"result"][@"currentDayofWeek"];
                NSInteger weekIndex = index.integerValue - 1;
                
                NSDictionary *dic = dateArray[weekIndex];
                NSNumber *status = dic[@"status"];
                if (status.integerValue == 302) {
                    weakSelf.coinSigned = YES;
                    
                    [weakSelf timerMethod2];
                }
                
              
            }
        }
    
       
    }];
}

#pragma mark - 显示首页按钮

- (void)showBtns
{
    NSLog(@"🎁 开始创建首页悬浮按钮");
    firstShow = YES;
    
    self.bgView = [[UIView alloc]initWithFrame:[UIScreen mainScreen].bounds];
    self.bgView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
    
    UITapGestureRecognizer *tapGes = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapClick:)];
    [self.bgView addGestureRecognizer:tapGes];

     UIPanGestureRecognizer   *panTouch    =   [[UIPanGestureRecognizer  alloc]initWithTarget:self action:@selector(handlePan:)];
     UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(ScreenWidth-100, ScreenHeight- cl_kTabBarHeight - 120, 100, 80)];
//    button.layer.cornerRadius = 27.5;
//    button.backgroundColor = [UIColor greenColor];
    [button addTarget:self action:@selector(clickAddButton:) forControlEvents:UIControlEventTouchUpInside];
    [button setImage:[UIImage imageNamed:@"首页-默认"] forState:UIControlStateNormal];
    button.hidden = YES;
    //button.hidden = YES;
    [button addGestureRecognizer:panTouch];
    [self.view addSubview:button];
    
    self.button = button;
    
    NSLog(@"🎁 首页悬浮按钮创建完成 - 位置: %@, 初始状态: hidden=YES", NSStringFromCGRect(button.frame));
    
    
    if (self.btnItemsArray.count == 4) {
        KKRedPackageClickEventModel *model = self.btnItemsArray[0];
        NSString *imageUrl = [NSString stringWithFormat:@"%@%@",KKFindPackageIP,model.menuIcon];
        NSLog(@"🎁 初始化网络图片: %@", imageUrl);
        NSLog(@"🎁 menuIcon字段值: %@", model.menuIcon);
        
        [self.button sd_setImageWithURL:[NSURL URLWithString:imageUrl] forState:UIControlStateNormal completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
            if (image) {
                NSLog(@"🎁 网络图片初始化成功 - 图片大小: %@", NSStringFromCGSize(image.size));
                // 检查是否为GIF
                if (image.images && image.images.count > 0) {
                    NSLog(@"🎁 检测到GIF动画 - 帧数: %lu", (unsigned long)image.images.count);
                }
                UIImage *refined = [UIImage imageWithCGImage:image.CGImage scale:2.0 orientation:image.imageOrientation];
                [self.button setImage:refined forState:UIControlStateNormal];
            } else {
                NSLog(@"🎁 网络图片初始化失败 - 错误: %@", error);
            }
        }];
    } else {
        NSLog(@"🎁 使用本地默认图片初始化 - btnItemsArray数量: %lu", (unsigned long)self.btnItemsArray.count);
        NSLog(@"🎁 悬浮按钮保持隐藏状态 - 需要btnItemsArray.count == 4才能显示");
    }

    TLMenuButtonView *tlMenuView =[TLMenuButtonView standardMenuView];
    tlMenuView.centerPoint = button.center;
    __weak typeof(self) weakSelf = self;
    tlMenuView.clickAddButton = ^(NSInteger tag, UIColor *color){
        //weakSelf.view.backgroundColor = color;
        self->_ISShowMenuButton = YES;
        [weakSelf clickAddButton:button];
        
        if (tag == 2) {

            if (self.btnItemsArray.count == 4) {
                KKRedPackageClickEventModel *model = self.btnItemsArray[3];
                [self goToClickServeReturnRedPackageVCWithModel:model];
            }else{

                if ([[NSUserDefaults standardUserDefaults]boolForKey:@"firstlog"]) {
                    
//                    [self goToShakeMoneyTreeVC];//摇钱树
                    [self addRedPackage];
                    
                    return;
                }else{
                    
                    [self unLoginTap];
                }
                
            }
            
            [NetworkRequest statisticsWithEventName:@"homeSuspensionBtn1"];
            
        }else if (tag == 3){
            
            if (self.btnItemsArray.count == 4) {
                KKRedPackageClickEventModel *model = self.btnItemsArray[2];
                [self goToClickServeReturnRedPackageVCWithModel:model];
            }else{
                //存钱罐
                if ([[NSUserDefaults standardUserDefaults]boolForKey:@"firstlog"]) {
                    
                    [GTCountSDK trackCountEvent:@"CQG_PUSH_click" withArgs:nil];
                    
                    [self GetyeepayUrl];
            
                    return;
                }else{
                    
                    [self unLoginTap];
                }
            }
            
            [NetworkRequest statisticsWithEventName:@"homeSuspensionBtn2"];
        }else if (tag == 4){
            if (self.btnItemsArray.count == 4) {
                KKRedPackageClickEventModel *model = self.btnItemsArray[1];
                [self goToClickServeReturnRedPackageVCWithModel:model];
                
            }else{
                
                if ([[NSUserDefaults standardUserDefaults]boolForKey:@"firstlog"]) {
                    
                    [GTCountSDK trackCountEvent:@"CQG_PUSH_click" withArgs:nil];
                    
                    [self goToOnlineJobVC];//在线兼职
            
                    return;
                }else{
                    [self unLoginTap];
                }
        
            }
            
            [NetworkRequest statisticsWithEventName:@"homeSuspensionBtn3"];
        }

    };
    _tlMenuView = tlMenuView;
}
/**
 *  处理拖动手势
 *
 *  @param recognizer 拖动手势识别器对象实例
 */
- (void)handlePan:(UIPanGestureRecognizer *)recognizer {
    if (_ISShowMenuButton) {
        return;
    }
    
    // 添加拖动日志
    if (recognizer.state == UIGestureRecognizerStateBegan) {
        NSLog(@"🎁 悬浮礼品盒按钮开始拖动");
    }
    
    //视图前置操作
    [recognizer.view.superview bringSubviewToFront:recognizer.view];
    
    CGPoint center = recognizer.view.center;
    CGFloat cornerRadius = recognizer.view.frame.size.width / 2;
    CGPoint translation = [recognizer translationInView:self.view];
    //NSLog(@"%@", NSStringFromCGPoint(translation));
    recognizer.view.center = CGPointMake(center.x + translation.x, center.y + translation.y);
    [recognizer setTranslation:CGPointZero inView:self.view];
    
    if (recognizer.state == UIGestureRecognizerStateEnded) {
        //计算速度向量的长度，当他小于200时，滑行会很短
        CGPoint velocity = [recognizer velocityInView:self.view];
        CGFloat magnitude = sqrtf((velocity.x * velocity.x) + (velocity.y * velocity.y));
        CGFloat slideMult = magnitude / 200;
        //NSLog(@"magnitude: %f, slideMult: %f", magnitude, slideMult); //e.g. 397.973175, slideMult: 1.989866
        
        //基于速度和速度因素计算一个终点
        float slideFactor = 0.1 * slideMult;
        CGPoint finalPoint = CGPointMake(center.x + (velocity.x * slideFactor),
                                         center.y + (velocity.y * slideFactor));
        //限制最小［cornerRadius］和最大边界值［self.view.bounds.size.width - cornerRadius］，以免拖动出屏幕界限
        finalPoint.x = MIN(MAX(finalPoint.x, cornerRadius),
                           self.view.bounds.size.width - cornerRadius);
        finalPoint.y = MIN(MAX(finalPoint.y, cornerRadius),
                           self.view.bounds.size.height - cornerRadius);
        
        //使用 UIView 动画使 view 滑行到终点
        [UIView animateWithDuration:slideFactor*2
                              delay:0
                            options:UIViewAnimationOptionCurveEaseOut
                         animations:^{
                             recognizer.view.center = finalPoint;
                         }
                         completion:nil];
    }
}
#pragma mark - 后台控制的点击事件
- (void)goToClickServeReturnRedPackageVCWithModel:(KKRedPackageClickEventModel *)model
{

    if (model.whetherLogin.boolValue && ![[NSUserDefaults standardUserDefaults]boolForKey:@"firstlog"]) {
        [self unLoginTap];
        return;
    }
    
    switch (model.type.integerValue) {
        case 1001:
            //原生
        {
            if ([model.menuTag isEqualToString:@"HomeCQG"]) {
                [self GetyeepayUrl];//存钱罐
            }else if ([model.menuTag isEqualToString:@"HomeLHB"]){
//                [self goToShakeMoneyTreeVC];//摇钱树
                [self addRedPackage];
            }else if ([model.menuTag isEqualToString:@"HomeZXJZ"]){
                [self goToOnlineJobVC];//在线兼职
            }
        }
            break;
        case 1002:
            //h5
        {
            if ([model.menuName isEqualToString:@"救助热线"]) {
                [self jumpToHTML5:@"http://hotline.treeyee.com" andJAnalytics:@"救助热线"];
                return;
            }
            
            WebVC *vc = [[WebVC alloc]init];
            vc.title = model.menuName;
            vc.url = model.content;
            vc.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:vc animated:YES];
           
        }
            break;
        case 1003:
            //小程序
        {
            if (![WXApi isWXAppInstalled]){
                [Tools showMessage:@"请安装微信APP后重试"];
                return;
            }
            
            WXLaunchMiniProgramReq *launchMiniProgramReq = [WXLaunchMiniProgramReq object];
            launchMiniProgramReq.userName = @"gh_f8a0e531525d";  //拉起的小程序的username
            launchMiniProgramReq.path = @"pages/base/redirect/index?routeKey=PH04_PRODUCT_TRANSFER_CY&wtagid=118.4.2";    //拉起小程序页面的可带参路径，不填默认拉起小程序首页
            launchMiniProgramReq.miniProgramType = WXMiniProgramTypeRelease; //拉起小程序的类型
            [WXApi sendReq:launchMiniProgramReq completion:^(BOOL success) {
                
            }];
           
        }
            break;
        case 1004:
            //其他
        {
            NSDictionary *dic = [self dictionaryWithJsonString:model.content];
            if (dic) {
                [self push:dic model:model];
            }
            
        }
            break;
        case 1005:
        {
            [self getFederatedLoginRequestWithModel:model];
        }
            break;
            
        default:
            break;
    }

}

- (void)tapClick:(UIGestureRecognizer *)ges
{
    NSLog(@"🎁 tapClick手势被触发 - 准备调用clickAddButton");
    [self clickAddButton:self.button];
}

- (void)clickAddButton:(UIButton *)sender{
    // 添加点击日志
    NSLog(@"🎁 首页右下角悬浮礼品盒按钮被点击 - 当前状态: %@", _ISShowMenuButton ? @"展开状态" : @"收起状态");
    NSLog(@"🎁 按钮图片: %@", sender.imageView.image);
    NSLog(@"🎁 btnItemsArray数量: %lu", (unsigned long)self.btnItemsArray.count);
    NSLog(@"🎁 点击时间: %@", [NSDate date]);
    
    sender.frame = CGRectMake(ScreenWidth-100, ScreenHeight- cl_kTabBarHeight - 120, 100, 80);
    
    if (!_ISShowMenuButton) {
//        [UIView animateWithDuration:0.2 animations:^{
//            CGAffineTransform rotate = CGAffineTransformMakeRotation( M_PI / 4 );
//            [sender setTransform:rotate];
//        }];

        [sender setImage:[UIImage imageNamed:@"X"] forState:UIControlStateNormal];
        
        [self.view addSubview:self.bgView];
        [self.view bringSubviewToFront:self.button];
        [_tlMenuView showItemsWithArray:self.btnItemsArray vc:self];
    }else{
//        [UIView animateWithDuration:0.2 animations:^{
//            CGAffineTransform rotate = CGAffineTransformMakeRotation( 0 );
//            [sender setTransform:rotate];
//        }];
        //[sender setImage:[UIImage imageNamed:@"首页-默认"] forState:UIControlStateNormal];
        if (self.btnItemsArray.count == 4) {
            KKRedPackageClickEventModel *model = self.btnItemsArray[0];
            NSString *imageUrl = [NSString stringWithFormat:@"%@%@",KKFindPackageIP,model.menuIcon];
            NSLog(@"🎁 设置网络图片: %@", imageUrl);
            [self.button sd_setImageWithURL:[NSURL URLWithString:imageUrl] forState:UIControlStateNormal completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
                if (image) {
                    NSLog(@"🎁 网络图片加载成功 - 图片大小: %@", NSStringFromCGSize(image.size));
                    UIImage *refined = [UIImage imageWithCGImage:image.CGImage scale:2.0 orientation:image.imageOrientation];
                    [self.button setImage:refined forState:UIControlStateNormal];
                } else {
                    NSLog(@"🎁 网络图片加载失败 - 错误: %@", error);
                }
            }];
            
        }else{
            NSLog(@"🎁 使用本地默认图片: 首页-默认");
            [sender setImage:[UIImage imageNamed:@"首页-默认"] forState:UIControlStateNormal];
        }
        [_tlMenuView dismiss];
        [self.bgView removeFromSuperview];
    }
    _ISShowMenuButton = !_ISShowMenuButton;
}
#pragma mark - 创建定时器
- (void)creatTimer {
    
    if (self.helperTimer == nil) {
        TimerProxy *proxy = [[TimerProxy alloc]initWithTarget:self];
        
        self.helperTimer = [NSTimer timerWithTimeInterval:4.0 target:proxy selector:@selector(timerMethod2) userInfo:nil repeats:YES];
        [[NSRunLoop currentRunLoop] addTimer:self.helperTimer forMode:NSRunLoopCommonModes];
    }
    
    [self timerMethod2];
    
}
#pragma mark - 看看助手头部定时器间接显示打卡或看天气
- (void)timerMethod2
{
    self.showWeather = !self.showWeather;
    
    if (self.showWeather && self.weatherDic) {
        
        self.newsHeaderView.lb_lunDate.text = [Tools getLunarDate];
        
        NSString *low_temp = self.weatherDic[@"today"][@"low_temp"];
        NSString *high_temp = self.weatherDic[@"today"][@"high_temp"];
        if (low_temp.length > 3 && high_temp.length > 3) {
            self.newsHeaderView.lb_dateAndWeather.text = [NSString stringWithFormat:@"%@ %@~%@ %@",[Tools getInternationDate],[low_temp substringFromIndex:2],[high_temp substringFromIndex:2],self.weatherDic[@"today"][@"weather"]];
        }
        
        
        [self.newsHeaderView.signBtn  setTitle:@"今日运势" forState:UIControlStateNormal];
        
    }else{
        
        if (self.coinSigned) {
            self.newsHeaderView.lb_lunDate.text = @"今日签到";
            self.newsHeaderView.lb_dateAndWeather.text = @"连续签到拿更多金币奖励";
            
            [self.newsHeaderView.signBtn  setTitle:@"已签到" forState:UIControlStateNormal];
        }else{
            self.newsHeaderView.lb_lunDate.text = @"今日签到";
            self.newsHeaderView.lb_dateAndWeather.text = @"连续签到拿更多金币奖励";
            
            [self.newsHeaderView.signBtn  setTitle:@"领取金币" forState:UIControlStateNormal];
        }
        
       
    }
}
#pragma mark - 获取联合登录链接
- (void)getFederatedLoginRequestWithModel:(KKRedPackageClickEventModel *)model
{
    NSString *url = [NSString stringWithFormat:@"%@",model.content];
    
    url = [url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet  URLQueryAllowedCharacterSet]];
    
    NSDictionary *params = @{
        @"uid":@([getPeopleID PeopleID]),
        @"tel":[getPeopleID PeopleIphoneNmber]
    };
    
    NSLog(@"联合登录url:%@",url);
    NSLog(@"params:%@",params);
    [KKLoadingAnimationView show];
    [NetworkRequest Get:url Params:params Success:^(id _Nonnull objc) {
        [KKLoadingAnimationView dismiss];
        NSLog(@"objc:%@",objc);
        NSString* state = [NSString stringWithFormat:@"%@",objc[@"state"]];
        NSString* describe = [NSString stringWithFormat:@"%@",objc[@"describe"]];
        if ([state isEqualToString:@"200"]) {
            NSString *url = [NSString stringWithFormat:@"%@",objc[@"result"]];
//            url = [url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet  URLQueryAllowedCharacterSet]];
            WebVC *webvc = [[WebVC alloc]init];
            webvc.url = url;
            webvc.title = model.menuName;
            webvc.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:webvc animated:YES];
        }else{
            [self alertShow:describe];
        }

    } Failure:^(NSError* error) {
        [KKLoadingAnimationView dismiss];
        NSLog(@"error:%@",error);
        [self alertShow:@"网络异常"];
    }];
    
}
#pragma mark - passImagesDelegate
- (void)passImages:(NSArray *)imagesArray
{
    NSLog(@"活体检测成功");
    
    NSMutableArray *originImage = [[NSMutableArray alloc]init];
    for (int i = 0; i < imagesArray.count; i++) {

        FaceImageModel*imageModel = imagesArray[i];
        [originImage addObject:imageModel.image];
    }
   
   TestViewController *testVC = [TestViewController new];
   testVC.title = @"查看图片";
   testVC.originImage = originImage;
    testVC.hidesBottomBarWhenPushed = YES;
   [self.navigationController pushViewController:testVC animated:YES];
    
}

#pragma mark - KSCUFeedPageScrollViewDelegate
/// 首次加载成功后,返回;仅返回一次
- (void)feedPage:(UIViewController *)vc scrollViewcallback:(UIScrollView *)scrollView{
    NSLog(@">>>>首次加载成功后,返回;仅返回一次");
}
/// FeedPage 即将进入滑滑流视频
- (void)willEnterContentVideoFeedPage
{
    NSLog(@">>>>>FeedPage 即将进入滑滑流视频");
}




#pragma mark - UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    // 注释掉原来的section数量，保留以便后续恢复
    // return 4;
    
    // 只显示4个section：顶部功能、消息、banner、生活服务
    return 4;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
//    if (section == 3) {
//        if (self.validateTime) {
//            return 0;
//        }else{
//            return 1;
//        }
//    }
    
//    if (section == 4) {
//        return 0;
//    }
//
    return 1;
    
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        HomeCollectionCell* cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
        UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, ScreenWidth, 210*WIDTHRADIU) byRoundingCorners:UIRectCornerTopRight|UIRectCornerTopLeft cornerRadii:CGSizeMake(20, 20)];
       CAShapeLayer *maskLayer = [[CAShapeLayer alloc]init];
       maskLayer.frame = CGRectMake(0, 0, ScreenWidth, 210*WIDTHRADIU);
       maskLayer.path = maskPath.CGPath;
       cell.contentView.layer.mask = maskLayer;
        
        cell.delegate = self;
        cell.Itemdelegate = self;
        cell.dataArray= self.DataArr;
        
        cell.hiddenButton = self.validateTime;

        [cell reloadData];
        return cell;

    }else if (indexPath.section == 1){
        
        if (self.msgModel && [[NSUserDefaults standardUserDefaults] boolForKey:@"firstlog"] && [self compareCurrentTime:self.msgModel.noticeTime]) {
            
            HomeNewAuthResultCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HomeNewAuthResultCell"];

            self.lb_msg = cell.lb_msg;

            [cell reloadDataWithModel:self.msgModel count:self.unreadCount];

            return cell;

        }
        
        // 添加log打印当前新闻数量
        NSLog(@"📊 section 1 cell配置 - 新闻数量: %lu, 是否显示新闻列表: %@", 
              (unsigned long)self.newsArray.count, 
              self.newsArray.count > 10 ? @"是" : @"否(显示看看助手)");
        
        if (self.newsArray.count > 10){
            HomeMiddleNewsCell *cell  = [tableView dequeueReusableCellWithIdentifier:@"HomeMiddleNewsCell"];
            
            cell.delegate = self;
            
          __block  JHNewsModel* model1 = self.newsArray[index*2];
          __block  JHNewsModel* model2 = self.newsArray[index*2 + 1];
            
            NSDictionary *attributes = @{NSFontAttributeName:[UIFont fontWithName:@"PingFangSC-Regular" size:15], NSForegroundColorAttributeName: [UIColor colorWithHex:0x4d4d4d]};
               
            NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString:model1.title attributes:attributes];
            NSMutableAttributedString *text2 = [[NSMutableAttributedString alloc] initWithString:model2.title attributes:attributes];
               //设置高亮色和点击事件
            [text yy_setTextHighlightRange:NSMakeRange(0, model1.title.length ) color:[UIColor colorWithHex:0x4d4d4d] backgroundColor:[UIColor colorWithHex:0x4d4d4d] userInfo:nil tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
                containerView.backgroundColor = [UIColor colorWithHex:0xcccccc];
                
                [self goToNewsDetaiVCWithModel:model1];
                
                dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                        //3秒后 执行block内的代码
                    containerView.backgroundColor = [UIColor clearColor];
                });
                
            } longPressAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
                [self goToNewsDetaiVCWithModel:model1];
            }];
    
            
            [text2 yy_setTextHighlightRange:NSMakeRange(0, model2.title.length ) color:[UIColor colorWithHex:0x4d4d4d] backgroundColor:[UIColor colorWithHex:0xcccccc] userInfo:nil tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
                containerView.backgroundColor = [UIColor colorWithHex:0xcccccc];
                
                [self goToNewsDetaiVCWithModel:model2];
                
                dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                        //3秒后 执行block内的代码
                    containerView.backgroundColor = [UIColor clearColor];
                });
            } longPressAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
                [self goToNewsDetaiVCWithModel:model2];
            }];
            
            cell.lb_content1.attributedText = text;
            cell.lb_content2.attributedText = text2;
            self.lb_content1 = cell.lb_content1;
            self.lb_content2 = cell.lb_content2;
            
            return cell;
        }
        
        socialAssistant *cell = [tableView dequeueReusableCellWithIdentifier:@"socialAssistant"];
        
        if (cell == nil) {
            cell = [[NSBundle mainBundle]loadNibNamed:@"socialAssistant" owner:nil options:nil].lastObject;
        }
        
        cell.KKHide.text =@"足不出户,安全认证,放心领钱";
        cell.AAReccord.text =@"";
        cell.AAImage.image= nil;

        cell.AAName.text =@"";
        cell.AAId.text = @"";
        cell.AATime.text =@"";
        
        return cell;
    }else if (indexPath.section == 2){
        
       Home3MiddleBannerCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Home3MiddleBannerCell"];
       cell.delegate = self;
       if (self.newsDataArray.count > 0) {
           cell.modelarray = self.newsDataArray;
           [cell setupCellWithModelArray:self.newsDataArray AdModel:nil delegate:self loca:self rootViewController:self];
//           if (self.adDataArray.count > 0) {
//              DHCWNativeAdDataObject *model = self.adDataArray[0];
//              [cell setupCellWithModelArray:self.newsDataArray AdModel:model delegate:self loca:self rootViewController:self];
//           }else{
//               [cell setupCellWithModelArray:self.newsDataArray AdModel:nil delegate:self loca:self rootViewController:self];
//           }
           
    
       }
        cell.contentView.backgroundColor = [UIColor whiteColor];
        
        cell.backgroundColor = [UIColor whiteColor];

        return cell;
    }else if (indexPath.section == 3) {
        
        // 注释掉原来的完整版本代码，保留以便后续恢复
        /*
        if (self.validateTime) {
            
            HomeService2TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HomeService2TableViewCell"];
            
            cell.lb_title.text = @"生活服务";
            
            cell.imageView1.image = [UIImage imageNamed:@"社保计算器11"];
            
            cell.imageView2.image = [UIImage imageNamed:@"home_lawService"];

            cell.imageView1.tag = 205;
            cell.imageView2.tag = 206;
            
            cell.delegate = self;
            
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            
            return cell;
            
        }
        
        HomeServiceTableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"HomeServiceTableViewCell"];
        
        cell.lb_title.text = @"生活服务";
        cell.imageView1.image = [UIImage imageNamed:@"大病求助"];
        cell.imageView2.image = [UIImage imageNamed:@"微医挂号"];
        cell.imageView3.image = [UIImage imageNamed:@"社保计算器11"];
        cell.imageView4.image = [UIImage imageNamed:@"home_quickMedical"];
        cell.imageView5.image = [UIImage imageNamed:@"home_lawService"];
        cell.imageView6.image = [UIImage imageNamed:@"home_listenLife"];
        
        cell.imageView1.tag = 200;
        cell.imageView2.tag = 201;
        cell.imageView3.tag = 202;
        cell.imageView4.tag = 203;
        cell.imageView5.tag = 204;
        cell.imageView6.tag = 205;
        
        cell.delegate = self;
        
        return cell;
        */
        
        HomeServiceTableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"HomeServiceTableViewCell"];
        
        cell.lb_title.text = @"生活服务";
        
        // 只显示2个功能：社保计算器、大家都在听
        cell.imageView1.image = [UIImage imageNamed:@"社保计算器11"];
        cell.imageView2.image = [UIImage imageNamed:@"home_listenLife"];
        
        // 注释掉其他功能，保留代码以便后续恢复
        // cell.imageView3.image = [UIImage imageNamed:@"home_lawService"];
        // cell.imageView4.image = [UIImage imageNamed:@"home_quickMedical"];
        // cell.imageView5.image = [UIImage imageNamed:@"大病求助"];
        // cell.imageView6.image = [UIImage imageNamed:@"微医挂号"];
        
        // 只显示第一行的2个功能
        cell.showOnlyFirstRow = YES;
        
        cell.imageView1.tag = 202; // 社保计算器
        cell.imageView2.tag = 205; // 大家都在听
        
        // 注释掉其他功能的tag设置
        // cell.imageView3.tag = 204; // 法律咨询
        // cell.imageView4.tag = 203; // 快速问诊
        // cell.imageView5.tag = 200; // 大病求助
        // cell.imageView6.tag = 201; // 微医挂号
        
        cell.delegate = self;
        
        return cell;
    }
    
//    HomeVideoContentCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HomeVideoContentCell"];
//
//    [cell setupVideoVCWithSelf:self];
//
//    self.videoCell = cell;

    return [UITableViewCell new];

}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *headView = [[UIView alloc]init];
    headView.backgroundColor = [UIColor colorWithHex:0xf4f4f4];
    return headView;
}
//- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
//
////    if (section == 3 || section == 4) {
////        HomeSectionHeaderView *headerView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"homeSection"];
////        if (section == 3) {
////            headerView.lb_title.text = @"爱心医疗";
////        }else if (section == 4){
////            headerView.lb_title.text = @"生活服务";
////        }
////        return headerView;
////    }
//
////    if (section == 1) {
////        HomeHelperHeaderView * headerView = [[HomeHelperHeaderView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 45 * WIDTHRADIU)];
////        headerView.delegate = self;
////        self.newsHeaderView = headerView;
////        return headerView;
////    }
//
//    if (section == 2) {
//        UIView *headView = [[UIView alloc]init];
//        headView.backgroundColor = [UIColor whiteColor];
//        return headView;
//    }
//
//    UIView *headView = [[UIView alloc]init];
//    headView.backgroundColor = [UIColor colorWithHex:0xf4f4f4];
//    return headView;
//}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        return 0.01;
    }
    return 2.0 * WIDTHRADIU;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.01;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        return 210*WIDTHRADIU;
    }else if (indexPath.section == 1){
//        return 110 ;
        return 75;
    }else if (indexPath.section == 2){
        UIImage *image = [UIImage imageNamed:@"home_middleBanner"];
        float width = image.size.width;
        float height = image.size.height;
        float widthProportion = self.view.bounds.size.width / width;
        return  height * widthProportion;
    }else if (indexPath.section == 3){
        // 注释掉原来的高度逻辑，保留以便后续恢复
        /*
        if (self.validateTime) {
            return 150 *WIDTHRADIU;
        }
        return 350 * WIDTHRADIU;
        */
        
        // 只显示2个功能，高度= 标题50 + view1高90 + 底部边距80 = 220
        return 220 * WIDTHRADIU;
    }
    
    // 注释掉可能导致滚动问题的默认高度，保留以便后续恢复
    // return  ScreenHeight ;
    
    // 返回一个合理的高度，避免滚动问题
    return 0;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
   [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    if (indexPath.section == 1) {
        
        
        if (self.msgModel && [[NSUserDefaults standardUserDefaults] boolForKey:@"firstlog"] && [self compareCurrentTime:self.msgModel.noticeTime]) {
            
//            if (![self compareWithLastDate:self.msgModel.noticeTime]) {
//                //[self goToAuthQueryVC];
//                [self goToAuthHelperWebVC];
//                return;
//            }
            
            [self goToAuthHelperWebVC];
            return;
        }

    }
}

#pragma mark - 电子社保卡支持的省份
- (void)essCardProvicne{
    NSString*version = nil;
    NSString*v = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
    NSArray*vArr = [v componentsSeparatedByString:@"."];
    for (int i = 0; i < vArr.count; i++) {
        if (version == nil) {
            version = [NSString stringWithFormat:@"%@",vArr[i]];
        }else{
            version = [version stringByAppendingFormat:@"%@",vArr[i]];
        }
    }
    NSString *url1 = [NSString stringWithFormat:@"%@dynamic/menu/get",[NetworkConfig ipYinShuConfig]];
    NSDictionary *params1 = @{
        @"configName":@"EssCardProvince",
        @"appName":@"kksh",
        @"version":version,
        @"systemType":@"iOS"
    };
    [NetworkRequest Post15:url1 Params:params1 Success:^(id _Nonnull objc) {
        if ([objc isKindOfClass:[NSDictionary class]]) {
            NSString *state = [NSString stringWithFormat:@"%@",objc[@"state"]];
            if ([state isEqualToString:@"200"]) {
                if ([objc[@"result"] isKindOfClass:[NSArray class]]) {
                    NSArray *result=objc[@"result"];
                    if (result!=nil&&result.count>0) {
                        NSDictionary *bean=[result objectAtIndex:0];
                        NSString *str=[NSString stringWithFormat:@"%@",bean[@"content"]];;
                        [[NSUserDefaults standardUserDefaults]setObject:str forKey:@"EssCardProvince"];
                    }
                }
            }
        }

    } Failure:^(NSError *error) {
        NSLog(@"EssCardProvince:%@",error);
    }];
}

//三方电子社保卡
-(void)essCardThird{
    NSURL * alipay_app_url = [NSURL URLWithString:@"alipay://"];
    BOOL ali = [[UIApplication sharedApplication] canOpenURL:alipay_app_url];
    if (ali) {
        NSString *url = @"alipays://platformapi/startapp?appId=20000067&url=https%3A%2F%2Frender.alipay.com%2Fp%2Fs%2Fmedical-card-online%2Fwww%2Findex.html%3FchInfo%3DPDA01B01C01D00%26__webview_options__%3D";
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
    }else{
        if (![[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"wechat://"]] ) {
            [self kkJumpALiRedPackageWebVC];
                      return;
         }
        [self kkWXMiniJump];
    }
}

#pragma mark - HometTopViewDelegate 顶部按钮跳转
- (void)HometTopViewWithItem:(NSInteger)item:(KKRedPackageClickEventModel*)model{
    if(model==nil){
        if (item == 0) {
           [NetworkRequest statisticsWithEventName:@"home_icon_11"];
            //电子社保卡签发
            [[clickEvent instance] clickEventRooterVC:self Content:@"homeOne1" menuName:@"homeOne1"];
        }else if(item == 1){//认证领钱
            [NetworkRequest statisticsWithEventName:@"home_icon_12"];
            [[clickEvent instance] clickEventRooterVC:self Content:@"homeNewAuth" menuName:@"homeNewAuth"];
        }else if(item == 2){//医保卡
            [NetworkRequest statisticsWithEventName:@"home_icon_13"];
            if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"alipays://"]]) {
                    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"alipays://platformapi/startapp?appId=2021001123625885&page=pages%2findex%2findex%3fprovideId%3d2088331168368991%26chInfo%3dXSbduanfanyong"] options:nil completionHandler:nil];
                return;
            }
            if (![WXApi isWXAppInstalled]){
                [Tools showMessage:@"请安装支付宝APP后重试"];
                return;
            }
            WXLaunchMiniProgramReq *launchMiniProgramReq = [WXLaunchMiniProgramReq object];
            launchMiniProgramReq.userName = @"gh_45334679e384";  //拉起的小程序的username
            launchMiniProgramReq.path = @"pages/nhsa-code/index/index?channel=AAEKTLpkFoE88Zic8BqWR87_&cityCode=440300";    //拉起小程序页面的可带参路径，不填默认拉起小程序首页
            launchMiniProgramReq.miniProgramType = WXMiniProgramTypeRelease; //拉起小程序的类型
            [WXApi sendReq:launchMiniProgramReq completion:^(BOOL success) {
            }];
        }else if(item == 3){
            [NetworkRequest statisticsWithEventName:@"home_icon_14"];
//            if (!self.validateTime) {
//                //[Tools showMessage:@"测试案例"];
//                [[clickEvent instance] clickEventRooterVC:self Content:@"homeNewBank" menuName:@"homeNewBank"];
//            }else{
//                if([[NSUserDefaults standardUserDefaults] boolForKey:@"firstlog"]){
//                    DistrictAuthenticationPersonalInfoController* vc = [DistrictAuthenticationPersonalInfoController new];
//                    vc.title = @"优抚核查";
//                    vc.hidesBottomBarWhenPushed = YES;
//                    [self.navigationController pushViewController:vc animated:YES];
//                }else{
//                    [self unLoginTap];
//                }
//            }
            [[clickEvent instance]clickEventRooterVC:self getFederatedLoginRequestWithUrl:@"https://web.kanface.com:444/common/forward/KK_WALLET" menuName:@"养老钱包"];
            
        }
    }else{
        if(![[NSUserDefaults standardUserDefaults] boolForKey:@"firstlog"]){
            [self unLoginTap];
            return;
        }
        [NetworkRequest statisticsWithEventName:[NSString stringWithFormat:@"%@",model.ID]];
        switch (model.type.integerValue) {
            case 1001://原生跳转
            {
                [[clickEvent instance] clickEventRooterVC:self model:model];
            }
                break;
            case 1002://h5跳转
            {
                WebVC *vc = [[WebVC alloc]init];
                vc.title = model.menuName;
                vc.url = model.content;
                vc.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:vc animated:YES];
            }
                break;
            case 1003://微信小程序
            {
                if (![WXApi isWXAppInstalled]){
                    [Tools showMessage:@"请安装微信APP后重试"];
                    return;
                }
                NSDictionary *resourceInfoDic = [self dictionaryWithJsonString:model.content];
                if (resourceInfoDic&& resourceInfoDic.allKeys.count > 1) {
                    NSString *userName = resourceInfoDic[@"userId"];
                    NSString *path = resourceInfoDic[@"path"];
                    WXLaunchMiniProgramReq *launchMiniProgramReq = [WXLaunchMiniProgramReq object];
                    launchMiniProgramReq.userName = userName; //拉起的小程序的username
                    launchMiniProgramReq.path = path; //拉起小程序页面的可带参路径，不填默认拉起小程序首页
                    launchMiniProgramReq.miniProgramType = WXMiniProgramTypeRelease; //拉起小程序的类型
                    [WXApi sendReq:launchMiniProgramReq completion:^(BOOL success) {
                    }];
                }
            }
                break;
            case 1004:{//其他
                NSDictionary *dic = [self dictionaryWithJsonString:model.content];
                if (dic) {
                    [self push:dic model:model];
                }
            }
                break;
            case 1005:{//联合登录
                if(![[NSUserDefaults standardUserDefaults] boolForKey:@"firstlog"]){
                    [self unLoginTap];
                    return;
                }
                [[clickEvent instance]clickEventRooterVC:self getFederatedLoginRequestWithUrl:model.content menuName:model.menuName];
               
//                WebVC *webvc = [[WebVC alloc]init];
//                webvc.url=[NSString stringWithFormat:@"http://172.16.10.109:1234/#/?userId=%d&phone=17775005839",[getPeopleID PeopleID]];
//                //webvc.url=@"http://172.16.10.157:1234/#/?userId=59354&phone=18255476769";
//                webvc.title=@"养老钱包";
//                [self.navigationController pushViewController:webvc animated:YES];
//                MiniPaySocial *webvc = [[MiniPaySocial alloc]init];
//                webvc.title=@"社保缴纳";
//                [self.navigationController pushViewController:webvc animated:YES];
            }
                break;
            default:
                break;
        }
    }
}

-(void) ftCjhx{
    NSString *url=@"https://cbservice.weface.com.cn/securities/getTokenParams/cjhxv2";
    //NSString *url=@"http://local.weface.com.cn:6001/securities/getTokenParams/axzq";
    url = [NSString stringWithFormat:@"%@",url];
    url = [url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet  URLQueryAllowedCharacterSet]];
    NSDictionary *params = @{@"uid":@([getPeopleID PeopleID]),@"tel":[getPeopleID PeopleIphoneNmber]};
    [NetworkRequest NewsPost:url Params:params Success:^(id _Nonnull objc) {
        NSLog(@"objc:%@",objc);
        NSString* state = [NSString stringWithFormat:@"%@",objc[@"state"]];
        NSString* describe = [NSString stringWithFormat:@"%@",objc[@"describe"]];
        if ([state isEqualToString:@"200"]){
            NSDictionary *result=objc[@"result"];
            NSString* appId = [NSString stringWithFormat:@"%@",result[@"appId"]];
            NSString* path = [NSString stringWithFormat:@"%@",result[@"path"]];
            NSString* query = [NSString stringWithFormat:@"%@",result[@"query"]];
            FATAppletRequest *request = [[FATAppletRequest alloc] init];
            request.appletId = @"63fd5a6fbd2c650001848a11";
            //request.apiServer = @"https://axzqgf-kksh-zl.fdep.cn";
            request.apiServer = @"https://api.finclip.com";
            NSDictionary *map=nil;
            if ([path isEqualToString:@"<null>"]) {
                map=@{@"query":query};
            }else{
                map=@{@"path":path,@"query":query};
            }
            request.startParams = map;
            [[FATClient sharedClient] startAppletWithRequest:request InParentViewController:self completion:^(BOOL result, FATError *error) {
                NSLog(@"打开小程序:%@", error);
            } closeCompletion:^{
                NSLog(@"关闭小程序");
            }];
        }else{
            [self alertShow:describe];
        }
    }
    Failure:^(NSError* error) {
        NSLog(@"NetworkRequest:error:%@",error);
    }];
}


#pragma mark - HomeMiddleNewsCellDelegate
- (void)clickNewsBtn:(UIButton *)btn
{
    JHNewsModel* model1 = nil;
    JHNewsModel* model2 = nil;
    
    if (index == 0) {
        model1 = self.newsArray[index*2];
        model2 = self.newsArray[index*2 + 1];
    }else{
        model1 = self.newsArray[(index - 1)*2];
        model2 = self.newsArray[(index - 1)*2 + 1];
    }
    
    switch (btn.tag) {
        case 200:
            [self goToNewsDetaiVCWithModel:model1];
            break;
        case 201:
            [self goToNewsDetaiVCWithModel:model2];
            break;
            
        default:
            break;
    }
    
}

- (void)clickHelpBtn:(UIButton *)btn
{
    [self goToAuthHelperWebVC];
}

#pragma mark - 认证查询
- (void)goToAuthQueryVC {
    if (![[NSUserDefaults standardUserDefaults] boolForKey:@"firstlog"]) {
        
        [[NSNotificationCenter defaultCenter]postNotificationName:KKSBJumpLoginVCNotificationName object:nil];
           
    }else{
        WeiJianQueryViewController* vc = [WeiJianQueryViewController new];
        vc.title = @"认证查询";
        vc.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:vc animated:YES];
    }
}
#pragma mark - 跳转看看助手认证结果
- (void)goToAuthHelperWebVC {
    if (![[NSUserDefaults standardUserDefaults] boolForKey:@"firstlog"]) {
        [[NSNotificationCenter defaultCenter]postNotificationName:KKSBJumpLoginVCNotificationName object:nil];
        return;
    }
    KKAuthHelperViewController *vc = [KKAuthHelperViewController new];
    vc.title = @"看看助手";
    vc.url = @"http://nginx.weface.com.cn/kkaide/#/Home";
    //vc.url = @"http://172.16.10.194:8080/#/bt11";
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
}

//#pragma mark - SDCycleScrollViewDelegate
////顶部banner代理
//- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index
//{
//    NSLog(@"---点击了第%ld张图片", (long)index);
//
//
//        if (self.arrayT.count > 0) {
//            homePageNewsResultModel *model = self.arrayT[index];
//            if (model.targetUrl && ![model.targetUrl isEqualToString:@""]) {
//
//
//                if([model.bak_01 isEqualToString:@"true"] && ![[NSUserDefaults standardUserDefaults] boolForKey:@"firstlog"]){
//
//
//                    [[NSNotificationCenter defaultCenter]postNotificationName:KKSBJumpLoginVCNotificationName object:nil];
//                                 return;
//
//                }
//
//                 [GTCountSDK trackCountEvent:@"home_topBannerClick" withArgs:@{}];
//                if ([model.title isEqualToString:@"合伙人"]) {
//                    [self getPartnerQuery];
//                    return;
//                }else if ([model.title isEqualToString:@"生活"]){
//                        KKLisenViewController*vc = [KKLisenViewController new];
//                        vc.hidesBottomBarWhenPushed = YES;
//                        vc.fromHome = YES;
//                        [self.navigationController pushViewController:vc animated:YES];
//                        return;
//                }else if ([model.title isEqualToString:@"存钱罐拉新"] || [model.title isEqualToString:@"存钱罐活动"]) {
//                    NSString*version = nil;
//                    NSString*v = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
//                    NSArray*vArr = [v componentsSeparatedByString:@"."];
//
//                    for (int i = 0; i < vArr.count; i++) {
//                        if (version == nil) {
//                            version = [NSString stringWithFormat:@"%@",vArr[i]];
//                        }else{
//                            version = [version stringByAppendingFormat:@"%@",vArr[i]];
//                        }
//                    }
//
//                    NSString* url = [NSString stringWithFormat:@"%@?userId=%@&phone=%@&version=%@&appName=kksh",model.targetUrl,@([getPeopleID PeopleID]),[getPeopleID PeopleIphoneNmber],version];
//
//                    [self jumpToUrl:url andTitle:model.title];
//                    return;
//                }else if ([model.title isEqualToString:@"智能问诊"]) {
//                    WeakSelf
//                         if (![[NSUserDefaults standardUserDefaults]boolForKey:@"aida_allow"]) {
//
//                             self.aiDaView = [AiDaAlertView showAlertViewWithTitle:nil imageName:nil ViewController:self type:AiDaAlertViewTypeAD block:^(BOOL success) {
//                                 [[NSUserDefaults standardUserDefaults]setBool:YES forKey:@"aida_allow"];
//                                 [[NSUserDefaults standardUserDefaults]synchronize];
//                                 [self aiDaTokenRequest:^(bool success, NSString *token) {
//                                   if (success) {
//                                       [weakSelf aidaUrlRequestWithToken:token];
//                                   }
//                                 }];
//                             }];
//
//                          return;
//
//                      }
//
//
//
//                      [self aiDaTokenRequest:^(bool success, NSString *token) {
//                          if (success) {
//                              [weakSelf aidaUrlRequestWithToken:token];
//                          }
//                      }];
//
//                    return;
//                }else if ([model.title isEqualToString:@"看视频"]) {
//                    [self goToTVVC:YES];
//                    return;
//                }else if ([model.title isEqualToString:@"存钱罐"]) {
//                    if ([[NSUserDefaults standardUserDefaults]boolForKey:@"firstlog"]) {
//
//                      [GTCountSDK trackCountEvent:@"CQG_PUSH_click" withArgs:nil];
//
//                      [self GetyeepayUrl];
//
//                      return;
//                    }else{
//
//                      [self unLoginTap];
//                    }
//                    return;
//                }else if ([model.title isEqualToString:@"电影随心看"]) {
//                    if ([[NSUserDefaults standardUserDefaults]boolForKey:@"firstlog"]) {
//
//                        [[clickEvent instance] clickEventRooterVC:self Content:@"getMovieUrl" menuName:model.title];
//
//                        return;
//                    }else{
//
//                      [self unLoginTap];
//                    }
//                    return;
//                }else if ([model.title isEqualToString:@"团油"]) {
//                    if ([[NSUserDefaults standardUserDefaults]boolForKey:@"firstlog"]) {
//
//                        [[clickEvent instance] clickEventRooterVC:self Content:@"homeTwoOil" menuName:model.title];
//
//                        return;
//                    }else{
//
//                      [self unLoginTap];
//                    }
//                    return;
//                }
//                WebVC * vc = [WebVC new];
//                vc.title= model.title;
//                vc.url = model.targetUrl;
//                vc.hidesBottomBarWhenPushed = YES;
//                [self.navigationController pushViewController:vc animated:YES];
//
//
//                return;
//    //            SSCardWebViewController *vc = [[SSCardWebViewController alloc]init];
//    //            vc.JSString = model.targetUrl;
//    //            vc.title = model.title;
//    //            vc.hidesBottomBarWhenPushed = YES;
//    //
//    //            [self.navigationController pushViewController:vc animated:YES];
//
//            }
//        }else{
//            if (index == 0) {
//            }else if (index == 1){
//                //[self getPartnerQuery];
//                //[self goToDaYiQunVC];
//            }else if (index == 2){
//                KKLisenViewController*vc = [KKLisenViewController new];
//                vc.hidesBottomBarWhenPushed = YES;
//                vc.fromHome = YES;
//                [self.navigationController pushViewController:vc animated:YES];
//                return;
//            }
//        }
//}

//#pragma mark - MiddleBannerViewCellDelegate 中部banner代理
//- (void)selectedItemCell:(NSInteger)index
//{
//    if (index == 1) {
//
//        if(![[NSUserDefaults standardUserDefaults] boolForKey:@"firstlog"]){
//
//            [[NSNotificationCenter defaultCenter]postNotificationName:KKSBJumpLoginVCNotificationName object:nil];
//
//            return;
//
//        }
//
//       // NSString * skipUrl = @"http://172.16.10.144/projects/html-nginx/html-nginx/yaodou/index.html";//内网
//        NSString * skipUrl = @"http://nginx.weface.com.cn/yaodou/index.html";
//                     WebVC * vc = [WebVC new];
//                       vc.title= @"健康防疫 共渡难关";
//                     vc.url = skipUrl;
//                    vc.hidesBottomBarWhenPushed = YES;
//                    [self.navigationController pushViewController:vc animated:YES];
//
//             /*
//               NSDictionary * params = @{@"appId":@"201912161758",
//                                            @"phone":[getPeopleID PeopleIphoneNmber]};
//                  __weak typeof(self) weakSelf = self;
//                  [YDAuthenticationHelper authentication:@"https://kankan.yaodouwang.com/user/login/open" body:params success:^(id  _Nonnull response) {
//                      if ([response isKindOfClass:[NSDictionary class]]) {
//                          NSDictionary * data = response[@"data"];
//                          NSURL * skipUrl = [YDAuthenticationHelper jointUrlWithBody:data andUrl:@"https://k.yaodouwang.com/coupon"];
//                          Web2ViewController * vc = [Web2ViewController new];
//                          vc.title= @"平价药房";
//                          vc.skipUrl = skipUrl;
//                          vc.type = @"优惠券";
//                          vc.hidesBottomBarWhenPushed = YES;
//                          [weakSelf.navigationController pushViewController:vc animated:YES];
//                          [GTCountSDK trackCountEvent:@"H5_PingMingYaoFang" withArgs:nil];
//
//                      }else{
//                          NSLog(@"数据格式不正确 ===> %@",response);
//                      }
//
//                  } fail:^(id  _Nonnull error) {
//
//                      NSLog(@"请求失败，请登录 ===> %@",error);
//                  }];
//
//*/
//
////        NSURL *taobaoUrl = [NSURL URLWithString:@"taobao://s.click.taobao.com/t?e=m%3D2%26s%3DPAQApF5FakQcQipKwQzePCperVdZeJviK7Vc7tFgwiFRAdhuF14FMfh0vFXOujvwRitN3%2FurF3yC37VbDH6dNsq8%2BfZOwT%2BoFeOdupi0HsA2yh0r3HIKLJ3PLI70IiRVfkwHTg4TQaeOJ2XZVrYPybh9YVht%2FlWEjPobR%2B9Wl%2BpnE8Dltr%2FIXMQ0hAfmY51Fh1lq2bdARU9Q83vPJEk6zGsFOLhERZOUamkFHdIFxePGDF1NzTQoPw%3D%3D&union_lens=lensId%3APUB%401572248051%400b0fd6a8_0dba_16e11495da8_0974%4001"];
//
////        [self jumpToHTML5:@"https://bor5gsp0.kuaizhan.com/35/99/p6236899770974e?xid=af3f1b&save_url=aHR0cHM6Ly93LnVybC5jbi9zL0FBSzkwTGQ=#/taocash" andJAnalytics:@"0元购"];
//
////        return;
////        if ([[UIApplication sharedApplication] canOpenURL:taobaoUrl]) {
////            [[UIApplication sharedApplication] openURL:taobaoUrl];
////        }else{
////            //[self jumpToHTML5:@"https://mos.m.taobao.com/activity_newer?from=pub&pid=mm_628080090_951800477_109687650240&union_lens=lensId%3APUB%401572578705%400b0af91d_0df6_16e24febf5c_0809%4001" andJAnalytics:@"淘宝"];
////            [self jumpToHTML5:@"https://w.url.cn/s/AwljBBX" andJAnalytics:@"0元购"];
////        }
////
////        [CTAPIBaseManager GET3:XiAoClickCountUrl params:@{} completionHandler:^(id  _Nonnull responseObject, NSError * _Nonnull error) {
////
////
////
////        }];
////
////        [GTCountSDK trackCountEvent:@"Coupon_XiAo_click" withArgs:@{}];
//
//    }else if (index == 0){
//
//        if ([[NSUserDefaults standardUserDefaults] boolForKey:@"firstlog"]) {
//            [self refreshCoins];
//        }else {
//
//            [[NSNotificationCenter defaultCenter]postNotificationName:KKSBJumpLoginVCNotificationName object:nil];
//        }
//
//
//    }else if (index == 2){
//
////                WXLaunchMiniProgramReq *launchMiniProgramReq = [WXLaunchMiniProgramReq object];
////                launchMiniProgramReq.userName = @"gh_f8a0e531525d";  //拉起的小程序的username
////                launchMiniProgramReq.path = @"WXMiniPro://gh_f8a0e531525d /pages/base/redirect/index?routeKey=PH14_PRODUCT_DETAIL&wtagid=104.83.453";    //拉起小程序页面的可带参路径，不填默认拉起小程序首页
////                launchMiniProgramReq.miniProgramType = WXMiniProgramTypeRelease; //拉起小程序的类型
////                [WXApi sendReq:launchMiniProgramReq];
//        WXLaunchMiniProgramReq *launchMiniProgramReq = [WXLaunchMiniProgramReq object];
//        launchMiniProgramReq.userName = @"gh_f8a0e531525d";  //拉起的小程序的username
//        launchMiniProgramReq.path = @"pages/base/redirect/index?routeKey=PROMOTION_GIFT_PACKAGE_NEW&activityCode=appDefault&wtagid=118.4.1";    //拉起小程序页面的可带参路径，不填默认拉起小程序首页
//        launchMiniProgramReq.miniProgramType = WXMiniProgramTypeRelease; //拉起小程序的类型
//        [WXApi sendReq:launchMiniProgramReq completion:^(BOOL success) {
//
//        }];
//
//    }
//    [GTCountSDK trackCountEvent:@"home_middleBannerCli" withArgs:@{}];
//}

//- (void)selectedItem:(BannerAdObjectModel *)model index:(NSInteger)index
//{
//
//    /*
//
//    if ([model.bak_01 isEqualToString:@"true"] && ![[NSUserDefaults standardUserDefaults] boolForKey:@"firstlog"]) {
//        [self unLoginTap];
//        return;
//    }
//
//    if (model.urlType == 1) {
//        WebVC * vc = [WebVC new];
//        vc.title= model.title;
//        vc.url = model.targetUrl;
//        vc.hidesBottomBarWhenPushed = YES;
//        [self.navigationController pushViewController:vc animated:YES];
//    }else if (model.urlType == 2){
//        if ([model.title isEqualToString:@"智能问诊"]) {
//            [self goToSmartConsultationVC];
//        }else if ([model.title isEqualToString:@"生活"]){
//            KKLisenViewController*vc = [KKLisenViewController new];
//            vc.hidesBottomBarWhenPushed = YES;
//            vc.fromHome = YES;
//            [self.navigationController pushViewController:vc animated:YES];
//            return;
//        }else if ([model.title isEqualToString:@"合伙人"]){
//            [self getPartnerQuery];
//        }else if ([model.title isEqualToString:@"抢红包"]){
//            [self getRdactiveListRequest];
//        }else if ([model.title isEqualToString:@"存钱罐拉新"] || [model.title isEqualToString:@"存钱罐活动"]) {
//            NSString*version = nil;
//            NSString*v = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
//            NSArray*vArr = [v componentsSeparatedByString:@"."];
//
//            for (int i = 0; i < vArr.count; i++) {
//                if (version == nil) {
//                    version = [NSString stringWithFormat:@"%@",vArr[i]];
//                }else{
//                    version = [version stringByAppendingFormat:@"%@",vArr[i]];
//                }
//            }
//
//            NSString* url = [NSString stringWithFormat:@"%@?userId=%@&phone=%@&version=%@&appName=kksh",model.targetUrl,@([getPeopleID PeopleID]),[getPeopleID PeopleIphoneNmber],version];
//
//            [self jumpToUrl:url andTitle:model.title];
//        }else if ([model.title isEqualToString:@"打卡赚金币"]){
//            CoinsCenterViewController *vc = [[CoinsCenterViewController alloc]init];
//            vc.title = @"打卡赚金币";
//            vc.hidesBottomBarWhenPushed = YES;
//            [self.navigationController pushViewController:vc animated:YES];
//        }else if ([model.title isEqualToString:@"金币抽奖"]){
//            [self refreshCoins];
//        }
//
//    }else if (model.urlType == 3){
//
//        NSString* targetUrl = model.targetUrl;
//        NSArray* array = [targetUrl componentsSeparatedByString:@"&"];
//        if (array.count == 2) {
//            NSString* userName = array[0];
//            NSString* path = array[1];
//
//            WXLaunchMiniProgramReq *launchMiniProgramReq = [WXLaunchMiniProgramReq object];
//            launchMiniProgramReq.userName = userName;  //拉起的小程序的username
//            launchMiniProgramReq.path = path;    //拉起小程序页面的可带参路径，不填默认拉起小程序首页
//            launchMiniProgramReq.miniProgramType = WXMiniProgramTypeRelease; //拉起小程序的类型
//            [WXApi sendReq:launchMiniProgramReq completion:^(BOOL success) {
//
//            }];
//        }
//
//    }
//
//     */
//
//    if (model.urlType == 1) {
//        if([model.bak_01 isEqualToString:@"true"] && ![[NSUserDefaults standardUserDefaults] boolForKey:@"firstlog"]){
//
//            [[NSNotificationCenter defaultCenter]postNotificationName:KKSBJumpLoginVCNotificationName object:nil];
//            return;
//        }
//          WeakSelf
//            if ([model.title isEqualToString:@"智能问诊"]) {
//                 if (![[NSUserDefaults standardUserDefaults]boolForKey:@"aida_allow"]) {
//
//                     UIView * _Nonnull extractedExpr = [AiDaAlertView showAlertViewWithTitle:nil imageName:nil ViewController:self type:AiDaAlertViewTypeAD block:^(BOOL success) {
//                         [[NSUserDefaults standardUserDefaults]setBool:YES forKey:@"aida_allow"];
//                         [[NSUserDefaults standardUserDefaults]synchronize];
//                         [self aiDaTokenRequest:^(bool success, NSString *token) {
//                             if (success) {
//                                 [weakSelf aidaUrlRequestWithToken:token];
//                             }
//                         }];
//                     }];
//                     self.aiDaView = extractedExpr;
//
//                  return;
//
//              }
//
//
//
//              [self aiDaTokenRequest:^(bool success, NSString *token) {
//                  if (success) {
//                      [weakSelf aidaUrlRequestWithToken:token];
//                  }
//              }];
//            }else if ([model.title isEqualToString:@"生活"]){
//                KKLisenViewController*vc = [KKLisenViewController new];
//                vc.hidesBottomBarWhenPushed = YES;
//                vc.fromHome = YES;
//                [self.navigationController pushViewController:vc animated:YES];
//                return;
//            }else if ([model.title isEqualToString:@"合伙人"]){
//                [self getPartnerQuery];
//            }else if ([model.title isEqualToString:@"抢红包"]){
//                [self getRdactiveListRequest];
//            }else if ([model.title isEqualToString:@"存钱罐拉新"] || [model.title isEqualToString:@"存钱罐活动"]) {
//                NSString*version = nil;
//                NSString*v = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
//                NSArray*vArr = [v componentsSeparatedByString:@"."];
//
//                for (int i = 0; i < vArr.count; i++) {
//                    if (version == nil) {
//                        version = [NSString stringWithFormat:@"%@",vArr[i]];
//                    }else{
//                        version = [version stringByAppendingFormat:@"%@",vArr[i]];
//                    }
//                }
//
//                NSString* url = [NSString stringWithFormat:@"%@?userId=%@&phone=%@&version=%@&appName=kksh",model.targetUrl,@([getPeopleID PeopleID]),[getPeopleID PeopleIphoneNmber],version];
//
//                [self jumpToUrl:url andTitle:model.title];
//            }else if ([model.title isEqualToString:@"打卡赚金币"]){
//                CoinsCenterViewController *vc = [[CoinsCenterViewController alloc]init];
//                vc.title = @"打卡赚金币";
//                vc.hidesBottomBarWhenPushed = YES;
//                [self.navigationController pushViewController:vc animated:YES];
//            }else if ([model.title isEqualToString:@"医保卡"]){
//                if (![WXApi isWXAppInstalled]){
//                    [Tools showMessage:@"请安装微信APP后重试"];
//                    return;
//                }
//
//                WXLaunchMiniProgramReq *launchMiniProgramReq = [WXLaunchMiniProgramReq object];
//                launchMiniProgramReq.userName = @"gh_45334679e384";  //拉起的小程序的username
//                launchMiniProgramReq.path = @"pages/nhsa-code/index/index?channel=AAEKTLpkFoE88Zic8BqWR87_&cityCode=440300";    //拉起小程序页面的可带参路径，不填默认拉起小程序首页
//                launchMiniProgramReq.miniProgramType = WXMiniProgramTypeRelease; //拉起小程序的类型
//                [WXApi sendReq:launchMiniProgramReq completion:^(BOOL success) {
//
//                }];
//                return;
//            }else if ([model.title isEqualToString:@"0元免费领"]){
//
//                [self getZeroInsuranceRequestWithType:@"100101"];
//
//            }else if ([model.title isEqualToString:@"免费果园"]){
////                if (self.adDataArray.count == 0) {
////                    [self loadBXMADViews];
////                }
//                [self goToFruitVC];
//            }else if ([model.title isEqualToString:@"存钱罐"]){
//                [[clickEvent instance] clickEventRooterVC:self Content:@"homeThree4" menuName:@"存钱罐"];
//                [NetworkRequest statisticsWithEventName:@"dialog_homeBanner_CQG"];
//            }else if ([model.title isEqualToString:@"金币兑换"]){
//                [[clickEvent instance] clickEventRooterVC:self Content:@"JBDH" menuName:@"金币兑换"];
//                [NetworkRequest statisticsWithEventName:@"dialog_homeBanner_JBDH"];
//            }else if ([model.title isEqualToString:@"团油"]){
//                [[clickEvent instance] clickEventRooterVC:self Content:@"homeTwoOil" menuName:@"团油"];
//                [NetworkRequest statisticsWithEventName:@"dialog_homeBanner_homeTwoOil"];
//            }else{
//                WebVC * vc = [WebVC new];
//                vc.title= model.title;
//                vc.url = model.targetUrl;
//                vc.hidesBottomBarWhenPushed = YES;
//                [self.navigationController pushViewController:vc animated:YES];
//            }
//
//    }else if (model.urlType == 2){
//
//         if (index == 1) {
//             if(![[NSUserDefaults standardUserDefaults] boolForKey:@"firstlog"]){
//
//                 [[NSNotificationCenter defaultCenter]postNotificationName:KKSBJumpLoginVCNotificationName object:nil];
//                 return;
//             }
//
//            NSString * skipUrl = @"http://nginx.weface.com.cn/yaodou/index.html";
//            // NSString * skipUrl = @"http://172.16.10.136/projects/html-nginx/html-nginx/yaodou/index.html";
//              WebVC * vc = [WebVC new];
//              vc.title= @"健康防疫 共渡难关";
//              vc.url = skipUrl;
//              vc.hidesBottomBarWhenPushed = YES;
//             [self.navigationController pushViewController:vc animated:YES];
//
//
//         /*
//             if(![[NSUserDefaults standardUserDefaults] boolForKey:@"firstlog"]){
//                              LoginVC *loginVC = [[LoginVC alloc]init];
//                              UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:loginVC];
//                              [self presentViewController:nav animated:YES completion:nil];
//                              return;
//                          }
//
//
//                           NSDictionary * params = @{@"appId":@"201912161758",
//                                                        @"phone":[getPeopleID PeopleIphoneNmber]};
//                              __weak typeof(self) weakSelf = self;
//                              [YDAuthenticationHelper authentication:@"https://kankan.yaodouwang.com/user/login/open" body:params success:^(id  _Nonnull response) {
//                                  if ([response isKindOfClass:[NSDictionary class]]) {
//                                      NSDictionary * data = response[@"data"];
//                                      NSURL * skipUrl = [YDAuthenticationHelper jointUrlWithBody:data andUrl:@"https://k.yaodouwang.com/coupon"];
//                                      Web2ViewController * vc = [Web2ViewController new];
//                                      vc.title= @"平价药房";
//                                      vc.type = @"优惠券";
//                                      vc.skipUrl = skipUrl;
//                                      vc.hidesBottomBarWhenPushed = YES;
//                                      [weakSelf.navigationController pushViewController:vc animated:YES];
//                                      [GTCountSDK trackCountEvent:@"H5_PingMingYaoFang" withArgs:nil];
//
//                                  }else{
//                                      NSLog(@"数据格式不正确 ===> %@",response);
//                                  }
//
//                              } fail:^(id  _Nonnull error) {
//
//                                  NSLog(@"请求失败，请登录 ===> %@",error);
//                              }];
//
//             */
////                WXLaunchMiniProgramReq *launchMiniProgramReq = [WXLaunchMiniProgramReq object];
////                launchMiniProgramReq.userName = @"gh_f8a0e531525d";  //拉起的小程序的username
////                launchMiniProgramReq.path = @"pages/base/redirect/index?routeKey=PH04_PRODUCT_TRANSFER_CY&wtagid=118.4.2";    //拉起小程序页面的可带参路径，不填默认拉起小程序首页
////                launchMiniProgramReq.miniProgramType = WXMiniProgramTypeRelease; //拉起小程序的类型
////                [WXApi sendReq:launchMiniProgramReq];
//
//        //        NSURL *taobaoUrl = [NSURL URLWithString:@"taobao://s.click.taobao.com/t?e=m%3D2%26s%3DPAQApF5FakQcQipKwQzePCperVdZeJviK7Vc7tFgwiFRAdhuF14FMfh0vFXOujvwRitN3%2FurF3yC37VbDH6dNsq8%2BfZOwT%2BoFeOdupi0HsA2yh0r3HIKLJ3PLI70IiRVfkwHTg4TQaeOJ2XZVrYPybh9YVht%2FlWEjPobR%2B9Wl%2BpnE8Dltr%2FIXMQ0hAfmY51Fh1lq2bdARU9Q83vPJEk6zGsFOLhERZOUamkFHdIFxePGDF1NzTQoPw%3D%3D&union_lens=lensId%3APUB%401572248051%400b0fd6a8_0dba_16e11495da8_0974%4001"];
//
//        //        [self jumpToHTML5:@"https://bor5gsp0.kuaizhan.com/35/99/p6236899770974e?xid=af3f1b&save_url=aHR0cHM6Ly93LnVybC5jbi9zL0FBSzkwTGQ=#/taocash" andJAnalytics:@"0元购"];
//
//        //        return;
//        //        if ([[UIApplication sharedApplication] canOpenURL:taobaoUrl]) {
//        //            [[UIApplication sharedApplication] openURL:taobaoUrl];
//        //        }else{
//        //            //[self jumpToHTML5:@"https://mos.m.taobao.com/activity_newer?from=pub&pid=mm_628080090_951800477_109687650240&union_lens=lensId%3APUB%401572578705%400b0af91d_0df6_16e24febf5c_0809%4001" andJAnalytics:@"淘宝"];
//        //            [self jumpToHTML5:@"https://w.url.cn/s/AwljBBX" andJAnalytics:@"0元购"];
//        //        }
//        //
//        //        [CTAPIBaseManager GET3:XiAoClickCountUrl params:@{} completionHandler:^(id  _Nonnull responseObject, NSError * _Nonnull error) {
//        //
//        //
//        //
//        //        }];
//        //
//        //        [GTCountSDK trackCountEvent:@"Coupon_XiAo_click" withArgs:@{}];
//
//            }else if (index == 0){
//
//                if ([[NSUserDefaults standardUserDefaults] boolForKey:@"firstlog"]) {
//                   [self refreshCoins];
//                    //[self JumpToVCLine3WithTitle:@"抢红包" button:nil model:nil];
//                }else {
//
//                    [[NSNotificationCenter defaultCenter]postNotificationName:KKSBJumpLoginVCNotificationName object:nil];
//                }
//
//
//            }else if (index == 2){
////                                WXLaunchMiniProgramReq *launchMiniProgramReq = [WXLaunchMiniProgramReq object];
////                                launchMiniProgramReq.userName = @"gh_f8a0e531525d";  //拉起的小程序的username
////                                launchMiniProgramReq.path = @"pages/base/redirect/index?routeKey=PH14_PRODUCT_DETAIL&wtagid=104.83.453";    //拉起小程序页面的可带参路径，不填默认拉起小程序首页
////                                launchMiniProgramReq.miniProgramType = WXMiniProgramTypeRelease; //拉起小程序的类型
////                                [WXApi sendReq:launchMiniProgramReq];
////                    BURewardedVideoModel *model = [[BURewardedVideoModel alloc] init];
////                    model.userId = @"";
////                    self.rewardedAd = [[BUNativeExpressRewardedVideoAd alloc] initWithSlotID:@"945165627" rewardedVideoModel:model];
////
////                    self.rewardedAd.delegate = self;
////                    [self.rewardedAd loadAdData];
////
////
////
////                    return;
////            self.rewardVideoAd = [[GDTRewardVideoAd alloc] initWithAppId:@"1110119875" placementId:@"4051816119319036"];
////            self.rewardVideoAd.delegate = self;
////            //self.rewardVideoAd.videoMuted = NO; // 设置激励视频是否静音
////            [self.rewardVideoAd loadAd];
//
//                WXLaunchMiniProgramReq *launchMiniProgramReq = [WXLaunchMiniProgramReq object];
//                launchMiniProgramReq.userName = @"gh_f8a0e531525d";  //拉起的小程序的username
//                launchMiniProgramReq.path = @"pages/base/redirect/index?routeKey=PROMOTION_GIFT_PACKAGE_NEW&activityCode=appDefault&wtagid=118.4.1";    //拉起小程序页面的可带参路径，不填默认拉起小程序首页
//                launchMiniProgramReq.miniProgramType = WXMiniProgramTypeRelease; //拉起小程序的类型
//                [WXApi sendReq:launchMiniProgramReq completion:^(BOOL success) {
//
//                }];
//            }
//    }else if (model.urlType == 3){
//        if (![WXApi isWXAppInstalled]){
//            [Tools showMessage:@"请安装微信APP后重试"];
//            return;
//        }
//
//        if ([model.targetUrl containsString:@"$"]) {
//            NSArray *array = [model.targetUrl componentsSeparatedByString:@"$"];
//
//            WXLaunchMiniProgramReq *launchMiniProgramReq = [WXLaunchMiniProgramReq object];
//            launchMiniProgramReq.userName = array[0];  //拉起的小程序的username
//            launchMiniProgramReq.path = array[1];    //拉起小程序页面的可带参路径，不填默认拉起小程序首页
//            launchMiniProgramReq.miniProgramType = WXMiniProgramTypeRelease; //拉起小程序的类型
//            [WXApi sendReq:launchMiniProgramReq completion:^(BOOL success) {
//
//            }];
//        }else{
//            WXLaunchMiniProgramReq *launchMiniProgramReq = [WXLaunchMiniProgramReq object];
//            launchMiniProgramReq.userName = model.targetUrl;  //拉起的小程序的username
//            launchMiniProgramReq.path = @"";    //拉起小程序页面的可带参路径，不填默认拉起小程序首页
//            launchMiniProgramReq.miniProgramType = WXMiniProgramTypeRelease; //拉起小程序的类型
//            [WXApi sendReq:launchMiniProgramReq completion:^(BOOL success) {
//
//            }];
//        }
//
//        return;
//    }
//
//
//    [GTCountSDK trackCountEvent:@"home_middleBannerCli" withArgs:@{}];
//}


- (void)shareWebPageToPlatformType:(UMSocialPlatformType)platformType
{
    //创建分享消息对象
    UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];

    //创建网页内容对象
    UMShareWebpageObject *shareObject = [UMShareWebpageObject shareObjectWithTitle:@"分享标题" descr:@"分享内容描述" thumImage:[UIImage imageNamed:@"icon"]];
    //设置网页地址
    shareObject.webpageUrl =@"http://mobile.umeng.com/social";

    //分享消息对象设置分享内容对象
    messageObject.shareObject = shareObject;

    //调用分享接口
    [[UMSocialManager defaultManager] shareToPlatform:platformType messageObject:messageObject currentViewController:self completion:^(id data, NSError *error) {
        if (error) {
            NSLog(@"************Share fail with error %@*********",error);
        }else{
            NSLog(@"response data is %@",data);
        }
    }];
}

- (NSString*)dictionaryToJson:(NSDictionary*)dic

{

    NSError*parseError =nil;

    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dic options:NSJSONWritingPrettyPrinted error:&parseError];



    return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];

}

- (void)test {
    
    // 创建可变字典用于存放Cookie
        NSMutableDictionary *cookieDic = [NSMutableDictionary dictionary];
        // 获取
        NSHTTPCookieStorage *cookieJar = [NSHTTPCookieStorage sharedHTTPCookieStorage];
        for (NSHTTPCookie *cookie in [cookieJar cookies]) {
            [cookieDic setObject:cookie.value forKey:cookie.name];
        }
    
    for (NSHTTPCookie *cookie in [cookieJar cookies]) {
        [cookieJar deleteCookie:cookie];
    }
        // 打印
        NSLog(@"%@",cookieDic);

    
}
#pragma mark - HomeItemDelegate
- (void)HomeItemCell:(KKRedPackageClickEventModel *)model{
    if(![[NSUserDefaults standardUserDefaults] boolForKey:@"firstlog"]){
        [self unLoginTap];
        return;
    }
    [NetworkRequest statisticsWithEventName:[NSString stringWithFormat:@"%@",model.ID]];
    switch (model.type.integerValue) {
        case 1001:
            //原生跳转
        {
            [[clickEvent instance] clickEventRooterVC:self model:model];
        }
            break;
        case 1002:
            //h5跳转
        {
            WebVC *vc = [[WebVC alloc]init];
            vc.title = model.menuName;
            vc.url = model.content;
            vc.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        case 1003:
            //微信小程序
        {
            if (![WXApi isWXAppInstalled]){
                [Tools showMessage:@"请安装微信APP后重试"];
                return;
            }
            
            NSDictionary *resourceInfoDic = [self dictionaryWithJsonString:model.content];
            if (resourceInfoDic&& resourceInfoDic.allKeys.count > 1) {
                NSString *userName = resourceInfoDic[@"userId"];
                NSString *path = resourceInfoDic[@"path"];
                WXLaunchMiniProgramReq *launchMiniProgramReq = [WXLaunchMiniProgramReq object];
                launchMiniProgramReq.userName = userName; //拉起的小程序的username
                launchMiniProgramReq.path = path; //拉起小程序页面的可带参路径，不填默认拉起小程序首页
                launchMiniProgramReq.miniProgramType = WXMiniProgramTypeRelease; //拉起小程序的类型
                [WXApi sendReq:launchMiniProgramReq completion:^(BOOL success) {
                    
                }];
            }
           
        }
            break;
        case 1004:
            //其他
        {
            NSDictionary *dic = [self dictionaryWithJsonString:model.content];
            if (dic) {
                [self push:dic model:model];
            }
        }
            break;
        case 1005:
        {
            [self getFederatedLoginRequestWithModel:model];
        }
            break;
        default:
            break;
    }
}
#pragma mark - HomeCollectionCellDelegate
- (void)HomeCollectionCell:(HomeCollectionCell *)collectionCell didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    if(self.DataArr!=nil&&self.DataArr.count>0){
        KKRedPackageClickEventModel *model=self.DataArr[indexPath.item];
        if(![[NSUserDefaults standardUserDefaults] boolForKey:@"firstlog"]){
            [self unLoginTap];
            return;
        }
        [NetworkRequest statisticsWithEventName:[NSString stringWithFormat:@"%@",model.ID]];
        switch (model.type.integerValue) {
            case 1001://原生跳转
            {
                [[clickEvent instance] clickEventRooterVC:self model:model];
            }
                break;
            case 1002://h5跳转
            {
                WebVC *vc = [[WebVC alloc]init];
                vc.title = model.menuName;
                vc.url = model.content;
                vc.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:vc animated:YES];
            }
                break;
            case 1003://微信小程序
            {
                if (![WXApi isWXAppInstalled]){
                    [Tools showMessage:@"请安装微信APP后重试"];
                    return;
                }
                NSDictionary *resourceInfoDic = [self dictionaryWithJsonString:model.content];
                if (resourceInfoDic&& resourceInfoDic.allKeys.count > 1) {
                    NSString *userName = resourceInfoDic[@"userId"];
                    NSString *path = resourceInfoDic[@"path"];
                    WXLaunchMiniProgramReq *launchMiniProgramReq = [WXLaunchMiniProgramReq object];
                    launchMiniProgramReq.userName = userName; //拉起的小程序的username
                    launchMiniProgramReq.path = path; //拉起小程序页面的可带参路径，不填默认拉起小程序首页
                    launchMiniProgramReq.miniProgramType = WXMiniProgramTypeRelease; //拉起小程序的类型
                    [WXApi sendReq:launchMiniProgramReq completion:^(BOOL success) {
                    }];
                }
            }
                break;
            case 1004:{//其他
                NSDictionary *dic = [self dictionaryWithJsonString:model.content];
                if (dic) {
                    [self push:dic model:model];
                }
            }
                break;
            case 1005:{//联合登录
                if(![[NSUserDefaults standardUserDefaults] boolForKey:@"firstlog"]){
                    [self unLoginTap];
                    return;
                }
                [self getFederatedLoginRequestWithModel:model];
            }
                break;
            default:
                break;
        }
    }else{
        if (indexPath.item == 0) {
            //政务便民
            [[clickEvent instance] clickEventRooterVC:self Content:@"homeTwo1" menuName:@"政务便民"];
            //[[clickEvent instance] clickEventRooterVC:self Content:@"moreRZCX" menuName:@"认证查询"];
        }else if(indexPath.item == 1){
            //缴社保
            [[clickEvent instance] clickEventRooterVC:self Content:@"miniPaySocial" menuName:@"缴社保"];
            //[[clickEvent instance] clickEventRooterVC:self Content:@"govSBCX" menuName:@"申报查询"];
        }else if(indexPath.item == 2){
            //社保计算机
            [[clickEvent instance] clickEventRooterVC:self Content:@"homeNewAuthRecord" menuName:@"认证查询"];
            //[self jumpToHTML5:@"http://www.wodeshebao.com/calc/index.html" andJAnalytics:@"社保计算器"];
        }else if(indexPath.item == 3){
            //视频
            //[[clickEvent instance] clickEventRooterVC:self Content:@"homeVideoMoney" menuName:@"视频"];
            [[clickEvent instance] clickEventRooterVC:self Content:@"homeThree2" menuName:@"打卡领钱"];
        }else if(indexPath.item == 4){
            //智能客服
            //[self jumpToHTML5:@"https://nginx.weface.com.cn/appH5/appoutlink/#/customer" andJAnalytics:@"智能客服"];
            [self jumpToHTML5:@"http://www.wodeshebao.com/calc/index.html" andJAnalytics:@"社保计算器"];
        }else if(indexPath.item == 5){
            //照相馆
            [[clickEvent instance] clickEventRooterVC:self Content:@"lifeZJZ" menuName:@"照相馆"];
        }else if(indexPath.item == 6){
            //诸葛找房homeNewBank
            [[clickEvent instance] clickEventRooterVC:self Content:@"homeNewBank" menuName:@"银行存款"];
            //[self jumpToHTML5:@"http://m.zhuge.com/city/house/?ad_source=cpc_kankanshebao&spread=sem_cpc_kankanshebao" andJAnalytics:@"诸葛找房"];
        }else if(indexPath.item == 7){
            //菜谱
            [[clickEvent instance] clickEventRooterVC:self Content:@"homeThree5" menuName:@"更多功能"];
//            [self jumpToHTML5:@"https://m.rilishipu.com/indexnew.html?Authorize=97d0eb43e3c43b9b3574606e4fd825d" andJAnalytics:@"菜谱"];
//            [getPeopleID changePlistContentand:@"菜谱"];
//            [[VisitCountManager shareInstance]updateDataWithTitle:@"菜谱" imageName:@"home_Menu" url:@"https://m.rilishipu.com/indexnew.html?Authorize=97d0eb43e3c43b9b3574606e4fd825d"];
        }else if(indexPath.item == 8){
            //万年历
            [self jumpToHTML5:@"http://nginx.weface.com.cn/appH5/calendar/#/"andJAnalytics:@"万年历"];
//            [self jumpToHTML5:@"https://mobile.51wnl.com/web/#/index"andJAnalytics:@"万年历"];
//            [getPeopleID changePlistContentand:@"万年历"];
//            [[VisitCountManager shareInstance]updateDataWithTitle:@"万年历" imageName:@"万年历2" url:@"https://m.wannianli.tianqi.com"];
        }else if(indexPath.item == 9){
            //周边游
            [self jumpToHTML5:@"https://www.ctrip.com/" andJAnalytics:@"周边游"];
        }else if(indexPath.item == 10){
            //话费充值
            [[clickEvent instance] clickEventRooterVC:self Content:@"Morecredit" menuName:@"话费充值"];
        }else if(indexPath.item == 11){
            //快递查询
            [self jumpToHTML5:@"https://m.kuaidi100.com/index_all.html"andJAnalytics:@"快递"];
            [getPeopleID changePlistContentand:@"快递查询"];
            [[VisitCountManager shareInstance]updateDataWithTitle:@"快递查询" imageName:@"快递查询2" url:@"https://m.kuaidi100.com/index_all.html"];
        }else if(indexPath.item == 12){
            //抢红包
            [[clickEvent instance] clickEventRooterVC:self Content:@"homeThree3" menuName:@"抢红包"];
        }else if(indexPath.item == 13){
            //酒店
            [self jumpToHTML5:@"http://m.ctrip.com/webapp/Hotel/?allianceid=452800&sid=949980&sourceid=xx&popup=close&autoawaken=close"  andJAnalytics:@"酒店"];
        }else if(indexPath.item == 14){
            //更多功能
            [[clickEvent instance] clickEventRooterVC:self Content:@"homeThree5" menuName:@"更多功能"];
        }
    }
    
}
//    return;
//    if (indexPath.section == 0) {
//        if (indexPath.item == 0) {
////            if ([[NSUserDefaults standardUserDefaults]boolForKey:@"firstlog"]) {
////                [self kkBindESSCCardListRequest];
////            }else{
////
////                [self unLoginTap];
////            }
////
////            return;
//
//             NSURL * alipay_app_url = [NSURL URLWithString:@"alipay://"];
//            BOOL ali = [[UIApplication sharedApplication] canOpenURL:alipay_app_url];
//            if (ali) {
//
//                NSString *url = @"alipays://platformapi/startapp?appId=20000067&url=https%3A%2F%2Frender.alipay.com%2Fp%2Fs%2Fmedical-card-online%2Fwww%2Findex.html%3FchInfo%3DPDA01B01C01D00%26__webview_options__%3D";
//
//                [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
//
//
////                if ([[NSUserDefaults standardUserDefaults]boolForKey:@"firstlog"]) {
////                    [self skipToAliSSCard];
////                }else{
////
////                    [self unLoginTap];
////                }
//            }else{
//                if (![[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"wechat://"]] ) {
//
//
//                    [self kkJumpALiRedPackageWebVC];
//                              return;
//                          }
//
//
//
//                [self kkWXMiniJump];
//                          return;
//            }
//        }else if (indexPath.item == 1){
//
//            if([[NSUserDefaults standardUserDefaults] boolForKey:@"firstlog"]){
//                [self kkJumpUserIdentifyViewController];
//            }else{
//
//                [self unLoginTap];
//            }
//        }else if (indexPath.item == 2){
//
//            BOOL isLogin = [[NSUserDefaults standardUserDefaults] boolForKey:@"firstlog"];
//                   if (!isLogin) {
//
//                       [self unLoginTap];
//
//                       return;
//                   }
//
//                DistrictAuthenticationPersonalInfoController* vc = [DistrictAuthenticationPersonalInfoController new];
//                vc.title = @"补贴认证";
//                vc.type = @"butie";
//                vc.hidesBottomBarWhenPushed = YES;
//                [self.navigationController pushViewController:vc animated:YES];
//                return;
//
//
//
//        }else if (indexPath.item == 3){
//
//            if (!self.validateTime) {
//
//
//                if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"alipays://"]]) {
//                        [[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"alipays://platformapi/startapp?appId=2021001123625885&page=pages%2findex%2findex%3fprovideId%3d2088331168368991%26chInfo%3dXSbduanfanyong"]];
//                    return;
//                    }
//
//                if (![WXApi isWXAppInstalled]){
//                    [Tools showMessage:@"请安装支付宝APP后重试"];
//                    return;
//                }
//
//                WXLaunchMiniProgramReq *launchMiniProgramReq = [WXLaunchMiniProgramReq object];
//                launchMiniProgramReq.userName = @"gh_45334679e384";  //拉起的小程序的username
//                launchMiniProgramReq.path = @"pages/nhsa-code/index/index?channel=AAEKTLpkFoE88Zic8BqWR87_&cityCode=440300";    //拉起小程序页面的可带参路径，不填默认拉起小程序首页
//                launchMiniProgramReq.miniProgramType = WXMiniProgramTypeRelease; //拉起小程序的类型
//                [WXApi sendReq:launchMiniProgramReq completion:^(BOOL success) {
//
//                }];
//                return;
//            }
//
//            BOOL isLogin = [[NSUserDefaults standardUserDefaults] boolForKey:@"firstlog"];
//                   if (!isLogin) {
//
//                       [self unLoginTap];
//
//                       return;
//                   }
//
//
//                DistrictAuthenticationPersonalInfoController* vc = [DistrictAuthenticationPersonalInfoController new];
//                vc.title = @"优抚核查";
//                vc.hidesBottomBarWhenPushed = YES;
//                [self.navigationController pushViewController:vc animated:YES];
//                return;
//        }
//    }else if (indexPath.section == 1){
//
//        if (indexPath.item == 0) {
//
//                    if (showJYCaiji) {
//
//                        if(![[NSUserDefaults standardUserDefaults] boolForKey:@"firstlog"]){
//                            [self unLoginTap];
//                            return;
//                        }
//                            UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
//                            dataGatherViewController*dataG=[sb instantiateViewControllerWithIdentifier:@"dataGatherViewController"];
//                            dataG.hidesBottomBarWhenPushed =YES;
//                            if(![self.navigationController.topViewController isKindOfClass:[dataG class]]) {
//                                 [self.navigationController pushViewController:dataG animated:YES];
//                            }
//
//
//                    }else{
//            //            WKSuperViewController *tc=[[WKSuperViewController alloc]init];
//            //            tc.titleStr=@"政务信息";
//            //            tc.pathStr=@"http://www.mohrss.gov.cn/wap/xw/";
//            //            tc.hidesBottomBarWhenPushed =YES;
//            //            [self.navigationController pushViewController:tc animated:YES];
//
//
//                        if (self.validateTime) {
//                            if(![[NSUserDefaults standardUserDefaults] boolForKey:@"firstlog"]){
//                                [self unLoginTap];
//                                return;
//                            }
//                            WeiJianQueryViewController* vc = [WeiJianQueryViewController new];
//                            vc.title = @"认证查询";
//                            vc.hidesBottomBarWhenPushed = YES;
//                            [self.navigationController pushViewController:vc animated:YES];
//                            return;
//
//                        }else{
//                            if(![[NSUserDefaults standardUserDefaults] boolForKey:@"firstlog"]){
//                                [self unLoginTap];
//                                return;
//                            }
//                            GovInfoViewController* govVC = [[GovInfoViewController alloc]init];
//                            govVC.title = @"政务便民";
//                            govVC.hidesBottomBarWhenPushed = YES;
//
//                            [self.navigationController pushViewController:govVC animated:YES];
//
//                            return;
//                        }
//
//                    }
//        }else if (indexPath.item == 1){
//
//            if(![[NSUserDefaults standardUserDefaults] boolForKey:@"firstlog"]){
//
//
//                [self unLoginTap];
//                return;
//            }
//
//            if (self.validateTime) {
//                ApplyStateQueryViewController* vc = [ApplyStateQueryViewController new];
//                vc.title = @"登记进度查询";
//                vc.hidesBottomBarWhenPushed = YES;
//                [self.navigationController pushViewController:vc animated:YES];
//                return;
//
//            }else{
//
//                if (self.locationTarget) {
//                    DistrictAuthenticationPersonalInfoController* vc = [DistrictAuthenticationPersonalInfoController new];
//                    vc.title = @"优抚认证";
//                    vc.hidesBottomBarWhenPushed = YES;
//                    [self.navigationController pushViewController:vc animated:YES];
//                    return;
//                }else{
//                    SSPaymenyViewController *vc = [[SSPaymenyViewController alloc]init];
//                    vc.title = @"社保缴费";
//                    vc.hidesBottomBarWhenPushed = YES;
//                    [self.navigationController pushViewController:vc animated:YES];
//                    return;
//                }
//
//
//            }
//
//        }else if (indexPath.item == 2){
//
////            NewsViewController*newsVC = [NewsViewController new];
////            newsVC.title = @"新闻";
////            newsVC.from = @"home";
////            newsVC.hidesBottomBarWhenPushed = YES;
////            [self.navigationController pushViewController:newsVC animated:YES];
////            return;
//
//            if (self.validateTime) {
//
////                KKLisenViewController*vc = [KKLisenViewController new];
////                vc.hidesBottomBarWhenPushed = YES;
////                vc.fromHome = YES;
////                [self.navigationController pushViewController:vc animated:YES];
////
////                return;
//                [self jumpToHTML5:@"https://www.xinshipu.com/" andJAnalytics:@"菜谱"];
//                [getPeopleID changePlistContentand:@"菜谱"];
//                [[VisitCountManager shareInstance]updateDataWithTitle:@"菜谱" imageName:@"home_Menu" url:@"https://www.xinshipu.com/"];
//                return;
//            }else{
//
//                if(![[NSUserDefaults standardUserDefaults] boolForKey:@"firstlog"]){
//
//
//                    [self unLoginTap];
//                    return;
//                }
//                //团油
//                [[clickEvent instance] clickEventRooterVC:self Content:@"homeTwoOil" menuName:@"团油"];
//
//                //[self jumpToHTML5:@"http://172.16.10.194:8080/#/home" andJAnalytics:@"找工作"];
//                return;
//            }
//
//
//            /*
//            if (self.validateTime) {
//                [self jumpToHTML5:@"https://m.ctrip.com/webapp/train/?allianceid=452800&sid=949980&sourceid=2055&popup=close&autoawaken=close&hiderecommapp=1" andJAnalytics:@"火车票"];
//                return;
//            }
//
//            NSString * strA = @"https://www.shuidihuzhu.com/toufang/throwIn?typeFrom=external&channel=sdhzkksb";
//
//
//             // [self jumpToHTML5:strA andJAnalytics:@"水滴互助"];
//             if(![[NSUserDefaults standardUserDefaults] boolForKey:@"firstlog"]){
//                 LoginVC *loginVC = [[LoginVC alloc]init];
//                 UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:loginVC];
//                 [self presentViewController:nav animated:YES completion:nil];
//                 return;
//             }
//
//
//
//
//          NSDictionary * params = @{@"appId":@"201912161758",
//                                       @"phone":[getPeopleID PeopleIphoneNmber]};
//             __weak typeof(self) weakSelf = self;
//             [YDAuthenticationHelper authentication:@"https://kankan.yaodouwang.com/user/login/open" body:params success:^(id  _Nonnull response) {
//                 if ([response isKindOfClass:[NSDictionary class]]) {
//                     NSDictionary * data = response[@"data"];
//                     NSURL * skipUrl = [YDAuthenticationHelper jointUrlWithBody:data andUrl:@"https://k.yaodouwang.com/"];
//                     Web2ViewController * vc = [Web2ViewController new];
//                     vc.title= @"平价药房";
//                     vc.skipUrl = skipUrl;
//                     vc.hidesBottomBarWhenPushed = YES;
//                     [weakSelf.navigationController pushViewController:vc animated:YES];
//                     [GTCountSDK trackCountEvent:@"H5_PingMingYaoFang" withArgs:nil];
//
//                 }else{
//                     NSLog(@"数据格式不正确 ===> %@",response);
//                 }
//             } fail:^(id  _Nonnull error) {
//                 NSLog(@"请求失败，请登录 ===> %@",error);
//                 //[weakSelf alertShow:@"网络异常,请稍后重试"];
//             }];
//            */
//        }else if (indexPath.item == 3){
//            if (self.validateTime) {
//                [self jumpToHTML5:@"https://www.ctrip.com/" andJAnalytics:@"周边游"];
//                return;
//            }
//
//            if([[NSUserDefaults standardUserDefaults] boolForKey:@"firstlog"]){
//                [self jumpToHTML5:@"https://nginx.weface.com.cn/appH5/workApp/#/home" andJAnalytics:@"找工作"];
//            }else{
//
//                  [self unLoginTap];
//            }
//            return;
//        }else if (indexPath.item == 4){
//
//
//            if (self.validateTime) {
//                WebViewController *tc=[WebViewController new];
//
//                 tc.janalytics = @"智能客服";
//
//                 //String url1 = "http://172.16.10.121/award/html-kefu/question/1cj.html";
//                 //String url2 = "http://172.16.10.121/award/html-kefu/question/3cj.html";
//
//                 tc.URL =[NSURL URLWithString: @"http://kefu.weface.com.cn/question/1cj.html"];
//
//
//                 tc.hidesBottomBarWhenPushed = YES;
//                 [self.navigationController pushViewController:tc animated:YES];
//            }else{
//                if(![[NSUserDefaults standardUserDefaults] boolForKey:@"firstlog"]){
//                    [self unLoginTap];
//                    return;
//                }
//                SmartInterrogationViewController* vc = [[SmartInterrogationViewController alloc]init];
//                vc.title = @"看病买药";
//                vc.hidesBottomBarWhenPushed = YES;
//
//                [self.navigationController pushViewController:vc animated:YES];
//
//                return;
//                //折扣
////                [self goToFanLiVC];
//            }
//
//        }
//    }else if (indexPath.section == 2){
//
//
//        if (indexPath.item == 0) {
//
//            if (self.validateTime) {
//                [self jumpToHTML5:@"http://m.zhuge.com/city/house/?ad_source=cpc_kankanshebao&spread=sem_cpc_kankanshebao" andJAnalytics:@"诸葛找房"];
//            }else{
////                ButtonModel *model = self.buttonArray[indexPath.item];
////
////               [self JumpToVCLine3WithTitle:model.buttonTitle button:nil model:model];
//
//                [self goToFruitVC];
//                return;
//
////                if (self.adDataArray.count == 0) {
////                    [self loadBXMADViews];
////                }
//            }
//
//        }else if (indexPath.item == 1) {
//
//
//            if (self.validateTime) {
//                if (![[NSUserDefaults standardUserDefaults] boolForKey:@"firstlog"]) {
//
//                    [[NSNotificationCenter defaultCenter]postNotificationName:KKSBJumpLoginVCNotificationName object:nil];
//
//                                return;
//                  }
//
//                [self goToTVVC:YES];
//                return;
//            }
//
//            [self JumpToVCLine3WithTitle:@"打卡" button:nil model:nil];
//
//        } else if (indexPath.item == 2){
//
//            if (self.validateTime || self.redPackageClickEventsArray.count <= 0) {
//                if (![[NSUserDefaults standardUserDefaults] boolForKey:@"firstlog"]) {
//                    [[NSNotificationCenter defaultCenter]postNotificationName:KKSBJumpLoginVCNotificationName object:nil];
//
//                                return;
//                  }
//
//                [self JumpToVCLine3WithTitle:@"抢红包" button:nil model:nil];
//            }else{
//
//                [self goToClickServeReturnRedPackageVC];//抢红包
//
//
//            }
//
//
//
//        } else if (indexPath.item == 3){
//
//            if (self.validateTime) {
//                [self jumpToHTML5:@"http://m.ctrip.com/webapp/Hotel/?allianceid=452800&sid=949980&sourceid=xx&popup=close&autoawaken=close"  andJAnalytics:@"酒店"];
//            }else{
//
//                    if ([[NSUserDefaults standardUserDefaults]boolForKey:@"firstlog"]) {
//
//                        [GTCountSDK trackCountEvent:@"CQG_PUSH_click" withArgs:nil];
//
//                        [self GetyeepayUrl];
//
//                        return;
//                    }else{
//
//                        [self unLoginTap];
//                    }
//            }
//        }else if (indexPath.item == 4){
//            SearchCollectionViewController* vc = [Storyboard instantiateViewControllerWithIdentifier:@"SearchCollectionViewController"];
//            vc.title = @"更多功能";
//            vc.fromHome = YES;
//            vc.hidesBottomBarWhenPushed = YES;
//            [self.navigationController pushViewController:vc animated:YES];
////               if (self.validateTime) {
////                       WebViewController *tc=[WebViewController new];
////
////                        tc.janalytics = @"智能客服";
////
////                        //String url1 = "http://172.16.10.121/award/html-kefu/question/1cj.html";
////                        //String url2 = "http://172.16.10.121/award/html-kefu/question/3cj.html";
////
////                        tc.URL =[NSURL URLWithString: @"http://kefu.weface.com.cn/question/1cj.html"];
////
////
////                        tc.hidesBottomBarWhenPushed = YES;
////                        [self.navigationController pushViewController:tc animated:YES];
////                }else{
////                        [self jumpToHTML5:@"http://nginx.weface.com.cn/lesson/dadiApp/index.html" andJAnalytics:@"实惠保险"];
////                }
//    }
//
//            /*
//            if (self.buttonArray.count == 1) {
//
//                if (indexPath.item == 0) {
//
//                    if (self.validateTime) {
//                        [self jumpToHTML5:@"http://m.zhuge.com/city/house/?ad_source=cpc_kankanshebao&spread=sem_cpc_kankanshebao" andJAnalytics:@"诸葛找房"];
//                    }else{
//                        ButtonModel *model = self.buttonArray[indexPath.item];
//
//                       [self JumpToVCLine3WithTitle:model.buttonTitle button:nil model:model];
//                    }
//
//                }else if (indexPath.item == 1) {
//
//                    if (![[NSUserDefaults standardUserDefaults] boolForKey:@"firstlog"]) {
//                                    LoginVC *loginVC = [[LoginVC alloc]init];
//                                    UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:loginVC];
//                                    [self presentViewController:nav animated:YES completion:nil];
//
//                                    return;
//                      }
//
//                    [self goToTVVC:YES];
//                } else if (indexPath.item == 2){
//
//                    if (![[NSUserDefaults standardUserDefaults] boolForKey:@"firstlog"]) {
//                                    LoginVC *loginVC = [[LoginVC alloc]init];
//                                    UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:loginVC];
//                                    [self presentViewController:nav animated:YES completion:nil];
//
//                                    return;
//                      }
//
//                    [self JumpToVCLine3WithTitle:@"抢红包" button:nil model:nil];
//                } else if (indexPath.item == 3){
//
//                    if (self.validateTime) {
//                        [self jumpToHTML5:@"http://m.ctrip.com/webapp/Hotel/?allianceid=452800&sid=949980&sourceid=xx&popup=close&autoawaken=close"andJAnalytics:@"酒店"];
//                    }else{
//
//                            if ([[NSUserDefaults standardUserDefaults]boolForKey:@"firstlog"]) {
//
//                                [GTCountSDK trackCountEvent:@"CQG_PUSH_click" withArgs:nil];
//
//                                [self judgeSaveAmountRequest];
//
//                                return;
//                            }else{
//
//                                [self unLoginTap];
//                            }
//                    }
//                }else if (indexPath.item == 4){
//                    SearchCollectionViewController* vc = [Storyboard instantiateViewControllerWithIdentifier:@"SearchCollectionViewController"];
//                    vc.title = @"更多功能";
//                    vc.fromHome = YES;
//                    vc.hidesBottomBarWhenPushed = YES;
//                    [self.navigationController pushViewController:vc animated:YES];
////               if (self.validateTime) {
////                       WebViewController *tc=[WebViewController new];
////
////                        tc.janalytics = @"智能客服";
////
////                        //String url1 = "http://172.16.10.121/award/html-kefu/question/1cj.html";
////                        //String url2 = "http://172.16.10.121/award/html-kefu/question/3cj.html";
////
////                        tc.URL =[NSURL URLWithString: @"http://kefu.weface.com.cn/question/1cj.html"];
////
////
////                        tc.hidesBottomBarWhenPushed = YES;
////                        [self.navigationController pushViewController:tc animated:YES];
////                }else{
////                        [self jumpToHTML5:@"http://nginx.weface.com.cn/lesson/dadiApp/index.html" andJAnalytics:@"实惠保险"];
////                }
//            }
//        }else{
//
//            if (indexPath.item == 0){
//                [self jumpToHTML5:@"http://m.zhuge.com/city/house/?ad_source=cpc_kankanshebao&spread=sem_cpc_kankanshebao" andJAnalytics:@"诸葛找房"];
//            }else if (indexPath.item == 1){
//                [self jumpToHTML5:@"https://m.wannianli.tianqi.com" andJAnalytics:@"万年历"];
//            }else if (indexPath.item == 2){
//                [self jumpToHTML5:@"https://m.kuaidi100.com/index_all.html" andJAnalytics:@"快递"];
//            }else if (indexPath.item == 3){
//
//                if (self.validateTime) {
//                    [self jumpToHTML5:@"http://m.ctrip.com/webapp/Hotel/?allianceid=452800&sid=949980&sourceid=xx&popup=close&autoawaken=close"andJAnalytics:@"酒店"];
//                }else{
//
//                        if ([[NSUserDefaults standardUserDefaults]boolForKey:@"firstlog"]) {
//
//                            [GTCountSDK trackCountEvent:@"CQG_PUSH_click" withArgs:nil];
//                            [self judgeSaveAmountRequest];
//
//                            return;
//                        }else{
//
//                            [self unLoginTap];
//                        }
//                }
//            }else if (indexPath.item == 4){
//                SearchCollectionViewController* vc = [Storyboard instantiateViewControllerWithIdentifier:@"SearchCollectionViewController"];
//                vc.title = @"更多功能";
//                vc.fromHome = YES;
//                vc.hidesBottomBarWhenPushed = YES;
//                [self.navigationController pushViewController:vc animated:YES];
////                if (self.validateTime) {
////                        WebViewController *tc=[WebViewController new];
////
////                        tc.title = @"智能客服";
////
////                        //String url1 = "http://172.16.10.121/award/html-kefu/question/1cj.html";
////                        //String url2 = "http://172.16.10.121/award/html-kefu/question/3cj.html";
////
////                        tc.URL =[NSURL URLWithString: @"http://kefu.weface.com.cn/question/1cj.html"];
////
////
////
////                        [self.navigationController pushViewController:tc animated:YES];
////                }else{
////                        [self jumpToHTML5:@"http://nginx.weface.com.cn/lesson/dadiApp/index.html" andJAnalytics:@"实惠保险"];
////                }
//            }
//        }*/
//    }
//}

#pragma mark - HomeServiceTableViewCellDelegate
- (void)cell:(HomeServiceTableViewCell *)cell didSelectImage:(UIImageView *)imageView {

    switch (imageView.tag) {
        case 200:
        {
            NSString * strA = @"https://www.shuidichou.com/tf/ads/business/register?channel=BD_cooperation_index_kankanshebao";
            [self jumpToHTML5:strA andJAnalytics:@"大病筹款"];
        }
            break;
        case 201:
        {
            //[self jumpToHTML5:@"https://kksb.wy.guahao.com/booking" andJAnalytics:@"医院挂号"];
            [self getHaoDaifuUrlRequest];
        }
            break;
        case 202:
        {
            
            [self jumpToHTML5:@"http://www.wodeshebao.com/calc/index.html" andJAnalytics:@"社保计算器"];
        }
            break;
        case 203:
        {
            //[self jumpToHTML5:@"https://kksb.wy.guahao.com/ask/entry/introduce" andJAnalytics:@"在线问诊"];
            [self jumpToHTML5:@"https://m.haodf.com/nopen/activity?partnerkey=9b6a9ed2bbf5910c" andJAnalytics:@"快速问诊"];
            
        }
            break;
        
        case 204:
        {
            [self jumpToHTML5:@"https://www.ilaw66.com/jasmine/?channel=kkss" andJAnalytics:@"问律师"];
        }
            break;
        case 205:
        {
            KKLisenViewController*vc = [KKLisenViewController new];
            vc.hidesBottomBarWhenPushed = YES;
            vc.fromHome = YES;
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        
        case 206:
        {
            if (![WXApi isWXAppInstalled]){
                [Tools showMessage:@"请安装微信APP后重试"];
                return;
            }
            
            WXLaunchMiniProgramReq *launchMiniProgramReq = [WXLaunchMiniProgramReq object];
            launchMiniProgramReq.userName = @"gh_f8a0e531525d";  //拉起的小程序的username
            launchMiniProgramReq.path = @"pages/base/redirect/index?routeKey=PH04_PRODUCT_TRANSFER_CY&wtagid=118.4.2";    //拉起小程序页面的可带参路径，不填默认拉起小程序首页
            launchMiniProgramReq.miniProgramType = WXMiniProgramTypeRelease; //拉起小程序的类型
            [WXApi sendReq:launchMiniProgramReq completion:^(BOOL success) {
                
            }];
        }
            break;
        default:
            break;
    }
    
}
#pragma mark - HomeService2TableViewCellDelegate
- (void)cell2:(HomeService2TableViewCell *)cell didSelectImage:(UIImageView *)imageView {
    switch (imageView.tag) {
        case 205:
        {
            [self jumpToHTML5:@"http://www.wodeshebao.com/calc/index.html" andJAnalytics:@"社保计算器"];
        }
            break;
        case 206:
        {
            [self jumpToHTML5:@"https://www.ilaw66.com/jasmine/?channel=kkss" andJAnalytics:@"问律师"];
        }
            break;
            
        default:
            break;
    }
}

#pragma mark - HomeHelperHeaderViewDelegate
- (void)HomeHelperHeaderViewBtnClickWithIndex:(NSInteger)index
{
    switch (index) {
        case 200:
        case 201:
        {
            if (self.showWeather && self.weatherDic){
//                [self jumpToHTML5:@"https://mobile.51wnl.com/web/#/index"andJAnalytics:@"万年历"];
                [self jumpToHTML5:@"http://nginx.weface.com.cn/appH5/calendar/#/"andJAnalytics:@"万年历"];
            }else{
                
                if (![[NSUserDefaults standardUserDefaults] boolForKey:@"firstlog"]) {
                    [self unLoginTap];
                    return;
                }
                
                CoinsCenterViewController *vc = [[CoinsCenterViewController alloc]init];
                vc.title = @"金币中心";
                vc.signBlock = ^(BOOL show) {
                    if (show) {
                        [self judgeSignOrNorSignRequest];
                    }
                };
                vc.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:vc animated:YES];
            }
            
        }
            break;

        default:
            break;
    }
    
}
#pragma mark - MiddleBannerViewCellDelegate 中部banner
- (void)selectedItem:(KKRedPackageClickEventModel *)model{
    if(![[NSUserDefaults standardUserDefaults] boolForKey:@"firstlog"]){
        [self unLoginTap];
        return;
    }
    [NetworkRequest statisticsWithEventName:[NSString stringWithFormat:@"%@",model.ID]];
    switch (model.type.integerValue) {
        case 1001:
            //原生跳转
        {
            [[clickEvent instance] clickEventRooterVC:self model:model];
        }
            break;
        case 1002:
            //h5跳转
        {
            WebVC *vc = [[WebVC alloc]init];
            vc.title = model.menuName;
            vc.url = model.content;
            vc.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        case 1003:
            //小程序
        {
            if (![WXApi isWXAppInstalled]){
                [Tools showMessage:@"请安装微信APP后重试"];
                return;
            }
            
            NSDictionary *resourceInfoDic = [self dictionaryWithJsonString:model.content];
            if (resourceInfoDic&& resourceInfoDic.allKeys.count > 1) {
                NSString *userName = resourceInfoDic[@"userId"];
                NSString *path = resourceInfoDic[@"path"];
                WXLaunchMiniProgramReq *launchMiniProgramReq = [WXLaunchMiniProgramReq object];
                launchMiniProgramReq.userName = userName; //拉起的小程序的username
                launchMiniProgramReq.path = path; //拉起小程序页面的可带参路径，不填默认拉起小程序首页
                launchMiniProgramReq.miniProgramType = WXMiniProgramTypeRelease; //拉起小程序的类型
                [WXApi sendReq:launchMiniProgramReq completion:^(BOOL success) {
                    
                }];
            }
           
        }
            break;
        case 1004:
            //本地配置跳转
        {
            NSDictionary *dic = [self dictionaryWithJsonString:model.content];
            if (dic) {
                [self push:dic model:model];
            }
        }
            break;
        case 1005:
        {
            [self getFederatedLoginRequestWithModel:model];
        }
            break;
        default:
            break;
    }
    
}
#pragma mark - BXMNativeAdDelegate
/// 广告加载成功
-(void)nativeRendAdsSuccessToLoad:(NSArray<DHCWNativeAdDataObject *> *)nativeAdDataArray nativeAd:(DHCWNativeRenderAd *)nativeAd
{
    NSLog(@"______自渲染加载成功");
    self.adDataArray = [NSMutableArray arrayWithArray:nativeAdDataArray];
    
    if (self.adDataArray.count > 0) {
        //DHCWNativeAdDataObject *model = self.adDataArray[0];
        NSIndexPath *indexPath1 = [NSIndexPath indexPathForRow:0 inSection:0];
        NSIndexPath *indexPath2 = [NSIndexPath indexPathForRow:0 inSection:2];
        //HomeCollectionCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
        //[cell setupCellWithModel:model delegate:self loca:self rootViewController:self];
        [self.tableView reloadRowsAtIndexPaths:@[indexPath1,indexPath2] withRowAnimation:UITableViewRowAnimationNone];
    }
}

/// 广告加载失败
-(void)nativeRendAdsLoadFailWithError:(NSError *)error nativeAd:(DHCWNativeRenderAd *)nativeAd
{
    NSString *toast = [NSString stringWithFormat:@"广告加载失败，code：%ld，%@", error.code, error.localizedDescription];
    NSLog(@"变现猫error:%@",toast);
}

#pragma mark - BXMNativeAdViewDelegate

/// 广告被点击
 - (void)nativeAdDidClick
{
    NSLog(@"______自渲染点击");
}

/// 广告详情页关闭
- (void)nativeAdDetailViewDidClosed
{
    NSLog(@"______关闭详情页");
}
#pragma mark ---------BXMNativeLocaVideoAdDelegate
/**
    加载视频
 */
-(void)loadNativeVideoWithAdId:(NSString *)adId loadVideoType:(DWLocalVideoType)videoType localVideoAd:(nonnull DHCWNativeLocalVideoAd *)localVideoAd
{
    [[LocalPlayerVideoManager manager]localVideoAd:localVideoAd];
}

/**
        展示视频
 */
-(void)showNativeVideoFromController:(UIViewController *)controller localVideoAd:(DHCWNativeLocalVideoAd *)localVideoAd
{
    
    [[LocalPlayerVideoManager manager] showVideoFromController:controller];
}



#pragma mark - 加载变现猫广告
- (void)loadBXMADViews
{
    self.nativeAd = [[DHCWNativeRenderAd alloc] initWithAdId:@"807696003001" imageSize:DWAdImageSize_Feed690_388];
    self.nativeAd.delegate = self;
    [self.nativeAd loadRendAdWithCount:1];
}

#pragma mark - 未登录跳转

- (void)unLoginTap {
    [[NSNotificationCenter defaultCenter]postNotificationName:KKSBJumpLoginVCNotificationName object:nil];
}

//#pragma mark - 智能问诊
//- (void)goToSmartConsultationVC {
//    WeakSelf
//    if (![[NSUserDefaults standardUserDefaults]boolForKey:@"aida_allow"]) {
//
//        UIView * _Nonnull extractedExpr = [AiDaAlertView showAlertViewWithTitle:nil imageName:nil ViewController:self type:AiDaAlertViewTypeAD block:^(BOOL success) {
//            [[NSUserDefaults standardUserDefaults]setBool:YES forKey:@"aida_allow"];
//            [[NSUserDefaults standardUserDefaults]synchronize];
//            [self aiDaTokenRequest:^(bool success, NSString *token) {
//                if (success) {
//                    [weakSelf aidaUrlRequestWithToken:token];
//                }
//            }];
//        }];
//        self.aiDaView = extractedExpr;
//
//     return;
//
// }
//
// [self aiDaTokenRequest:^(bool success, NSString *token) {
//     if (success) {
//         [weakSelf aidaUrlRequestWithToken:token];
//     }
// }];
//
//}

//#pragma mark - 领钱答疑群
//- (void)goToDaYiQunVC {
//
//    NSString *provinceName = [UserDefault objectForKey:@"locationProvince"];
//
//    NSString *cityName = [UserDefault objectForKey:@"locationCity"];
//
//    NSString *countyName = [UserDefault objectForKey:@"locationCounty"];
//
//
//    WebVC * vc = [WebVC new];
//    vc.title= @"领钱答疑群";
//    //vc.url = @"http://172.16.10.139/projects/html-nginx/html-nginx/appH5/kefu/index.html";
//    vc.url = @"http://nginx.weface.com.cn/appH5/kefu/index.html";
//    vc.provincename = [Tools isBlankString:provinceName] ? @"" : provinceName;
//    vc.cityname = [Tools isBlankString:cityName] ? @"" : cityName;
//    vc.countryname = [Tools isBlankString:countyName] ? @"" : countyName;
//    vc.verytype = 0;
//    vc.hidesBottomBarWhenPushed = YES;
//    [self.navigationController pushViewController:vc animated:YES];
//}


#pragma mark - 社保认证跳转
- (void)kkJumpUserIdentifyViewController {
    KKUserIdentifyViewController*vc = [[KKUserIdentifyViewController alloc]init];
    vc.title = @"社保认证";
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
}
#pragma mark - 支付宝抢红包
- (void)kkJumpALiRedPackageWebVC {
    [SVProgressHUD showInfoWithStatus:@"请下载支付宝"];
   WKSuperViewController *tc=[[WKSuperViewController alloc]init];
  tc.titleStr=@"支付宝抢红包";
  tc.pathStr=@"https://render.alipay.com/p/f/jfxb4alj/pages/receive-redpacket/index.html?__webview_options__=ttb%253Dauto&partnerId=zfb89&sceneCode=KF_DYW02&shareChannel=QRCode&shareUserId=2088131170838949&sharedUserId=";
  tc.hidesBottomBarWhenPushed =YES;
  [self.navigationController pushViewController:tc animated:YES];
}

#pragma mark - 微信小程序跳转
- (void)kkWXMiniJump {
    WXLaunchMiniProgramReq *launchMiniProgramReq = [WXLaunchMiniProgramReq object];
    launchMiniProgramReq.userName = @"gh_c02ba94d95e2";  //拉起的小程序的username
    launchMiniProgramReq.path = @"pages/activity2/index/main?channel=AAEa8uDL_CLi4rjQ2mxeJFys";    //拉起小程序页面的可带参路径，不填默认拉起小程序首页
    launchMiniProgramReq.miniProgramType = WXMiniProgramTypeRelease; //拉起小程序的类型

    [WXApi sendReq:launchMiniProgramReq completion:nil];
}

#pragma mark 跳转到比财
- (void)goToSaveVC
{
    if ([[NSUserDefaults standardUserDefaults]boolForKey:@"firstlog"]) {
        
        [GTCountSDK trackCountEvent:@"CQG_PUSH_click" withArgs:nil];
        [self GetyeepayUrl];

        return;
    }else{
        
        [[NSNotificationCenter defaultCenter]postNotificationName:KKSBJumpLoginVCNotificationName object:nil];
    }
}
#pragma mark - 在线兼职
- (void)goToOnlineJobVC
{
//    WebVC *webvc = [[WebVC alloc]init];
//    webvc.url = [NSString stringWithFormat:@"https://squirrel.kxbwmedia.com/ditch/task?union_id=10222&phoneNum=%@&uuid=%@",[getPeopleID PeopleIphoneNmber],@([getPeopleID PeopleID])];
//    webvc.title = @"在线兼职";
//    webvc.hidesBottomBarWhenPushed = YES;
//    [self.navigationController pushViewController:webvc animated:YES];
    [[clickEvent instance] clickEventRooterVC:self Content:@"homeTwo3" menuName:@""];
}

#pragma mark - 跳转电子社保卡
- (void)skipToAliSSCard
{
    SSTerminationViewController *vc = [[SSTerminationViewController alloc]init];
    vc.title = @"电子社保卡";
    
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
}

//#pragma mark - 摇钱树
//- (void)goToShakeMoneyTreeVC
//{
//    [YXAdSDKManager defaultManager].channelID = @"kksh-ios";
//    [YXAdSDKManager defaultManager].vuid = [NSString stringWithFormat:@"kksh_%@",@([getPeopleID PeopleID])];//渠道号前缀+_+用户ID
//
//    [self getH52TaskWebViewWithPostID:@"kksh-wd-banner"];
//}

#pragma mark - 云晴跳转
- (void)getH52TaskWebViewWithPostID:(NSString *)postID {
    
//    [YXAdSDKManager getMaterialWithPostID:postID Success:^(id  _Nonnull json) {
//        
//        if (json) {
//            dispatch_async(dispatch_get_main_queue(), ^{
//                NSLog(@"接口请求成功 data=%@",json);
//                NSDictionary *dataDict = (NSDictionary *)json;
//                NSDictionary *dict = dataDict[@"data"];
//                if (dict[@"material_path"]) {
//                    //活动入口 标题与logo
//                    //展示到页面时 上报report_url ，具体参考文档
//                }
//                
//                if ([postID isEqualToString:@"kksh-wd-banner"]) {
//                    NSDate *oldDate = [NSDate date];
//                    [[NSUserDefaults standardUserDefaults]setObject:oldDate forKey:@"YQADShowLastTime"];
//                    [[NSUserDefaults standardUserDefaults]synchronize];
//                }
//                
//                SFWebTaskViewController *taskVC = [SFWebTaskViewController new];
//                taskVC.urlStr = dict[@"page_url"];
//                taskVC.posId = postID;
//                taskVC.hidesBottomBarWhenPushed = YES;
//                [self.navigationController pushViewController:taskVC animated:YES];
//            });
//        }
//    } fail:^(NSError * _Nonnull error) {
//        NSLog(@"接口请求失败 error=%@",error);
//    }];
}


#pragma mark - 跳转到H5
-(void)JumpToVCLine3WithTitle:(NSString *)title button:(UIButton *)sender model:(ButtonModel *)model
{
    if (![title isEqualToString:@"抢红包"]) {
         [[VisitCountManager shareInstance]updateDataWithTitle:model.buttonTitle imageName:model.imageName url:model.url];
    }
   
    if ([title isEqualToString:@"抢红包"]) {
        
       // [[VisitCountManager shareInstance]updateDataWithTitle:@"抢红包" imageName:@"抢红包2" url:@""];
        
        if ([getPeopleID LimmitedToBanbana] == YES){
                           
//            [self getRdactiveListRequest];
//            return;
//                      if ([self ALIisLogin]) {
//                          if (ingeerr % 2 == 0) {
//                               [self refreshCoins];
//                          }else if (ingeerr % 2 == 1){
//                              WKSuperViewController *tc=[[WKSuperViewController alloc]init];
//                                  tc.titleStr=@"抢红包";
//                              tc.pathStr=@"https://wallet.95516.com/s/wl/webV3/activity/vInvite/html/snsIndex.html?r=482d1540fbd626e4f873736a594ae107&code=bdyx&channel=3";
//                                  tc.hidesBottomBarWhenPushed =YES;
//                                 [self.navigationController pushViewController:tc animated:YES];
//                          }
//                      }else{
//
//                          if (ingeerr % 2 == 0) {
//                               [self refreshCoins];
//                          }else if (ingeerr % 2 == 1){
//                              WKSuperViewController *tc=[[WKSuperViewController alloc]init];
//                                  tc.titleStr=@"支付宝抢红包";
//                              tc.pathStr=@"https://render.alipay.com/p/f/jfxb4alj/pages/receive-redpacket/index.html?partnerId=&sharedUserId=&shareUserId=2088331168368991&__webview_options__=ttb%253Dauto&shareChannel=QRCode&sceneCode=KF_DYW04";
//                                  tc.hidesBottomBarWhenPushed =YES;
//                                 [self.navigationController pushViewController:tc animated:YES];
//                          }
//                      }
            if (![[NSUserDefaults standardUserDefaults] boolForKey:@"firstlog"]){
                
                [[NSNotificationCenter defaultCenter]postNotificationName:KKSBJumpLoginVCNotificationName object:nil];
                return;
            }
//             [self refreshCoins];
//
//            return;
            
            
            
            BOOL show =  [UserDefault boolForKey:@"grabRedEnvelope"];
            
            if (show) {
                
                [self goToTVVC:NO];
                
            }else{
                
                [self refreshCoins];
                
            }
            
            show = !show;
            
            [UserDefault setBool:show forKey:@"grabRedEnvelope"];
            [UserDefault synchronize];
                      
          }
        

    }else if ([title isEqualToString:@"短视频"]){
//        VideoVC *vc = [[VideoVC alloc]init];
//           vc.hidesBottomBarWhenPushed = YES;
//           [self.navigationController pushViewController:vc animated:YES];
    }else if ([title isEqualToString:@"周边游"]){
        ZHOUBIANYOU
    }else if ([title isEqualToString:@"打卡"]){
        if (![[NSUserDefaults standardUserDefaults] boolForKey:@"firstlog"]){
            
            [[NSNotificationCenter defaultCenter]postNotificationName:KKSBJumpLoginVCNotificationName object:nil];
            return;
        }
        
        CoinsCenterViewController *vc = [[CoinsCenterViewController alloc]init];
        vc.title = @"打卡领钱";
        vc.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:vc animated:YES];
    } else{
        [self jumpToHTML5:model.url andJAnalytics:model.buttonTitle];
    }
}
-(void)jumpToHTML5:(NSString*)url andJAnalytics:(NSString*)janalytics
{
    if ([janalytics isEqualToString:@"0元购"]  || [janalytics isEqualToString:@"找工作"]) {
        WebVC *webvc = [[WebVC alloc]init];
        webvc.url = url;
        webvc.title = janalytics;
        webvc.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:webvc animated:YES];
        return;
    }else if ([janalytics isEqualToString:@"快速问诊"]){
        Web2ViewController*tc = [Web2ViewController new];
        tc.skipUrl =[NSURL URLWithString:url];
        tc.hidesBottomBarWhenPushed =YES;
        tc.title = janalytics;
        [self.navigationController pushViewController:tc animated:YES];
        return;
    }
    
    
    WebViewController *tc=[WebViewController new];
    tc.URL =[NSURL URLWithString:url];
            tc.hidesBottomBarWhenPushed =YES;
    tc.janalytics = janalytics;
    [self.navigationController pushViewController:tc animated:YES];

}

-(void)jump2ToHTML5:(NSString*)url andJAnalytics:(NSString*)janalytics
{
    WebVC *webvc = [[WebVC alloc]init];
    webvc.url = url;
    webvc.title = janalytics;
    webvc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:webvc animated:YES];
}


-(void)jumpToUrl:(NSString*)url andTitle:(NSString*)title
{
    WebVC *webvc = [[WebVC alloc]init];
    webvc.url = url;
    webvc.title = title;
    webvc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:webvc animated:YES];
}

#pragma mark - 抽奖
- (void)refreshCoins
{
    
    if ([[NSUserDefaults standardUserDefaults] boolForKey:@"firstlog"]) {
        if ([getPeopleID PeopleID] && [getPeopleID PeopleIphoneNmber])
        {
            NSDictionary *params = @{
                                     @"userId":[NSNumber numberWithInteger:[getPeopleID PeopleID]],
                                     @"telephone": [EnercryTool encryptUseDES:[getPeopleID PeopleIphoneNmber] key:DESKEY]
                                     };
            NSString *url =[NSString stringWithFormat:@"%@score/getpersonintegrals",CoinsBaseUrl];
            
            WeakSelf;
            [BaseNetManager POST2:url parameters:params completionHandler:^(id responseObj, NSError *error) {
                if (responseObj) {
                    NSString *code = [responseObj[@"code"] stringValue];
                    if ([code isEqualToString:@"0"]) {
                        [getPeopleID getTotalCoins:responseObj[@"result"]];
                        
                        if ([self.navigationController.visibleViewController isKindOfClass:[HomeViewController class]]) {
                            
                            WebVC *webVC = [[WebVC alloc]init];
                             webVC.type = @"home";
                             webVC.title = @"金币抽奖";
                             //外网http://nginx.weface.com.cn/lesson/award/src/award.html
                             //内网@"http://172.16.10.121/projects/html-nginx/html-nginx/lesson/award/src/award.html"
                            //webVC.url = @"http://nginx.weface.com.cn/lesson/award/src/award.html";
                              webVC.url = CoinsRewardedUrl;
                             webVC.hidesBottomBarWhenPushed =YES;
                             [weakSelf.navigationController pushViewController:webVC animated:YES];
                            
                        }
                    }
                }
            }];
        }
    }else {
        
        [[NSNotificationCenter defaultCenter]postNotificationName:KKSBJumpLoginVCNotificationName object:nil];
    }

}

#pragma mark - 激励视频随机红包接口
- (NSDictionary *)getRdactiveListRequestParams
{
    NSDictionary *params = @{
        @"userId":[NSNumber numberWithInteger:[getPeopleID PeopleID]]
    };
    return params;
}

- (void)getRdactiveListRequest
{
    NSString*urlString = [NSString stringWithFormat:@"%@score/getrdactivelist",CoinsBaseUrl];
    NSLog(@"激励视频url:%@",urlString);
    NSLog(@"params:%@",[self getRdactiveListRequestParams]);
    
    [KKLoadingAnimationView show];
    [NetworkRequest Post2:urlString Params:[self getRdactiveListRequestParams] Success:^(id _Nonnull objc) {
        [KKLoadingAnimationView dismiss];
        NSLog(@"objc:%@",objc);
        if ([objc isKindOfClass:[NSDictionary class]]) {
            NSString*code = [NSString stringWithFormat:@"%@",objc[@"code"]];
            if ([code isEqualToString:@"0"]) {
                NSDictionary*dic = objc[@"result"];
                DDActiveModel*model = [DDActiveModel mj_objectWithKeyValues:dic];
                if (![[NSUserDefaults standardUserDefaults] boolForKey:@"firstlog"]) {
                    
                    [[NSNotificationCenter defaultCenter]postNotificationName:KKSBJumpLoginVCNotificationName object:nil];
                           return;
                    }
                               
                           RewardPackageViewController*vc = [RewardPackageViewController new];
                           vc.title = @"抢红包";
                           vc.hidesBottomBarWhenPushed = YES;
                           vc.model = model;
                           [self.navigationController pushViewController:vc animated:YES];
                
            }else{
                [self refreshCoins];
            }
        }else{
//            [SVProgressHUD showErrorWithStatus:@"系统异常"];
        }
    } Failure:^(NSError* error) {
        [KKLoadingAnimationView dismiss];
        NSLog(@"error:%@",error);
        [SVProgressHUD showErrorWithStatus:@"网络异常"];
    }];
}


#pragma mark - 跳转到小视频
- (void)goToTVVC:(BOOL)fromHome {
    
    if (![[NSUserDefaults standardUserDefaults]boolForKey:@"firstlog"]) {
        
        [[NSNotificationCenter defaultCenter]postNotificationName:KKSBJumpLoginVCNotificationName object:nil];

        return;
    }

    KKSVideoViewController *oneVC = [[KKSVideoViewController alloc]initWithType:fromHome];
    oneVC.title = fromHome ?@"看视频" :@"红包视频";
    oneVC.view.backgroundColor = [UIColor whiteColor];
    oneVC.hidesBottomBarWhenPushed = YES;
    
    [self.navigationController pushViewController:oneVC animated:YES];
    
    
//    KKTabBarViewController *tabBarVC = [[KKTabBarViewController alloc]initWithType:fromHome];
    
    
//    LittleVideoViewController *twoVC = [[LittleVideoViewController alloc] init];
//    twoVC.title = fromHome ?@"看视频" :@"红包视频";
//    twoVC.view.backgroundColor = [UIColor whiteColor];
//    twoVC.tabBarItem = [self getCustomItemWithTitle:@"更多" image:@"" selectedImage:@""];
//    UINavigationController *nav1 = [[UINavigationController alloc] initWithRootViewController:twoVC];
//    [tabBarVC addChildViewController:nav1];
    

//    KKVideoViewController *oneVC = [[KKVideoViewController alloc] init];
//    oneVC.title = fromHome ?@"看视频" :@"红包视频";
//    oneVC.view.backgroundColor = [UIColor whiteColor];
//    oneVC.tabBarItem = [self getCustomItemWithTitle:@"小视频" image:@"" selectedImage:@""];
//    UINavigationController *nav2 = [[UINavigationController alloc] initWithRootViewController:oneVC];
//    [tabBarVC addChildViewController:nav2];
//    KKSVideoViewController *oneVC = [[KKSVideoViewController alloc] init];
//    oneVC.title = fromHome ?@"看视频" :@"红包视频";
//    oneVC.view.backgroundColor = [UIColor whiteColor];
//    oneVC.tabBarItem = [self getCustom3ItemWithTitle:@"小视频" image:@"" selectedImage:@""];
//    UINavigationController *nav2 = [[UINavigationController alloc] initWithRootViewController:oneVC];
//    [tabBarVC addChildViewController:nav2];
//
//
//    KKSFeedPageViewController *twoVC = [[KKSFeedPageViewController alloc] init];
//    twoVC.title = fromHome ?@"更多" :@"更多";
//    twoVC.view.backgroundColor = [UIColor whiteColor];
//    twoVC.tabBarItem = [self getCustom3ItemWithTitle:@"更多" image:@"" selectedImage:@""];
//    UINavigationController *nav1 = [[UINavigationController alloc] initWithRootViewController:twoVC];
//    [tabBarVC addChildViewController:nav1];
    
    
    
    //tabBarVC.fromHome = fromHome;
    
    
    //修改主题的颜色
    //tabBarVC.tabBar.tintColor = [UIColor colorWithHex:0x137ef6];
    
    
    
//    [tabBarVC.navigationController setNavigationBarHidden:YES];
//    tabBarVC.hidesBottomBarWhenPushed = YES;
//    [self.navigationController pushViewController:tabBarVC animated:YES];
    
}

#pragma mark - 0元领TabVC
- (void)goToInsurnceVC:(NSArray<KKInsuranceModel *> *)array
{
   
    KKInsuranceModel* leftModel = array[0];
    KKInsuranceContainerController *containerVC = [KKInsuranceContainerController new];
    
    containerVC.title = leftModel.title;

    containerVC.dataArray = array;

    containerVC.hidesBottomBarWhenPushed = YES;

    [self.navigationController pushViewController:containerVC animated:YES];
    

    return;
    
    
     
    
}

#pragma mark - 开启活体检测
- (void)startCheckFace
{
    LivenessViewController* dvc = [[LivenessViewController alloc] init];
   dvc.delegate = self;
   NSArray *array_ =nil;
                           
   array_ =[[NSArray alloc]initWithObjects:@1, nil];
 

   [dvc livenesswithList:array_ order:YES numberOfLiveness:0];
   
   dvc.modalPresentationStyle = UIModalPresentationFullScreen;
   
   [self presentViewController:dvc animated:YES completion:nil];
}


#pragma mark - 提示
- (void)alertShow:(NSString *)msg
{
    if (@available(iOS 9.0,*)) {
        
        UIAlertController * alertV = [UIAlertController alertControllerWithTitle:@"提示" message:msg preferredStyle:UIAlertControllerStyleAlert];
        
        UIAlertAction *confirm = [UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            
        }];
        
        [alertV addAction:confirm];
        
        [self presentViewController:alertV animated:YES completion:nil];
        
    }else{
        UIAlertView *alertV = [[UIAlertView alloc]initWithTitle:@"提示" message:msg delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil];
        [alertV show];
    }
}


#pragma mark - 跳转看看助手新闻
- (void)goToNewsDetaiVCWithModel:(JHNewsModel *)model
{
    JHNewsModel*newsModel = (JHNewsModel *)model;
    
    NewsWebViewController *vc = [[NewsWebViewController alloc]init];
    
    vc.title = @"新闻资讯";
    
    
    NSString* usr_id  = nil;
    
    if ([UserDefault boolForKey:@"firstlog"]) {
        usr_id = [NSString stringWithFormat:@"%@",@([getPeopleID PeopleID])];
    }
    
    if ([Tools isBlankString:usr_id]) {
        vc.url = [newsModel.news_url stringByAppendingFormat:@"&usr_id=%@",[Tools getDeviceUUID]];
    }else{
        vc.url = [newsModel.news_url stringByAppendingFormat:@"&usr_id=%@",usr_id];
    }
    
    vc.model = newsModel;
   
    
    //vc.delegate = self;
    
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
}

#pragma mark - 后台控制的抢红包点击事件
- (void)goToClickServeReturnRedPackageVC
{
    KKRedPackageClickEventModel *model = self.redPackageClickEventsArray[currentCount];
    
    if (model.whetherLogin.boolValue && ![[NSUserDefaults standardUserDefaults]boolForKey:@"firstlog"]) {
        [self unLoginTap];
        return;
    }
    
    switch (model.type.integerValue) {
        case 1001:
            //原生
        {
            if ([model.menuTag isEqualToString:@"coins_reward"]) {
                [self refreshCoins];
            }else if ([model.menuTag isEqualToString:@"watch_vedio"]){
                [self goToTVVC:NO];
            }
            currentCount++;
        }
            break;
        case 1002:
            //h5
        {
            WebVC *vc = [[WebVC alloc]init];
            vc.title = model.menuName;
            vc.url = model.content;
            vc.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:vc animated:YES];
            currentCount++;
        }
            break;
        case 1003:
            //小程序
        {
            if (![WXApi isWXAppInstalled]){
                [Tools showMessage:@"请安装微信APP后重试"];
                return;
            }
            
            WXLaunchMiniProgramReq *launchMiniProgramReq = [WXLaunchMiniProgramReq object];
            launchMiniProgramReq.userName = @"gh_f8a0e531525d";  //拉起的小程序的username
            launchMiniProgramReq.path = @"pages/base/redirect/index?routeKey=PH04_PRODUCT_TRANSFER_CY&wtagid=118.4.2";    //拉起小程序页面的可带参路径，不填默认拉起小程序首页
            launchMiniProgramReq.miniProgramType = WXMiniProgramTypeRelease; //拉起小程序的类型
            [WXApi sendReq:launchMiniProgramReq completion:^(BOOL success) {
                
            }];
            currentCount++;
        }
            break;
        case 1004:
            //其他
        {
            NSDictionary *dic = [self dictionaryWithJsonString:model.content];
            if (dic) {
                [self push:dic model:model];
            }
            currentCount++;
        }
            break;
        case 1005:
            
            [self getFederatedLoginRequestWithModel:model];
            
            break;
            
        default:
            break;
    }

    if (currentCount >= self.redPackageClickEventsArray.count) {
        currentCount = 0;
    }
}
//#pragma mark - 返利网
//- (void)goToFanLiVC
//{
//
//    NSString *url = [NSString stringWithFormat:@"https://web.kanface.com:444/get/fanli/url?uid=%@",@([getPeopleID PeopleID])];
//
//    url = [url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet  URLQueryAllowedCharacterSet]];
//
//    NSDictionary *params = @{
//        @"uid":@([getPeopleID PeopleID]),
//        @"tel":[getPeopleID PeopleIphoneNmber]
//    };
//
//    NSLog(@"联合登录url:%@",url);
//    NSLog(@"params:%@",params);
//    [KKLoadingAnimationView show];
//    [NetworkRequest Get:url Params:params Success:^(id _Nonnull objc) {
//        [KKLoadingAnimationView dismiss];
//        NSLog(@"objc:%@",objc);
//        NSString* state = [NSString stringWithFormat:@"%@",objc[@"state"]];
//        NSString* describe = [NSString stringWithFormat:@"%@",objc[@"describe"]];
//        if ([state isEqualToString:@"200"]) {
//            NSString *url = [NSString stringWithFormat:@"%@",objc[@"result"]];
//
//            url = [url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet  URLQueryAllowedCharacterSet]];
//
//            [self jumpToHTML5:url andJAnalytics:@"限时特惠"];
//
//
//        }else{
//            [self alertShow:describe];
//        }
//
//
//    } Failure:^(NSError* error) {
//        [KKLoadingAnimationView dismiss];
//        NSLog(@"error:%@",error);
//        [self alertShow:@"网络异常"];
//    }];
//}
//#pragma mark - 免费果园
//- (void)goToFruitVC
//{
//    MyFruitViewController *fruitVC = [MyFruitViewController new];
//    fruitVC.title = @"免费果园";
//    fruitVC.placeId = @"6666";
//    fruitVC.buId = @"946405751";
//    fruitVC.gdtAdId = @"2062615177198724";
//    fruitVC.hidesBottomBarWhenPushed = YES;
//    [self.navigationController pushViewController:fruitVC animated:YES];
//}

#pragma mark - 幸运红包
- (void)addRedPackage
{
    [NetworkRequest statisticsWithEventName:@"dialog_home_Envelope"];
    //素材使用代码
   //素材曝光,一般在素材加载完成的时候调用.如果不知道素材加载好的时机,可以在素材所在页面加载完成的时候调用
//  __block NSString*adId = [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString];
   //加载素材
   //__weak typeof(self) weakSelf = self; 9194
   [BXMediaMaterialManager getEntranceMaterialsWithAppkey:@"kksh-IOS-hdgj_xsekjn" placId:@"9194" thirdUserId:@"" success:^(BXMMaterialModel *model) {
       if (model) {
           [BXMediaMaterialManager entranceShowEventTrackingWithPlaceId:@"9194" userId:@"" materialModel:model];
           
           [BXMediaMaterialManager entranceClickEventTrackingWithPlaceId:@"9194" userId:@"" materialModel:nil];
           
           KKActivityViewController *vc = [KKActivityViewController new];
           vc.title = @"幸运红包";
           vc.placeId = @"9194";
//           vc.buId = @"947689995";
//           vc.gdtAdId = @"2062615177198724";
           vc.hidesBottomBarWhenPushed = YES;
           [self.navigationController pushViewController:vc animated:YES];
       }
   } fail:^(NSString *error) {
       
   }];
}


#pragma mark - 发射跳转
- (void)push:(NSDictionary *)params model:(KKRedPackageClickEventModel *)model
{
    // 类名
    NSString *class =[NSString stringWithFormat:@"%@", params[@"class"]];
    const char *className = [class cStringUsingEncoding:NSASCIIStringEncoding];
    
    // 从一个字串返回一个类
    Class newClass = objc_getClass(className);
    if (!newClass)
    {
        // 创建一个类
        Class superClass = [NSObject class];
        newClass = objc_allocateClassPair(superClass, className, 0);
        // 注册你创建的这个类
        objc_registerClassPair(newClass);
    }
    // 创建对象
    UIViewController* instance = [[newClass alloc] init];
    
    // 对该对象赋值属性
    NSDictionary * propertys = params[@"property"];
    [propertys enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
        // 检测这个对象是否存在该属性
        if ([self checkIsExistPropertyWithInstance:instance verifyPropertyName:key]) {
            // 利用kvc赋值
            [instance setValue:obj forKey:key];
        }
    }];
    
    instance.title = model.menuName;
    
    instance.hidesBottomBarWhenPushed = YES;
    // 跳转到对应的控制器
    [self.navigationController pushViewController:instance animated:YES];
}


- (BOOL)checkIsExistPropertyWithInstance:(id)instance verifyPropertyName:(NSString *)verifyPropertyName
{
    unsigned int outCount, i;
    
    // 获取对象里的属性列表
    objc_property_t * properties = class_copyPropertyList([instance
                                                           class], &outCount);
    
    for (i = 0; i < outCount; i++) {
        objc_property_t property =properties[i];
        //  属性名转成字符串
        NSString *propertyName = [[NSString alloc] initWithCString:property_getName(property) encoding:NSUTF8StringEncoding];
        // 判断该属性是否存在
        if ([propertyName isEqualToString:verifyPropertyName]) {
            free(properties);
            return YES;
        }
    }
    free(properties);
    
    return NO;
}

#pragma mark - json 转字典
+ (NSDictionary *)dictionaryWithJsonString:(NSString *)jsonString
{
    if (jsonString == nil) {
        return nil;
    }

    NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
    NSError *err;
    NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData
                                                        options:NSJSONReadingMutableContainers
                                                          error:&err];
    if(err)
    {
        NSLog(@"json解析失败：%@",err);
        return nil;
    }
    return dic;
}

#pragma mark - 判断当前时间是否在7天内
- (BOOL)compareCurrentTime:(NSString *)str
{
    //把字符串转为NSdate
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSDate *timeDate = [dateFormatter dateFromString:str];
    
    //得到与当前时间差
    NSTimeInterval  timeInterval = [timeDate timeIntervalSinceNow];
    timeInterval = -timeInterval;
    timeInterval = timeInterval ;
    long temp = 0;
    NSString *result;
    BOOL isToday;
    if (timeInterval < 60 * 5) {
        result = [NSString stringWithFormat:@"刚刚"];
        isToday = YES;
    }
    else if((temp = timeInterval/60) < 60){
        result = [NSString stringWithFormat:@"%ld分钟前",temp];
        isToday = YES;
    }
    
    else if((temp = temp/60) < 24){
        result = [NSString stringWithFormat:@"%ld小时前",temp];
        isToday = YES;
    }else if((temp = temp/24) < 7){
        result = [NSString stringWithFormat:@"%ld小时前",temp];
        isToday = YES;
    }
    
    else {
        isToday = NO;
    }
    return  isToday;
}


#pragma mark - event response
- (void)backToTopClick:(UIButton *)sender
{
    UIScrollView* feedScrollView = [self.videoCell.feedPage.feedViewController getKSCUFeedPageScrollView];
    
    [feedScrollView setContentOffset:CGPointMake(0, 0)];
    [self.tableView scrollRectToVisible:CGRectMake(0, 0, 1, 1) animated:NO];
 
}
- (void)tapNewsClick:(UITapGestureRecognizer *)tap {
   
    JHNewsModel* model1 = self.newsArray[index*2];
    JHNewsModel* model2 = self.newsArray[index*2 + 1];
    switch (tap.view.tag) {
        case 200:
            [self goToNewsDetaiVCWithModel:model1];
            break;
        case 201:
            [self goToNewsDetaiVCWithModel:model2];
            break;
            
        default:
            break;
    }
}
-(void)onClick:(UITapGestureRecognizer *)sender{
    
    if([[NSUserDefaults standardUserDefaults] boolForKey:@"firstlog"]){
 
    long t = sender.view.tag;
    
    if (t == 1) {
        NSString * strA = @"https://www.shuidichou.com/tf/ads/business/register?channel=BD_cooperation_index_kankanshebao";
       
       
       [self jumpToHTML5:strA andJAnalytics:@"大病筹款"];
        
        
    }else if (t == 2){
        
        
          [self jumpToHTML5:@"https://kksb.wy.guahao.com/booking" andJAnalytics:@"医院挂号"];
        
        
    }else if(t == 3){
//        NSString * strA;
//        long i = [getPeopleID PeopleID];
//        NSString *s= [NSString stringWithFormat:@"%ld",i];
//        NSString *str = @"https://healthapi.axzchou.com/medicine/index?channel=kankan&loginId=";
//        strA = [str stringByAppendingString:s];
        
       // [self jumpToHTML5:@"https://kksb.wy.guahao.com/standard/index" andJAnalytics:@"在线问诊"];
        //[self jumpToHTML5:@"https://kksb.wy.guahao.com/ask/entry/introduce?pageFrom=10020" andJAnalytics:@"在线问诊"];
        [self jumpToHTML5:@"https://kksb.wy.guahao.com/ask/entry/introduce" andJAnalytics:@"在线问诊"];
       // [self jumpToHTML5:@"http://www.wodeshebao.com/calc/index.html" andJAnalytics:@"社保计算器"];
        
    }else if (t == 4){
        NSString * strA;
        long i = [getPeopleID PeopleID];
        NSString *s= [NSString stringWithFormat:@"%ld",i];
        NSString *str = @"http://www.zhonghuijia.cn?cha?channel=kankan&loginId=";
        strA = [str stringByAppendingString:s];
        
        [self jumpToHTML5:strA andJAnalytics:@"海外医疗"];
        
    }else if (t == 5){
        // [self jumpToHTML5:@"https://kksb.wy.guahao.com/ask/entry/introduce" andJAnalytics:@"在线问诊"];
        [self jumpToHTML5:@"http://www.wodeshebao.com/calc/index.html" andJAnalytics:@"社保计算器"];
    }else if (t == 6){
        
        if (self.validateTime) {
            KKLisenViewController*vc = [KKLisenViewController new];
            vc.hidesBottomBarWhenPushed = YES;
            vc.fromHome = YES;
            [self.navigationController pushViewController:vc animated:YES];
            return;
        }else{
            WebViewController *tc=[WebViewController new];
                              
            NSString*url = @"http://www.mohrss.gov.cn/wap/xw/";
            url = [url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
            tc.URL =[NSURL URLWithString:url];
            tc.hidesBottomBarWhenPushed =YES;
            tc.janalytics = @"政务信息";
            [self.navigationController pushViewController:tc animated:YES];
        }
        return;
        
        if (![WXApi isWXAppInstalled]){
            [Tools showMessage:@"请安装微信APP后重试"];
            return;
        }
        
        WXLaunchMiniProgramReq *launchMiniProgramReq = [WXLaunchMiniProgramReq object];
        launchMiniProgramReq.userName = @"gh_f8a0e531525d";  //拉起的小程序的username
        launchMiniProgramReq.path = @"pages/base/redirect/index?routeKey=PH04_PRODUCT_TRANSFER_CY&wtagid=118.4.2";    //拉起小程序页面的可带参路径，不填默认拉起小程序首页
        launchMiniProgramReq.miniProgramType = WXMiniProgramTypeRelease; //拉起小程序的类型
        [WXApi sendReq:launchMiniProgramReq completion:^(BOOL success) {
            
        }];
    }
    }else{
        [[NSNotificationCenter defaultCenter]postNotificationName:KKSBJumpLoginVCNotificationName object:nil];
        
    }
}


//判断两个日期之间相差是否大于2天
- (BOOL)compareWithLastDate:(NSString *)lastDateStr
{
    
    NSDateFormatter* formater = [[NSDateFormatter alloc] init];

    [formater setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    
    NSDate *lastDate =  [formater dateFromString:lastDateStr];
    NSTimeInterval distanceBetweenDates = [[NSDate date] timeIntervalSinceDate:lastDate];
    distanceBetweenDates = fabs(distanceBetweenDates);
    NSInteger hoursBetweenDates = distanceBetweenDates / (60 * 60);
    
    if (hoursBetweenDates >= 6) {
        return YES;
    }else{
        return NO;
    }
}

- (HomeTableView *)tableView{
    if (!_tableView) {
        _tableView = [[HomeTableView alloc]initWithFrame:CGRectMake(0, cl_kNavigationBarHeight + 220*WIDTHRADIU, ScreenWidth, ScreenHeight-cl_kNavigationBarHeight-220*WIDTHRADIU ) style:UITableViewStyleGrouped];
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.dataSource = self;
        _tableView.delegate = self;
        _tableView.scrollEnabled = YES;
        _tableView.estimatedSectionHeaderHeight = 0;
        _tableView.estimatedSectionFooterHeight = 0;
        _tableView.estimatedRowHeight = 0;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        //_tableView.tableHeaderView=self.topBkgView;
        //_tableView.backgroundColor = [UIColor colorWithHex:0x2591f3];
//        _tableView.backgroundColor = [UIColor colorWithHex:0xf4f4f4];
        [_tableView registerNib:[UINib nibWithNibName:@"HomeCollectionCell" bundle:nil] forCellReuseIdentifier:@"cell"];
        [_tableView registerNib:[UINib nibWithNibName:@"HomeMiddleNewsCell" bundle:nil] forCellReuseIdentifier:@"HomeMiddleNewsCell"];
        [_tableView registerClass:[Home3MiddleBannerCell class] forCellReuseIdentifier:@"Home3MiddleBannerCell"];
        [_tableView registerNib:[UINib nibWithNibName:@"HomeNewAuthResultCell" bundle:nil] forCellReuseIdentifier:@"HomeNewAuthResultCell"];
        [_tableView registerClass:[HomeServiceTableViewCell class] forCellReuseIdentifier:@"HomeServiceTableViewCell"];
        [_tableView registerClass:[HomeService2TableViewCell class] forCellReuseIdentifier:@"HomeService2TableViewCell"];
        [_tableView registerClass:[HomeVideoContentCell class] forCellReuseIdentifier:@"HomeVideoContentCell"];
        [_tableView registerClass:[HomeSectionHeaderView class] forHeaderFooterViewReuseIdentifier:@"homeSection"];

    }
    return _tableView;
}

- (UIView *)footerView
{
    if (!_footerView) {
        _footerView = [[UIView alloc]init];
        _footerView.backgroundColor = [UIColor whiteColor];
        _footerView.frame = CGRectMake(0, 0, ScreenWidth, ScreenHeight + 52);
        
        UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 2)];
        lineView.backgroundColor = [UIColor colorWithHex:0xf4f4f4];
        [_footerView addSubview:lineView];

        UILabel *headerLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 2, ScreenWidth - 20, 50)];
        headerLabel.textColor = [UIColor colorWithHex:0x4d4d4d];
        headerLabel.font = [UIFont boldSystemFontOfSize:20];
        headerLabel.text = @"推荐";
        [_footerView addSubview:headerLabel];
        
        HomeVideoContentCell *cell = [[HomeVideoContentCell alloc]init];
        cell.frame = CGRectMake(0, 52, ScreenWidth, ScreenHeight);
        [_footerView addSubview:cell];
        self.videoCell = cell;
        
    }
    return _footerView;
}

#pragma mark - 顶部item
- (void)requestIconsAndTargetEvent{
    NSString*version = nil;
    NSString*v = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
    NSArray*vArr = [v componentsSeparatedByString:@"."];
    for (int i = 0; i < vArr.count; i++) {
        if (version == nil) {
            version = [NSString stringWithFormat:@"%@",vArr[i]];
        }else{
            version = [version stringByAppendingFormat:@"%@",vArr[i]];
        }
    }
    NSString *url1 = [NSString stringWithFormat:@"%@dynamic/menu/get",[NetworkConfig ipYinShuConfig]];
//    NSString *url1 = [NSString stringWithFormat:@"%@dynamic/menu/get",@"http://172.16.10.18:8017/"];
    NSString *giUid = [UserDefault valueForKey:@"giUid"];
    if (giUid.length == 0) {
        giUid = @"";
    }
    NSDictionary *params1 = @{
        @"configName":@"NewHomeMenuVB",
        @"appName":@"kksh",
        @"version":version,
        @"systemType":@"iOS",
        @"gid":giUid,
        @"uid":[NSString stringWithFormat:@"%ld",(long)[getPeopleID PeopleID]]
    };
    typeof(self) wSelf = self;
    [NetworkRequest Post15:url1 Params:params1 Success:^(id _Nonnull objc) {
        NSLog(@"首页按钮===objc:%@",objc);
        if ([objc isKindOfClass:[NSDictionary class]]) {
            NSString *state = [NSString stringWithFormat:@"%@",objc[@"state"]];
            if ([state isEqualToString:@"200"]) {
                if ([objc[@"result"] isKindOfClass:[NSArray class]]) {
                    wSelf.DataArr = [NSMutableArray array];
                    for (NSDictionary *dic in objc[@"result"]) {
                        KKRedPackageClickEventModel *model = [KKRedPackageClickEventModel mj_objectWithKeyValues:dic];

                        [wSelf.DataArr addObject:model];
                    }
                }
                [wSelf.tableView reloadData];
            }
        }

    } Failure:^(NSError *error) {
        NSLog(@"error:%@",error);
    }];
}
@end

