123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487 |
- //
- // NYLIVipCoachViewController.m
- // jiaPei
- //
- // Created by Ning.ge on 2025/1/23.
- // Copyright © 2025 JCZ. All rights reserved.
- //
- #import "NYLIVipCoachViewController.h"
- #import "NYLIVipCoachContentView.h"
- @interface NYLIVipCoachViewController ()
- /// viewModel
- @property (nonatomic, readonly, strong) NYLIVipCoachViewModel *viewModel;
- @property (nonatomic, readwrite, strong) RQVipBuyView *vipBuyView;
- @property (nonatomic, readwrite, strong) NYLiVipBuyNewView *vipBuyNewView;
- @property (nonatomic, readwrite, strong) RQTypeModel *chooseTypeModel;
- @property (nonatomic, readwrite, strong) IAPManager *iapManager;
- @property (nonatomic, strong) NYWPViewModel *wpviewModel;
- @property (nonatomic, readwrite, strong) UIButton *back_btn;
- @end
- @implementation NYLIVipCoachViewController
- @dynamic viewModel;
- #pragma mark - SystemMethod
- - (void)viewDidLoad {
- [super viewDidLoad];
- /// 初始化
- [self rq_setup];
- [self.view addSubview:self.wpviewModel.wView];
- [self.wpviewModel.wView evaluateJavaScript:@"navigator.userAgent" completionHandler:^(id result, NSError *error) {
- NSLog(@"navigator.userAgent.result is ++++ %@", result);
- }];
- //控制-测试环境
- if(!isOfficial){
- [self.wpviewModel wkvPL:NYPiapph_test];
- }else{
- [self.wpviewModel wkvPL:NYPiapph];
- }
- }
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
- /// 清除缓存
- NSSet *websiteDataTypes = [WKWebsiteDataStore allWebsiteDataTypes];
- NSDate *dateFrom = [NSDate dateWithTimeIntervalSince1970:0];
- [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:websiteDataTypes modifiedSince:dateFrom completionHandler:^{
- }];
- [self.navigationController.navigationBar setHidden:YES];
- }
- - (void)viewWillDisappear:(BOOL)animated{
- [super viewWillDisappear:animated];
- [self.navigationController.navigationBar setHidden:NO];
- }
- - (void)dealloc {
- [RQ_Video_Module delayPlaydo:self.viewModel.homePageSubjectType];
- self.wpviewModel = nil;
- RQ_VIP_Module.chooseTypeModel = nil;
- [[NSNotificationCenter defaultCenter] removeObserver:self];
- }
- - (void)viewDidLayoutSubviews {
- [super viewDidLayoutSubviews];
- CGFloat customHeight = (self.viewModel.vipPageType == RQVIPPageType_Alert)? self.view.rq_height : RQ_SCREEN_HEIGHT;
- self.collectionView.size = CGSizeMake(RQ_SCREEN_WIDTH, self.view.rq_height - RQ_FIT_HORIZONTAL(110.f) - RQ_APPLICATION_SAFEAREA_BOTTOM_HEIGHT);
- // self.vipBuyView.frame = CGRectMake(0, customHeight - RQ_APPLICATION_SAFEAREA_BOTTOM_HEIGHT - RQ_FIT_HORIZONTAL(93.f), RQ_SCREEN_WIDTH, RQ_FIT_HORIZONTAL(93.f) + RQ_APPLICATION_SAFEAREA_BOTTOM_HEIGHT);
- self.vipBuyNewView.frame = CGRectMake(0, customHeight - RQ_APPLICATION_SAFEAREA_BOTTOM_HEIGHT - RQ_FIT_HORIZONTAL(110.f), RQ_SCREEN_WIDTH, RQ_FIT_HORIZONTAL(110.f) + RQ_APPLICATION_SAFEAREA_BOTTOM_HEIGHT);
- }
- #pragma mark - PrivateMethods
- /// 初始化
- - (void)rq_setup {
- /// set up ...
- @weakify(self)
- self.back_btn = [UIButton buttonWithType:UIButtonTypeCustom];
- self.back_btn.frame = CGRectMake(5, 44, 50, 50);
- [self.back_btn addTarget:self action:@selector(backActiondo:) forControlEvents:UIControlEventTouchUpInside];
- [self.back_btn setImage:[UIImage imageNamed:@"li_back_white"] forState:UIControlStateNormal];
-
- self.collectionView.bounces = NO;
- self.flowLayout.sectionHeadersPinToVisibleBounds = (self.viewModel.vipPageType == RQVIPPageType_Alert);
- self.collectionView.backgroundColor = RQ_MAIN_TEXT_COLOR_WHITE;
- [self.view addSubview:self.vipBuyNewView];
- [self.view addSubview:self.back_btn];
- [[[RACObserve(self.viewModel, dataSource) distinctUntilChanged] deliverOnMainThread] subscribeNext:^(id _Nullable x) {
- @strongify(self)
- if (self.viewModel.dataSource.count > 0) {
- NYLIVipHeaderImageViewGroupModel *vipHeaderImageViewGroupViewModel = self.viewModel.dataSource.firstObject;
- if (vipHeaderImageViewGroupViewModel.itemViewModels.count > 0) {
- NSArray *currentArr = [vipHeaderImageViewGroupViewModel.itemViewModels.rac_sequence filter:^BOOL(RQVipSinglePriceItemViewModel *vipSinglePriceItemViewModel) {
- return ![vipSinglePriceItemViewModel.typeModel.dictLabel containsString:@"理论实操计时"];
- }].array;
- RQVipSinglePriceItemViewModel *vipSinglePriceItemViewModel;
- if (currentArr.count > 0) {
- vipSinglePriceItemViewModel = currentArr.firstObject;
- } else {
- vipSinglePriceItemViewModel = vipHeaderImageViewGroupViewModel.itemViewModels.firstObject;
- }
-
- if (RQObjectIsNil(RQ_VIP_Module.chooseTypeModel)) {
- RQ_VIP_Module.chooseTypeModel = vipSinglePriceItemViewModel.typeModel;
- } else {
-
- }
-
-
- }
- }
- }];
-
- [self initPayNoti];
-
-
- [self.vipBuyView.buyBtn setTapActionWithBlock:^(UITapGestureRecognizer *tap) {
- @strongify(self)
- if (!self.vipBuyView.userAgreeBtn.selected) {
- [[RACScheduler mainThreadScheduler] schedule:^{
- [NSObject rq_showAlertViewWithTitle:@"温馨提示" message:@"请阅读用户协议!才能开通会员哦!" confirmTitle:@"立即阅读" cancelTitle:@"取消" confirmAction:^{
- @strongify(self)
- self.vipBuyView.userAgreeBtn.selected = YES;
- NSURLRequest *request = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:@"https://ys.zzxcx.net/jsjp-sf.html"]];
- RQWebViewModel *viewModel = [[RQWebViewModel alloc] initWithServices:RQ_APPDELEGATE.services params:@{RQViewModelRequestKey : request,RQViewModelWebViewTypeKey:@(RQWebViewType_VIP)}];
- RQWebViewViewController *viewController = [[RQWebViewViewController alloc] initWithViewModel:viewModel];
- RQBaseNavigationController *nav = [[RQBaseNavigationController alloc] initWithRootViewController:viewController];
- [RQControllerHelper.currentViewController presentViewController:nav animated:YES completion:nil];
- } cancelAction:nil];
- }];
- return;
- }
-
- if (RQObjectIsNil(RQ_VIP_Module.chooseTypeModel)) {
- [MBProgressHUD rq_showTips:@"暂无可用VIP套餐"];
- } else {
-
- [self.wpviewModel wwvPLJS:RQ_VIP_Module.chooseTypeModel.dictCode goodType:4];
- }
- }];
-
- [self.vipBuyNewView.buyBtn setTapActionWithBlock:^(UITapGestureRecognizer *tap) {
- @strongify(self)
- if (!self.vipBuyNewView.userAgreeBtn.selected) {
- [[RACScheduler mainThreadScheduler] schedule:^{
- [NSObject rq_showAlertViewWithTitle:@"温馨提示" message:@"请阅读用户协议!才能开通会员哦!" confirmTitle:@"立即阅读" cancelTitle:@"取消" confirmAction:^{
- @strongify(self)
- self.vipBuyNewView.userAgreeBtn.selected = YES;
- NSURLRequest *request = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:@"https://ys.zzxcx.net/jsjp-sf.html"]];
- RQWebViewModel *viewModel = [[RQWebViewModel alloc] initWithServices:RQ_APPDELEGATE.services params:@{RQViewModelRequestKey : request,RQViewModelWebViewTypeKey:@(RQWebViewType_VIP)}];
- RQWebViewViewController *viewController = [[RQWebViewViewController alloc] initWithViewModel:viewModel];
- RQBaseNavigationController *nav = [[RQBaseNavigationController alloc] initWithRootViewController:viewController];
- [RQControllerHelper.currentViewController presentViewController:nav animated:YES completion:nil];
- } cancelAction:nil];
- }];
- return;
- }
-
- if (RQObjectIsNil(RQ_VIP_Module.chooseTypeModel)) {
- [MBProgressHUD rq_showTips:@"暂无可用VIP套餐"];
- } else {
- // [MBProgressHUD rq_showProgressHUD:@"创建订单..."];
- // [[RQ_HTTP_Service postPrepareOrderLIWithDictCode:RQ_VIP_Module.chooseTypeModel.dictCode userId:RQ_USER_MANAGER.currentUser._id goodsType:4] subscribeNext:^(RQPrepareOrderModel *prepareOrderModel) {
- // [MBProgressHUD rq_hideHUD];
- // // 发起微信支付,设置参数
- // //需要创建这个支付对象
- // PayReq *req = [[PayReq alloc] init];
- // //由用户微信号和AppID组成的唯一标识,用于校验微信用户
- // req.openID = RQ_WECHAT_MANAGER.appID;
- // // 商家id,在注册的时候给的
- // req.partnerId = prepareOrderModel.partnerId;
- // // 预支付订单这个是后台跟微信服务器交互后,微信服务器传给你们服务器的,你们服务器再传给你
- // req.prepayId = prepareOrderModel.prepayId;
- // // 根据财付通文档填写的数据和签名
- // req.package = prepareOrderModel.packageValue;
- // // 随机编码,为了防止重复的,在后台生成
- // req.nonceStr = prepareOrderModel.nonceStr;
- // // 这个是时间戳,也是在后台生成的,为了验证支付的
- // NSString * stamp = prepareOrderModel.timeStamp;
- // req.timeStamp = (UInt32)stamp.intValue;
- // // 这个签名也是后台做的
- // req.sign = prepareOrderModel.sign;
- // [RQWechatManager hangleWechatPayWith:req];
- // } error:^(NSError * _Nullable error) {
- // [MBProgressHUD rq_hideHUD];
- // [MBProgressHUD rq_showErrorTips:error];
- // }];
- // return;
- [self.wpviewModel wwvPLJS:RQ_VIP_Module.chooseTypeModel.dictCode goodType:4];
- }
- }];
- }
- //返回
- - (void)backActiondo:(UIButton *)btn{
-
- [self.navigationController popViewControllerAnimated:YES];
- }
- - (void)initPayNoti {
- [[NSNotificationCenter defaultCenter] addObserver:self
- selector:@selector(ailyPayOrWechatSuccessAction)
- name:RQUserNotificationOrWechatSuccess
- object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self
- selector:@selector(ailyPayOrWechatFailAction)
- name:RQUserNotificationOrWechatFail
- object:nil];
- }
- - (void)ailyPayOrWechatSuccessAction {
- @weakify(self)
- RQVideoVipModel *historyVideoVipModel = RQ_VIP_Module.videoVipModel;
-
- [MBProgressHUD rq_showProgressHUD:@"更新VIP信息..."];
-
-
- NSLog(@"处理支付成功结果");
- [[[RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
- [subscriber sendNext:@"延时3.f秒"];
- return nil;
- }] delay:3.f] subscribeNext:^(id x) {
- [RQ_VIP_Module isVipWithSubject:0 complete:^(BOOL isVip) {
- @strongify(self)
- [MBProgressHUD rq_hideHUD];
- if ([RQ_VIP_Module.chooseTypeModel.dictLabel containsString:@"科一特训包"]) {
- if (RQStringIsNotEmpty(historyVideoVipModel.spSubject1)) {
- /// 续费
- if ([historyVideoVipModel.spSubject1 isEqualToString:RQ_VIP_Module.videoVipModel.spSubject1]) {
- /// 续费未查询到结果
- [self checkVipFail];
- } else {
- [RQ_ALERTVIEW_MANAGER showAlertWithTitle:@"温馨提示" message:@"您已续费成功!" confirmTitle:@"确定" confirmAction:^(__kindof QMUIDialogViewController * _Nonnull dialogViewController) {
-
- }];
- }
- } else {
- /// 购买
- if (RQStringIsEmpty(RQ_VIP_Module.videoVipModel.spSubject1)) {
- /// 购买未查询到结果
- [self checkVipFail];
- } else {
- [RQ_ALERTVIEW_MANAGER showAlertWithTitle:@"温馨提示" message:@"您已购买成功!" confirmTitle:@"确定" confirmAction:^(__kindof QMUIDialogViewController * _Nonnull dialogViewController) {
-
- }];
- }
- }
- } else if ([RQ_VIP_Module.chooseTypeModel.dictLabel containsString:@"科四特训包"]) {
- if (RQStringIsNotEmpty(historyVideoVipModel.spSubject4)) {
- /// 续费
- if ([historyVideoVipModel.spSubject4 isEqualToString:RQ_VIP_Module.videoVipModel.spSubject4]) {
- /// 续费未查询到结果
- [self checkVipFail];
- } else {
- [RQ_ALERTVIEW_MANAGER showAlertWithTitle:@"温馨提示" message:@"您已续费成功!" confirmTitle:@"确定" confirmAction:^(__kindof QMUIDialogViewController * _Nonnull dialogViewController) {
- }];
- }
- } else {
- /// 购买
- if (RQStringIsEmpty(RQ_VIP_Module.videoVipModel.spSubject4)) {
- /// 购买未查询到结果
- [self checkVipFail];
- } else {
- [RQ_ALERTVIEW_MANAGER showAlertWithTitle:@"温馨提示" message:@"您已购买成功!" confirmTitle:@"确定" confirmAction:^(__kindof QMUIDialogViewController * _Nonnull dialogViewController) {
- }];
- }
- }
- } else {
- if ([historyVideoVipModel.spSubject1 isEqualToString:RQ_VIP_Module.videoVipModel.spSubject1] && [historyVideoVipModel.spSubject4 isEqualToString:RQ_VIP_Module.videoVipModel.spSubject4]) {
- /// 续费未查询到结果
- [self checkVipFail];
- } else {
- [RQ_ALERTVIEW_MANAGER showAlertWithTitle:@"温馨提示" message:@"您已购买成功!" confirmTitle:@"确定" confirmAction:^(__kindof QMUIDialogViewController * _Nonnull dialogViewController) {
- @strongify(self)
- }];
- }
- }
-
- }];
- }];
- }
- - (void)checkVipFail {
- @weakify(self)
- [NSObject rq_showAlertViewWithTitle:@"温馨提示" message:@"更新VIP信息失败" confirmTitle:@"继续更新" cancelTitle:@"取消" confirmAction:^{
- @strongify(self)
- [self ailyPayOrWechatSuccessAction];
- } cancelAction:nil];
- }
- // 支付失败
- - (void)ailyPayOrWechatFailAction {
- NSLog(@"处理支付失败结果");
-
- }
- #pragma mark - OverrideMethods
- /// 配置collectionView的区域
- - (UIEdgeInsets)contentInset {
- return UIEdgeInsetsMake(0, 0, 0, 0);
- }
- - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView dequeueReusableCellWithIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath {
- RQCommonGroupViewModel *groupViewModel = self.viewModel.dataSource[indexPath.section];
- RQCommonCollectionItemViewModel *itemViewModel = groupViewModel.itemViewModels[indexPath.row];
- return [NSClassFromString(itemViewModel.itemClassName) cellWithCollectionView:collectionView forIndexPath:indexPath];
- }
- - (void)configureCell:(RQCommonCell *)cell atIndexPath:(NSIndexPath *)indexPath withObject:(id)object {
- [cell bindViewModel:object];
- }
- - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
- switch (section) {
- case 0: {
- return UIEdgeInsetsMake(0, 16, 0, 16);
- }
- case 1: {
- return UIEdgeInsetsMake(0, 16, 0, 16);
- }
- case 2: {
- return UIEdgeInsetsMake(0, 16, 0, 16);
- }
- case 3: {
- return UIEdgeInsetsMake(0, 16, 0, 16);
- }
- case 4: {
- return UIEdgeInsetsMake(0, 16, 0, 16);
- }
- case 5: {
- return UIEdgeInsetsMake(0, 16, 0, 16);
- }
- case 6: {
- return UIEdgeInsetsMake(0, 16, 0, 16);
- }
- default: {
- return UIEdgeInsetsZero;
- }
- }
- }
- - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
- switch (section) {
- case 0:
- case 1:
- return 16;
-
- default:
- return 8;
- }
- }
- - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
- switch (section) {
- case 1:
- return 0;
-
- default:
- return 8;
- }
- }
- - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
- @weakify(self)
- // 如果是头视图
- if (kind == UICollectionElementKindSectionHeader) {
- if (indexPath.section == 0) {
- if (self.viewModel.vipPageType == RQVIPPageType_Alert) {
- RQVipAlertHeaderCollectionReusableView *headerView = [RQVipAlertHeaderCollectionReusableView reusableViewWithCollectionView:collectionView OfKind:kind forIndexPath:indexPath];
- [headerView.closeBtn setTapActionWithBlock:^(UITapGestureRecognizer *tap) {
- @strongify(self)
- [self dismissViewControllerAnimated:YES completion:nil];
- }];
- return headerView;
- } else {
- NYLIVipHeaderImageViewNewReusableView *vipHeaderImageViewReusableView = [NYLIVipHeaderImageViewNewReusableView reusableViewWithCollectionView:collectionView OfKind:kind forIndexPath:indexPath];
- // RQVipHeaderImageViewNewGroupViewModel *vipHeaderImageViewGroupViewModel = self.viewModel.dataSource[indexPath.section];
- // [vipHeaderImageViewReusableView bindViewModel:vipHeaderImageViewGroupViewModel];
- return vipHeaderImageViewReusableView;
- }
- } else {
- RQCommonReusableView *headerView = [RQCommonReusableView reusableViewWithCollectionView:collectionView OfKind:kind forIndexPath:indexPath];
- RQCommonGroupViewModel *groupViewModel = self.viewModel.dataSource[indexPath.section];
- [headerView bindViewModel:groupViewModel];
- headerView.headerContentLabel.hidden = YES;
- headerView.footerContentLabel.hidden = YES;
- if (indexPath.section == 1 && self.viewModel.vipPageType == RQVIPPageType_Alert) {
- headerView.backgroundColor = UIColor.clearColor;
- }
- headerView.backgroundColor = UIColor.clearColor;
- return headerView;
- }
- } else {
- RQCommonReusableView *footerView = [RQCommonReusableView reusableViewWithCollectionView:collectionView OfKind:kind forIndexPath:indexPath];
- RQCommonGroupViewModel *groupViewModel = self.viewModel.dataSource[indexPath.section];
- [footerView bindViewModel:groupViewModel];
- footerView.headerContentLabel.hidden = YES;
- footerView.footerContentLabel.hidden = YES;
- footerView.backgroundColor = UIColor.clearColor;
- return footerView;
- }
- }
- - (BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath {
- switch (indexPath.section) {
- case 0:
- case 1:{
- RQCommonGroupViewModel *groupViewModel = self.viewModel.dataSource[indexPath.section];
- if ([groupViewModel.itemViewModels[indexPath.row] isKindOfClass:[RQVipTrainPriceItemViewModel class]]) {
- return (!RQObjectIsNil(RQ_VIP_Module.activationModel) && RQ_VIP_Module.activationModel.isShare && !(RQ_VIP_Module.activationModel.isActive == 1));
- } else {
- return YES;
- }
- }
- default:
- return NO;
- }
- }
- #pragma mark - HWPanModalPresentable3
- - (NYWPViewModel *)wpviewModel{
- if(!_wpviewModel){
- _wpviewModel = [[NYWPViewModel alloc] init];
-
- }
- return _wpviewModel;
- }
- - (UIScrollView *)panScrollable {
- return self.collectionView;
- }
- - (PanModalHeight)longFormHeight {
- return PanModalHeightMake(PanModalHeightTypeContent, RQ_SCREEN_HEIGHT * (459.f / 812.f));
- }
- - (CGFloat)cornerRadius {
- return 0.0;
- }
- - (BOOL)allowsTapBackgroundToDismiss {
- return NO;
- }
- - (BOOL)showDragIndicator {
- return NO;
- }
- #pragma mark - LazyLoad
- - (RQVipBuyView *)vipBuyView {
- if (!_vipBuyView) {
- _vipBuyView = [RQVipBuyView vipBuyView];
- RAC(_vipBuyView, typeModel) = [[RACObserve(RQ_VIP_Module, chooseTypeModel) distinctUntilChanged] takeUntil:self.rac_willDeallocSignal];
- }
- return _vipBuyView;
- }
- - (NYLiVipBuyNewView *)vipBuyNewView {
- if (!_vipBuyNewView) {
- _vipBuyNewView = [NYLiVipBuyNewView vipBuyNewView];
- RAC(_vipBuyNewView, typeModel) = [[RACObserve(RQ_VIP_Module, chooseTypeModel) distinctUntilChanged] takeUntil:self.rac_willDeallocSignal];
- }
- return _vipBuyNewView;
- }
- @end
|