YOUPAILZVipDetailsVC.m 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  1. //
  2. // YOUPAILZVipDetailsVC.m
  3. // VQU
  4. //
  5. // Created by CY on 2021/8/20.
  6. // Copyright © 2021 MS. All rights reserved.
  7. //
  8. #import "YOUPAILZVipDetailsVC.h"
  9. #import "YOUPAILZVipHeaderView.h"
  10. #import "YOUPAILZVipPrivilegeCell.h"
  11. #import "YOUPAILZVipInfoModel.h"
  12. #import "YOUPAILZVipFooterView.h"
  13. #import "YOUPAILZVipPayWindow.h"
  14. #import "UIViewController+TFPresent.h"
  15. #import "YOUPAILZVipCoinWalletVC.h"
  16. #import "YOUPAILZVipNobleWindow.h"
  17. #import <SVGAPlayer.h>
  18. #import <SVGAParser.h>
  19. #import "IPAManager.h"
  20. #import "YOUPAILZPaySuccessVC.h"
  21. #import "YOUPAILCIMSessionVC.h"
  22. #define LZVipHeaderViewSize CGSizeMake(KScreenWidth,ScaleSize(318.0f))
  23. @interface YOUPAILZVipDetailsVC () <UICollectionViewDelegate,UICollectionViewDataSource,SVGAPlayerDelegate>
  24. @property (nonatomic,weak) UICollectionView *youpaipcollectionView;
  25. @property (nonatomic,weak) YOUPAILZVipFooterView *youpaipfooterView;
  26. @property (nonatomic,strong) YOUPAILZVipInfoModel *youpaipmodel;
  27. @property (nonatomic, strong) SVGAPlayer *youpaipsvgaPlayer;
  28. @property (nonatomic, strong) SVGAParser *youpaipparser;
  29. @property (nonatomic, strong) NSString *paySuccessStr;
  30. @end
  31. @implementation YOUPAILZVipDetailsVC
  32. - (void)dealloc{
  33. [[NSNotificationCenter defaultCenter] removeObserver:self];
  34. }
  35. - (void)viewDidLoad {
  36. [super viewDidLoad];
  37. [self youpaifinitUI];
  38. [self youpaifrequestVipInfo];
  39. [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(youpaifApplePaySuccess:) name:@"yqApplePaySuccess" object:nil];
  40. }
  41. - (void)youpaifApplePaySuccess:(NSNotification*)noti{
  42. [self youpaifrequestVipInfo];
  43. }
  44. - (void)youpaifinitUI{
  45. YOUPAILZVipFooterView *footerView = [[YOUPAILZVipFooterView alloc] init];
  46. footerView.backgroundColor = [UIColor colorWithPatternImage:[LCTools ColorImage:CGSizeMake(KScreenWidth, 70.0f + SafeHeight) FromColors:@[HexColorFromRGB(0xFBD893),HexColorFromRGB(0xD66F47)] ByGradientType:GradientTopToBottom]];
  47. @weakify(self);
  48. [footerView setPayBlock:^{
  49. @strongify(self);
  50. if ([self.youpaipmodel.youpaippay_info.youpaipstatus isEqual:@"none"]) {//开通
  51. [self youpaifpayModeWithModel:self.youpaipmodel];
  52. }else
  53. if ([self.youpaipmodel.youpaippay_info.youpaipstatus isEqual:@"activity"]){//活动开通
  54. NIMSession *session = [NIMSession session:@"4" type:NIMSessionTypeP2P];
  55. @weakify(self);
  56. [ZCHUDHelper show];
  57. [[[NIMSDK sharedSDK] userManager] fetchUserInfos:@[session.sessionId] completion:^(NSArray<NIMUser *> * _Nullable users, NSError * _Nullable error) {
  58. @strongify(self);
  59. [ZCHUDHelper dismiss];
  60. YOUPAILCIMSessionVC *vc = [[YOUPAILCIMSessionVC alloc] initWithSession:session];
  61. [self.navigationController pushViewController:vc animated:YES];
  62. }];
  63. }else{//续费
  64. YOUPAILZVipPayWindow *window = [[YOUPAILZVipPayWindow alloc] init];
  65. window.youpaipvipId = self.youpaipvipId;
  66. [window setPayBlock:^(YOUPAILZVipRenewModel * _Nonnull model) {
  67. @strongify(self);
  68. [self youpaifpayModeWithModel:model];
  69. }];
  70. [self TFPresentVC:window completion:^{}];
  71. }
  72. }];
  73. [self.view addSubview:footerView];
  74. self.youpaipfooterView = footerView;
  75. [footerView mas_makeConstraints:^(MASConstraintMaker *make) {
  76. make.left.right.bottom.offset(0.0f);
  77. make.height.offset(70.0f + SafeHeight);
  78. }];
  79. UICollectionViewFlowLayout * flowLayout = [[UICollectionViewFlowLayout alloc] init];
  80. flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
  81. flowLayout.minimumInteritemSpacing = 20.0f;
  82. flowLayout.minimumLineSpacing = 20.0f;
  83. CGFloat width = (KScreenWidth - 60.0f) / 3.0f;
  84. CGFloat height = width * 1.f;
  85. flowLayout.itemSize = CGSizeMake(width, height);
  86. flowLayout.sectionInset = UIEdgeInsetsMake(0.0f, 10.0f, 10.0f, 10.0f);
  87. UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:flowLayout];
  88. collectionView.backgroundColor = HexColorFromRGB(0x2A2935);
  89. collectionView.alwaysBounceVertical = YES;
  90. collectionView.delegate = self;
  91. collectionView.dataSource = self;
  92. [collectionView registerClass:YOUPAILZVipPrivilegeCell.class forCellWithReuseIdentifier:@"cell"];
  93. [collectionView registerClass:YOUPAILZVipHeaderView.class forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"header"];
  94. [self.view addSubview:collectionView];
  95. self.youpaipcollectionView = collectionView;
  96. [collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
  97. make.left.right.top.offset(0.0f);
  98. make.bottom.equalTo(footerView.mas_top);
  99. }];
  100. self.youpaipsvgaPlayer = [[SVGAPlayer alloc] init];
  101. self.youpaipsvgaPlayer.contentMode = UIViewContentModeScaleAspectFit;
  102. self.youpaipsvgaPlayer.delegate = self;
  103. [self.view addSubview:self.youpaipsvgaPlayer];
  104. [self.youpaipsvgaPlayer mas_makeConstraints:^(MASConstraintMaker *make) {
  105. make.left.top.bottom.right.offset(0.0f);
  106. }];
  107. UITapGestureRecognizer *panGes = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(youpaiftouchCarClick)];
  108. [self.youpaipsvgaPlayer addGestureRecognizer:panGes];
  109. self.youpaipsvgaPlayer.hidden = YES;
  110. self.youpaipsvgaPlayer.loops = 1;
  111. self.youpaipsvgaPlayer.clearsAfterStop = true;
  112. self.youpaipparser = [[SVGAParser alloc] init];
  113. }
  114. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
  115. return 1;
  116. }
  117. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
  118. return self.youpaipmodel.youpaipprivilege.count;
  119. }
  120. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
  121. YOUPAILZVipPrivilegeCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
  122. [cell youpaifreloadWithModel:self.youpaipmodel.youpaipprivilege[indexPath.item]];
  123. return cell;
  124. }
  125. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section {
  126. return LZVipHeaderViewSize;
  127. }
  128. - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
  129. UICollectionReusableView *reusableview = nil;
  130. if (kind == UICollectionElementKindSectionHeader){
  131. YOUPAILZVipHeaderView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"header" forIndexPath:indexPath];
  132. [headerView youpaifreloadWithModel:self.youpaipmodel];
  133. @weakify(self);
  134. [headerView setClickVipCoinBlock:^{
  135. @strongify(self);
  136. if(self.youpaipmodel != nil){
  137. YOUPAILZVipCoinWalletVC *walletVC = [[YOUPAILZVipCoinWalletVC alloc] init];
  138. [self.navigationController pushViewController:walletVC animated:YES];
  139. }
  140. }];
  141. [headerView setClickCarBlock:^{
  142. @strongify(self);
  143. [self.youpaipsvgaPlayer stopAnimation];
  144. self.youpaipsvgaPlayer.hidden = YES;
  145. if (self.youpaipmodel.youpaipcar.youpaipbig_preview_img.length != 0) {
  146. self.youpaipsvgaPlayer.hidden = NO;
  147. }
  148. NSString* svgaName = [[self.youpaipmodel.youpaipcar.youpaipbig_preview_img componentsSeparatedByString:@"/"] lastObject];
  149. NSString* svgaCanchesPath= [[NSString alloc]initWithFormat:@"%@/%@/%@",CachesPath,@"SVGA",svgaName];
  150. if (![LCTools giftSVGAWithSvgaUrlStr:self.youpaipmodel.youpaipcar.youpaipbig_preview_img]){
  151. NSString* urlStr = [NSString stringWithFormat:@"%@/%@",[LCSaveData getImageUrl]?[LCSaveData getImageUrl]:BaseImgUrl,self.youpaipmodel.youpaipcar.youpaipbig_preview_img];
  152. @weakify(self);
  153. [self.youpaipparser parseWithURLRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlStr]] completionBlock:^(SVGAVideoEntity * _Nullable videoItem) {
  154. @strongify(self);
  155. if (videoItem != nil) {
  156. self.youpaipsvgaPlayer.videoItem = videoItem;
  157. [self.youpaipsvgaPlayer startAnimation];
  158. }
  159. } failureBlock:^(NSError * _Nullable error) {
  160. @strongify(self);
  161. self.youpaipsvgaPlayer.hidden = YES;
  162. }];
  163. [LCTools giftSVGAWithSvgaUrlStr:self.youpaipmodel.youpaipcar.youpaipbig_preview_img];
  164. }else{
  165. @weakify(self);
  166. [self.youpaipparser parseWithData:[LCTools giftSVGAWithSvgaUrlStr:self.youpaipmodel.youpaipcar.youpaipbig_preview_img] cacheKey:svgaCanchesPath completionBlock:^(SVGAVideoEntity * _Nonnull videoItem) {
  167. @strongify(self);
  168. if (videoItem != nil) {
  169. self.youpaipsvgaPlayer.videoItem = videoItem;
  170. [self.youpaipsvgaPlayer startAnimation];
  171. }
  172. } failureBlock:^(NSError * _Nonnull error) {
  173. @strongify(self);
  174. self.youpaipsvgaPlayer.hidden = YES;
  175. }];
  176. }
  177. }];
  178. reusableview = headerView;
  179. }
  180. return reusableview;
  181. }
  182. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  183. if (![LCSaveData getWhiteVersion]) {
  184. YOUPAILZVipPrivilegeModel *model = self.youpaipmodel.youpaipprivilege[indexPath.item];
  185. if (model.youpaipis_show == 1) {
  186. YOUPAILZVipNobleWindow *window = [[YOUPAILZVipNobleWindow alloc] init];
  187. window.isTouchDismiss = YES;
  188. window.youpaipimageHeight = model.youpaipheight;
  189. window.youpaipimagePath = model.youpaipshow_img;
  190. [self TFPresentVC:window completion:^{}];
  191. }
  192. }
  193. }
  194. //- (void)youpaifpayModeWithModel:(id)model{
  195. // NSString *price = @"";
  196. // NSString *vipId = @"";
  197. // NSString *type = @"";
  198. // NSString *paySuccessStr = @"";
  199. // if ([model isKindOfClass:[YOUPAILZVipInfoModel class]]) {
  200. // YOUPAILZVipInfoModel *infoModel = model;
  201. // price = infoModel.youpaippay_info.youpaipprice;
  202. // vipId = infoModel.youpaipnoble.youpaipid;
  203. // type = infoModel.youpaippay_info.youpaipstatus;
  204. // paySuccessStr = [NSString stringWithFormat:@"恭喜你,成为%@贵族!",infoModel.youpaipnoble.youpaipname];
  205. // }else{
  206. // YOUPAILZVipRenewModel *infoModel = model;
  207. // price = infoModel.youpaippay_info.youpaipprice;
  208. // vipId = infoModel.youpaipid;
  209. // type = infoModel.youpaippay_info.youpaipstatus;
  210. // paySuccessStr = [NSString stringWithFormat:@"恭喜你,成为%@贵族!",infoModel.youpaipname];
  211. // }
  212. //
  213. // VQ_LZPayModeChooseVC *vc = [[VQ_LZPayModeChooseVC alloc] init];
  214. // vc.youpaipmoney = [price integerValue];
  215. // vc.youpaipapi = VipPay;
  216. // vc.youpaipparams = @{@"id":vipId,@"type":type};
  217. // vc.youpaippaySuccessStr = paySuccessStr;
  218. // [self.navigationController pushViewController:vc animated:YES];
  219. //}
  220. - (void)youpaifpayModeWithModel:(id)model{
  221. NSString *ios_product_id = @"";
  222. if ([model isKindOfClass:[YOUPAILZVipInfoModel class]]) {
  223. YOUPAILZVipInfoModel *infoModel = model;
  224. ios_product_id = infoModel.youpaippay_info.youpaipios_product_id;
  225. self.paySuccessStr = [NSString stringWithFormat:@"恭喜你,成为%@贵族!",infoModel.youpaipnoble.youpaipname];
  226. }else{
  227. YOUPAILZVipRenewModel *infoModel = model;
  228. ios_product_id = infoModel.youpaippay_info.youpaipios_product_id;
  229. self.paySuccessStr = [NSString stringWithFormat:@"恭喜你,成为%@贵族!",infoModel.youpaipname];
  230. }
  231. [self applePay:ios_product_id];
  232. }
  233. - (void)applePay:(NSString *)ios_product_id{
  234. // self.rechargeBtn.userInteractionEnabled = NO;
  235. /// 内购
  236. [ZCHUDHelper showWithStatus:@"支付中..."];
  237. NSLog(@"%@",ios_product_id);
  238. [[IPAManager shareIAPManager] startPurchWithID:ios_product_id completeHandle:^(IAPPurchType type, NSString *data) {
  239. if (type == IAPPurchSuccess) {
  240. [LCSaveData saveReceiptData:data];
  241. [self requestApplePayBack:data];
  242. }else{
  243. // dispatch_async(dispatch_get_main_queue(), ^{
  244. // self.rechargeBtn.userInteractionEnabled = YES;
  245. // });
  246. NSString *title = @"";
  247. switch (type) {
  248. case IAPPurchFailed:
  249. title = @"购买失败";
  250. break;
  251. case IAPPurchCancle:
  252. title = @"已取消购买";
  253. break;
  254. case IAPPurchVerFailed:
  255. title = @"订单校验失败";
  256. break;
  257. // case IAPPurchVerSuccess:
  258. // NSLog(@"订单校验成功");
  259. // break;
  260. case IAPPurchNotArrow:
  261. title = @"不允许程序内付费";
  262. break;
  263. default:
  264. break;
  265. }
  266. if (title.length == 0) {
  267. [ZCHUDHelper dismiss];
  268. }else{
  269. [ZCHUDHelper showTitle:title];
  270. }
  271. }
  272. }];
  273. }
  274. - (void)requestApplePayBack:(NSString *)receipt_data{
  275. NSLog(@"receipt_data == %@",receipt_data);
  276. [LCHttpHelper requestWithURLString:ApplePayBack parameters:@{@"receipt_data":receipt_data} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  277. NSDictionary* dict = (NSDictionary*)responseObject;
  278. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  279. // dispatch_async(dispatch_get_main_queue(), ^{
  280. // self.rechargeBtn.userInteractionEnabled = YES;
  281. // });
  282. if (code == 0) {
  283. [LCSaveData removeReceiptData:receipt_data];
  284. NSInteger type = 2;
  285. if (![LCSaveData getOnlineVersion]) {
  286. type = 4;
  287. }
  288. [[NSNotificationCenter defaultCenter]postNotificationName:@"yqApplePaySuccess" object:nil userInfo:nil];
  289. [self youpaifrequestVipInfo];
  290. }
  291. [ZCHUDHelper showTitle:[dict objectForKey:@"message"]];
  292. } failure:^(NSError *error) {
  293. // dispatch_async(dispatch_get_main_queue(), ^{
  294. // self.rechargeBtn.userInteractionEnabled = YES;
  295. // });
  296. [ZCHUDHelper showTitle:error.localizedDescription];
  297. }];
  298. }
  299. - (void)goPaySuccessVC{
  300. YOUPAILZPaySuccessVC *vc = [[YOUPAILZPaySuccessVC alloc] init];
  301. vc.youpaipcontent = self.paySuccessStr;
  302. NSMutableArray <UIViewController *>* newvcs = [NSMutableArray array];
  303. for (UIViewController *vcont in self.navigationController.viewControllers) {
  304. if ([vcont isKindOfClass:self.class]) {
  305. break;
  306. }else{
  307. [newvcs addObject:vcont];
  308. }
  309. }
  310. [newvcs addObject:vc];
  311. [self.navigationController setViewControllers:newvcs animated:YES];
  312. [self youpaifrefreshData];
  313. }
  314. - (void)youpaifrefreshData{
  315. [LCHttpHelper requestWithURLString:UserCenter parameters:nil needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  316. NSDictionary* dict = (NSDictionary*)responseObject;
  317. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  318. if (code==0) {//成功
  319. NSDictionary *anchor = [[dict objectForKey:@"data"]objectForKey:@"anchor"];
  320. NSDictionary *info = [[dict objectForKey:@"data"]objectForKey:@"userinfo"];
  321. if ([[anchor allKeys] containsObject:@"open_video_status"]) {
  322. if ([[anchor objectForKey:@"open_video_status"] integerValue] == 0) {//0 未开启 1 已开启
  323. [LCSaveData saveVideoOpenStatu:NO];
  324. }else{
  325. [LCSaveData saveVideoOpenStatu:YES];
  326. }
  327. }
  328. if ([[anchor allKeys] containsObject:@"order_switch"]) {
  329. if ([[anchor objectForKey:@"order_switch"] integerValue] == 1) {//1隐藏 2不隐藏
  330. [LCSaveData saveOrderOpenStatu:YES];
  331. }else{
  332. [LCSaveData saveOrderOpenStatu:NO];
  333. }
  334. }
  335. if ([[info allKeys] containsObject:@"is_msg_refuse"]) {
  336. if ([[info objectForKey:@"is_msg_refuse"] integerValue] == 1) {//1开启 0关闭
  337. [LCSaveData saveProfileWuraoStatus:YES];
  338. }else{
  339. [LCSaveData saveProfileWuraoStatus:NO];
  340. }
  341. }
  342. YOUPAILCBaseInfo* userinfo = [YOUPAILCBaseInfo mj_objectWithKeyValues:[[dict objectForKey:@"data"]objectForKey:@"userinfo"]];
  343. if (userinfo.youpaipalbum_list_new.count>0) {
  344. NSMutableArray *arrm = [NSMutableArray new];
  345. [userinfo.youpaipalbum_list_new enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  346. album_list_newModel *model = [album_list_newModel mj_objectWithKeyValues:obj];
  347. [arrm addObject:model];
  348. }];
  349. userinfo.youpaipalbum_list_new = arrm;
  350. }
  351. YOUPAILCUserModel* userModel = [LCSaveModel getUserModel];
  352. userModel.youpaipuserinfo = userinfo;
  353. [LCSaveModel saveUserModel:userModel];
  354. }
  355. } failure:^(NSError *error) {
  356. }];
  357. }
  358. - (void)youpaifrequestVipInfo{
  359. @weakify(self);
  360. [LCHttpHelper requestWithURLString:VipDetails parameters:@{@"noble_id":self.youpaipvipId} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  361. @strongify(self);
  362. NSDictionary* dict = (NSDictionary*)responseObject;
  363. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  364. if (code == 0) {//成功
  365. self.youpaipmodel = [YOUPAILZVipInfoModel mj_objectWithKeyValues:dict[@"data"]];
  366. [self.youpaipcollectionView reloadData];
  367. NSString *status = dict[@"data"][@"red_dot"][@"is_watch_setting"];
  368. [[NSNotificationCenter defaultCenter]postNotificationName:@"changeRedDotStatus" object:nil userInfo:@{@"redDot":status}];
  369. [self.youpaipfooterView youpaifreloadWithModel:self.youpaipmodel];
  370. }
  371. } failure:^(NSError *error) {
  372. }];
  373. }
  374. #pragma mark - SVGAPlayerDelegate
  375. - (void)svgaPlayerDidFinishedAnimation:(SVGAPlayer *)player{
  376. [self.youpaipsvgaPlayer stopAnimation];
  377. self.youpaipsvgaPlayer.hidden = YES;
  378. }
  379. - (void)youpaiftouchCarClick{
  380. [self.youpaipsvgaPlayer stopAnimation];
  381. self.youpaipsvgaPlayer.hidden = YES;
  382. }
  383. #pragma mark - JXCategoryListContentViewDelegate
  384. - (UIView *)listView{
  385. return self.view;
  386. }
  387. @end