//
//  KKTodayProfitViewController.m
//  Open
//
//  Created by 雷俊博 on 2021/8/13.
//  Copyright © 2021 黄江涛 . All rights reserved.
//

#import "KKTodayProfitViewController.h"
#import "Constants.h"

#import "CoinsListItemTableViewCell.h"
#import "CoinsDetailHeaderView.h"

#import "CoinsExchangeVC.h"
#import "WithDrawViewController.h"
#import "OrderProgressViewController.h"

#import "CoinDetailModel.h"
#import "MyWalletListModel.h"

#import "CoinsDetailFooterView.h"

#import "CTAPIBaseManager.h"


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

#import "LittleGoldHouseWebVC.h"

//存钱罐
#import "StatisticsViewController.h"
#import "SaveTabBarController.h"
#import "SaveProductListController.h"
#import "MyAssetsController.h"
#import "LittleGoldHouseWebVC.h"
#import "ProductDetailController.h"
#import "KKActivityRedPackageBaseView.h"
#import "KKCLFundViewController.h"
//摇钱树
//#import <YXLaunchAds/YXLaunchAds.h>

@interface KKTodayProfitViewController ()<UITableViewDelegate,UITableViewDataSource,UIScrollViewDelegate,CoinsDetailHeaderViewDelegate>

@property (nonatomic, strong)UITableView *tableView;
@property (nonatomic, strong)UIButton *btn_gold;
@property (nonatomic, strong)UIButton *btn_Exchange;
@property (nonatomic, strong)CoinsDetailHeaderView *headerView;

@property (nonatomic, strong)NSMutableArray *dataArray;

@property (nonatomic, strong)CoinsDetailFooterView *footerView;

@property (nonatomic, strong)UIView *emptyView;

@end

@implementation KKTodayProfitViewController
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    [self.navigationController setNavigationBarHidden:YES animated:animated];
    [self.navigationController.navigationBar navBarBackGroundColor:[UIColor colorWithHex:0xf98505] image:nil isOpaque:YES];//颜色
         
    [self.navigationController.navigationBar navBarBottomLineHidden:YES];
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self.view addSubview:self.tableView];
    
    [self navConfig];
    
    //[self.view addSubview:self.btn_gold];
    [self.view addSubview:self.btn_Exchange];
    
    if (@available(iOS 11.0, *)) {
        self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }else{
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
    
    [self loadWalletApi];
    
    [self.headerView refreshData];
    [self refreshCoins];
    
    //[self showGuideView];
}

- (void)viewWillLayoutSubviews
{
    [super viewWillLayoutSubviews];
    CGFloat bottomViewHeight = cl_kNavigationBarHeight > 64 ? 55 * WIDTHRADIU  : 44 * WIDTHRADIU;
    
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.offset(0);
        make.top.offset(cl_kNavigationBarHeight);
        make.bottom.offset(-bottomViewHeight);
    }];
    
//    [self.btn_gold mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.offset(0);
//        make.height.offset(bottomViewHeight);
//        make.width.offset(0.3 * ScreenWidth);
//        make.top.equalTo(self.tableView.mas_bottom);
//    }];
    
    [self.btn_Exchange mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.offset(0);
        make.height.offset(bottomViewHeight);
        make.top.equalTo(self.tableView.mas_bottom);
    }];
    
    [self.view layoutIfNeeded];
    
}

- (void)navConfig
{
    UIView*navView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, cl_kNavigationBarHeight)];
    navView.backgroundColor = [UIColor colorWithHex:0xf98505];
    //返回按钮
    UIButton* backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [backBtn setTitle:@"返回" forState:UIControlStateNormal];
    [backBtn setImage:[UIImage imageNamed:@"返回"] forState:UIControlStateNormal];
    [backBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    backBtn.frame = CGRectMake(10, cl_kStatusBarHeight, 60, 44);
    [backBtn layoutButtonWithEdgeInsetsStyle:GLButtonEdgeInsetsStyleLeft imageTitleSpace:4];
    [backBtn addTarget:self action:@selector(backClick:) forControlEvents:UIControlEventTouchUpInside];
    
    
    UILabel* lb_title = [UILabel new];
    lb_title.text = self.title;
    lb_title.font = [UIFont boldSystemFontOfSize:17];
    lb_title.textAlignment = NSTextAlignmentCenter;
    lb_title.textColor = [UIColor whiteColor];
    [navView addSubview:backBtn];
    [navView addSubview:lb_title];
    [lb_title mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(cl_kStatusBarHeight);
        make.centerX.equalTo(navView);
        make.height.offset(44);
    }];
    [self.view addSubview:navView];
}

- (void)showGuideView
{
    
    NSDate *oldTime = [[NSUserDefaults standardUserDefaults]objectForKey:@"GuideYaoQianShu"];

    if (oldTime && [self isSameDay:[NSDate date] date2:oldTime]) {
        return;
    }
    
    NSDate *oldDate = [NSDate date];
    [[NSUserDefaults standardUserDefaults]setObject:oldDate forKey:@"GuideYaoQianShu"];
    [[NSUserDefaults standardUserDefaults]synchronize];
    
    
    WeakSelf
    [GuideAlertView showWithImageName:@"mywallet_yqs" VC:self Block:^(BOOL success) {
        [NetworkRequest statisticsWithEventName:@"mywallet_yqs"];
        [weakSelf goToShakeMoneyTreeVC];
    }];
    return;
}


- (void)refreshCoins
{
    
    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];
        [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"]];
                   
                    [self.headerView refreshData];
                    
                    return ;
                }
            }
            
        
        }];
    }
}


#pragma mark - 查询钱包记录
- (void)loadWalletApi
{
    [SVProgressHUD show];
     WeakSelf
     dispatch_group_t group = dispatch_group_create();
     
     dispatch_queue_t searialQueue = dispatch_queue_create("com.walletlistqueue.www", DISPATCH_QUEUE_SERIAL);
     
     dispatch_group_enter(group);
     dispatch_group_async(group, searialQueue, ^{
         //网络请求1
         if ([getPeopleID PeopleID])
         {
             NSString*tel =  [getPeopleID PeopleIphoneNmber];
             
             tel = [EnercryTool AES256Encrypt:tel key:DESKEY];
             NSDictionary *params = @{
                                      @"userId":[NSNumber numberWithInteger:[getPeopleID PeopleID]],
                                      @"telephone":tel
                                      };
             NSString *url =[NSString stringWithFormat:@"%@userQuery/getTodayProfit",CoinsBaseUrl];
             
            
             
             [BaseNetManager POST2:url parameters:params completionHandler:^(id responseObj, NSError *error) {
                 
                 NSLog(@"钱包记录:responseObj:%@",responseObj);
                 NSLog(@"钱包记录:error:%@",error);
                 if (responseObj) {
                     
                     if ([responseObj[@"code"] isKindOfClass:[NSNumber class]]) {
                         NSNumber *code = (NSNumber *)responseObj[@"code"];
                         if (code.integerValue == 0) {
                             NSArray *array = nil;
                             if ([responseObj[@"result"] isKindOfClass:[NSArray class]])
                             {
                                     array = responseObj[@"result"];
                                             
                             }
                             
                              

                            weakSelf.dataArray = [MyWalletListModel mj_objectArrayWithKeyValuesArray:array];
                         }
                     }
                     
                 }
                 
                 dispatch_group_leave(group);
             }];
         }
     });
     dispatch_group_enter(group);
     dispatch_group_async(group, searialQueue, ^{
         
         //网络请求2
         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];
             [BaseNetManager POST2:url parameters:params completionHandler:^(id responseObj, NSError *error) {
                 NSLog(@"金币刷新接口:responseObj:%@",responseObj);
                 NSLog(@"金币刷新接口:error:%@",error);
                 if (responseObj) {

                     if ([responseObj[@"code"] isKindOfClass:[NSNumber class]]) {
                         NSNumber *code = (NSNumber *)responseObj[@"code"];
                         if (code.integerValue == 0) {
                             [getPeopleID getTotalCoins:responseObj[@"result"]];
                             
                             
                             NSLog(@"取数据:%@",[getPeopleID totalCoins]);
                             
                         }
                     }
                     
                 }
                 
                 dispatch_group_leave(group);
             }];
         }
             
             
        
         
     });
     //2个网络请求结束后,刷新UI
     dispatch_group_notify(group, searialQueue, ^{
         dispatch_async(dispatch_get_global_queue(0, 0), ^{
             dispatch_async(dispatch_get_main_queue(), ^{
                 
                 [SVProgressHUD dismiss];
                 
                 if (weakSelf.dataArray.count > 0) {
                     weakSelf.tableView.tableFooterView = self.footerView;
                 }
                 
                 [weakSelf.tableView reloadData];
                 
               [weakSelf.headerView refreshData];
             
                 
                 
                 
               
                 
             });
         });
     });
}



#pragma mark - CoinsDetailHeaderViewDelegate
- (void)clickBtn
{
    WebVC *webVC = [[WebVC alloc]init];
    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;
    [self.navigationController pushViewController:webVC animated:YES];
    
    //[self goToTVVC:NO];
}

#pragma mark -  UIScrollViewDelegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    if (scrollView == self.tableView) {
        CGFloat offsetY = scrollView.contentOffset.y;
        NSLog(@"%f",offsetY);
        
        if (offsetY <=0) {
            scrollView.contentOffset = CGPointMake(scrollView.contentOffset.x, 0);
        }
    }
}

#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataArray.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CoinsListItemTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    
    cell.type = ListVCTypeMyWallet;
    
    [cell refreshUIWithData:self.dataArray[indexPath.row]];
    
    
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 62*WIDTHRADIU;
}


#pragma mark - event responses
- (void)backClick:(UIButton *)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)btnClick:(UIButton *)sender
{
    
//    WithDrawViewController *vc =[[WithDrawViewController alloc]init];
//    vc.title = @"提现中心";
//    [self.navigationController pushViewController:vc animated:YES];
    
    [self goToTVVC:NO];
   
}

- (void)goldBtnClick:(UIButton *)sender
{
//    [self judgeSaveAmountRequest];
    [[clickEvent instance] clickEventRooterVC:self Content:@"homeThree4" menuName:@"存钱罐"];
}

- (void)goTocoinCostListVC:(UIButton *)btn
{
    CoinsDetailListVC *vc = [[CoinsDetailListVC alloc]init];
    vc.title = @"金币消费";
    vc.type = ListVCTypeCoinsCost;
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
}


//#pragma mark - 判断是否有存款
//- (void)judgeSaveAmountRequest
//{
//    NSString* url = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipYinShuConfig],BCGetSaveAmountRequest];
//    NSLog(@"获取乌当和比财账户存款金额总数量url:%@",url);
//
//    NSMutableDictionary *params = [NetworkPublicParams getBCPublicParams];
//    [params setObject:[getPeopleID PeopleIphoneNmber] forKey:@"loginPhoneNum"];
//
//
//    NSLog(@"params:%@",params);
//    [KKLoadingAnimationView show];
//    [NetworkRequest Post6:url Params:params Success:^(id _Nonnull objc) {
//        [KKLoadingAnimationView dismiss];
//        NSLog(@"objc:%@",objc);
//        NSString *state = [NSString stringWithFormat:@"%@",objc[@"state"]];
//        NSString *describe = [NSString stringWithFormat:@"%@",objc[@"describe"]];
//        if ([state isEqualToString:@"200"]) {
//            NSDictionary *result = objc[@"result"];
//            if ([result isKindOfClass:[NSDictionary class]]) {
//                NSString *sumAmount = [NSString stringWithFormat:@"%@",result[@"sumAmount"]];
//
//
//                if (sumAmount.doubleValue > 0) {
//
//                    SaveTabBarController*tabVC = (SaveTabBarController*)[self getTabVC:YES];
//
//                    [tabVC.navigationController setNavigationBarHidden:YES];
//                    tabVC.hidesBottomBarWhenPushed = YES;
//                    [self.navigationController pushViewController:tabVC animated:YES];
//                }else{
//
////                    LittleGoldHouseWebVC *oneVC = [[LittleGoldHouseWebVC alloc] init];
////                    oneVC.title = @"小金库";
////                    oneVC.view.backgroundColor = [UIColor whiteColor];
////                    oneVC.fromHome = YES;
////                    oneVC.hidesBottomBarWhenPushed = YES;
////                    [self.navigationController pushViewController:oneVC animated:YES];
//                    SaveTabBarController*tabVC = (SaveTabBarController*)[self getTabVC2];
//
//                    [tabVC.navigationController setNavigationBarHidden:YES];
//                    tabVC.hidesBottomBarWhenPushed = YES;
//                    [self.navigationController pushViewController:tabVC animated:YES];
//
//
//                }
//
//
//
//
//            }
//
//        }else{
//            [Tools showMessage:describe];
//        }
//
//    } Failure:^(NSError* error) {
//        [KKLoadingAnimationView dismiss];
//        NSLog(@"error:%@",error);
//
//        [Tools showMessage:@"网络出小差了,请稍后重试"];
//
//    }];
//}



//#pragma mark - 跳转到子视图tabcontroller
//- (UITabBarController *)getTabVC:(BOOL)showBC
//{
//    //2.设置窗口的根控制器
//      SaveTabBarController *tabBarVC = [[SaveTabBarController alloc] init];
//      tabBarVC.showBC = showBC;
//      //添加子控制器
//      //默认显示的第一个添加的子控制器的View
//      //tabBarVC里面有多少个子控制器,tabBar当中就有多少个平分的按钮
//
//      //UITabBarController中的tabBar的内容是有对应按钮的控制器来决定的.
//      //tabBar的内容是有对应按钮的控制器的tabBarItem来决定
//
////    if (showBC) {
////
////        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];
////
////    }else{
////        LittleGoldHouseWebVC *oneVC = [[LittleGoldHouseWebVC alloc] init];
////        oneVC.title = @"小金库";
////        oneVC.view.backgroundColor = [UIColor whiteColor];
////        oneVC.url = @"https://lc.jr.jd.com/ck/xjkHold/index/?channel=a00308";
////        oneVC.tabBarItem = [self getCustomItemWithTitle:@"小金库" image:@"product_unselected" selectedImage:@"product_selected"];
////        UINavigationController *nav1 = [[UINavigationController alloc] initWithRootViewController:oneVC];
////        [tabBarVC addChildViewController:nav1];
////    }
//
//
//    KKCLFundViewController *oneVC = [[KKCLFundViewController 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];
//
//
//
//    LittleGoldHouseWebVC *twoVC = [[LittleGoldHouseWebVC alloc] init];
//    twoVC.title = @"小金库";
//    twoVC.view.backgroundColor = [UIColor whiteColor];
//    twoVC.url = @"https://lc.jr.jd.com/ck/xjkHold/index/?channel=a00308";
//    twoVC.tabBarItem = [self getCustomItemWithTitle:@"小金库" image:@"xiaojinku_unselected" selectedImage:@"xiaojinku_selected"];
//    UINavigationController *nav2 = [[UINavigationController alloc] initWithRootViewController:twoVC];
//    [tabBarVC addChildViewController:nav2];
//
//
//      MyAssetsController *threeVC = [[MyAssetsController alloc] init];
//    threeVC.title = @"其他资产";
//    threeVC.view.backgroundColor = [UIColor whiteColor];
//    threeVC.tabBarItem = [self getCustomItemWithTitle:@"其他资产" image:@"myAssets_unselected" selectedImage:@"myAssets_selected"];
//      UINavigationController *nav3 = [[UINavigationController alloc] initWithRootViewController:threeVC];
//      [tabBarVC addChildViewController:nav3];
//
//
//
//
//      //修改主题的颜色
//      tabBarVC.tabBar.tintColor = [UIColor colorWithHex:0x137ef6];
//
//
//
//    return tabBarVC;
//}
//
//- (UITabBarController *)getTabVC2
//{
//    SaveTabBarController *tabBarVC = [[SaveTabBarController alloc] init];
//
//    KKCLFundViewController *oneVC = [[KKCLFundViewController 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];
//
//
//
//    LittleGoldHouseWebVC *twoVC = [[LittleGoldHouseWebVC alloc] init];
//    twoVC.title = @"小金库";
//    twoVC.view.backgroundColor = [UIColor whiteColor];
//    twoVC.url = @"https://lc.jr.jd.com/ck/xjkHold/index/?channel=a00308";
//    twoVC.tabBarItem = [self getCustomItemWithTitle:@"小金库" image:@"xiaojinku_unselected" selectedImage:@"xiaojinku_selected"];
//    UINavigationController *nav2 = [[UINavigationController alloc] initWithRootViewController:twoVC];
//    [tabBarVC addChildViewController:nav2];
//
//    //修改主题的颜色
//    tabBarVC.tabBar.tintColor = [UIColor colorWithHex:0x137ef6];
//
//
//
//
//    return tabBarVC;
//
//}

#pragma mark - 跳转到小视频
- (void)goToTVVC:(BOOL)fromHome {
    
    KKSVideoViewController *oneVC = [[KKSVideoViewController alloc]initWithType:fromHome];
    oneVC.title = fromHome ?@"看视频" :@"红包视频";
    oneVC.view.backgroundColor = [UIColor whiteColor];
    oneVC.hidesBottomBarWhenPushed = YES;
    
    [self.navigationController pushViewController:oneVC animated:YES];
    
    /*
    KKTabBarViewController *tabBarVC = [[KKTabBarViewController alloc]initWithType:fromHome];
    
    
    LittleVideoViewController *twoVC = [[LittleVideoViewController alloc] init];
    twoVC.title = fromHome ?@"看视频" :@"红包视频";
    twoVC.view.backgroundColor = [UIColor whiteColor];
    twoVC.tabBarItem = [self getCustomItemWithTitle:@"更多" image:@"" selectedImage:@""];
    UINavigationController *nav1 = [[UINavigationController alloc] initWithRootViewController:twoVC];
    [tabBarVC addChildViewController:nav1];
    
    KKVideoViewController *oneVC = [[KKVideoViewController alloc] init];
    oneVC.title = fromHome ?@"看视频" :@"红包视频";
    oneVC.view.backgroundColor = [UIColor whiteColor];
    oneVC.tabBarItem = [self getCustomItemWithTitle:@"小视频" image:@"" selectedImage:@""];
    UINavigationController *nav2 = [[UINavigationController alloc] initWithRootViewController:oneVC];
    [tabBarVC addChildViewController:nav2];
    
    
    
    //tabBarVC.fromHome = fromHome;
    
    
    //修改主题的颜色
    tabBarVC.tabBar.tintColor = [UIColor colorWithHex:0x137ef6];
    
    
    
    [tabBarVC.navigationController setNavigationBarHidden:YES];
    tabBarVC.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:tabBarVC animated:YES];
     
     */
    
}

//- (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];
//    [tabbarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor colorWithHex:0x7a7a7a], NSForegroundColorAttributeName,[UIFont systemFontOfSize:15],NSFontAttributeName, nil] forState:UIControlStateNormal];
//
//    return tabbarItem;
//}


-(void)addShadowToView:(UIView *)theView withColor:(UIColor *)theColor {

    theView.layer.shadowColor = theColor.CGColor;
    theView.layer.shadowOffset = CGSizeMake(-1,-1);
    theView.layer.shadowOpacity = 0.5;
    theView.layer.shadowRadius = 5;
    // 单边阴影 顶边
    float shadowPathWidth = theView.layer.shadowRadius;
    CGRect shadowRect = CGRectMake(0, 0-shadowPathWidth/2.0, theView.bounds.size.width, shadowPathWidth);
    UIBezierPath *path = [UIBezierPath bezierPathWithRect:shadowRect];
    theView.layer.shadowPath = path.CGPath;
}

-(void)addShadow2ToView:(UIView *)theView withColor:(UIColor *)theColor {

    theView.layer.shadowColor = theColor.CGColor;
    theView.layer.shadowOffset = CGSizeMake(1,-1);
    theView.layer.shadowOpacity = 0.5;
    theView.layer.shadowRadius = 5;
    // 单边阴影 顶边
    float shadowPathWidth = theView.layer.shadowRadius;
    CGRect shadowRect = CGRectMake(0, 0-shadowPathWidth/2.0, theView.bounds.size.width, shadowPathWidth);
    UIBezierPath *path = [UIBezierPath bezierPathWithRect:shadowRect];
    theView.layer.shadowPath = path.CGPath;
}


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

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


#pragma mark - 判断是否是同一天
- (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 getters and setters
- (UITableView *)tableView
{
    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
        _tableView.showsHorizontalScrollIndicator = NO;
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        [_tableView registerClass:[CoinsListItemTableViewCell class] forCellReuseIdentifier:@"cell"];
        
        _tableView.tableHeaderView = self.headerView;
        _tableView.tableFooterView = self.emptyView;
    }
    return _tableView;
}

- (UIButton *)btn_gold
{
    if (!_btn_gold) {
        _btn_gold =[UIButton buttonWithType:UIButtonTypeCustom];
        _btn_gold.backgroundColor = [UIColor whiteColor];
        _btn_gold.titleLabel.font = [UIFont systemFontOfSize:15 * WIDTHRADIU];
        [_btn_gold setTitle:@"灵活理财" forState:UIControlStateNormal];
        [_btn_gold addTarget:self action:@selector(goldBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [_btn_gold setTitleColor:[UIColor colorWithHex:0x4d4d4d] forState:UIControlStateNormal];
        _btn_gold.layer.shadowOffset =  CGSizeMake(-2, -1);
        _btn_gold.layer.shadowOpacity = 0.2;
        _btn_gold.layer.shadowColor =  [UIColor blackColor].CGColor;
        
    }
    return _btn_gold;
}

- (UIButton *)btn_Exchange
{
    if (!_btn_Exchange) {
        _btn_Exchange =[UIButton buttonWithType:UIButtonTypeCustom];
        _btn_Exchange.backgroundColor = [UIColor colorWithHex:0xf98505];
        _btn_Exchange.titleLabel.font = [UIFont systemFontOfSize:15 * WIDTHRADIU];
        [_btn_Exchange setTitle:@"去赚钱" forState:UIControlStateNormal];
        [_btn_Exchange addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        _btn_Exchange.layer.shadowOffset =  CGSizeMake(2, -1);
        _btn_Exchange.layer.shadowOpacity = 0.2;
        _btn_Exchange.layer.shadowColor =  [UIColor blackColor].CGColor;
        //_btn_Exchange.hidden = YES;
    }
    return _btn_Exchange;
}

- (CoinsDetailHeaderView *)headerView
{
    if (!_headerView) {
        _headerView = [[CoinsDetailHeaderView alloc]init];
        
        NSDictionary *dic = [getPeopleID totalCoins];
        
        NSNumber *amountMoney = dic[@"amountMoney"];
        
        if (amountMoney.doubleValue > 0) {
            _headerView.frame = CGRectMake(0, 0, ScreenWidth, 125 * WIDTHRADIU);
        }else{
            _headerView.frame = CGRectMake(0, 0, ScreenWidth, 95 * WIDTHRADIU);
        }
               
        
        _headerView.delegate = self;
        _headerView.type = ListVCTypeTodayProfit;
    }
    return _headerView;
}

- (CoinsDetailFooterView *)footerView
{
    if (!_footerView) {
        _footerView = [[CoinsDetailFooterView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 42 * WIDTHRADIU)];
        _footerView.lb_title.text = @"系统仅展示今日收益";
    }
    return _footerView;
}

- (UIView *)emptyView
{
    if (!_emptyView) {
        CGFloat bottomViewHeight = cl_kNavigationBarHeight > 64 ? 55 * WIDTHRADIU  : 44 * WIDTHRADIU;
        _emptyView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight - cl_kNavigationBarHeight - 125 * WIDTHRADIU - bottomViewHeight)];
        
        UIImageView *emptyImg = [[UIImageView alloc]init];
        emptyImg.image = [UIImage imageNamed:@"log_todayprofitEmpty"];
        
        CGFloat emptyHeight = _emptyView.size.height - 151 * WIDTHRADIU;
        
        emptyImg.frame = CGRectMake((ScreenWidth - 180 * WIDTHRADIU)/2.0,1/3.0 * emptyHeight, 180 * WIDTHRADIU, 151 * WIDTHRADIU);
        
        [_emptyView addSubview:emptyImg];
        
    }
    return _emptyView;
}

- (NSMutableArray *)dataArray
{
    if (!_dataArray) {
        _dataArray = [[NSMutableArray alloc]init];
    }
    return _dataArray;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
