//
//  ViewController.m
//  Open
//
//  Created by 黄江涛  on 16/9/7.
//  Copyright © 2016年 黄江涛 . All rights reserved.
//




#import "ViewController.h"
#import "PhotoViewController.h"
#import "SDCycleScrollView.h"
#import "MJExtension.h"
#import "ShowPicker.h"
#import <MobileCoreServices/MobileCoreServices.h>
#import <AVFoundation/AVFoundation.h>
#import <MediaPlayer/MediaPlayer.h>
#import "MyPickerViewController.h"

#import <AddressBookUI/AddressBookUI.h>
#import <Contacts/Contacts.h>
#import "CLMarkButton.h"
#import "WebViewController.h"
#import "homePageNewsModel.h"
#import "weatherNetModel.h"
#import "LoginViewController.h"
#import "LoginVC.h"
#import "AppDelegate.h"
#import "NewSCell.h"
#import "newsViewModel.h"
#import "UIImageView+WebCache.h"
#import "uitableViewController.h"
#import "myJDCell.h"
#import "socialAssistant.h"
#import "fontFZ.h"
#import "NewEditionTestManager.h"
#import "TYImageCache.h"


#import <SDWebImage/UIImage+GIF.h>

#import "MyTableViewCell_d.h"

//区头
#import "HomeSectionHeaderView.h"


//雷俊博
#import "LittleProcedureTableViewCell.h"
#import "Home3MiddleBannerCell.h"

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


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




#import "CTAPIBaseManager.h"

#import "DeathProveViewController.h"
#import "SSTerminationViewController.h"
#import "SSPaymenyViewController.h"
#import "SSTerminationViewController.h"
#import "tabViewController.h"

#import "SSCardWebViewController.h"


//测试
//#import "OnFootEarnCoinsViewController.h"
#import "SocialSecurityApproveSuccessVC.h"
#import "MyPrizeListVC.h"
#import "CollectionAddressSelectedViewController.h"
#import "MyAdViewController.h"
#import "successViewController.h"
#import "AddressAlertView.h"
#import "CitiesDataTool.h"
#import "PayAttentionToWXAlertView.h"
#import "SelectLocationView.h"
#import "PrizeInfoCommitSuccessAlertView.h"
#import "SmartInterrogationViewController.h"
#import "AiDaAlertView.h"
#import "RedPackageView.h"
#import "InsuredInfoViewController.h"
#import "GreenChannelAlertView.h"
#import "quickInsuredInfoViewController.h"
#import "EmergencyContactPeople.h"
#import "SocialSecurityVerificationFailureViewController.h"
#import "TestViewController.h"
#import "JoinPartnerViewController.h"
#import "RewardTimeAlertView.h"
#import "GovInfoViewController.h"
#import "chooseAddressViewController.h"


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


//广告
#import "BannerAdObjectModel.h"


#import "ButtonModel.h"

//药兜网
#import "YDAuthenticationHelper.h"

//隐私协议
#import "PrivateAlertService.h"

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

#import "PasswordLoginViewController.h"


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


#import "RewardPackageViewController.h"

//穿山甲
#import <BUAdSDK/BUAdSDK.h>

//腾讯广点通
#import <GDTRewardVideoAd.h>

#import "DDActiveModel.h"


//新闻
#import "NewsViewController.h"

//喜马拉雅
#import "KKLisenViewController.h"


#import "StatisticsViewController.h"
#import "SaveTabBarController.h"
#import "SaveProductListController.h"
#import "MyAssetsController.h"
#import "ProductDetailController.h"
#import "KKActivityRedPackageBaseView.h"

#import "GovNewVc.h"

#define  NUMBERFORHEIGHT 84.1
#define  NUMBERFORHEIGHT_2 168

#define statusRect  [[UIApplication sharedApplication] statusBarFrame]
@import AVKit;

@interface ViewController ()<SDCycleScrollViewDelegate,MKMapViewDelegate,CLLocationManagerDelegate,UITableViewDelegate,UITableViewDataSource,MiddleBannerViewCellDelegate,BMKLocationManagerDelegate,passImagesDelegate,BUNativeExpressRewardedVideoAdDelegate,GDTRewardedVideoAdDelegate>{
    BOOL hiddenStatusBar;
    //检测是否已进入主页
    BOOL isHomeVC;
    
    //检测定位是否是河北,黑龙江,就业采集
    BOOL showJYCaiji;
}

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *KKtableHeight;

@property(nonatomic,strong)	 CLLocationManager *manager;
@property (weak, nonatomic) IBOutlet UILabel *loactionText;
@property (weak, nonatomic) IBOutlet UIView *viewLine;
@property(nonatomic,strong)UIViewController *vm;

@property (weak, nonatomic) IBOutlet UIButton *socialSecurity;
@property (weak, nonatomic) IBOutlet UIButton *waterPay;//2
@property (weak, nonatomic) IBOutlet UIButton *nongzi;//3
@property (weak, nonatomic) IBOutlet UIButton *shenghuojifei;//4
@property (weak, nonatomic) IBOutlet UIButton *searchExpressage;//5
@property (weak, nonatomic) IBOutlet UIButton *mianfeifabu;//6
@property (weak, nonatomic) IBOutlet UIButton *searchTrafficViolation;//7
@property (weak, nonatomic) IBOutlet UIButton *medcine;
@property (weak, nonatomic) IBOutlet UIButton *zhiwuxinxi;

@property (weak, nonatomic) IBOutlet UIButton *pai_er_one;

@property (weak, nonatomic) IBOutlet UIButton *pai_er_two;

@property (weak, nonatomic) IBOutlet UIButton *pai_er_three;

@property (weak, nonatomic) IBOutlet UIButton *pai_er_four;

@property (weak, nonatomic) IBOutlet UIView *pushHidel;

@property(nonatomic,strong)NSMutableArray *arrayP;
@property(nonatomic,strong)NSMutableArray *arrayT;

@property(nonatomic,strong)NSMutableArray *baocun;
@property(nonatomic,strong)PostMessageViewModel*postVM;
@property(nonatomic,strong)NSMutableArray *array_k1;
@property(nonatomic,strong)NSMutableArray *array_k2;
@property(nonatomic,strong)NSMutableArray *array_k3;
@property(nonatomic,strong)NSMutableArray *array_k4;
@property(nonatomic,strong)NSMutableArray *array_k5;
@property(nonatomic,strong)NSArray *arr111;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *socialWidth;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *bbb;

@property(nonatomic,strong)NSString *longtitudeAndLatitude;
@property(nonatomic,strong)NSString *GPS;


@property (weak, nonatomic) IBOutlet UILabel *weather_label;
@property (weak, nonatomic) IBOutlet UIScrollView *scrollViewNews;

@property (weak, nonatomic) IBOutlet UIImageView *weather_image;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *heighForIphone6Plus;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *heightForIphone6plus_2;


//雷俊博
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *BannerScrollViewtopConstraints;
@property(nonatomic,strong)UIViewController *vc;

//雷俊博



@property (weak, nonatomic) IBOutlet UITableView *tableViewNews;
@property(nonatomic,strong)	 newsViewModel *viewModel;

@property(nonatomic,strong)NSArray *newsArray;


@property (weak, nonatomic) IBOutlet NSLayoutConstraint *controllerForTopheight;

@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) UIImageView *loadingImageView;

@property (weak, nonatomic) IBOutlet UIImageView *moneyCount;
@property (weak, nonatomic) IBOutlet UIImageView *moneyCount1;
@property (weak, nonatomic) IBOutlet UIImageView *moneyCount2;
@property (weak, nonatomic) IBOutlet UIImageView *moneyCount4;

//穿山甲
@property (nonatomic, strong)BUNativeExpressRewardedVideoAd* rewardedAd;

//腾讯
@property (nonatomic, strong) GDTRewardVideoAd *rewardVideoAd;


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


@property (nonatomic, strong)NSMutableArray *newsDataArray;

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


@property (nonatomic, assign)BOOL validateTime;

@property (nonatomic, strong)AiDaAlertView* aiDaView;





@end

@implementation ViewController
{
    int ingeerr;
    
}

#pragma mark - cycle
- (void)viewDidLoad {
    
    [super viewDidLoad];
    
    [self judgeLoginTimeInvalid];
    
    
    
    self.validateTime = YES;
      
    //广告
//    self.vc  = [[UIStoryboard storyboardWithName:@"LaunchScreen" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"sbID"];
//    [self.view addSubview: self.vc.view];
//    [self createSplash];
    
    //[self locationDisplay];
    [self locationDisplay2];
    [self getOCR];

    //[NewEditionTestManager checkNewEditionWithAppID:@"1227583739" ctrl:self];
    //1种用法，系统Alert
    
      [[VersionUpdateTool sharedInstance]VersionUpdate];
    self.scrollViewNews.bounces =NO;
    self.scrollViewNews.showsVerticalScrollIndicator = NO;
    self.tableViewNews.bounces = NO;
    self.tableViewNews.sectionFooterHeight = 6;
    self.tableViewNews.contentInset = UIEdgeInsetsMake(0, 0,5, 0);
//    UIImage *image = [UIImage imageNamed:@"大病求助"];
//    CGFloat scale = image.size.height / image.size.width;
    self.KKtableHeight.constant = 663+114-208-20-75-75-10+6 ;
    
   

    
   
    
    //观察跳转广告页
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pushToAd:) name:@"ZLPushToAdvert" object:nil];
    
    //观察认证成功后刷新
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshKankanAssistant) name:@"ZLAuthenticationAssistant" object:nil];
    
    
    
    
    [self.tableViewNews registerClass:[HomeSectionHeaderView class] forHeaderFooterViewReuseIdentifier:@"homeSection"];
    [self.tableViewNews registerClass:[Home3MiddleBannerCell class] forCellReuseIdentifier:@"Home3MiddleBannerCell"];
    
    
    
    
    //获取未读消息数
    [self getUnreadState];
    
    [self loadMiddleBannerApiRequest];
    
    
    self.newsDataArray = [[NSMutableArray alloc]init];
    
    
    NSArray *imageNameArray =  @[@"诸葛找房-home",@"万年历2",@"快递查询2",@"home_Train",@"home_busTicket",@"home_airPlane",@"home_Hotel",@"home_Menu",@"home_radiostation",@"home_Travel",@"home_sport"];
    NSArray *buttonTitleArray = @[@"诸葛找房",@"万年历",@"快递查询",@"火车票",@"汽车票",@"飞机票",@"酒店",@"菜谱",@"FM电台",@"周边游",@"运动"];
    NSArray *urlArray = @[@"http://m.zhuge.com/city/house/?ad_source=cpc_kankanshebao&spread=sem_cpc_kankanshebao",
                          @"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://m.rilishipu.com/indexnew.html?Authorize=97d0eb43e3c43b9b3574606e4fd825d",
                          @"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]];
            }
        }
        
        self.buttonArray = [NSMutableArray array];
        
        [self queryButton];
        
        [[VisitCountManager shareInstance]deleteOldTable];
        
        
        NSLog(@"%lu",(unsigned long)self.buttonArray.count);
        
//        [self.buttonArray sortUsingComparator:^NSComparisonResult(ButtonModel*  _Nonnull obj1, ButtonModel*  _Nonnull obj2) {
//            if (obj2.count > obj1.count) {
//                return NSOrderedDescending;
//            }else if (obj2.count == obj1.count){
//                return NSOrderedSame;
//            }else{
//               return  NSOrderedAscending;
//            }
//        }];
        
    }
    
    //[[VisitCountManager shareInstance]deleteOldTable];
    
    
   //NSString* mobile = [EnercryTool AES128Encrypt:@"15618673678" key:@"ADA-kankan-AES-KEY-12345"];
    
   
   
//    RedPackageView *packageView = [[RedPackageView alloc]initWithFrame:CGRectMake((ScreenWidth - 245)/2.0, (ScreenHeight - 290)/2.0, 245, 290)];
    
//    UIWindow* keyWindow = self.view.window;
//
//    if (keyWindow == nil) {
//        keyWindow = [UIApplication sharedApplication].keyWindow;
//    }
//
//    [keyWindow addSubview:alertView];
//
   
    NSLog(@"进入首页");
    [self configNav];
}

- (void)configNav
{
    UIBarButtonItem * backButtonItem = [[UIBarButtonItem alloc] init];
    backButtonItem.title = @"返回";
    self.navigationItem.backBarButtonItem = backButtonItem;
}



- (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 4 ;"];
           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 < 2) {
                       [self.buttonArray addObject:model];
                   
               }
               
               
           }
       }
       
       [db close];
}

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

}

-(void)viewWillDisappear:(BOOL)animated
{
    
    [super viewWillDisappear:YES];
     self.pushHidel.hidden = YES;
    
    //雷俊博
    //取消隐藏导航栏
    if (!(self.presentedViewController || self.presentingViewController )) {
          [self.navigationController setNavigationBarHidden:NO animated:animated];
      }
    
   
    UIWindow *curWindow = [[UIApplication sharedApplication].delegate window];
    if (self.aiDaView) {
         [curWindow  sendSubviewToBack:self.aiDaView];
        [curWindow  sendSubviewToBack:self.aiDaView.maskView];
    }
    
    
  
}

-(void)viewWillAppear:(BOOL)animated{
    
    [super viewWillAppear:animated];
    //雷俊博
    //隐藏导航栏
    
   

    [self.navigationController setNavigationBarHidden:YES animated:animated]
    ;
    UIWindow *curWindow = [[UIApplication sharedApplication].delegate window];
    
    
    if (self.aiDaView) {
        [curWindow  bringSubviewToFront:self.aiDaView.maskView];
         [curWindow bringSubviewToFront:self.aiDaView];
    }
    
  
    
    
    
    //导航栏颜色
    self.navigationController.navigationBar.barTintColor = K_MainColor;
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor],
                                                                      NSFontAttributeName : [UIFont fontWithName:@"Helvetica-Bold" size:17]}];
    
    [self.transitionCoordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext>  _Nonnull context) {
        self.navigationController.navigationBar.barTintColor = K_MainColor;
    } completion:^(id<UIViewControllerTransitionCoordinatorContext>  _Nonnull context) {
    }];
    
    
   
   
    self.pushHidel.hidden = NO;
 __block   AppDelegate * app = (AppDelegate*)[[UIApplication sharedApplication]delegate];
    self.navigationController.navigationBar.translucent = YES;
    [[AFNetworkActivityIndicatorManager sharedManager] setEnabled:YES];
    [[AFNetworkReachabilityManager sharedManager] setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
        switch (status) {
            case AFNetworkReachabilityStatusReachableViaWWAN:
            case AFNetworkReachabilityStatusReachableViaWiFi:
                app.onLine = YES;
                break;
            case AFNetworkReachabilityStatusNotReachable:
                
            default:
                  [self NETWORKing];//添加本地图片
                app.onLine = NO;
                [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"networkCantUse"];
                if (app.onLine == NO ) {
                         [SVProgressHUD doneShow];
                    [SVProgressHUD showErrorWithStatus:@"网络状态不佳"];
                    return;
                }        
                break;
        }
    }];
    [[AFNetworkReachabilityManager sharedManager] startMonitoring];

    if ([[NSUserDefaults standardUserDefaults] boolForKey:@"networkCantUse"] == NO) {
        self.weather_label.text =@"天气:晴";
     [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"networkCantUse"];
    }

    
    
    if ([[UIScreen mainScreen]bounds].size.height  == 736 ) {

        self.heighForIphone6Plus.constant = NUMBERFORHEIGHT;
        self.heightForIphone6plus_2.constant = NUMBERFORHEIGHT_2;
    }else if ([[UIScreen mainScreen]bounds].size.height  == 568){
        self.heighForIphone6Plus.constant = NUMBERFORHEIGHT;
        self.heightForIphone6plus_2.constant = NUMBERFORHEIGHT_2;
        self.controllerForTopheight.constant =160.426;
    }else{
    self.heighForIphone6Plus.constant = NUMBERFORHEIGHT;
        self.heightForIphone6plus_2.constant = NUMBERFORHEIGHT_2;
    }
    
    
//    NSString *path=[[NSBundle mainBundle] pathForResource:@"socialNews" ofType:@"plist"];
//
//
//    self.newsArray = [[NSArray alloc]init];
//    self.newsArray = [NSArray arrayWithContentsOfFile:path];
//
//


    
    
 self.navigationController.toolbarHidden=YES;
    
   
    getPeopleID *pi = [[getPeopleID alloc]init];
  

     self.arr111 =[[pi readPlist] copy];

    if(_arr111.count ==0){
        [self.mianfeifabu setBackgroundImage:[UIImage imageNamed:@"菜谱2"] forState:UIControlStateNormal];
        [self.searchTrafficViolation setBackgroundImage:[UIImage imageNamed:@"电台2"] forState:UIControlStateNormal];
        [self.medcine setBackgroundImage:[UIImage imageNamed:@"万年历2"] forState:UIControlStateNormal];
        [self.zhiwuxinxi setBackgroundImage:[UIImage imageNamed:@"免费发布2"] forState:UIControlStateNormal];
      
    }else{
        
        //如果能查到
        if (self.buttonArray.count == 2) {
          
            [self sortMyButton];
            
        }else{
            
            
            
            [self.mianfeifabu setImage:[UIImage imageNamed:@"万年历2"]  forState:normal];
            [self.mianfeifabu setTitle:@"万年历" forState:normal];
            [self.searchTrafficViolation setImage:[UIImage imageNamed:[self.arr111[2] stringByAppendingString:@"2"]]  forState:normal];

            if([getPeopleID LimmitedToBanbana] == YES){
                [self.searchTrafficViolation setImage:[UIImage imageNamed:@"诸葛找房-home"]  forState:normal];
            [self.searchTrafficViolation setTitle:@"诸葛找房" forState:normal];

            }else{
              [self.searchTrafficViolation setTitle:self.arr111[2] forState:normal];
            }
            
            if([getPeopleID LimmitedToBanbana] == YES){
                [self.medcine setImage:[UIImage imageNamed:@"抢红包2"] forState:normal];
                self.moneyCount.image = [JobUtil changeImageToGit:@"haveMoney.gif"];
              [self.medcine setTitle:@"抢红包" forState:normal];
            }else{
                 [self.searchTrafficViolation setImage:[UIImage imageNamed:[self.arr111[1] stringByAppendingString:@"2"]]  forState:normal];

                  [self.medcine setTitle:self.arr111[1] forState:normal];

            }
            
            [self.zhiwuxinxi  setImage:[UIImage imageNamed:[self.arr111[0] stringByAppendingString:@"2"]]  forState:normal];
            [self.zhiwuxinxi  setTitle:self.arr111[0] forState:normal];
            
        }
        

      
        
        
        
        
        
        
        
      
    }
    if ([getPeopleID LimmitedToBanbana] == YES) {

        [self.pai_er_three setImage:[UIImage imageNamed:@"home_blueNews"] forState:UIControlStateNormal];
        [self.pai_er_three  setTitle:@"新闻" forState:normal];
        [self initButton:self.pai_er_three];
        
    }else{
        [self.pai_er_three setImage:[UIImage imageNamed:@"智慧出行20"] forState:UIControlStateNormal];
        [self.pai_er_three  setTitle:@"智慧出行" forState:normal];
    }
    
    BOOL showJiuYe = [[NSUserDefaults standardUserDefaults]boolForKey:@"jiuyecaiji"];
    if (showJiuYe) {
        [self showSBDataCollect];
    }
    
    
   
    
    
    [self.socialSecurity setTitle:@"电子社保卡" forState:UIControlStateNormal];
    NSURL * alipay_app_url = [NSURL URLWithString:@"alipay://"];
    
    BOOL ali = [[UIApplication sharedApplication] canOpenURL:alipay_app_url];
    if (ali) {
        [self.socialSecurity setImage:[UIImage imageNamed:@"home_Electronicsocialsecuritycard_normal"] forState:UIControlStateNormal];
    }
    [self initButton:self.socialSecurity];
    [self initButton:self.waterPay];
    [self initButton:self.nongzi];
    [self initButton:self.shenghuojifei];
    [self initButton:self.searchExpressage];
    [self initButton:self.mianfeifabu];//万年历
    [self initButton:self.searchTrafficViolation];//诸葛找房
    [self initButton:self.medcine];//抢红包
    [self initButton:self.zhiwuxinxi];//快递查询
    [self initButton:self.pai_er_one];
    [self initButton:self.pai_er_two];
    [self initButton:self.pai_er_three];
    [self initButton:self.pai_er_four];
//    [self.tableViewNews reloadData];
    
  

self.BannerScrollViewtopConstraints.constant = - kStatusBarHeight;
    
    
    
    
    [self changeABC];
    
    

    
    
    

     
    [self.navigationController.navigationBar navBarBackGroundColor:K_MainColor image:nil isOpaque:YES];//颜色
    
    [self.navigationController.navigationBar navBarBottomLineHidden:YES];
    
    
   
//    NSString* tel =  [EnercryTool decryptUseDES:@"8mWNg2DlB73pvG7RkGRkGqxcw==" key:AESKEY];
    
    
    

}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    
   
    

}


//对按钮重新排序
- (void)sortMyButton
{
    
    //button1
    
    for (int i = 0; i < 2; i++) {
        
        ButtonModel *model = self.buttonArray[i];
        if (i == 0) {
            //按钮1
            [self.mianfeifabu setImage:[UIImage imageNamed:model.imageName]  forState:normal];
            [self.mianfeifabu setTitle:model.buttonTitle forState:normal];
            [self initButton:self.mianfeifabu];
            
            
        }else if (i == 1){
            //按钮2
            
              
            [self.searchTrafficViolation setImage:[UIImage imageNamed:model.imageName]  forState:normal];
            [self.searchTrafficViolation setTitle:model.buttonTitle forState:normal];
            [self initButton:self.searchTrafficViolation];
            
        }//else if (i == 2){
//            //按钮3
//            [self.medcine setImage:[UIImage imageNamed:model.imageName] forState:normal];
//              self.moneyCount.image = [JobUtil changeImageToGit:@"haveMoney.gif"];
//            [self.medcine setTitle:model.buttonTitle forState:normal];
//
//        }else if (i == 3){
//            //按钮4
//            [self.zhiwuxinxi  setImage:[UIImage imageNamed:model.imageName]  forState:normal];
//            [self.zhiwuxinxi  setTitle:model.buttonTitle forState:normal];
//        }
        
        
        if ([model.buttonTitle isEqualToString:@"抢红包"]) {
            
            if (i == 0) {
                self.moneyCount1.hidden = YES;
                self.moneyCount1.image = [JobUtil changeImageToGit:@"haveMoney.gif"];
            }else if (i == 1){
                self.moneyCount2.hidden = YES;
                self.moneyCount2.image = [JobUtil changeImageToGit:@"haveMoney.gif"];
            }else if (i == 2){
                self.moneyCount.hidden = NO;
                self.moneyCount.image = [JobUtil changeImageToGit:@"haveMoney.gif"];
            }else{
                self.moneyCount4.hidden = NO;
                self.moneyCount4.image = [JobUtil changeImageToGit:@"haveMoney.gif"];
            }
        }else{
            if (i == 0) {
                self.moneyCount1.hidden = YES;
              
            }else if (i == 1){
                self.moneyCount2.hidden = YES;
            }else if (i == 2){
                self.moneyCount.hidden = YES;
            }else{
                self.moneyCount4.hidden = YES;
            }
        }
    }
     
               
                [self.medcine setImage:[UIImage imageNamed:@"抢红包2"] forState:normal];
                self.moneyCount.image = [JobUtil changeImageToGit:@"haveMoney.gif"];
                self.moneyCount.hidden = NO;
                [self.medcine setTitle:@"抢红包" forState:normal];
                [self initButton:self.medcine];
                
    
                if (self.validateTime) {
                    
                    [self.zhiwuxinxi  setImage:[UIImage imageNamed:@"快递查询2"]  forState:normal];
                    [self.zhiwuxinxi  setTitle:@"快递查询" forState:normal];
                    [self initButton:self.zhiwuxinxi];
                }else{
                    
                    [self.zhiwuxinxi  setImage:[UIImage imageNamed:@"home_insurance"]  forState:normal];
                    [self.zhiwuxinxi  setTitle:@"实惠保险" forState:normal];
                    [self initButton:self.zhiwuxinxi];
                    

                }
    
               
                
    
           
    
    
   
}




-(void)changeABC{
    AppDelegate *delegate=(AppDelegate*)[[UIApplication sharedApplication]delegate];
    if ([delegate.changeProgress isEqualToString:@"开始"]) {
        delegate.changeProgress =@"结束";
        [self searchProgress];
    }
    
}

- (void)dealloc
{
    NSLog(@"首页被销毁了");
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"ZLPushToAdvert" object:nil];
    
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"ZLAuthenticationAssistant" object:nil];
}

-(void)searchProgress{
    
    
    [SearchProgressNet getgetBindIdCardsListHandle:^(SearchProgress *model, NSError *error) {
        
        self.shenghuojifei.userInteractionEnabled = YES;
        if (model.code ==0) {
            
            if (model.result.count == 0) {
                UIStoryboard *sbs =[UIStoryboard storyboardWithName:@"Main" bundle:nil];
                startProgressViewcontroller *tc=[sbs instantiateViewControllerWithIdentifier:@"startProgressViewcontroller"];
                tc.hidesBottomBarWhenPushed =YES;
                [self.navigationController pushViewController:tc animated:YES];
            }else{
                UIStoryboard *sbs =[UIStoryboard storyboardWithName:@"Main" bundle:nil];
                SearchProgressViewController *tc=[sbs instantiateViewControllerWithIdentifier:@"SearchProgressViewController"];
                tc.hidesBottomBarWhenPushed =YES;
                [self.navigationController pushViewController:tc animated:YES];
                
            }
        }else
        {
            codeSelected *code = [codeSelected MustTakeReturn:model.code];
            [code returnCodeMethod];
        }
    }];
    
    
    
}






- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    NSLog(@"内存不够了");
}

-(void)NETWORKing{
                dispatch_async(dispatch_get_main_queue(), ^{
                    UIImageView *backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"005.jpg"]];
                    backgroundView.frame = self.view.bounds;
                    [self.view addSubview:backgroundView];
                    int g = 180;
                    if ([[UIScreen mainScreen]bounds].size.height  == 568){

                        g =152.42;
                    }
                    UIScrollView *demoContainerView = [[UIScrollView alloc] initWithFrame:CGRectMake(self.scrollViewNews.bounds.origin.x, 0, self.view.bounds.size.width, g)];
                    demoContainerView.contentSize = CGSizeMake(self.view.frame.size.width, 300);
                    [self.scrollViewNews addSubview:demoContainerView];
                    CGFloat w = self.view.bounds.size.width;
                    SDCycleScrollView *cycleScrollView2 = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, w, g) delegate:self placeholderImage:[UIImage imageNamed:@"placeholder"]];
                    demoContainerView.bounces=NO;
                    demoContainerView.scrollEnabled=NO;
                    cycleScrollView2.pageControlAliment = SDCycleScrollViewPageContolAlimentRight;
                    cycleScrollView2.autoScrollTimeInterval = 3.0;
                    cycleScrollView2.titlesGroup = @[@"智慧人设 服务民生",@"合伙人招募",@"大家都在听"];
                    cycleScrollView2.currentPageDotColor = [UIColor whiteColor];
                    
       __block  NSMutableArray *array2 =[NSMutableArray new];
                        [array2 removeAllObjects];
                        [array2 addObject:[UIImage imageNamed:@"shouye0.jpg"]];
                        [array2 addObject:[UIImage imageNamed:@"shouye1.jpg"]];
                        [array2 addObject:[UIImage imageNamed:@"shouye2.jpg"]];
                        cycleScrollView2.localizationImageNamesGroup = array2;
                    [demoContainerView addSubview:cycleScrollView2];
                    
                   
                });
}
-(void)acquirePicture:(CLPlacemark*)placeMark andL:(CLLocation *)location
{

     [self NETWORKing];
    
     NSDictionary *addressDic = placeMark.addressDictionary;
      NSString *subLocality=[addressDic objectForKey:@"SubLocality"];

      dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
    [NewsNetModel acquirePicture:MHSafeStrings(subLocality)  andlocationCoordinate:[NSString stringWithFormat:@"%ld,%ld",(long)location.coordinate.latitude,(long)location.coordinate.longitude] andint:1 complete:^(homePageNewsModel* model, NSError *error) {
        
        if (error) {
               [self NETWORKing];
            return ;
        }
        
    __block  NSMutableArray *array1 =[NSMutableArray new];
     __block  NSMutableArray *array2 =[NSMutableArray new];
 
       // [self.arrayT addObjectsFromArray:model.Result];
        [self.arrayT removeAllObjects];
        for (int i = 0; i < model.Result.count; i++) {
            NSArray *retArray = (NSArray *)model.Result;
            [self.arrayT addObject:retArray[i]];
        }

        [array1 removeAllObjects];
        [array2 removeAllObjects];
        for ( homePageNewsResultModel*str1 in model.Result) {
            [array1 addObject:(NSString*)str1.title];
              [array2 addObject:(NSString*)str1.KKImage];
            NSLog(@"%@",str1.title);
            NSLog(@"%@",array1);
             NSLog(@"%@",array2);
        }


        
        

        dispatch_async(dispatch_get_main_queue(), ^{

            UIImageView *backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"005.jpg"]];
            backgroundView.frame = self.view.bounds;
            [self.view addSubview:backgroundView];
            int g = 180;
            if ([[UIScreen mainScreen]bounds].size.height  == 568){
                
                g =152.42;
            }
            
        
            
            
            UIScrollView *demoContainerView = [[UIScrollView alloc] initWithFrame:CGRectMake(self.scrollViewNews.bounds.origin.x, 0, self.view.bounds.size.width, g)];
            demoContainerView.contentSize = CGSizeMake(self.view.frame.size.width, 300);
            [self.scrollViewNews addSubview:demoContainerView];
            CGFloat w = self.view.bounds.size.width;
            SDCycleScrollView *cycleScrollView2 = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, w, g) delegate:self placeholderImage:[UIImage imageNamed:@"shouye1.jpg"]];
            demoContainerView.bounces=NO;
            demoContainerView.scrollEnabled=NO;
            cycleScrollView2.pageControlAliment = SDCycleScrollViewPageContolAlimentRight;
            cycleScrollView2.autoScrollTimeInterval = 3.0;
            if (array1.count>0) {
                cycleScrollView2.titlesGroup = array1;
            }else{
                   cycleScrollView2.titlesGroup = @[@"智慧人设 服务民生",@"合伙人招募",@"大家都在听"];
            }
            cycleScrollView2.currentPageDotColor = [UIColor whiteColor]; // 自定义分页控件小圆标颜色
            self.isgetter =TRUE;//我改动的地方
            
            if (array2.count>0) {
                if (![array2[0] containsString:@"05"]) {
                    self.isgetter =FALSE;
                }
                if (![array2[1] containsString:@"13"]) {
                    self.isgetter =FALSE;
                }
                if (![array2[2] containsString:@"20"]) {
                    self.isgetter =FALSE;
                }
            }
            
            
            
            if ( self.isgetter ==FALSE) {

                 cycleScrollView2.imageURLStringsGroup =array2;
            }else{
                [array2 removeAllObjects];
               
                [array2 addObject:[UIImage imageNamed:@"shouye0.jpg"]];
                [array2 addObject:[UIImage imageNamed:@"shouye1.jpg"]];
                [array2 addObject:[UIImage imageNamed:@"shouye2.jpg"]];
                cycleScrollView2.localizationImageNamesGroup = array2;
            }
            
            
            [demoContainerView addSubview:cycleScrollView2];
            
         });
   }];
      });
}


-(void)drawALine
{

}

-(void)locationDisplay
{
    
    if ([[NSUserDefaults standardUserDefaults] objectForKey:@"weatherti1"]==nil) {
        self.weather_label.text=  @"天气:晴";
        self.weather_image.image = [UIImage imageNamed:@"W0"];
    }
    
       [self acquirePicture:nil andL:0];
    
    
    
    
    [[XWLocationManager sharedXWLocationManager] getCurrentLocation:^(CLLocation *location, CLPlacemark *placeMark, NSString *error) {
        
        
        
        
        
        
        
        if (error) {
            self.loactionText.text = MHSafeStrings(@"当前无法定位");
            NSLog(@"定位出错,错误信息:%@",error);
            [SVProgressHUD showErrorWithStatus:@"当前网络状态不佳"];
            return;
        }else{
            NSLog(@"     定位成功:经度:%f 纬度:%lf 当前地址:%@  \n location详细信息:%@ \n ",location.coordinate.latitude, location.coordinate.longitude, placeMark.name, location);
            

             AppDelegate *delegate=(AppDelegate*)[[UIApplication sharedApplication]delegate];
            delegate.jin =[NSString stringWithFormat:@"%f",location.coordinate.latitude];
            delegate.wei =[NSString stringWithFormat:@"%f",location.coordinate.longitude];
            
            //雷俊博注释,该接口已失效
           // weatherObject *weaher =[weatherObject new];
            /*[weaher weathermessage:^(NSError *error) {
 dispatch_async(dispatch_get_main_queue(), ^{
                if ([weaher.haveSomeThing isEqualToString:@"have"]) {
                    [[NSUserDefaults standardUserDefaults] setObject:weaher.strWeather  forKey:@"weatherti1"];
                    [[NSUserDefaults standardUserDefaults]synchronize];
                    [[NSUserDefaults standardUserDefaults] setObject:weaher.imageWeather forKey:@"weatherti2"];
                    [[NSUserDefaults standardUserDefaults]synchronize];
                }

         self.weather_label.text=  [[NSUserDefaults standardUserDefaults] objectForKey:@"weatherti1"];
         self.weather_image.image = [UIImage imageNamed: [[NSUserDefaults standardUserDefaults] objectForKey:@"weatherti2"]];
     
     

                 });

             }];*/
//            NSString *url = WeatherUrl;
//            AFHTTPSessionManager *manager = [[AFHTTPSessionManager alloc]init];
//            manager.requestSerializer = [AFHTTPRequestSerializer serializer];
//            manager.responseSerializer = [AFJSONResponseSerializer serializer];
//            manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"text/html", nil];
//            //默认:application/x-www-form-urlencoded
//            [manager.requestSerializer setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
//            
//            manager.requestSerializer.timeoutInterval = 20;
//            [manager POST:url parameters:nil headers:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
//                if (responseObject) {
//                    
//                   
//                    NSLog(@"%@",responseObject);
//                    
//                    NSNumber *ret = responseObject[@"ret"];
//                    if ([ret isKindOfClass:[NSNumber class]]) {
//                        if (ret.integerValue == 200) {
//                            NSDictionary *dic = responseObject;
//                            NSMutableDictionary *tqData =  [[NSMutableDictionary alloc]initWithDictionary:dic[@"data"]];
//                            [tqData setObject:![NSString blankString:placeMark.addressDictionary[@"City"]] ? placeMark.addressDictionary[@"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];
//                        }
//                       
//                    }
//                    
//                    
//                   
//                }
//            } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
//                
//            }];
//
            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) {
                    NSMutableDictionary *tqData =  [[NSMutableDictionary alloc]initWithDictionary:dic];
                    [tqData setObject:![NSString blankString:placeMark.addressDictionary[@"City"]] ? placeMark.addressDictionary[@"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];
                }
            } Failure:^(NSError * _Nonnull error) {
                NSLog(@"error:%@",error);
              
            }];
          
                
                
                NSDictionary *addressDic = placeMark.addressDictionary;
                //NSString *state=[addressDic objectForKey:@"State"];
                NSString *city=[addressDic objectForKey:@"City"];
               // NSString *subLocality=[addressDic objectForKey:@"SubLocality"];
               // NSString *street=[addressDic objectForKey:@"Street"];
            AppDelegate *dele=(AppDelegate*)[[UIApplication sharedApplication]delegate];
            [getPeopleID getAppleyPay:MHSafeStrings(city)];
            if ([getPeopleID applePaycity]) {
                dele.isLogin=YES;
            }else{
                dele.isLogin=NO;
            }
            
            [self.loactionText setText:[NSString stringWithFormat:@"%@%@%@",
                                        MHSafeStrings(placeMark.administrativeArea),
                                        MHSafeStrings(placeMark.thoroughfare),
                                        MHSafeStrings(placeMark.name)
                                        ]];
          
            self.GPS =self.loactionText.text;

        }
    } onViewController:self];

}

-(void)inWeather{
    waterViewController *waterV = [[waterViewController alloc]init];
    [self presentViewController:waterV animated:YES completion:^{
        
    }];
    
}


//定位
-(void)locationDisplay2
{
    
    if ([[NSUserDefaults standardUserDefaults] objectForKey:@"weatherti1"]==nil) {
           self.weather_label.text=  @"天气:晴";
           self.weather_image.image = [UIImage imageNamed:@"W0"];
       }
       
          [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 requestLocationWithReGeocode:YES withNetworkState:YES completionBlock:^(BMKLocation * _Nullable location, BMKLocationNetworkState state, NSError * _Nullable error) {
        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);
                
                [[NSUserDefaults standardUserDefaults]setObject:location.rgcData.city forKey:@"locationCity"];
                [[NSUserDefaults standardUserDefaults]synchronize];
            }
            
            
                       

                        AppDelegate *delegate=(AppDelegate*)[[UIApplication sharedApplication]delegate];
            delegate.jin =[NSString stringWithFormat:@"%f",location.location.coordinate.latitude];
            delegate.wei =[NSString stringWithFormat:@"%f",location.location.coordinate.longitude];
                       
                       //雷俊博注释,该接口已失效
                      // weatherObject *weaher =[weatherObject new];
                       /*[weaher weathermessage:^(NSError *error) {
            dispatch_async(dispatch_get_main_queue(), ^{
                           if ([weaher.haveSomeThing isEqualToString:@"have"]) {
                               [[NSUserDefaults standardUserDefaults] setObject:weaher.strWeather  forKey:@"weatherti1"];
                               [[NSUserDefaults standardUserDefaults]synchronize];
                               [[NSUserDefaults standardUserDefaults] setObject:weaher.imageWeather forKey:@"weatherti2"];
                               [[NSUserDefaults standardUserDefaults]synchronize];
                           }

                    self.weather_label.text=  [[NSUserDefaults standardUserDefaults] objectForKey:@"weatherti1"];
                    self.weather_image.image = [UIImage imageNamed: [[NSUserDefaults standardUserDefaults] objectForKey:@"weatherti2"]];
                
                

                            });

                        }];*/
//                       NSString *url = WeatherUrl;
//                       AFHTTPSessionManager *manager = [[AFHTTPSessionManager alloc]init];
//                       manager.requestSerializer = [AFHTTPRequestSerializer serializer];
//                       manager.responseSerializer = [AFJSONResponseSerializer serializer];
//                       manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"text/html", nil];
//                       //默认:application/x-www-form-urlencoded
//                       [manager.requestSerializer setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
//
//                       manager.requestSerializer.timeoutInterval = 20;
//            [manager POST:url parameters:nil headers:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
//                if (responseObject) {
//
//
//                    NSLog(@"%@",responseObject);
//
//                    NSNumber *ret = responseObject[@"ret"];
//                    if ([ret isKindOfClass:[NSNumber class]]) {
//                        if (ret.integerValue == 200) {
//                            NSDictionary *dic = responseObject;
//                            NSMutableDictionary *tqData =  [[NSMutableDictionary alloc]initWithDictionary:dic[@"data"]];
//                            [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];
//                        }
//
//                    }
//
//
//
//                }
//            } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
//
//            }];
            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) {
                    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];
                }
                
                 
            } 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;
           }
        
           [self.loactionText setText:[NSString stringWithFormat:@"%@%@",
                                       MHSafeStrings(location.rgcData.street),
                                       MHSafeStrings(location.rgcData.streetNumber)
                                       ]];
         
           self.GPS =self.loactionText.text;

            NSString*province = location.rgcData.province;
            if ([province isEqualToString:@"黑龙江省"] || [province isEqualToString:@"河北省"] || [province isEqualToString:@"贵州省"]) {
                [[NSUserDefaults standardUserDefaults]setBool:YES forKey:@"jiuyecaiji"];
                [[NSUserDefaults standardUserDefaults]synchronize];
                
                [self showSBDataCollect];
            }
        }
        
    }];
          
}


#pragma mark - 显示社保数据采集
- (void)showSBDataCollect
{
    
    showJYCaiji = YES;
    [self.pai_er_one setImage:[UIImage imageNamed:@"就业采集2"]  forState:normal];
    [self.pai_er_one setTitle:@"就业采集" forState:normal];
    [self initButton:self.pai_er_one];
}


                                                                                                                                                         
- (IBAction)buttonForSocialAll:(UIButton *)sender {
     
   if ([[NSUserDefaults standardUserDefaults]boolForKey:@"firstlog"]) {
           
           [GTCountSDK trackCountEvent:@"CQG_PUSH_click" withArgs:nil];
           UITabBarController*tabVC = [self getTabVC];
           [tabVC.navigationController setNavigationBarHidden:YES];
           tabVC.hidesBottomBarWhenPushed = YES;
           [self.navigationController pushViewController:tabVC animated:YES];
   
           return;
       }else{
           LoginVC *loginVC = [[LoginVC alloc]init];
           UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:loginVC];
           [self presentViewController:nav animated:YES completion:nil];
       }
   return;
    
//    WeakSelf
//    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];
//          }
//        }];
//    }];
//    self.maskView = self.aiDaView.maskView;
    
    


//    TestViewController*vc = [[TestViewController alloc]initWithNibName:@"TestViewController" bundle:[NSBundle mainBundle]];
//
//    vc.title = @"检测结果";
//    vc.hidesBottomBarWhenPushed = YES;
//    [self.navigationController pushViewController:vc animated:YES];
//    return ;
//    
//    SocialSecurityVerificationFailureViewController *vc = [[SocialSecurityVerificationFailureViewController alloc]init];
//    vc.title = @"照片选取";
//    vc.hidesBottomBarWhenPushed = YES;
//    [self.navigationController pushViewController:vc animated:YES];
//    return;
    


//    [self getPartnerQuery];
//    return;
    
    if(sender == self.socialSecurity){
        
       
        
       
        
//        LivenessViewController* dvc = [[LivenessViewController alloc] init];
//        dvc.delegate = self;
//
//          [dvc livenesswithList:@[@(1)] order:YES numberOfLiveness:0];
//
//        [self presentViewController:dvc animated:YES completion:nil];
        

        
        
//        SSPaymenyViewController *vc = [[SSPaymenyViewController alloc]init];
//        vc.title = @"社保缴费";
//        vc.hidesBottomBarWhenPushed = YES;
//        [self.navigationController pushViewController:vc animated:YES];
//        return;
        
        
//        UIStoryboard *sb  =[UIStoryboard storyboardWithName:@"Main" bundle:nil];
//       successViewController *blueVC = [sb instantiateViewControllerWithIdentifier:@"successViewController"];
//       blueVC.hidesBottomBarWhenPushed = YES;
//       [self.navigationController pushViewController:blueVC animated:YES];
//
//        return;
//
//
//        MyAdViewController *adVC = [[MyAdViewController alloc]init];
//
//        adVC.hidesBottomBarWhenPushed = YES;
//
//
//        [self.navigationController pushViewController:adVC animated:YES];
//
//
//        return;
//
//
//////
//                   CollectionAddressSelectedViewController *vc = [[CollectionAddressSelectedViewController alloc]init];
//                   vc.title = @"请选择采集地址";
//                   vc.hidesBottomBarWhenPushed = YES;
//                   [self.navigationController pushViewController:vc animated:YES];
//
//        return;
        
        
    
        
        
        
        
        
        
        

   if([[NSUserDefaults standardUserDefaults] boolForKey:@"firstlog"]){
       
                //微信小程序id:wxa32b480c19453653
       //pages/activity2/index/main?channel=AAEa8uDL_CLi4rjQ2mxeJFys
       NSURL * alipay_app_url = [NSURL URLWithString:@"alipay://"];

       BOOL ali = [[UIApplication sharedApplication] canOpenURL:alipay_app_url];
       if (ali) {
           
//           CollectionAddressSelectedViewController *vc = [[CollectionAddressSelectedViewController alloc]init];
//           vc.title = @"请选择采集地址";
//           vc.hidesBottomBarWhenPushed = YES;
//           [self.navigationController pushViewController:vc animated:YES];
           
           [self skipToAliSSCard];
           //[self jumpToHTML5:@"https://ur.alipay.com/383cSU" andJAnalytics:@"电子社保卡"];
           return;
       }else{
           
           if (![[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"wechat://"]] ) {
              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];
               return;
           }
           
           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:^(BOOL success) {
               
           }];
           
           [SVProgressHUD showInfoWithStatus:@"请下载支付宝"];
           return;
       }
       
   
   }else{
       
//       LoginViewController *logVC =    [LoginViewController sharedInstance];logVC.hidesBottomBarWhenPushed =YES;
//       if(![self.navigationController.topViewController isKindOfClass:[logVC class]]) {
//               [self.navigationController pushViewController:logVC animated:YES];
//       }
       LoginVC *loginVC = [[LoginVC alloc]init];
       UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:loginVC];
       [self presentViewController:nav animated:YES completion:nil];
   }
     
    }else if(sender == self.waterPay){

if([[NSUserDefaults standardUserDefaults] boolForKey:@"firstlog"]){
    
                        
  /*   //一整套逻辑
                            LivenessViewController* dvc = [[LivenessViewController alloc] init];
                            NSArray *array_ =nil;
                            NSInteger kankanZhang =   [[NSUserDefaults standardUserDefaults]integerForKey:@"huoti_kankan_int"];
                            //array_ =[[NSArray alloc]initWithObjects:@1,@1, nil];
                              array_ =[[NSArray alloc]initWithObjects:@1, nil];
    //                        if (kankanZhang ==9999) {
    //
    //                            array_ =[[NSArray alloc]initWithObjects:@5, nil];
    //                        }

                            [dvc livenesswithList:array_ order:YES numberOfLiveness:0];
                            __weak typeof(self) weakSelf = self;
                            dvc.completion = ^(NSDictionary *images, NSMutableArray *originImage) {


                                if (originImage.count == 4) {
                                    TestViewController*vc = [[TestViewController alloc]initWithNibName:@"TestViewController" bundle:[NSBundle mainBundle]];
                                    
                                    vc.title = @"检测结果";
                                    vc.hidesBottomBarWhenPushed = YES;
                                    
                                    vc.originImage = originImage;
                                    
                                    [weakSelf.navigationController pushViewController:vc animated:YES];
                                    return ;
                                }

                                //finish

                            };
                            [weakSelf presentViewController:dvc animated:YES completion:nil];
    */
    
    [self performSegueWithIdentifier:@"socialSecurity" sender:self];
    
}else{
//    LoginViewController *logVC =    [LoginViewController sharedInstance];
//    logVC.hidesBottomBarWhenPushed =YES;
//    if(![self.navigationController.topViewController isKindOfClass:[logVC class]]) {
//        [self.navigationController pushViewController:logVC animated:YES];
//    }
        LoginVC *loginVC = [[LoginVC alloc]init];
        UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:loginVC];
        [self presentViewController:nav animated:YES completion:nil];
    
}
    
    
    
    }else if(sender == self.mianfeifabu){

      
        if (self.arr111.count == 0)
            [self functionAllAnd:@"菜谱"];
        else{
            
//            if (self.validateTime) {
//                  [self functionAllAnd:@"菜谱"];
//            }else{
//                [self jumpToHTML5:@"http://nginx.weface.com.cn/lesson/dadiApp/index.html" andJAnalytics:@"实惠保险"];
//            }
            if (self.buttonArray.count == 2) {
                ButtonModel *model = self.buttonArray[0];
                [self JumpToVCLine3WithTitle:model.buttonTitle button:sender model:model];
            }else{
                [self functionAllAnd:@"万年历"];
            }
        }

         
        
    }else if (sender ==self.zhiwuxinxi){
      if (self.arr111.count == 0)
            [self functionAllAnd:@"快递查询"];
      else{
          if (self.buttonArray.count == 2) {
              if (self.validateTime) {
                   [self functionAllAnd:@"快递查询"];
              }else{
                  [self jumpToHTML5:@"http://nginx.weface.com.cn/lesson/dadiApp/index.html" 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;
//                         }
//
                 // [self getPartnerQuery];
              }
              
//              ButtonModel *model = self.buttonArray[3];
//              [self JumpToVCLine3WithTitle:model.buttonTitle button:sender model:model];
          }else{
              [self functionAllAnd:self.arr111[0]];
          }
      }
          
 
    }else if (sender ==self.searchTrafficViolation)
    {

        
        if (self.arr111.count == 0)
            [self functionAllAnd:@"电台"];
        else{
            if (self.buttonArray.count == 2) {
                ButtonModel *model = self.buttonArray[1];
                [self JumpToVCLine3WithTitle:model.buttonTitle button:sender model:model];
               
                
//                ButtonModel *model = self.buttonArray[1];
//                [self JumpToVCLine3WithTitle:model.buttonTitle button:sender model:model];
            }else{
                [self functionAllAnd:@"诸葛找房"];
            }
        }

            

        
        
    }else if(sender==self.nongzi){
       
        if(![[NSUserDefaults standardUserDefaults] boolForKey:@"firstlog"]){
            
            LoginVC *loginVC = [[LoginVC alloc]init];
            UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:loginVC];
            [self presentViewController:nav animated:YES completion:nil];
            return;
        }
       
        
        SSPaymenyViewController *vc = [[SSPaymenyViewController alloc]init];
        vc.title = @"社保缴费";
        vc.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:vc animated:YES];
        return;
        
 
        NSDate*date = [NSDate date];
        NSCalendar*calendar = [NSCalendar currentCalendar];
        NSDateComponents*comps;

        comps =[calendar components:(NSCalendarUnitWeekOfYear | NSCalendarUnitWeekday |NSCalendarUnitWeekdayOrdinal)
                           fromDate:date];
        NSInteger week = [comps weekOfYear]; // 今年的第几周
        if(week > 0){
            if (week %2 == 0) {
         NONGZI
            }else{

                
                WKSuperViewController *tc=[[WKSuperViewController alloc]init];
                tc.titleStr=@"政务信息";
                tc.pathStr=@"http://www.mca.gov.cn/wap/";
                tc.hidesBottomBarWhenPushed =YES;
                [self.navigationController pushViewController:tc animated:YES];
  
            }

        }
        
        
    }else if (sender==self.shenghuojifei){

        sender.userInteractionEnabled = NO;
        
        
        if (![[NSUserDefaults standardUserDefaults] boolForKey:@"firstlog"]) {
            LoginVC *loginVC = [[LoginVC alloc]init];
            UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:loginVC];
            [self presentViewController:nav animated:YES completion:nil];
            sender.userInteractionEnabled = YES;
        }else{
             [self searchProgress];
        }
       
       
        
        
       
        
    }else if(sender == self.medcine){


        if (self.arr111.count == 0)
        {
            [self functionAllAnd:@"万年历"];
        }else{
            
            if (![[NSUserDefaults standardUserDefaults] boolForKey:@"firstlog"]) {
                            LoginVC *loginVC = [[LoginVC alloc]init];
                            UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:loginVC];
                            [self presentViewController:nav animated:YES completion:nil];
                            sender.userInteractionEnabled = YES;
                            return;
              }
            
            [self JumpToVCLine3WithTitle:@"抢红包" button:self.medcine model:nil];
            
            return;
            ButtonModel *model = self.buttonArray[1];
            [self JumpToVCLine3WithTitle:model.buttonTitle button:sender model:model];
            return;
            if (self.validateTime) {
                [self functionAllAnd:@"菜谱"];
                return;
            }
            
             if (![[NSUserDefaults standardUserDefaults] boolForKey:@"firstlog"]) {
                 LoginVC *loginVC = [[LoginVC alloc]init];
                 UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:loginVC];
                 [self presentViewController:nav animated:YES completion:nil];
                 sender.userInteractionEnabled = YES;
                 return;
             }
            
            WeakSelf
            if (![[NSUserDefaults standardUserDefaults]boolForKey:@"bicai_allow"]) {
                           
                   
                [AiDaAlertView showAlertViewWithTitle:@"比财数据" imageName:@"bicailogo" ViewController:self type:AiDaAlertViewTypeBC block:^(BOOL success) {
                    [[NSUserDefaults standardUserDefaults]setBool:YES forKey:@"bicai_allow"];
                    [[NSUserDefaults standardUserDefaults]synchronize];
                    [weakSelf aiDaTokenRequest:^(bool success, NSString *token) {
                        [weakSelf getBCRequest:token];
                       
                    }];
                }];
                
                 return;
                          
            }
            
             [self aiDaTokenRequest:^(bool success, NSString *token) {
                    [weakSelf getBCRequest:token];
             }];
            
            
             
              
        
    }

            
            
            
            
        
    }else if(sender ==self.pai_er_one){
      
        
        if (showJYCaiji) {
            
            if(![[NSUserDefaults standardUserDefaults] boolForKey:@"firstlog"]){
                LoginVC *loginVC = [[LoginVC alloc]init];
                
                UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:loginVC];
                [self presentViewController:nav animated:YES completion:nil];
                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];
            
            GovNewVc* govVC = [[GovNewVc alloc]init];
                govVC.title = @"政务信息";
                govVC.hidesBottomBarWhenPushed = YES;
            
                [self.navigationController pushViewController:govVC animated:YES];
            
                return;
               
            
        }
        
       
        



    }else if(sender ==self.pai_er_two){
        
        
        if (self.validateTime) {
            [self jumpToHTML5:@"https://www.ctrip.com/" andJAnalytics:@"周边游"];
            return;
        }
        
        if([[NSUserDefaults standardUserDefaults] boolForKey:@"firstlog"]){
                   
                   SmartInterrogationViewController* vc = [[SmartInterrogationViewController alloc]init];
                   vc.title = @"看病买药";
                   vc.hidesBottomBarWhenPushed = YES;

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

                   return;
                     
                    
               }else{
                   LoginVC *loginVC = [[LoginVC alloc]init];
                   
                   UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:loginVC];
                   [self presentViewController:nav animated:YES completion:nil];
               }
                     return;
        
        //以前人写的
      //MIANFIFABU
        
        //雷俊博
        NSString * strA = @"https://kksb.wy.guahao.com/ask/entry/introduce?pageFrom=10020";
        
        
        [self jumpToHTML5:strA andJAnalytics:@"快速问诊"];
        
    }else if(sender ==self.pai_er_three){
        
       NewsViewController*newsVC = [NewsViewController new];
       newsVC.title = @"新闻";
        newsVC.from = @"home";
       newsVC.hidesBottomBarWhenPushed = YES;
       [self.navigationController pushViewController:newsVC animated:YES];
      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;
//      }
//
//       sender.userInteractionEnabled = NO;
//
//
//        [self getYDUrlRequest:sender];
//
//        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);
//              }
//              sender.userInteractionEnabled = YES;
//          } fail:^(id  _Nonnull error) {
//              sender.userInteractionEnabled = YES;
//              NSLog(@"请求失败，请登录 ===> %@",error);
//              [weakSelf alertShow:@"网络异常,请稍后重试"];
//          }];
        
       
//        if ([getPeopleID LimmitedToBanbana] == YES) {
//
//
//            if([[NSUserDefaults standardUserDefaults] boolForKey:@"firstlog"]){
//
//                [weatherNetModel findJobInfoLoginID:0 handle:^(verifyAdressModel *model, NSError *error) {
//                    if (error) {
//                        return;
//                    }
//
//                    if (model.state == 404 ) {
//                        FiveEightCityViewController *moasd =[[FiveEightCityViewController alloc]init];
//                        moasd.hidesBottomBarWhenPushed =YES;
//                        [self.navigationController pushViewController:moasd animated:YES];
//                    }else{
//                        if (model.state  == 200 ) {
//                            if (model.RESULT) {
//                                NSString * pathNew1 =  [model.RESULT stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
//                                NSLog(@"%@",model.RESULT);
//
//                                [self jumpToHTML5:pathNew1 andJAnalytics:@"58速聘"];
//                            }
//                        }
//                    }
//
//                }];
//
//            }else{
//                    LoginViewController *logVC =    [LoginViewController sharedInstance];
//                    logVC.hidesBottomBarWhenPushed =YES;
//                    if(![self.navigationController.topViewController isKindOfClass:[logVC class]]) {
//                        [self.navigationController pushViewController:logVC animated:YES];
//                    }
//
//                }
//
//
//
//
//
//
//
//        }else{
//
//
//        }
 
        
    }else if(sender ==self.pai_er_four){
        
       
        
        ZHINENGKEFU
        
        
        
               
    
    }
    

    
    
    
}



-(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 (ingeerr % 2 == 0) {
//                //[self getRdactiveListRequest];
//                [self refreshCoins];
//            }else{
//                [self refreshCoins];
//            }
            
                      
            ingeerr ++;

                                  
          }else{
              
               [self functionAllAnd:self.arr111[1]];
              
          }
        

    }else if ([title isEqualToString:@"短视频"]){
//        VideoVC *vc = [[VideoVC alloc]init];
//           vc.hidesBottomBarWhenPushed = YES;
//           [self.navigationController pushViewController:vc animated:YES];
    }else if ([title isEqualToString:@"周边游"]){
        ZHOUBIANYOU
    } 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;
    }
    
    WebViewController *tc=[WebViewController new];
    tc.URL =[NSURL URLWithString:url];
            tc.hidesBottomBarWhenPushed =YES;
    tc.janalytics = janalytics;
    [self.navigationController pushViewController:tc animated:YES];

}


- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

    if ([segue.identifier isEqualToString:@"socialSecurity"]) {
        PhotoViewController *cvc =segue.destinationViewController;
        cvc.title = @"社保认证";
        cvc.hidesBottomBarWhenPushed =YES;
    }
    
    
    if ([segue.identifier isEqualToString:@"postMessage"])  {
        postMessgaeTotal *blueVC = segue.destinationViewController;
        if (self.baocun.count >0) {
             blueVC.superData = [self.baocun copy];
        }
        if (self.array_k1.count >0) {
              blueVC.superChildData_1 =[self.array_k1 copy];
      }
        if (self.array_k2.count >0) {
                 blueVC.superChildData_2 =[self.array_k2 copy];
      }
        if (self.array_k3.count >0) {
                     blueVC.superChildData_3 =[self.array_k3 copy];
      }
        if (self.array_k4.count >0) {
              blueVC.superChildData_4 =[self.array_k4 copy];
      }
        if (self.array_k5.count >0) {
            blueVC.superChildData_5 =[self.array_k5 copy];
        }
        blueVC.hidesBottomBarWhenPushed=YES;
    }
}
-(void)getSuperData
{
    __weak typeof(self) weakSelf = 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);
        [postMessageMNet getSuperCatalogcompletionHandle:^(postMessageModel *model, NSError *error) {
                [weakSelf.baocun removeAllObjects];
                if (model.Result.count >0) {
                    for (postMessageResultModel *models in model.Result) {
                        
                        [weakSelf.baocun addObject:models.categoryname];
                        NSLog(@"_superData:%@",weakSelf.baocun);
                    }
                }
                
             dispatch_group_leave(group);
        }];
        
 
    });
    dispatch_group_async(group, queue, ^{
        dispatch_group_enter(group);
        [postMessageMNet getChildCatalog:1 completionHandle:^(postMessageModel *model, NSError *error) {
   
                [weakSelf.array_k1 removeAllObjects];
                if (model.Result.count >0) {
                    for (postMessageResultModel *models in model.Result) {
                        
                        [weakSelf.array_k1 addObject:models.categoryname];
                        NSLog(@"_superData:%@",weakSelf.array_k1);
                    }
                    
                }
                
                     dispatch_group_leave(group);
        }];

  
    });
    dispatch_group_async(group, queue, ^{
        dispatch_group_enter(group);
        [postMessageMNet getChildCatalog:2 completionHandle:^(postMessageModel *model, NSError *error) {
            [self.array_k2 removeAllObjects];
            if (model.Result.count >0) {
                for (postMessageResultModel *models in model.Result) {
                    
                    [weakSelf.array_k2 addObject:models.categoryname];
                }
            }
                  dispatch_group_leave(group);
        }];

        
    });
    dispatch_group_async(group, queue, ^{
        dispatch_group_enter(group);
        [postMessageMNet getChildCatalog:3 completionHandle:^(postMessageModel *model, NSError *error) {
            [weakSelf.array_k3 removeAllObjects];
            if (model.Result.count >0) {
                for (postMessageResultModel *models in model.Result) {
                    
                    [weakSelf.array_k3 addObject:models.categoryname];
                }
            }
                dispatch_group_leave(group);
        }];
  
        
    });
    dispatch_group_async(group, queue, ^{
        dispatch_group_enter(group);
        [postMessageMNet getChildCatalog:4 completionHandle:^(postMessageModel *model, NSError *error) {
            [weakSelf.array_k4 removeAllObjects];
            if (model.Result.count >0) {
                for (postMessageResultModel *models in model.Result) {
                    
                    [weakSelf.array_k4 addObject:models.categoryname];
                }
            }
                 dispatch_group_leave(group);
        }];
 
        
    });
    dispatch_group_async(group, queue, ^{
        dispatch_group_enter(group);
        [postMessageMNet getChildCatalog:5 completionHandle:^(postMessageModel *model, NSError *error) {
            [weakSelf.array_k5 removeAllObjects];
            if (model.Result.count >0) {
                for (postMessageResultModel *models in model.Result) {
                    
                    [weakSelf.array_k5 addObject:models.categoryname];
                }
            }
            
              dispatch_group_leave(group);
        }];
      
        
    });
    dispatch_group_notify(group, dispatch_get_main_queue(), ^{
    });
    
    
    
    
}

#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:[ViewController 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 - 比财

- (NSDictionary *)getBCRequestParam
{
    NSDictionary *params = @{
        @"phone":[[getPeopleID PeopleIphoneNmber] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]],
        @"id":[NSNumber numberWithInteger:[getPeopleID PeopleID]].stringValue
    };
    return params;
}

- (void)getBCRequest:(NSString *)token
{
   NSString*url = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipAdDaUrlConfig],BCUrlRequest];
    NSLog(@"比财url的url:%@",url);
    
    NSLog(@"params:%@",[self getBCRequestParam]);
    
    [NetworkRequest Get2:url Params:[self getBCRequestParam] 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:@"%@&appBarHide=hide",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:[ViewController 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 -合伙人查询
- (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;
                [weakSelf.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;
                    [weakSelf.navigationController pushViewController:vc animated:YES];
                
                    return;
            }else if ([state isEqualToString:@"203"]){
                JoinPartnerResultViewController* vc = [JoinPartnerResultViewController new];
                vc.type = @"fail";
                vc.hidesBottomBarWhenPushed = YES;
                [weakSelf.navigationController pushViewController:vc animated:YES];
            }else if ([state isEqualToString:@"201"]){
                
                JoinPartGuideViewController *vc = [JoinPartGuideViewController new];
                vc.title = @"加入合伙人";
                vc.hidesBottomBarWhenPushed = YES;
                [weakSelf.navigationController pushViewController:vc animated:YES];
                   
                
                    return;
            }else{
                [SVProgressHUD showErrorWithStatus:describe];
            }
        }else{
            [SVProgressHUD showErrorWithStatus:@"服务器异常"];
        }
        
    } Failure:^(NSError * _Nonnull error) {
        NSLog(@"error:%@",error);
        [SVProgressHUD showErrorWithStatus:@"网络异常"];
    }];
    
    
}

#pragma mark - 药兜网
- (void)getYDUrlRequest:(UIButton *)sender
{
    NSString* urlString = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipYDConfig],YDURLRequest];
    NSDictionary*params = @{
        @"phone":[getPeopleID PeopleIphoneNmber]
    };
    WeakSelf
    [NetworkRequest Get:urlString Params:params Success:^(id _Nonnull objc) {
        NSLog(@"objc:%@",objc);
        sender.userInteractionEnabled = YES;
        if ([objc isKindOfClass:[NSDictionary class]]) {
            NSString*state = [NSString stringWithFormat:@"%@",objc[@"state"]];
            if ([state isEqualToString:@"200"]) {
                NSDictionary * data = objc[@"result"][@"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{
                 [self alertShow:@"网络异常,请稍后重试"];
            }
        }else{
            [self alertShow:@"网络异常,请稍后重试"];
        }
    } Failure:^(NSError* error) {
        sender.userInteractionEnabled = YES;
        NSLog(@"error:%@",error);
        [self alertShow:@"网络异常,请稍后重试"];
    }];
    
}



#pragma mark - 中部banner api请求
- (void)loadMiddleBannerApiRequest
{   __block BOOL requestSuccess = NO;
    __block BOOL show = NO;
    __weak typeof(self) weakSelf = 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);
        
        NSDictionary *params =@{
                                @"showType":@"3",
                                @"versionId":[NSNumber numberWithInt:2001]
        };

          NSLog(@"params:%@",params);
        
          NSString * url =[IPDIZHI stringByAppendingString:@"/socialsecurity/kankan/getNews"];
        NSLog(@"url:%@",url);
        
        
        [CTAPIBaseManager POST6:url params:params completionHandler:^(id  _Nonnull responseObject, NSError * _Nonnull error) {
            if ([responseObject[@"code"] isEqualToNumber:@0]) {
                
                NSArray *results = responseObject[@"result"];
                
                if ([results isKindOfClass:[NSArray class]]) {
                    for (int i = 0; i < results.count; i++) {
                        BannerAdObjectModel *model = [BannerAdObjectModel mj_objectWithKeyValues:results[i]];
                        [weakSelf.newsDataArray addObject:model];
                        
                        requestSuccess = YES;
                        
                        
                    }
                }
                
                
            }
            
            dispatch_group_leave(group);
            
        }];
        
    });
    
    dispatch_group_async(group, queue, ^{
        
        dispatch_group_enter(group);
        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
        };
        [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;
                }
                
            }
            //show = YES;
            dispatch_group_leave(group);
            
        } Failure:^(NSError* error) {
            dispatch_group_leave(group);
        }];
        
    });
    
    dispatch_group_notify(group, dispatch_get_main_queue(), ^{
        
        if (requestSuccess) {
            [self.tableViewNews reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:0 inSection:1]] withRowAnimation:UITableViewRowAnimationNone];
        }
        
        if (show) {
//            [self.mianfeifabu setImage:[UIImage imageNamed:@"home_insurance"]  forState:normal];
//            [self.mianfeifabu setTitle:@"实惠保险" forState:normal];
//            [self initButton:self.mianfeifabu];
//            [self.medcine setImage:[UIImage imageNamed:@"home_bank"] forState:normal];
//            self.moneyCount.image = [JobUtil changeImageToGit:@"haveMoney.gif"];
//            self.moneyCount.hidden = NO;
//            [self.medcine setTitle:@"存钱罐" forState:normal];
            //[self initButton:self.medcine];
            [self.zhiwuxinxi  setImage:[UIImage imageNamed:@"home_insurance"]  forState:normal];
            [self.zhiwuxinxi  setTitle:@"实惠保险" forState:normal];
            [self.pai_er_two setImage:[UIImage imageNamed:@"home_Quickconsultation_normal"] forState:UIControlStateNormal];
            [self.pai_er_two setTitle:@"看病买药" forState:UIControlStateNormal];
            
            
            [self initButton:self.zhiwuxinxi];
            [self initButton:self.pai_er_two];
            
            self.validateTime = NO;
        
            UIImage *image = [UIImage imageNamed:@"大病求助"];
            CGFloat scale = image.size.height / image.size.width;
            self.KKtableHeight.constant = 663+114-208-20-75-75-10+6 + 34 + 10+30 + 80 + (ScreenWidth - 30)/2 *scale;
            [self.tableViewNews reloadData];
        }
    });
    
}



#pragma mark - 广告异步点击检测
//返回曝光检测地址请求
- (void)loadOtherData:(NSArray *)array
{
    dispatch_group_t group = dispatch_group_create();
    
    dispatch_queue_t searialQueue = dispatch_queue_create("com.hmc4.www", DISPATCH_QUEUE_SERIAL);
    
    
    
    for (NSString *urlStr in array) {
        dispatch_group_enter(group);
        dispatch_group_async(group, searialQueue, ^{
            //网络请求1
            [CTAPIBaseManager GET2:urlStr params:@{} completionHandler:^(id  _Nonnull responseObject, NSError * _Nonnull error) {
                dispatch_group_leave(group);
            }];
        });
    }
    
    //多个网络请求结束后,刷新UI
    dispatch_group_notify(group, searialQueue, ^{
        dispatch_async(dispatch_get_global_queue(0, 0), ^{
            dispatch_async(dispatch_get_main_queue(), ^{
                NSLog(@"返回异步点击c检测地址请求");
            });
        });
    });
}


#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]);
    
    [SVProgressHUD shows];
    [NetworkRequest Post2:urlString Params:[self getRdactiveListRequestParams] Success:^(id _Nonnull objc) {
        [SVProgressHUD doneShow];
        [SVProgressHUD 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"]) {
                           LoginVC *loginVC = [[LoginVC alloc]init];
                           UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:loginVC];
                           [self presentViewController:nav animated:YES completion: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) {
        [SVProgressHUD doneShow];
        [SVProgressHUD dismiss];
        NSLog(@"error:%@",error);
        [SVProgressHUD showErrorWithStatus:@"网络异常"];
    }];
}


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

#pragma mark - 跳转广告业
- (void)pushToAd:(NSNotification *)noti
{
    
    WebViewController *tc=[WebViewController new];

    //urlPath
    NSDictionary *dict = noti.userInfo;
  
    NSArray *click_tracking_urls = dict[@"click_tracking_urls"];

    if (click_tracking_urls.count > 0) {
        [GTCountSDK trackCountEvent:@"advertisementClickSStatistics" withArgs:@{}];
        [self loadOtherData:dict[@"click_tracking_urls"]];
    }

    tc.URL =[NSURL URLWithString: dict[@"url"]];
    

    if (click_tracking_urls.count > 0) {
//        if (@available(iOS 10.0, *)) {
//            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:dict[@"url"]] options:@{} completionHandler:nil];
//        }else{
//            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:dict[@"url"]]];
//        }
        tc.hidesBottomBarWhenPushed =YES;
        [self.navigationController pushViewController:tc animated:YES];
    }else{
            tc.hidesBottomBarWhenPushed =YES;
            [self.navigationController pushViewController:tc animated:YES];
    }
    
    
   
}


#pragma mark - 认证成功后刷新
- (void)refreshKankanAssistant
{
    NSIndexPath *indexPath1 = [NSIndexPath indexPathForRow:0 inSection:0];
    [self.tableViewNews reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath1, nil] withRowAnimation:UITableViewRowAnimationNone];
}

#pragma mark - BUNativeExpressRewardedVideoAdDelegate

- (void)nativeExpressRewardedVideoAdDidLoad:(BUNativeExpressRewardedVideoAd *)rewardedVideoAd
{
    
}


- (void)nativeExpressRewardedVideoAd:(BUNativeExpressRewardedVideoAd *)rewardedVideoAd didFailWithError:(NSError *_Nullable)error
{
    
}

- (void)nativeExpressRewardedVideoAdDidDownLoadVideo:(BUNativeExpressRewardedVideoAd *)rewardedVideoAd
{
    
}

- (void)nativeExpressRewardedVideoAdViewRenderSuccess:(BUNativeExpressRewardedVideoAd *)rewardedVideoAd
{
   [self.rewardedAd showAdFromRootViewController:self];
}


- (void)nativeExpressRewardedVideoAdViewRenderFail:(BUNativeExpressRewardedVideoAd *)rewardedVideoAd error:(NSError *_Nullable)error
{
    
}

- (void)nativeExpressRewardedVideoAdWillVisible:(BUNativeExpressRewardedVideoAd *)rewardedVideoAd
{
    
}


- (void)nativeExpressRewardedVideoAdDidVisible:(BUNativeExpressRewardedVideoAd *)rewardedVideoAd
{
    
}

/**
 This method is called when video ad is about to close.
 */
- (void)nativeExpressRewardedVideoAdWillClose:(BUNativeExpressRewardedVideoAd *)rewardedVideoAd
{
    
}

/**
 This method is called when video ad is closed.
 */
- (void)nativeExpressRewardedVideoAdDidClose:(BUNativeExpressRewardedVideoAd *)rewardedVideoAd
{
    WXLaunchMiniProgramReq *launchMiniProgramReq = [WXLaunchMiniProgramReq object];
    launchMiniProgramReq.userName = @"gh_f8a0e531525d";  //拉起的小程序的username
    launchMiniProgramReq.path = @"WXMiniPro://gh_f8a0e531525d/pages/base/redirect/index?routeKey=PROMOTION_GIFT_PACKAGE_NEW&activityCode=appDefault&wtagid=118.4.1";    //拉起小程序页面的可带参路径，不填默认拉起小程序首页
    launchMiniProgramReq.miniProgramType = WXMiniProgramTypeRelease; //拉起小程序的类型
    [WXApi sendReq:launchMiniProgramReq completion:^(BOOL success) {
        
    }];
}

/**
 This method is called when video ad is clicked.
 */
- (void)nativeExpressRewardedVideoAdDidClick:(BUNativeExpressRewardedVideoAd *)rewardedVideoAd
{
    
}

/**
 This method is called when the user clicked skip button.
 */
- (void)nativeExpressRewardedVideoAdDidClickSkip:(BUNativeExpressRewardedVideoAd *)rewardedVideoAd
{
    
}

/**
 This method is called when video ad play completed or an error occurred.
 @param error : the reason of error
 */
- (void)nativeExpressRewardedVideoAdDidPlayFinish:(BUNativeExpressRewardedVideoAd *)rewardedVideoAd didFailWithError:(NSError *_Nullable)error
{
    
}

/**
 Server verification which is requested asynchronously is succeeded.
 @param verify :return YES when return value is 2000.
 */
- (void)nativeExpressRewardedVideoAdServerRewardDidSucceed:(BUNativeExpressRewardedVideoAd *)rewardedVideoAd verify:(BOOL)verify
{
    
}

/**
 Server verification which is requested asynchronously is failed.
 Return value is not 2000.
 */
- (void)nativeExpressRewardedVideoAdServerRewardDidFail:(BUNativeExpressRewardedVideoAd *)rewardedVideoAd
{
    
}
-(BOOL)shouldAutorotate{
    return YES;
}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskAll;
}

#pragma mark - passImagesDelegate
- (void)passImages
{
    [self alertShow:@"检测成功"];
    
    [SVProgressHUD showSuccessWithStatus:@"检测成功"];
}

- (void)passFail
{
    [SVProgressHUD showErrorWithStatus:@"检测失败"];
}

- (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 - UITableViewDataSource
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 6;

}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    if (self.validateTime&& (section ==3 || section == 4) ) {
        return 0;
    }
    
   return   1;
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    //雷俊博
    if(indexPath.section == 1) {
//        static NSString *cellIdentifier = @"littleProcedure";
//        LittleProcedureTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
//
//        if (cell == nil) {
//            cell = [[[NSBundle mainBundle]loadNibNamed:@"LittleProcedureTableViewCell" owner:self options:nil]objectAtIndex:0];
//        }
        
        Home3MiddleBannerCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Home3MiddleBannerCell"];
        cell.delegate = self;
        
        if (self.newsDataArray.count >=3) {
            cell.modelarray = self.newsDataArray;
        }
        
        
        
        return cell;
    }
    //雷俊博
    if (  indexPath.section == 2) {
        static NSString *CellIdentifier =@"myJDCell";
        myJDCell *cell = [tableView dequeueReusableCellWithIdentifier:@"myJDCell"];
        if (cell == nil) {
            cell = [[myJDCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
            
        }

        
        return cell;
    }else if(indexPath.section == 0){
        static NSString *CellIdentifier =@"socialAssistant";
        socialAssistant *cell = [tableView dequeueReusableCellWithIdentifier:@"socialAssistant"];
     
        if (cell == nil) {
            cell = [[socialAssistant alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        }
     __block  NSString *address = nil;
            [CityNetManager phonenumberAndCompletionHandle:^(resulTModel *model, NSError *error) {
                if (model.result  != nil) {
                    address = model.result;
                      NSLog(@"%@",address);
                    
                    if ([getPeopleID socialSate] == 0) {
                         if ([getPeopleID LimmitedToBanbana] == YES) {
                        cell.KKHide.text =@"足不出户,安全认证,放心领钱";
                         }else{
                        cell.KKHide.text =@"足不出户,安全认证,放心领钱";

                         }
                        cell.AAReccord.text =@"";
                        cell.AAImage.image= nil;
                        
                        cell.AAName.text =@"";
                        cell.AAId.text = @"";
                        cell.AATime.text =@"";
                        
                        
                    }else if ([getPeopleID socialSate] == 1 ){
                        //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) {
                                    cell.KKHide.text =@"足不出户,安全认证,放心领钱";
                                    cell.AAReccord.text =@"";
                                    cell.AAImage.image= nil;
                                    
                                    cell.AAName.text =@"";
                                    cell.AAId.text = @"";
                                    cell.AATime.text =@"";
                                    
                                    return;
                                }else{
                                    socialResultModel *models =(socialResultModel*)model.result[0];
                                    NSLog(@"%@",models.createTime);
                                    cell.record =1;
                                    cell.socModel = models;

                                }



                            }


                        }];
                        
 
                        
                    }else{
                        
                        cell.KKHide.text =@"足不出户,安全认证,放心领钱";//我改动的地方
                        
                        
                        
                        cell.AAReccord.text =@"";
                        cell.AAImage.image= nil;
                        
                        cell.AAName.text =@"";
                        cell.AAId.text = @"";
                        cell.AATime.text =@"";
                    }
                }else{
                    //当请求失败时
                    cell.KKHide.text =@"足不出户,安全认证,放心领钱";
                    
                    
                    
                    cell.AAReccord.text =@"";
                    cell.AAImage.image= nil;
                    
                    cell.AAName.text =@"";
                    cell.AAId.text = @"";
                    cell.AATime.text =@"";
                }
                
            }];
        return cell;
    }else{
          //创建静态标识符
         static NSString *CellIdentifier =@"MyCell";
        
         //根据标识符从重用池取得cell
        MyTableViewCell_d *cell = [tableView dequeueReusableCellWithIdentifier:@"MyCell"];
        
         //没有则创建新的cell
        if (cell == nil) {
            cell = [[MyTableViewCell_d alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
        }
        
        
UITapGestureRecognizer * tag = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(onClick:)];
UITapGestureRecognizer * tag1 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(onClick:)];
        UITapGestureRecognizer * tag2 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(onClick:)];
        UITapGestureRecognizer * tag3 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(onClick:)];
        UITapGestureRecognizer * tag4 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(onClick:)];
        UITapGestureRecognizer * tag5 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(onClick:)];
                        switch (indexPath.section) {
                            case 3:

                                cell.imageleft.image =[UIImage imageNamed:@"大病求助"];
                                cell.imageright.image =[UIImage imageNamed:@"微医挂号"];
                                cell.selectionStyle=UITableViewCellSelectionStyleNone;
                                cell.imageleft.tag = 1;
                                cell.imageright.tag =2;
                                cell.imageleft.userInteractionEnabled = YES;
                                cell.imageright.userInteractionEnabled = YES;
                            
                                [cell.imageleft addGestureRecognizer:tag];
                                [cell.imageright addGestureRecognizer:tag1];
                                
                               
                                

                                break;
                            case 4:
                                cell.imageleft.image =[UIImage imageNamed:@"在线问诊"];
                               
                                cell.imageright.image =[UIImage imageNamed:@"海外医疗"];
                                cell.selectionStyle=UITableViewCellSelectionStyleNone;
                                cell.imageleft.tag = 3;
                                cell.imageright.tag =4;
                                cell.imageleft.userInteractionEnabled = YES;
                                cell.imageright.userInteractionEnabled = YES;
                                
                                [cell.imageleft addGestureRecognizer:tag2];
                                [cell.imageright addGestureRecognizer:tag3];
                                
                                
                                
                                break;
                            case 5:
                                cell.imageleft.image =[UIImage imageNamed:@"社保计算器11"];
                                cell.imageright.image =[UIImage imageNamed:@"微保"];
                                cell.selectionStyle=UITableViewCellSelectionStyleNone;
                                cell.imageleft.tag = 5;
                                cell.imageright.tag =6;
                                cell.imageleft.userInteractionEnabled = YES;
                                cell.imageright.userInteractionEnabled = YES;
                                
                                [cell.imageleft addGestureRecognizer:tag4];
                                [cell.imageright addGestureRecognizer:tag5];
                                
                                
                                
                                break;

//
//                            case 5:
//        cell.newsTitle.text =self.newsArray[2][@"bigTitleNews"];
//                                [cell.imageNews sd_setImageWithURL:self.newsArray[2][@"imageNews"] placeholderImage:[UIImage imageNamed:@"shebao_3"]];
//                                cell.textNews.text =self.newsArray[2][@"titleNews"];
//
//                                break;
//                            case 6:
//        cell.newsTitle.text =self.newsArray[3][@"bigTitleNews"];
//                                [cell.imageNews sd_setImageWithURL:self.newsArray[3][@"imageNews"] placeholderImage:[UIImage imageNamed:@"shebao_4"]];
//                                cell.textNews.text =self.newsArray[3][@"titleNews"];
//                                break;
//                            case 7:
//                 cell.newsTitle.text =self.newsArray[4][@"bigTitleNews"];
//                                [cell.imageNews sd_setImageWithURL:self.newsArray[4][@"imageNews"] placeholderImage:[UIImage imageNamed:@"shebao_5"]];
//                                cell.textNews.text =self.newsArray[4][@"titleNews"];
//                                break;
                            default:
                                break;
                        }

                return cell;
        
        
        
    
    }
    
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    
    if (indexPath.section == 0) {
        return 110;
    }else if ( indexPath.section == 1){
    
        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 == 2){
        
        return  0;
        
    }else if (indexPath.section == 6){
        
          return  0;
        
    }else if (indexPath.section == 7){
        
           return  0;
        
    }else{
        
       UIImage *image = [UIImage imageNamed:@"大病求助"];
        CGFloat scale = image.size.height / image.size.width;
         return  (ScreenWidth - 30)/2 *scale;
        
    }
 
    
    

    
    
}

#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{

    //不要显示
    if ( section==2 ||section == 4 || section == 6 || section == 7) {
        return 0.00000000001;
    }else if (section == 3 ||section == 5){
        if (section == 3 && self.validateTime) {
            return 0.1;
        }
        return 40;
    }
    else{
    
        return 10;
    }
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    
    if (section == 2 || section == 4) {
        
        if (self.validateTime && section == 4) {
            return 0.1;
        }
        return 10;
    }
    return 0.00001;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    if (section == 3 || section == 5) {
        if (section == 3 && self.validateTime) {
            UIView *headView = [[UIView alloc]init];
            headView.backgroundColor = [UIColor clearColor];
            return headView;
        }
        HomeSectionHeaderView *headerView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"homeSection"];
        if (section == 3) {
            headerView.lb_title.text = @"爱心医疗";
        }else if (section == 5){
            headerView.lb_title.text = @"生活服务";
        }
        return headerView;
    }
    
    UIView *headView = [[UIView alloc]init];
    headView.backgroundColor = [UIColor clearColor];
    return headView;
}
//-(CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath
//{
//
//    return UITableViewAutomaticDimension;
//
//}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    
    if (indexPath.section == 0) {

        switch ([getPeopleID socialSate]) {
            case 1:
                if([[NSUserDefaults standardUserDefaults] boolForKey:@"firstlog"]){
                    
                  
                    
                    UIStoryboard *sb  =[UIStoryboard storyboardWithName:@"Main" bundle:nil];



                    socialRecord*vc=[sb instantiateViewControllerWithIdentifier:@"socialRecord"];
                    vc.hidesBottomBarWhenPushed =YES;
                    vc.isHomeVC = YES;
                    [self.navigationController pushViewController:vc animated:YES];
                }else
                {
//                    LoginViewController *logVC =    [LoginViewController sharedInstance];
//                    logVC.hidesBottomBarWhenPushed =YES;
//                    if(![self.navigationController.topViewController isKindOfClass:[logVC class]]) {
//                        [self.navigationController pushViewController:logVC animated:YES];
//                    }
                    LoginVC *loginVC = [[LoginVC alloc]init];
                    UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:loginVC];
                    [self presentViewController:nav animated:YES completion:nil];
                }
                break;
            case 2:
                if([[NSUserDefaults standardUserDefaults] boolForKey:@"firstlog"]){
                    UIStoryboard *sb  =[UIStoryboard storyboardWithName:@"Main" bundle:nil];
                    
                   
                    
                    socialRecord*vc=[sb instantiateViewControllerWithIdentifier:@"socialRecord"];
                    vc.record = 1;
                    vc.isHomeVC = YES;
                    vc.hidesBottomBarWhenPushed =YES;
                    [self.navigationController pushViewController:vc animated:YES];
                }else
                {
//                    LoginViewController *logVC =    [LoginViewController sharedInstance];
//                    logVC.hidesBottomBarWhenPushed =YES;
//                    if(![self.navigationController.topViewController isKindOfClass:[logVC class]]) {
//                        [self.navigationController pushViewController:logVC animated:YES];
//                    }
                    LoginVC *loginVC = [[LoginVC alloc]init];
                    UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:loginVC];
                    [self presentViewController:nav animated:YES completion:nil];
                }
                
                break;
        }
        
    }else if (indexPath.section == 3 || indexPath.section == 4 || indexPath.section == 5 || indexPath.section == 6 || indexPath.section == 7  ){
//        NSString *strURL  =@"";
        switch (indexPath.section) {
            case 3:
                
                //                http://politics.people.com.cn/n1/2017/0730/c1001-29436837.html
                //                strURL =@"https://mp.weixin.qq.com/s/d5m6gTS9M6qhccIBmJuI2w";
                break;
            case 4:
                
                //
                //                strURL =@"https://mp.weixin.qq.com/s/ZSQxoYi0UfcG3FYa6o2xtQ";
                break;
            case 5:
                
                //                strURL =@"https://mp.weixin.qq.com/s/urK_x8JrwbRAYac2WVWOrQ";
                break;
            case 6:
                
                //                strURL =@"https://mp.weixin.qq.com/s/dT-wxr-uR3sTXrXgBIP8AA";
                
                break;
            case 7:
                
                //           strURL=@"https://mp.weixin.qq.com/s/48YXQjhCIjIOk3swZe4Zag";
                break;
            default:
                break;
        }
        
        //        [self jumpToHTML5:strURL andJAnalytics:@"政务信息"];
        
    }else if(indexPath.section == 1){
        
//        WXLaunchMiniProgramReq *launchMiniProgramReq = [WXLaunchMiniProgramReq object];
//        launchMiniProgramReq.userName = @"gh_f8a0e531525d";  //拉起的小程序的username
//        launchMiniProgramReq.path = @"WXMiniPro://gh_f8a0e531525d/pages/base/redirect/index?routeKey=PH04_PRODUCT_TRANSFER_CY&wtagid=118.4.2";    //拉起小程序页面的可带参路径，不填默认拉起小程序首页
//        launchMiniProgramReq.miniProgramType = WXMiniProgramTypeRelease; //拉起小程序的类型
//        [WXApi sendReq:launchMiniProgramReq];
        
        
    }else if(indexPath.section == 2){
        
    }
    
    
    
    
}


#pragma mark - SDCycleScrollViewDelegate
- (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"]) {
                if(![[NSUserDefaults standardUserDefaults] boolForKey:@"firstlog"]){
                                 LoginVC *loginVC = [[LoginVC alloc]init];
                                 UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:loginVC];
                                 [self presentViewController:nav animated:YES completion:nil];
                                 return;
                             }
            }
            
             [GTCountSDK trackCountEvent:@"home_topBannerClick" withArgs:@{}];
            if ([model.title isEqualToString:@"合伙人"]) {
                [self getPartnerQuery];
                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];
        }else if (index == 2){
            
        }
    }
    
}

#pragma mark - MiddleBannerViewCellDelegate
- (void)selectedItemCell:(NSInteger)index
{
    return;
    if (index == 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;
              }
        
        
          
       // 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 {
            LoginVC *loginVC = [[LoginVC alloc]init];
            UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:loginVC];
            [self presentViewController:nav animated:YES completion: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 = @"WXMiniPro://gh_f8a0e531525d/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.urlType == 1) {
        if (index == 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;
        }
          WeakSelf
            if ([model.title isEqualToString:@"智能问诊"]) {
                 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];
                  }
              }];
            } else{
                WebVC * vc = [WebVC new];
                vc.title= model.title;
                vc.url = model.targetUrl;
                vc.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:vc animated:YES];
            }
            
            
            
        }else{
            [self jumpToHTML5:model.targetUrl andJAnalytics:model.title];
        }
         
    }else if (model.urlType == 2){
         if (index == 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;
             }
             
             
            
            
            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 = @"WXMiniPro://gh_f8a0e531525d/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 {
                    LoginVC *loginVC = [[LoginVC alloc]init];
                    UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:loginVC];
                    [self presentViewController:nav animated:YES completion: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];
//                    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 = @"WXMiniPro://gh_f8a0e531525d/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:@{}];
}

#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:[ViewController 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 {
        LoginVC *loginVC = [[LoginVC alloc]init];
        UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:loginVC];
        [self presentViewController:nav animated:YES completion:nil];
    }
    
    
   
}

#pragma mark -
- (void)getUnreadState
{
    
    WeakSelf
    if ([getPeopleID PeopleID])
    {
        NSDictionary *params = @{
                                 @"userId":[NSNumber numberWithInteger:[getPeopleID PeopleID]],
                                 };
        NSString *url =[NSString stringWithFormat:@"%@/socialsecurity/kankan/getUnreadState",IPDIZHI];
        [BaseNetManager POST2:url parameters:params completionHandler:^(id responseObj, NSError *error) {
            
            if (error) {
                //[SVProgressHUD showInfoWithStatus:@"无网络"];
                return ;
            }
            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) {
                            [weakSelf.tabBarController.tabBar showBadgeOnItemIndex:3];
                        }else{
                            [weakSelf.tabBarController.tabBar hideBadgeOnItemIndex:3];
                        }
                        
                        
                    }
                   
                    
                    return ;
                }
            }
            
        
        }];
    }
}



#pragma mark - BMKLocationManagerDelegate
/**
 *  @brief 为了适配app store关于新的后台定位的审核机制（app store要求如果开发者只配置了使用期间定位，则代码中不能出现申请后台定位的逻辑），当开发者在plist配置NSLocationAlwaysUsageDescription或者NSLocationAlwaysAndWhenInUseUsageDescription时，需要在该delegate中调用后台定位api：[locationManager requestAlwaysAuthorization]。开发者如果只配置了NSLocationWhenInUseUsageDescription，且只有使用期间的定位需求，则无需在delegate中实现逻辑。
 *  @param manager 定位 BMKLocationManager 类。
 *  @param locationManager 系统 CLLocationManager 类 。
 *  @since 1.6.0
 */
- (void)BMKLocationManager:(BMKLocationManager * _Nonnull)manager doRequestAlwaysAuthorization:(CLLocationManager * _Nonnull)locationManager{
    
    

}

/**
 *  @brief 当定位发生错误时，会调用代理的此方法。
 *  @param manager 定位 BMKLocationManager 类。
 *  @param error 返回的错误，参考 CLError 。
 */
- (void)BMKLocationManager:(BMKLocationManager * _Nonnull)manager didFailWithError:(NSError * _Nullable)error{
    NSLog(@"百度地图定位失败error:%@",error);
    
}

#pragma mark - GDTRewardedVideoAdDelegate
- (void)gdt_rewardVideoAdDidLoad:(GDTRewardVideoAd *)rewardedVideoAd
{
    [self.rewardVideoAd showAdFromRootViewController:self];
}

/**
 视频播放页关闭回调

 @param rewardedVideoAd GDTRewardVideoAd 实例
 */
- (void)gdt_rewardVideoAdDidClose:(GDTRewardVideoAd *)rewardedVideoAd
{
    
//    NSString *inputValue1 = @"late()";
//    [self.webView evaluateJavaScript:inputValue1 completionHandler:^(id _Nullable response, NSError * _Nullable error) {
//           NSLog(@"value图片: %@ error: %@", response, error);
//     }];
//
    
//    [self getCoinsByWhatVideos:selectActiveModel.activeId];
    
    WXLaunchMiniProgramReq *launchMiniProgramReq = [WXLaunchMiniProgramReq object];
    launchMiniProgramReq.userName = @"gh_f8a0e531525d";  //拉起的小程序的username
    launchMiniProgramReq.path = @"WXMiniPro://gh_f8a0e531525d/pages/base/redirect/index?routeKey=PROMOTION_GIFT_PACKAGE_NEW&activityCode=appDefault&wtagid=118.4.1";    //拉起小程序页面的可带参路径，不填默认拉起小程序首页
    launchMiniProgramReq.miniProgramType = WXMiniProgramTypeRelease; //拉起小程序的类型
    [WXApi sendReq:launchMiniProgramReq completion:^(BOOL success) {
        
    }];
   
}

/**
 视频广告信息点击回调

 @param rewardedVideoAd GDTRewardVideoAd 实例
 */
- (void)gdt_rewardVideoAdDidClicked:(GDTRewardVideoAd *)rewardedVideoAd
{
    
}

/**
 视频广告各种错误信息回调

 @param rewardedVideoAd GDTRewardVideoAd 实例
 @param error 具体错误信息
 */
- (void)gdt_rewardVideoAd:(GDTRewardVideoAd *)rewardedVideoAd didFailWithError:(NSError *)error
{
    
}

/**
 视频广告播放达到激励条件回调

 @param rewardedVideoAd GDTRewardVideoAd 实例
 */
- (void)gdt_rewardVideoAdDidRewardEffective:(GDTRewardVideoAd *)rewardedVideoAd
{
    
}

/**
 视频广告视频播放完成

 @param rewardedVideoAd GDTRewardVideoAd 实例
 */
- (void)gdt_rewardVideoAdDidPlayFinish:(GDTRewardVideoAd *)rewardedVideoAd
{
    
}


#pragma mark - 判断是否处在登录时间内,或者是否有登陆过
- (void)judgeLoginTimeInvalid
{
    WeakSelf
    
     if([[NSUserDefaults standardUserDefaults] boolForKey:@"firstlog"]){
         
            NSString* accountStr = [getPeopleID getDefaultLoginAccount];
            NSString* passwordStr = [getPeopleID getDefaultLoginPassword];
            
            if ([NSString blankString:accountStr] || [NSString blankString:passwordStr]) {
                 [self loginOut];
            }else{
                [[PasswordLoginViewController new]defaultLogin:^(bool success) {
                    
                    if (!success) {
                       [weakSelf loginOut];
                    }
                    
                }];
            }
         
     }
   
    
    return;
    NSDate *loginTime = [getPeopleID getLoginTime];
    NSDate *currentDate = [NSDate date];
    
    if (loginTime == nil || ![self isSameDay:loginTime date2:currentDate]) {
        
        [self loginOut];

    }
}


- (void)loginOut
{
     [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"firstlog"];
     [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"secondImage"];
     [getPeopleID getpeopleLimitedAuthority:NO];
     [getPeopleID socialSate:0];
     [[NSNotificationCenter defaultCenter] postNotificationName:@"ZLAuthenticationAssistant" object:nil userInfo:nil];
   
     //雷俊博退出时清除登录类型和账号密码
     [getPeopleID getLoginType:nil];
     [getPeopleID getLoginAccount:nil];
     [getPeopleID getLoginPassword:nil];
     [getPeopleID getTotalCoins:nil];
     [getPeopleID clearTotalCoins];
     [getPeopleID clearDefaultProvince];
   
   
     [PayUserInfoManager sharedManager].model = nil;
   
     //清除分享时间
     [[NSUserDefaults standardUserDefaults]setObject:nil forKey:@"shareLastTime"];
     //清除最近认证记录
     [[NSUserDefaults standardUserDefaults]setObject:nil forKey:@"ValidationDic"];
     //清除认证成功弹框时间
     [[NSUserDefaults standardUserDefaults]setObject:nil forKey:@"coinsauthenticationLastTime"];
   
     //清除走路赚金币领取时间
     [[NSUserDefaults standardUserDefaults]setObject:nil forKey:@"onFootCoinsDate"];
   
     [[NSUserDefaults standardUserDefaults]synchronize];
    
    LoginVC *loginVC = [[LoginVC alloc]init];
    UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:loginVC];
    [self presentViewController:nav animated:YES completion:nil];
    
    //[self deleterzUserTable];
}
//删除认证表
- (void)deleterzUserTable{
    FMDatabase *db = [FMDatabase databaseWithPath:[self getrzUserDBPath]];
       if ([db open]){
             BOOL res = [db executeUpdate:@"DROP TABLE t_rzUser%ld",[getPeopleID PeopleID]];
           if (res) {
               NSLog(@"表格删除成功");
           }else{
               NSLog(@"表格删除失败");
           }
           [db close];
       }
       
       
}

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

}

#pragma mark - 判断是否是同一天
// 判断是否是同一天
- (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];
}



#pragma mark - 跳转到子视图tabcontroller
- (UITabBarController *)getTabVC
{
    //2.设置窗口的根控制器
      SaveTabBarController *tabBarVC = [[SaveTabBarController alloc] init];
      //添加子控制器
      //默认显示的第一个添加的子控制器的View
      //tabBarVC里面有多少个子控制器,tabBar当中就有多少个平分的按钮
      
      //UITabBarController中的tabBar的内容是有对应按钮的控制器来决定的.
      //tabBar的内容是有对应按钮的控制器的tabBarItem来决定
      
      SaveProductListController *oneVC = [[SaveProductListController alloc] init];
      oneVC.title = @"产品列表";
      oneVC.view.backgroundColor = [UIColor whiteColor];
      oneVC.tabBarItem = [self getCustomItemWithTitle:@"产品列表" image:@"product_unselected" selectedImage:@"product_selected"];
      UINavigationController *nav1 = [[UINavigationController alloc] initWithRootViewController:oneVC];
      [tabBarVC addChildViewController:nav1];
      
      MyAssetsController *twoVC = [[MyAssetsController alloc] init];
      twoVC.title = @"我的资产";
      twoVC.view.backgroundColor = [UIColor whiteColor];
      twoVC.tabBarItem = [self getCustomItemWithTitle:@"我的资产" image:@"myAssets_unselected" selectedImage:@"myAssets_selected"];
      UINavigationController *nav2 = [[UINavigationController alloc] initWithRootViewController:twoVC];
      [tabBarVC addChildViewController:nav2];
      
      
      
      
      //修改主题的颜色
      tabBarVC.tabBar.tintColor = [UIColor colorWithHex:0x137ef6];
    
    
    
    return tabBarVC;
}

- (UITabBarItem *)getCustomItemWithTitle:(NSString *)title image:(NSString *)imageName selectedImage:(NSString *)selectedImageName
{
    UIImage *image = [[UIImage imageNamed:imageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UIImage* selectedImage = [[UIImage imageNamed:selectedImageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
     UITabBarItem *tabbarItem = [[UITabBarItem alloc] initWithTitle:title image:image selectedImage:selectedImage];
    [tabbarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor colorWithHex:0x137ef6], NSForegroundColorAttributeName, nil] forState:UIControlStateSelected];
    
    return tabbarItem;
}

#pragma mark - event response
-(void)vcJumpOtherVc:(NSInteger)row
{
    
    governmentNewsViewController *gVC   =   [[governmentNewsViewController alloc]init];
    gVC.index = row;
    gVC.hidesBottomBarWhenPushed =YES;
    gVC.titleNews = self.newsArray[row][@"titleNews"];
    [self.navigationController pushViewController:gVC  animated:YES];
    
}





-(void)tapImageView
{

}

- (IBAction)jiazaigengduoxinwen:(id)sender {
    
   
}


-(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){
        
        [self jumpToHTML5:@"http://www.mca.gov.cn/" andJAnalytics:@"政务便民"];
        return;
        WXLaunchMiniProgramReq *launchMiniProgramReq = [WXLaunchMiniProgramReq object];
        launchMiniProgramReq.userName = @"gh_f8a0e531525d";  //拉起的小程序的username
        launchMiniProgramReq.path = @"WXMiniPro://gh_f8a0e531525d/pages/base/redirect/index?routeKey=PH04_PRODUCT_TRANSFER_CY&wtagid=118.4.2";    //拉起小程序页面的可带参路径，不填默认拉起小程序首页
        launchMiniProgramReq.miniProgramType = WXMiniProgramTypeRelease; //拉起小程序的类型
        [WXApi sendReq:launchMiniProgramReq completion:^(BOOL success) {
            
        }];
    }
    }else{
//        LoginViewController *logVC =    [LoginViewController sharedInstance];
//        logVC.hidesBottomBarWhenPushed =YES;
//        if(![self.navigationController.topViewController isKindOfClass:[logVC class]]) {
//            [self.navigationController pushViewController:logVC animated:YES];
//        }
        LoginVC *loginVC = [[LoginVC alloc]init];
        UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:loginVC];
        [self presentViewController:nav animated:YES completion:nil];
        
    }
}
-(void)functionAllAnd:(NSString*)all
{
    
    if(![all isEqualToString:@"智慧出行"]){
        [getPeopleID changePlistContentand:all];
    }
    
    
    
    if ([all isEqualToString:@"火车票"]) {
        HUOCHEPIAO
    }else if([all isEqualToString:@"汽车票"]){
        
        QICHIPIAO
        
    }else if([all isEqualToString:@"飞机票"]){
        
        FEIJIPIAO
        
    }else if([all isEqualToString:@"电台"]){
        DIANTAI
        
        
    }else if([all isEqualToString:@"菜谱"]){
        
        
        CAIPU
    }else if([all isEqualToString:@"酒店"]){
        
        JIUDIAN
        
    }else if([all isEqualToString:@"万年历"]){
        
        
        RILI
    }else if([all isEqualToString:@"周边游"]){
        
        ZHOUBIANYOU
    }else if([all isEqualToString:@"运动"]){
        YUNDONG
    }else if([all isEqualToString:@"智慧出行"]){
        
    }else if([all isEqualToString:@"快递查询"]){
        KUAIDI
    }else if([all isEqualToString:@"抢红包"]){
        QIANGHONGBAO
    }else if([all isEqualToString:@"短视频"]){
        
//        VideoVC *vc = [[VideoVC alloc]init];
//        vc.hidesBottomBarWhenPushed = YES;
//        [self.navigationController pushViewController:vc animated:YES];
    }else if ([all isEqualToString:@"诸葛找房"]){
        [self jumpToHTML5:@"http://m.zhuge.com/city/house/?ad_source=cpc_kankanshebao&spread=sem_cpc_kankanshebao" andJAnalytics:@"诸葛找房"];
    }
    
}


#pragma mark - private methods
-(void)initButton:(UIButton*)button{
    
    CGFloat offset = 15.0f;
    button.titleEdgeInsets = UIEdgeInsetsMake(0, -button.imageView.frame.size.width, -button.imageView.frame.size.height-offset/2, 0);
    
    button.imageEdgeInsets = UIEdgeInsetsMake(-button.titleLabel.intrinsicContentSize.height-offset/2, 0, 0, -button.titleLabel.intrinsicContentSize.width);
    
}
- (UIImage*)imageByScalingAndCroppingForSize:(CGSize)targetSize and:(UIImage*)imageKs
{
    UIImage *sourceImage = imageKs;
    UIImage *newImage = nil;
    CGSize imageSize = sourceImage.size;
    CGFloat width = imageSize.width;
    CGFloat height = imageSize.height;
    CGFloat targetWidth = targetSize.width;
    CGFloat targetHeight = targetSize.height;
    CGFloat scaleFactor = 0.0;
    CGFloat scaledWidth = targetWidth;
    CGFloat scaledHeight = targetHeight;
    CGPoint thumbnailPoint = CGPointMake(0.0,0.0);
    
    if (CGSizeEqualToSize(imageSize, targetSize) == NO)
    {
        CGFloat widthFactor = targetWidth / width;
        CGFloat heightFactor = targetHeight / height;
        
        if (widthFactor > heightFactor)
            scaleFactor = widthFactor;
        else
            scaleFactor = heightFactor;
        scaledWidth= width * scaleFactor;
        scaledHeight = height * scaleFactor;
        
        
        if (widthFactor > heightFactor)
        {
            thumbnailPoint.y = (targetHeight - scaledHeight) * 0.5;
        }
        else if (widthFactor < heightFactor)
        {
            thumbnailPoint.x = (targetWidth - scaledWidth) * 0.5;
        }
    }
    
    //UIGraphicsBeginImageContext(targetSize);
    UIGraphicsImageRenderer*re=[[UIGraphicsImageRenderer alloc] initWithSize:targetSize];
    CGRect thumbnailRect = CGRectZero;
    thumbnailRect.origin = thumbnailPoint;
    thumbnailRect.size.width= scaledWidth;
    thumbnailRect.size.height = scaledHeight;
    
    [sourceImage drawInRect:thumbnailRect];
    
    newImage = UIGraphicsGetImageFromCurrentImageContext();
    if(newImage == nil)
        NSLog(@"could not scale image");
    
    
    UIGraphicsEndImageContext();
    return newImage;
}

+ (UIImage *)thumbnailWithImage:(UIImage *)originalImage size:(CGSize)size
{
    
    CGSize originalsize = [originalImage size];
    
    //原图长宽均小于标准长宽的，不作处理返回原图
    
    if (originalsize.width<size.width && originalsize.height<size.height)
        
    {
        
        return originalImage;
        
    }
    
    
    
    //原图长宽均大于标准长宽的，按比例缩小至最大适应值
    
    else if(originalsize.width>size.width && originalsize.height>size.height)
        
    {
        
        CGFloat rate = 1.0;
        
        CGFloat widthRate = originalsize.width/size.width;
        
        CGFloat heightRate = originalsize.height/size.height;
        
        
        
        rate = widthRate>heightRate?heightRate:widthRate;
        
        
        
        CGImageRef imageRef = nil;
        
        
        
        if (heightRate>widthRate)
            
        {
            
            imageRef = CGImageCreateWithImageInRect([originalImage CGImage], CGRectMake(0, originalsize.height/2-size.height*rate/2, originalsize.width, size.height*rate));//获取图片整体部分
            
        }
        
        else
            
        {
            
            imageRef = CGImageCreateWithImageInRect([originalImage CGImage], CGRectMake(originalsize.width/2-size.width*rate/2, 0, size.width*rate, originalsize.height));//获取图片整体部分
            
        }
        
        //UIGraphicsBeginImageContext(size);//指定要绘画图片的大小
        UIGraphicsImageRenderer*re=[[UIGraphicsImageRenderer alloc] initWithSize:size];
        CGContextRef con = UIGraphicsGetCurrentContext();
        
        
        
        CGContextTranslateCTM(con, 0.0, size.height);
        
        CGContextScaleCTM(con, 1.0, -1.0);
        
        
        
        CGContextDrawImage(con, CGRectMake(0, 0, size.width, size.height), imageRef);
        
        
        
        UIImage *standardImage = UIGraphicsGetImageFromCurrentImageContext();
        
        
        
        UIGraphicsEndImageContext();
        
        CGImageRelease(imageRef);
        
        
        
        return standardImage;
        
    }
    
    
    
    
    else if(originalsize.height>size.height || originalsize.width>size.width)
        
    {
        
        CGImageRef imageRef = nil;
        
        
        
        if(originalsize.height>size.height)
            
        {
            
            imageRef = CGImageCreateWithImageInRect([originalImage CGImage], CGRectMake(0, originalsize.height/2-size.height/2, originalsize.width, size.height));
            
        }
        
        else if (originalsize.width>size.width)
            
        {
            
            imageRef = CGImageCreateWithImageInRect([originalImage CGImage], CGRectMake(originalsize.width/2-size.width/2, 0, size.width, originalsize.height));
            
        }
        
        
        
        //UIGraphicsBeginImageContext(size);
        UIGraphicsImageRenderer*re=[[UIGraphicsImageRenderer alloc] initWithSize:size];
        
        
        CGContextRef con = UIGraphicsGetCurrentContext();
        
        CGContextTranslateCTM(con, 0.0, size.height);
        
        CGContextScaleCTM(con, 1.0, -1.0);
        
        
        
        CGContextDrawImage(con, CGRectMake(0, 0, size.width, size.height), imageRef);
        
        
        
        UIImage *standardImage = UIGraphicsGetImageFromCurrentImageContext();
        
        NSLog(@"改变后图片的宽度为%f,图片的高度为%f",[standardImage size].width,[standardImage size].height);
        
        
        
        UIGraphicsEndImageContext();
        
        CGImageRelease(imageRef);
        
        
        
        return standardImage;
        
    }
    
    
    
    
    else
        
    {
        
        return originalImage;
        
    }
    
    
    
}

-(UIImage *)LoadingImageViews:(NSString *)baseImageName
{
    
    NSString  *name = baseImageName;
    NSString  *filePath = [[NSBundle bundleWithPath:[[NSBundle mainBundle] bundlePath]] pathForResource:name ofType:nil];
    NSData  *imageData = [NSData dataWithContentsOfFile:filePath];
    
    if (!self.loadingImageView) {
        self.loadingImageView = [[UIImageView alloc]init];
    }
    self.loadingImageView.backgroundColor = [UIColor clearColor];
    
    
    self.loadingImageView.image = [UIImage sd_animatedGIFWithData:imageData];
    
    return self.loadingImageView.image;
    
}

-(void)getOCR
{
    
#if TARGET_IPHONE_SIMULATOR
    
#else
    Gint ret = 0;
    Gint vaule = 1;
    ret = TREC_StartUP(TREC_GetEngineTimeKEY());
    if (ret == 100) {
        return;
    }
    if (ret == 100) {
        return;
    }if (ret == 101) {
        return;
    }
    
    ret = TREC_SetParam(T_SET_HEADIMG, &vaule);
    ret = TREC_SetSupportEngine(TIDCARD2);// 演示使用身份证，其他证件以此类推
    if (ret != 1) {
        
        TREC_ClearUP();
        return;
    }
    
    ret = TREC_ClearUP();
#endif
    
}


//检测是否安装了支付宝
-(BOOL)ALIisLogin{
    
    if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"alipay://"]]) {
        return YES;
    }
    else {
        //        NSLog(@"未安装");
        return NO;
    }
}

//退出应用
- (void)exitApplication{
    exit(0);
}

/**
 *  判断当前时间是否处于某个时间段内
 *
 *  @param startTime        开始时间
 *  @param expireTime       结束时间
 */

- (BOOL)validateWithStartTime:(NSString *)startTime withExpireTime:(NSString *)expireTime {
    NSDate *today = [NSDate date];
    
    NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
    // 时间格式,此处遇到过坑,建议时间HH大写,手机24小时进制和12小时禁止都可以完美格式化
    [dateFormat setDateFormat:@"yyyy-MM-dd HH:mm"];
    
    NSDate *start = [dateFormat dateFromString:startTime];
    NSDate *expire = [dateFormat dateFromString:expireTime];
    
    if ([today compare:start] == NSOrderedDescending && [today compare:expire] == NSOrderedAscending) {
        return YES;
    }
    return NO;
}



#pragma mark - getters and setters

-(newsViewModel *)viewModel{
    if (!_viewModel) {
        _viewModel =[newsViewModel new ];
    }
    return _viewModel;
}

-(NSMutableArray *)baocun
{
    if (!_baocun) {
        _baocun=[NSMutableArray new];
    }
    return _baocun;
}
-(NSMutableArray *)array_k1
{
    if (!_array_k1) {
        _array_k1 =[NSMutableArray new];
    }
    return _array_k1;
}
-(NSMutableArray *)array_k2
{
    if (!_array_k2) {
        _array_k2 =[NSMutableArray new];
    }
    return _array_k2;
}
-(NSMutableArray *)array_k3
{
    if (!_array_k3) {
        _array_k3 =[NSMutableArray new];
    }
    return _array_k3;
}
-(NSMutableArray *)array_k4
{
    if (!_array_k4) {
        _array_k4 =[NSMutableArray new];
    }
    return _array_k4;
}
-(NSMutableArray *)array_k5
{
    if (!_array_k5) {
        _array_k5 =[NSMutableArray new];
    }
    return _array_k5;
}

-(PostMessageViewModel *)postVM
{
    if (!_postVM) {
        _postVM =[PostMessageViewModel new];
    }
    return _postVM;
    
}

-(NSMutableArray *)arrayP
{
    if (_arrayP) {
        _arrayP =[NSMutableArray new];
    }
    return  _arrayP;
}
-(NSMutableArray *)arrayT
{
    if (!_arrayT) {
        _arrayT=[NSMutableArray new];
    }
    return _arrayT;
}











@end
