// // YOUPAILZVipCoinRechargeVC.m // VQU // // Created by CY on 2021/8/26. // Copyright © 2021 MS. All rights reserved. // #import "YOUPAILZVipCoinRechargeVC.h" #import "YOUPAILZVipCoinRechargeCell.h" #import "YOUPAILCIMSessionVC.h" #import "YOUPAILZVipCoinRechargeModel.h" #import "UIViewController+TFPresent.h" #import "YOUPAILZPaySuccessVC.h" #import "IPAManager.h" @interface YOUPAILZVipCoinRechargeVC () @property (nonatomic,weak) UILabel *youpaipbalanceL; @property (nonatomic,weak) UICollectionView *youpaipcollectionView; @property (nonatomic,strong) NSArray *youpaipdataSource; @property (nonatomic,strong) YOUPAILZVipCoinRechargeModel *youpaipcurrentModel; @property (nonatomic,strong) UIButton *youpaiprechargeBtn; @end @implementation YOUPAILZVipCoinRechargeVC - (void)dealloc{ [[NSNotificationCenter defaultCenter] removeObserver:self]; } - (void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; [self.navigationController.navigationBar setBlackBar]; } - (void)viewWillDisappear:(BOOL)animated{ [super viewWillDisappear:animated]; [self.navigationController.navigationBar setDefaultBar]; } - (UIStatusBarStyle)preferredStatusBarStyle{ return UIStatusBarStyleLightContent; } - (void)youpaifback{ [self.navigationController popViewControllerAnimated:YES]; } - (void)viewDidLoad { [super viewDidLoad]; self.title = @"贵族币充值"; [self youpaifinitUI]; self.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithTarget:self action:@selector(youpaifback) image:[UIImage imageNamed:@"vqu_images_nav_return_white"]]; [self youpaifrequestVipCoinRechargeList]; [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(youpaifApplePaySuccess:) name:@"yqApplePaySuccess" object:nil]; } - (void)youpaifApplePaySuccess:(NSNotification*)noti{ [self youpaifrequestVipCoinRechargeList]; [self youpaifgoPaySuccessVC]; } - (void)youpaifgoPaySuccessVC{ YOUPAILZPaySuccessVC *vc = [[YOUPAILZPaySuccessVC alloc] init]; vc.youpaipcontent = @"恭喜你,充值成功"; [self.navigationController pushViewController:vc animated:YES]; } - (void)youpaifinitUI{ [self.view addLineWithColor:HexColorFromRGB(0x1C1D23) lineRect:CGRectMake(0, NavBarHeight, KScreenWidth, ScaleSize(92.0f))]; UIImageView *balanceBgV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"vqu_images_ic_vip_coin_recharge_bg"]]; balanceBgV.userInteractionEnabled = YES; [self.view addSubview:balanceBgV]; [balanceBgV mas_makeConstraints:^(MASConstraintMaker *make) { make.left.offset(ScaleSize(14.0f)); make.top.offset(NavBarHeight + ScaleSize(10.0f)); make.right.offset(ScaleSize(-14.0f)); make.height.offset(ScaleSize(82.0f)); }]; UILabel *coinDescL = [[UILabel alloc] init]; coinDescL.text = @"贵族币余额"; coinDescL.textColor = HexColorFromRGB(0xFDCC88); coinDescL.font = LCFont(ScaleSize(14.0f)); [balanceBgV addSubview:coinDescL]; [coinDescL mas_makeConstraints:^(MASConstraintMaker *make) { make.left.top.offset(ScaleSize(14.0f)); }]; UILabel *balanceL = [[UILabel alloc] init]; balanceL.text = @"0"; balanceL.textColor = HexColorFromRGB(0xFDCC88); balanceL.font = LCFont(ScaleSize(36.0f)); [balanceBgV addSubview:balanceL]; self.youpaipbalanceL = balanceL; [balanceL mas_makeConstraints:^(MASConstraintMaker *make) { make.left.offset(ScaleSize(14.0f)); make.top.equalTo(coinDescL.mas_bottom).offset(ScaleSize(6.0f)); }]; UIButton *serviceBtn = [UIButton buttonWithType:UIButtonTypeCustom]; serviceBtn.layer.cornerRadius = ScaleSize(27.0f) / 2.0f; serviceBtn.clipsToBounds = YES; [serviceBtn setTitle:LCStr(word34) forState:UIControlStateNormal];//@"人工通道" [serviceBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; serviceBtn.titleLabel.font = LCFont12; serviceBtn.backgroundColor = HexColorFromRGB(0x4F4B5B); [serviceBtn addTarget:self action:@selector(youpaifserviceBtnClick) forControlEvents:UIControlEventTouchUpInside]; [balanceBgV addSubview:serviceBtn]; [serviceBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(balanceBgV); make.right.offset(ScaleSize(-12.0f)); make.size.mas_offset(CGSizeMake(ScaleSize(76.0f), ScaleSize(27.0f))); }]; if ([LCSaveData getWhiteVersion]) { serviceBtn.hidden = YES; } UIView *footerBgV = [[UIView alloc] init]; footerBgV.backgroundColor = [UIColor whiteColor]; [self.view addSubview:footerBgV]; [footerBgV mas_makeConstraints:^(MASConstraintMaker *make) { make.left.bottom.right.offset(0.0f); make.height.offset(30.0f+SafeHeight+48.0f+10.0f); }]; UIButton *rechargeBtn = [UIButton buttonWithType:UIButtonTypeCustom]; rechargeBtn.layer.cornerRadius = 24.0f; rechargeBtn.clipsToBounds = YES; [rechargeBtn setTitle:@"立即充值" forState:UIControlStateNormal]; [rechargeBtn setTitleColor:HexColorFromRGB(0x75170A) forState:UIControlStateNormal]; rechargeBtn.titleLabel.font = LCFont16; [rechargeBtn setBackgroundImage:[LCTools ColorImage:CGSizeMake(KScreenWidth - 80.0f, 48.0f) FromColors:@[HexColorFromRGB(0xFBD893),HexColorFromRGB(0xD66F47)] ByGradientType:GradientTopToBottom] forState:UIControlStateNormal]; [rechargeBtn addTarget:self action:@selector(youpaifrechargeBtnClick) forControlEvents:UIControlEventTouchUpInside]; [footerBgV addSubview:rechargeBtn]; self.youpaiprechargeBtn = rechargeBtn; [rechargeBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.top.offset(10.0f); make.centerX.equalTo(footerBgV); make.size.mas_offset(CGSizeMake(KScreenWidth - 80.0f, 48.0f)); }]; UIView *centerBgV = [[UIView alloc] init]; centerBgV.backgroundColor = [UIColor whiteColor]; [self.view addSubview:centerBgV]; [centerBgV mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.offset(0.0f); make.top.equalTo(balanceBgV.mas_bottom).offset(0.0f); make.bottom.equalTo(footerBgV.mas_top).offset(0.0f); }]; UILabel *rechargeDescL = [[UILabel alloc] init]; rechargeDescL.text = @"请选择充值金额:"; rechargeDescL.textColor = LZA3AABEColor; rechargeDescL.font = LCFont(ScaleSize(12.0f)); [centerBgV addSubview:rechargeDescL]; [rechargeDescL mas_makeConstraints:^(MASConstraintMaker *make) { make.left.offset(ScaleSize(14.0f)); make.top.offset(ScaleSize(38.0f)); }]; UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init]; flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical; flowLayout.itemSize = CGSizeMake((KScreenWidth - ScaleSize(33.0f)) / 2.0f, ScaleSize(74.0f)); flowLayout.minimumLineSpacing = ScaleSize(5.0f); flowLayout.minimumInteritemSpacing = ScaleSize(5.0f); flowLayout.sectionInset = UIEdgeInsetsMake(0.0f, ScaleSize(14.0f), 0.0f, ScaleSize(14.0f)); UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:flowLayout]; collectionView.backgroundColor = [UIColor clearColor]; collectionView.alwaysBounceVertical = YES; collectionView.delegate = self; collectionView.dataSource = self; [collectionView registerClass:YOUPAILZVipCoinRechargeCell.class forCellWithReuseIdentifier:@"cell"]; [collectionView registerClass:UICollectionReusableView.class forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"footer"]; collectionView.showsVerticalScrollIndicator = NO; collectionView.showsHorizontalScrollIndicator = NO; [centerBgV addSubview:collectionView]; self.youpaipcollectionView = collectionView; [collectionView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.bottom.right.offset(0.0f); make.top.equalTo(rechargeDescL.mas_bottom).offset(ScaleSize(12.0f)); }]; } - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{ return 1; } - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{ return self.youpaipdataSource.count; } - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ YOUPAILZVipCoinRechargeCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath]; [cell youpaifreloadWithModel:self.youpaipdataSource[indexPath.item]]; return cell; } - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath { UICollectionReusableView *reusableview = nil; if (kind == UICollectionElementKindSectionFooter){ reusableview = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"footer" forIndexPath:indexPath]; for (UIView *subV in reusableview.subviews) { [subV removeFromSuperview]; } UILabel *lab = [[UILabel alloc] init]; lab.numberOfLines = 0; lab.textColor = LZ273145Color; lab.font = LCFont(ScaleSize(12.0f)); lab.text =LCStr(word35);// @"为方便大额用户,贵族币与人民币比例为1:1\n可以用于购买贵族、兑换钻石"; [reusableview addSubview:lab]; [lab mas_makeConstraints:^(MASConstraintMaker *make) { make.top.offset(ScaleSize(16.0f)); make.left.offset(ScaleSize(26.0f)); make.right.offset(ScaleSize(-26.0f)); }]; if ([LCSaveData getWhiteVersion]) { lab.hidden = YES; } } return reusableview; } - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section { return CGSizeMake(KScreenWidth,ScaleSize(66.0f)); //查看跟多群成员 } - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{ self.youpaipcurrentModel.youpaipisSelected = NO; self.youpaipcurrentModel = self.youpaipdataSource[indexPath.item]; self.youpaipcurrentModel.youpaipisSelected = YES; [self.youpaipcollectionView reloadData]; } - (void)youpaifrequestVipCoinRechargeList{ @weakify(self); [LCHttpHelper requestWithURLString:GetNobleCoin parameters:@{} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) { @strongify(self); NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code == 0) { NSInteger user_noble_coin = [[[dict objectForKey:@"data"]objectForKey:@"user_noble_coin"] integerValue]; NSArray *recharge_coin = [[dict objectForKey:@"data"]objectForKey:@"recharge_coin"]; self.youpaipbalanceL.text = [NSString stringWithFormat:@"%@",@(user_noble_coin)]; self.youpaipdataSource = [YOUPAILZVipCoinRechargeModel mj_objectArrayWithKeyValuesArray:recharge_coin]; if (self.youpaipdataSource.count != 0) { self.youpaipcurrentModel = self.youpaipdataSource[0]; self.youpaipcurrentModel.youpaipisSelected = YES; } [self.youpaipcollectionView reloadData]; } } failure:^(NSError *error) { }]; } - (void)youpaifserviceBtnClick{ NIMSession *session = [NIMSession session:@"4" type:NIMSessionTypeP2P]; @weakify(self); [ZCHUDHelper show]; [[[NIMSDK sharedSDK] userManager] fetchUserInfos:@[session.sessionId] completion:^(NSArray * _Nullable users, NSError * _Nullable error) { @strongify(self); [ZCHUDHelper dismiss]; YOUPAILCIMSessionVC *vc = [[YOUPAILCIMSessionVC alloc] initWithSession:session]; [self.navigationController pushViewController:vc animated:YES]; }]; } - (void)youpaifrechargeBtnClick{ if (self.youpaipcurrentModel != nil) { [self applePay]; } } - (void)applePay{ self.youpaiprechargeBtn.userInteractionEnabled = NO; /// 内购 [ZCHUDHelper showWithStatus:@"支付中..."]; NSLog(@"%@",self.youpaipcurrentModel.ios_product_id); [[IPAManager shareIAPManager] startPurchWithID:self.youpaipcurrentModel.ios_product_id completeHandle:^(IAPPurchType type, NSString *data) { if (type == IAPPurchSuccess) { [LCSaveData saveReceiptData:data]; [self requestApplePayBack:data]; }else{ dispatch_async(dispatch_get_main_queue(), ^{ self.youpaiprechargeBtn.userInteractionEnabled = YES; }); NSString *title = @""; switch (type) { case IAPPurchFailed: title = @"购买失败"; break; case IAPPurchCancle: title = @"已取消购买"; break; case IAPPurchVerFailed: title = @"订单校验失败"; break; // case IAPPurchVerSuccess: // NSLog(@"订单校验成功"); // break; case IAPPurchNotArrow: title = @"不允许程序内付费"; break; default: break; } if (title.length == 0) { [ZCHUDHelper dismiss]; }else{ [ZCHUDHelper showTitle:title]; } } }]; } - (void)requestApplePayBack:(NSString *)receipt_data{ NSLog(@"receipt_data == %@",receipt_data); [LCHttpHelper requestWithURLString:ApplePayBack parameters:@{@"receipt_data":receipt_data} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) { NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; dispatch_async(dispatch_get_main_queue(), ^{ self.youpaiprechargeBtn.userInteractionEnabled = YES; }); if (code == 0) { [LCSaveData removeReceiptData:receipt_data]; NSInteger type = 2; if (![LCSaveData getOnlineVersion]) { type = 4; } [self youpaifrequestVipCoinRechargeList]; } [ZCHUDHelper showTitle:[dict objectForKey:@"message"]]; } failure:^(NSError *error) { dispatch_async(dispatch_get_main_queue(), ^{ self.youpaiprechargeBtn.userInteractionEnabled = YES; }); [ZCHUDHelper showTitle:error.localizedDescription]; }]; } @end