// // YOUPAILZVipDetailsVC.m // VQU // // Created by CY on 2021/8/20. // Copyright © 2021 MS. All rights reserved. // #import "YOUPAILZVipDetailsVC.h" #import "YOUPAILZVipHeaderView.h" #import "YOUPAILZVipPrivilegeCell.h" #import "YOUPAILZVipInfoModel.h" #import "YOUPAILZVipFooterView.h" #import "YOUPAILZVipPayWindow.h" #import "UIViewController+TFPresent.h" #import "YOUPAILZVipCoinWalletVC.h" #import "YOUPAILZVipNobleWindow.h" #import #import #import "IPAManager.h" #import "YOUPAILZPaySuccessVC.h" #import "YOUPAILCIMSessionVC.h" #define LZVipHeaderViewSize CGSizeMake(KScreenWidth,ScaleSize(318.0f)) @interface YOUPAILZVipDetailsVC () @property (nonatomic,weak) UICollectionView *youpaipcollectionView; @property (nonatomic,weak) YOUPAILZVipFooterView *youpaipfooterView; @property (nonatomic,strong) YOUPAILZVipInfoModel *youpaipmodel; @property (nonatomic, strong) SVGAPlayer *youpaipsvgaPlayer; @property (nonatomic, strong) SVGAParser *youpaipparser; @property (nonatomic, strong) NSString *paySuccessStr; @end @implementation YOUPAILZVipDetailsVC - (void)dealloc{ [[NSNotificationCenter defaultCenter] removeObserver:self]; } - (void)viewDidLoad { [super viewDidLoad]; [self youpaifinitUI]; [self youpaifrequestVipInfo]; [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(youpaifApplePaySuccess:) name:@"yqApplePaySuccess" object:nil]; } - (void)youpaifApplePaySuccess:(NSNotification*)noti{ [self youpaifrequestVipInfo]; } - (void)youpaifinitUI{ YOUPAILZVipFooterView *footerView = [[YOUPAILZVipFooterView alloc] init]; footerView.backgroundColor = [UIColor colorWithPatternImage:[LCTools ColorImage:CGSizeMake(KScreenWidth, 70.0f + SafeHeight) FromColors:@[HexColorFromRGB(0xFBD893),HexColorFromRGB(0xD66F47)] ByGradientType:GradientTopToBottom]]; @weakify(self); [footerView setPayBlock:^{ @strongify(self); if ([self.youpaipmodel.youpaippay_info.youpaipstatus isEqual:@"none"]) {//开通 [self youpaifpayModeWithModel:self.youpaipmodel]; }else if ([self.youpaipmodel.youpaippay_info.youpaipstatus isEqual:@"activity"]){//活动开通 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]; }]; }else{//续费 YOUPAILZVipPayWindow *window = [[YOUPAILZVipPayWindow alloc] init]; window.youpaipvipId = self.youpaipvipId; [window setPayBlock:^(YOUPAILZVipRenewModel * _Nonnull model) { @strongify(self); [self youpaifpayModeWithModel:model]; }]; [self TFPresentVC:window completion:^{}]; } }]; [self.view addSubview:footerView]; self.youpaipfooterView = footerView; [footerView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.bottom.offset(0.0f); make.height.offset(70.0f + SafeHeight); }]; UICollectionViewFlowLayout * flowLayout = [[UICollectionViewFlowLayout alloc] init]; flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical; flowLayout.minimumInteritemSpacing = 20.0f; flowLayout.minimumLineSpacing = 20.0f; CGFloat width = (KScreenWidth - 60.0f) / 3.0f; CGFloat height = width * 1.f; flowLayout.itemSize = CGSizeMake(width, height); flowLayout.sectionInset = UIEdgeInsetsMake(0.0f, 10.0f, 10.0f, 10.0f); UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:flowLayout]; collectionView.backgroundColor = HexColorFromRGB(0x2A2935); collectionView.alwaysBounceVertical = YES; collectionView.delegate = self; collectionView.dataSource = self; [collectionView registerClass:YOUPAILZVipPrivilegeCell.class forCellWithReuseIdentifier:@"cell"]; [collectionView registerClass:YOUPAILZVipHeaderView.class forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"header"]; [self.view addSubview:collectionView]; self.youpaipcollectionView = collectionView; [collectionView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.top.offset(0.0f); make.bottom.equalTo(footerView.mas_top); }]; self.youpaipsvgaPlayer = [[SVGAPlayer alloc] init]; self.youpaipsvgaPlayer.contentMode = UIViewContentModeScaleAspectFit; self.youpaipsvgaPlayer.delegate = self; [self.view addSubview:self.youpaipsvgaPlayer]; [self.youpaipsvgaPlayer mas_makeConstraints:^(MASConstraintMaker *make) { make.left.top.bottom.right.offset(0.0f); }]; UITapGestureRecognizer *panGes = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(youpaiftouchCarClick)]; [self.youpaipsvgaPlayer addGestureRecognizer:panGes]; self.youpaipsvgaPlayer.hidden = YES; self.youpaipsvgaPlayer.loops = 1; self.youpaipsvgaPlayer.clearsAfterStop = true; self.youpaipparser = [[SVGAParser alloc] init]; } - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{ return 1; } - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{ return self.youpaipmodel.youpaipprivilege.count; } - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ YOUPAILZVipPrivilegeCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath]; [cell youpaifreloadWithModel:self.youpaipmodel.youpaipprivilege[indexPath.item]]; return cell; } - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section { return LZVipHeaderViewSize; } - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath { UICollectionReusableView *reusableview = nil; if (kind == UICollectionElementKindSectionHeader){ YOUPAILZVipHeaderView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"header" forIndexPath:indexPath]; [headerView youpaifreloadWithModel:self.youpaipmodel]; @weakify(self); [headerView setClickVipCoinBlock:^{ @strongify(self); if(self.youpaipmodel != nil){ YOUPAILZVipCoinWalletVC *walletVC = [[YOUPAILZVipCoinWalletVC alloc] init]; [self.navigationController pushViewController:walletVC animated:YES]; } }]; [headerView setClickCarBlock:^{ @strongify(self); [self.youpaipsvgaPlayer stopAnimation]; self.youpaipsvgaPlayer.hidden = YES; if (self.youpaipmodel.youpaipcar.youpaipbig_preview_img.length != 0) { self.youpaipsvgaPlayer.hidden = NO; } NSString* svgaName = [[self.youpaipmodel.youpaipcar.youpaipbig_preview_img componentsSeparatedByString:@"/"] lastObject]; NSString* svgaCanchesPath= [[NSString alloc]initWithFormat:@"%@/%@/%@",CachesPath,@"SVGA",svgaName]; if (![LCTools giftSVGAWithSvgaUrlStr:self.youpaipmodel.youpaipcar.youpaipbig_preview_img]){ NSString* urlStr = [NSString stringWithFormat:@"%@/%@",[LCSaveData getImageUrl]?[LCSaveData getImageUrl]:BaseImgUrl,self.youpaipmodel.youpaipcar.youpaipbig_preview_img]; @weakify(self); [self.youpaipparser parseWithURLRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlStr]] completionBlock:^(SVGAVideoEntity * _Nullable videoItem) { @strongify(self); if (videoItem != nil) { self.youpaipsvgaPlayer.videoItem = videoItem; [self.youpaipsvgaPlayer startAnimation]; } } failureBlock:^(NSError * _Nullable error) { @strongify(self); self.youpaipsvgaPlayer.hidden = YES; }]; [LCTools giftSVGAWithSvgaUrlStr:self.youpaipmodel.youpaipcar.youpaipbig_preview_img]; }else{ @weakify(self); [self.youpaipparser parseWithData:[LCTools giftSVGAWithSvgaUrlStr:self.youpaipmodel.youpaipcar.youpaipbig_preview_img] cacheKey:svgaCanchesPath completionBlock:^(SVGAVideoEntity * _Nonnull videoItem) { @strongify(self); if (videoItem != nil) { self.youpaipsvgaPlayer.videoItem = videoItem; [self.youpaipsvgaPlayer startAnimation]; } } failureBlock:^(NSError * _Nonnull error) { @strongify(self); self.youpaipsvgaPlayer.hidden = YES; }]; } }]; reusableview = headerView; } return reusableview; } - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{ if (![LCSaveData getWhiteVersion]) { YOUPAILZVipPrivilegeModel *model = self.youpaipmodel.youpaipprivilege[indexPath.item]; if (model.youpaipis_show == 1) { YOUPAILZVipNobleWindow *window = [[YOUPAILZVipNobleWindow alloc] init]; window.isTouchDismiss = YES; window.youpaipimageHeight = model.youpaipheight; window.youpaipimagePath = model.youpaipshow_img; [self TFPresentVC:window completion:^{}]; } } } //- (void)youpaifpayModeWithModel:(id)model{ // NSString *price = @""; // NSString *vipId = @""; // NSString *type = @""; // NSString *paySuccessStr = @""; // if ([model isKindOfClass:[YOUPAILZVipInfoModel class]]) { // YOUPAILZVipInfoModel *infoModel = model; // price = infoModel.youpaippay_info.youpaipprice; // vipId = infoModel.youpaipnoble.youpaipid; // type = infoModel.youpaippay_info.youpaipstatus; // paySuccessStr = [NSString stringWithFormat:@"恭喜你,成为%@贵族!",infoModel.youpaipnoble.youpaipname]; // }else{ // YOUPAILZVipRenewModel *infoModel = model; // price = infoModel.youpaippay_info.youpaipprice; // vipId = infoModel.youpaipid; // type = infoModel.youpaippay_info.youpaipstatus; // paySuccessStr = [NSString stringWithFormat:@"恭喜你,成为%@贵族!",infoModel.youpaipname]; // } // // VQ_LZPayModeChooseVC *vc = [[VQ_LZPayModeChooseVC alloc] init]; // vc.youpaipmoney = [price integerValue]; // vc.youpaipapi = VipPay; // vc.youpaipparams = @{@"id":vipId,@"type":type}; // vc.youpaippaySuccessStr = paySuccessStr; // [self.navigationController pushViewController:vc animated:YES]; //} - (void)youpaifpayModeWithModel:(id)model{ NSString *ios_product_id = @""; if ([model isKindOfClass:[YOUPAILZVipInfoModel class]]) { YOUPAILZVipInfoModel *infoModel = model; ios_product_id = infoModel.youpaippay_info.youpaipios_product_id; self.paySuccessStr = [NSString stringWithFormat:@"恭喜你,成为%@贵族!",infoModel.youpaipnoble.youpaipname]; }else{ YOUPAILZVipRenewModel *infoModel = model; ios_product_id = infoModel.youpaippay_info.youpaipios_product_id; self.paySuccessStr = [NSString stringWithFormat:@"恭喜你,成为%@贵族!",infoModel.youpaipname]; } [self applePay:ios_product_id]; } - (void)applePay:(NSString *)ios_product_id{ // self.rechargeBtn.userInteractionEnabled = NO; /// 内购 [ZCHUDHelper showWithStatus:@"支付中..."]; NSLog(@"%@",ios_product_id); [[IPAManager shareIAPManager] startPurchWithID: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.rechargeBtn.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.rechargeBtn.userInteractionEnabled = YES; // }); if (code == 0) { [LCSaveData removeReceiptData:receipt_data]; NSInteger type = 2; if (![LCSaveData getOnlineVersion]) { type = 4; } [[NSNotificationCenter defaultCenter]postNotificationName:@"yqApplePaySuccess" object:nil userInfo:nil]; [self youpaifrequestVipInfo]; } [ZCHUDHelper showTitle:[dict objectForKey:@"message"]]; } failure:^(NSError *error) { // dispatch_async(dispatch_get_main_queue(), ^{ // self.rechargeBtn.userInteractionEnabled = YES; // }); [ZCHUDHelper showTitle:error.localizedDescription]; }]; } - (void)goPaySuccessVC{ YOUPAILZPaySuccessVC *vc = [[YOUPAILZPaySuccessVC alloc] init]; vc.youpaipcontent = self.paySuccessStr; NSMutableArray * newvcs = [NSMutableArray array]; for (UIViewController *vcont in self.navigationController.viewControllers) { if ([vcont isKindOfClass:self.class]) { break; }else{ [newvcs addObject:vcont]; } } [newvcs addObject:vc]; [self.navigationController setViewControllers:newvcs animated:YES]; [self youpaifrefreshData]; } - (void)youpaifrefreshData{ [LCHttpHelper requestWithURLString:UserCenter parameters:nil needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) { NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code==0) {//成功 NSDictionary *anchor = [[dict objectForKey:@"data"]objectForKey:@"anchor"]; NSDictionary *info = [[dict objectForKey:@"data"]objectForKey:@"userinfo"]; if ([[anchor allKeys] containsObject:@"open_video_status"]) { if ([[anchor objectForKey:@"open_video_status"] integerValue] == 0) {//0 未开启 1 已开启 [LCSaveData saveVideoOpenStatu:NO]; }else{ [LCSaveData saveVideoOpenStatu:YES]; } } if ([[anchor allKeys] containsObject:@"order_switch"]) { if ([[anchor objectForKey:@"order_switch"] integerValue] == 1) {//1隐藏 2不隐藏 [LCSaveData saveOrderOpenStatu:YES]; }else{ [LCSaveData saveOrderOpenStatu:NO]; } } if ([[info allKeys] containsObject:@"is_msg_refuse"]) { if ([[info objectForKey:@"is_msg_refuse"] integerValue] == 1) {//1开启 0关闭 [LCSaveData saveProfileWuraoStatus:YES]; }else{ [LCSaveData saveProfileWuraoStatus:NO]; } } YOUPAILCBaseInfo* userinfo = [YOUPAILCBaseInfo mj_objectWithKeyValues:[[dict objectForKey:@"data"]objectForKey:@"userinfo"]]; if (userinfo.youpaipalbum_list_new.count>0) { NSMutableArray *arrm = [NSMutableArray new]; [userinfo.youpaipalbum_list_new enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { album_list_newModel *model = [album_list_newModel mj_objectWithKeyValues:obj]; [arrm addObject:model]; }]; userinfo.youpaipalbum_list_new = arrm; } YOUPAILCUserModel* userModel = [LCSaveModel getUserModel]; userModel.youpaipuserinfo = userinfo; [LCSaveModel saveUserModel:userModel]; } } failure:^(NSError *error) { }]; } - (void)youpaifrequestVipInfo{ @weakify(self); [LCHttpHelper requestWithURLString:VipDetails parameters:@{@"noble_id":self.youpaipvipId} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) { @strongify(self); NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code == 0) {//成功 self.youpaipmodel = [YOUPAILZVipInfoModel mj_objectWithKeyValues:dict[@"data"]]; [self.youpaipcollectionView reloadData]; NSString *status = dict[@"data"][@"red_dot"][@"is_watch_setting"]; [[NSNotificationCenter defaultCenter]postNotificationName:@"changeRedDotStatus" object:nil userInfo:@{@"redDot":status}]; [self.youpaipfooterView youpaifreloadWithModel:self.youpaipmodel]; } } failure:^(NSError *error) { }]; } #pragma mark - SVGAPlayerDelegate - (void)svgaPlayerDidFinishedAnimation:(SVGAPlayer *)player{ [self.youpaipsvgaPlayer stopAnimation]; self.youpaipsvgaPlayer.hidden = YES; } - (void)youpaiftouchCarClick{ [self.youpaipsvgaPlayer stopAnimation]; self.youpaipsvgaPlayer.hidden = YES; } #pragma mark - JXCategoryListContentViewDelegate - (UIView *)listView{ return self.view; } @end