// // YMHomePageViewModel.m // MSYOUPAI // // Created by YoMi on 2024/2/4. // Copyright © 2024 MS. All rights reserved. // #import "YMHomePageViewModel.h" #import "YMAdvertModel.h" #import "YMAdolescentModelViewModel.h" @interface YMHomePageViewModel () /// 首页BannerVM @property (nonatomic, strong, readwrite) YMHomePageBannerViewModel *bannerVM; /// 首页ViewModel列表 @property (nonatomic, strong, readwrite) NSArray *homePageVMListDataArray; ///// 推荐VM //@property (nonatomic, strong,readwrite) YMHomePageListViewModel *recommendVM; /////男神VM //@property (nonatomic, strong,readwrite) YMHomePageListViewModel *maleGoldVM; ///// 在线VM //@property (nonatomic, strong,readwrite) YMHomePageListViewModel *onlineVM; ///// 同城 //@property (nonatomic, strong,readwrite) YMHomePageListViewModel *sameCityVM; ///// 推荐for男性(登录男号) //@property (nonatomic, strong,readwrite) YMHomePageListViewModel *recommendForMaleVM; @property (nonatomic, strong,readwrite) YMHomePageListViewModel *homeIndexVM; @property (nonatomic, strong,readwrite) YMHomePageListViewModel *homeSkillAnchorsVM; @property (nonatomic, strong,readwrite) YMHomePageListViewModel *homeRecommendAnchorsVM; @property (nonatomic, strong,readwrite) YMHomePageListViewModel *homeRecommendVM; @property (nonatomic, strong,readwrite) YMHomePageListViewModel *homeWCWVM; @property (nonatomic, strong,readwrite) YMHomePageListViewModel *homeOnlineListVM; @property (nonatomic, strong,readwrite) YMHomePageListViewModel *homeOnlineVM; @property (nonatomic, strong,readwrite) YMHomePageListViewModel *homeGetDesignatedVM; @property (nonatomic, strong,readwrite) YMHomePageListViewModel *homeGetSameCityUserVM; @property (nonatomic, strong,readwrite) YMHomePageListViewModel *homeActiveAnchorsVM; @property (nonatomic, strong,readwrite) YMHomePageListViewModel *homeNewAnchorsVM; @property (nonatomic, strong,readwrite) YMHomePageListViewModel *homeCityAnchorsVM; @property (nonatomic, strong,readwrite) YMHomePageListViewModel *homeBannerVM; @end @implementation YMHomePageViewModel - (void)ym_initialize{ [super ym_initialize]; if(self.isFemaleGender){ self.homePageVMListDataArray = @[ self.homeWCWVM, self.homeGetDesignatedVM, self.homeOnlineVM, self.homeRecommendVM, ]; } else { self.homePageVMListDataArray = @[ self.homeWCWVM, self.homeGetDesignatedVM, self.homeOnlineVM, ]; } } - (void)judgementsIsOpenAdolescentModel{ [self getAdolescentModelStatusData]; // //先判断是否设置了青少年模式 // kAppDelegate.kadolescentStatus = [LCSaveData getYoungMode]; // if(kAppDelegate.kadolescentStatus == 1){ // [self closeAdolescentModelPopup]; // }else{ // ///在判断是否提醒过 // ///检查更新 根据时间戳 设定12小时/一天之内调用一次 // NSString* updateTime = [LCSaveData getYoungNoticeTime]; // NSDate * newData = [NSDate date]; // NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; // [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; // if (!updateTime) { // NSString* dataString = [dateFormatter stringFromDate:newData]; // [LCSaveData saveYoungNoticeTime:dataString]; // ///弹出设置青少年模式弹窗 // ///要不要检查一下status 防止卸载后重装 // [self getAdolescentModelStatusData]; // // }else{ // //获取与当前的时间差 // NSDate *timeDate = [dateFormatter dateFromString:updateTime]; // NSTimeInterval timeInterval = [timeDate timeIntervalSinceNow]; // timeInterval = -timeInterval; // //超过30天 // if (timeInterval > 60 * 60 * 24) { // NSString* dataString = [dateFormatter stringFromDate:newData]; // [LCSaveData saveYoungNoticeTime:dataString]; // //弹出青少年模式弹窗 // [self openAdolescentModelPopup]; // } // } // } } - (void)getAdolescentModelStatusData { [LCHttpHelper requestWithURLString:GetAdolescentStatus parameters:@{} needToken:YES type:HttpRequestTypePost success:^(id responseObject) { NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code == 0) { NSDictionary *data = [dict dictionaryValueForKey:@"data" defaultValue:@{}]; NSInteger adoleStatus = [data integerValueForKey:@"is_set_adolescent" defaultValue:0]; [LCSaveData saveYoungMode:adoleStatus]; if(adoleStatus == 1){ [self closeAdolescentModelPopup]; }else{ ///在判断是否提醒过 ///检查更新 根据时间戳 设定12小时/一天之内调用一次 NSString* updateTime = [LCSaveData getYoungNoticeTime]; NSDate * newData = [NSDate date]; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; if (!updateTime) { NSString* dataString = [dateFormatter stringFromDate:newData]; [LCSaveData saveYoungNoticeTime:dataString]; ///弹出设置青少年模式弹窗 ///要不要检查一下status 防止卸载后重装 }else{ //获取与当前的时间差 NSDate *timeDate = [dateFormatter dateFromString:updateTime]; NSTimeInterval timeInterval = [timeDate timeIntervalSinceNow]; timeInterval = -timeInterval; //超过30天 if (timeInterval > 60 * 60 * 24) { NSString* dataString = [dateFormatter stringFromDate:newData]; [LCSaveData saveYoungNoticeTime:dataString]; //弹出青少年模式弹窗 [self openAdolescentModelPopup]; } } } }else{ [ZCHUDHelper showTitle:[dict stringValueForKey:@"message" defaultValue:@""]]; } } failure:^(NSError *error) { [ZCHUDHelper showTitle:error.localizedDescription]; }]; } - (void)zhidingData{ [LCHttpHelper requestWithURLString:HomeZhiDing parameters:@{} needToken:YES type:HttpRequestTypePost success:^(id responseObject) { NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code == 0) { NSDictionary *dataDic = [dict dictionaryValueForKey:@"data" defaultValue:@{}]; NSString *str = [dataDic objectForKey:@"msg"]; [ZCHUDHelper showTitle:[NSString stringWithFormat:@"置顶成功,%@",str]]; if(self.refreshHomeListData){ self.refreshHomeListData(); } } } failure:^(NSError *error) { }]; } /// 群打招呼 - (void)groupGreetingData { [LCHttpHelper requestWithURLString:HomeZhiDing parameters:@{} needToken:YES type:HttpRequestTypePost success:^(id responseObject) { NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code == 0) { NSDictionary *dataDic = [dict dictionaryValueForKey:@"data" defaultValue:@{}]; NSString *str = [dataDic objectForKey:@"msg"]; [ZCHUDHelper showTitle:[NSString stringWithFormat:@"置顶成功,%@",str]]; if(self.refreshHomeListData){ self.refreshHomeListData(); } } } failure:^(NSError *error) { }]; } - (void)getAdvertData{ [LCHttpHelper requestWithURLString:GetAdvert parameters:@{ @"source_id":@"2" } needToken:YES type:HttpRequestTypePost success:^(id responseObject) { NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code == 0) { NSDictionary *data = [dict dictionaryValueForKey:@"data" defaultValue:@{}]; YMAdvertModel *model = [YMAdvertModel yy_modelWithJSON:[data dictionaryValueForKey:@"advert" defaultValue:@{}]]; NSInteger link_type = [dict[@"data"][@"advert"][@"link_type"] integerValue]; NSString *link_url = dict[@"data"][@"advert"][@"link_url"]; NSInteger window_type = [dict[@"data"][@"advert"][@"window_type"] integerValue]; if (model.status == 1 && model.image.length>5) { if (window_type == 2) { // YOUPAIHRWebWindow *window = [[YOUPAIHRWebWindow alloc] init]; // window.isTouchDismiss = YES; // window.youpaipurl = dict[@"data"][@"advert"][@"window_link"]; // window.youpaipwidth = [dict[@"data"][@"advert"][@"width"] floatValue]; // window.youpaipheight = [dict[@"data"][@"advert"][@"height"] floatValue]; // window.youpaipgravity = dict[@"data"][@"advert"][@"gravity"]; // [self TFPresentVC:window completion:^{}]; }else{ // YOUPAIZYAdvertWindow *VC= [[YOUPAIZYAdvertWindow alloc]init]; // VC.youpaipdelegate = self; // VC.vWidth = KScreenWidth -30; // VC.vHeight = KScreenWidth-30; // VC.youpaipimageurl = image; // VC.youpaiplink_type = link_type; // VC.youpaiplink_url = link_url; // VC.isTouchDismiss = YES; // [self TFPresentVC:VC completion:^{}]; } } } } failure:^(NSError *error) { }]; } /// 获取等级图标数据 - (void)getLevelIconData{ [LCHttpHelper requestWithURLString:LevelInfo parameters:@{} needToken:YES type:HttpRequestTypePost success:^(id responseObject) { NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code == 0) { NSDictionary *data = [dict dictionaryValueForKey:@"data" defaultValue:@{}]; [LCSaveData saveLevelInfo:data]; } } failure:^(NSError *error) { }]; } /// 获取徽章和贵族图标数据 - (void)getBadgesAndNobilityIconData{ [LCHttpHelper requestWithURLString:AllBadge parameters:@{} needToken:YES type:HttpRequestTypePost success:^(id responseObject) { NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code == 0) { NSDictionary *data = [dict dictionaryValueForKey:@"data" defaultValue:@{}]; NSDictionary* badge = [data dictionaryValueForKey:@"badge" defaultValue:@{}]; NSDictionary* noble = [data dictionaryValueForKey:@"noble" defaultValue:@{}]; [LCSaveData saveBadgeInfo:badge]; [LCSaveData saveNobleInfo:noble]; } } failure:^(NSError *error) { }]; } - (void)gotoSearchUser{ YMSearchUserViewModel *searchUserVM = [[YMSearchUserViewModel alloc]initWithParams:@{}]; [YMRouter openURL:stringFormat(@"%@%@",YM_ROUTER_URL_PREFIX,YM_ROUTER_SEARCH_USER) withUserInfo:@{ RouterViewModel:searchUserVM } completion:nil]; } - (void)openAdolescentModelPopup{ YMOpenAdolescentModelPopupView *customView = [[YMOpenAdolescentModelPopupView alloc]init]; YMPopupView *popupView = [YMPopupView initWithCustomView:customView parentView:nil popStyle:YMPopupStyleFade dismissStyle:YMDismissStyleFade]; popupView.priority = 998; popupView.cornerRadius = adapt(10); popupView.rectCorners = UIRectCornerAllCorners; popupView.positionStyle = YMPositionStyleCenter; popupView.isHideBg = NO; popupView.bgAlpha = 0.3; @weakify(popupView) customView.noMoreRemindersButtonBlock = ^{ @strongify(popupView) [popupView dismissWithStyle:YMDismissStyleFade duration:2.0]; }; customView.gotoAdolescentModelButtonBlock = ^{ @strongify(popupView) [popupView dismissWithStyle:YMDismissStyleFade duration:2.0]; YMAdolescentModelViewModel *adolescentModelVM = [[YMAdolescentModelViewModel alloc]initWithParams:@{ ParamsCategoryType:@(YMAdolescentModelTypeSettingPassword) }]; [YMRouter openURL:stringFormat(@"%@%@", YM_ROUTER_URL_PREFIX, YM_ROUTER_ADOLESCENT_MODEL) withUserInfo:@{ RouterViewModel:adolescentModelVM } completion:nil]; }; [popupView pop]; } - (void)closeAdolescentModelPopup{ YMCloseAdolescentModelPopupView *customView = [[YMCloseAdolescentModelPopupView alloc]init]; YMPopupView *popupView = [YMPopupView initWithCustomView:customView parentView:nil popStyle:YMPopupStyleFade dismissStyle:YMDismissStyleFade]; popupView.priority = 998; popupView.cornerRadius = adapt(10); popupView.rectCorners = UIRectCornerAllCorners; popupView.positionStyle = YMPositionStyleCenter; popupView.isHideBg = NO; popupView.bgAlpha = 0.3; @weakify(popupView) customView.openOrCloseAdolescentModelButtonBlock = ^{ @strongify(popupView) [popupView dismissWithStyle:YMDismissStyleFade duration:2.0]; YMAdolescentModelViewModel *adolescentModelVM = [[YMAdolescentModelViewModel alloc]initWithParams:@{ ParamsCategoryType:@(YMAdolescentModelTypeClosePassword) }]; [YMRouter openURL:stringFormat(@"%@%@", YM_ROUTER_URL_PREFIX, YM_ROUTER_ADOLESCENT_MODEL) withUserInfo:@{ RouterViewModel:adolescentModelVM } completion:nil]; }; customView.forgotPasswordBlock = ^{ @strongify(popupView) [popupView dismissWithStyle:YMDismissStyleFade duration:2.0]; }; [popupView pop]; } - (YMHomePageBannerViewModel *)bannerVM{ if (!_bannerVM) { _bannerVM = [[YMHomePageBannerViewModel alloc]initWithParams:@{}]; } return _bannerVM; } //- (YMHomePageListViewModel *)recommendVM{ // if (!_recommendVM) { // _recommendVM = [[YMHomePageListViewModel alloc]initWithParams:@{ // ParamsCategoryType:@(YMHomePageCategoryTypeRecommend) // }]; // } // return _recommendVM; //} // //- (YMHomePageListViewModel *)maleGoldVM{ // if (!_maleGoldVM) { // _maleGoldVM = [[YMHomePageListViewModel alloc]initWithParams:@{ // ParamsCategoryType:@(YMHomePageCategoryTypeMaleGold) // }]; // } // return _maleGoldVM; //} // //- (YMHomePageListViewModel *)onlineVM{ // if (!_onlineVM) { // _onlineVM = [[YMHomePageListViewModel alloc]initWithParams:@{ // ParamsCategoryType:@(YMHomePageCategoryTypeOnline) // }]; // } // return _onlineVM; //} // //- (YMHomePageListViewModel *)sameCityVM{ // if (!_sameCityVM) { // _sameCityVM = [[YMHomePageListViewModel alloc]initWithParams:@{ // ParamsCategoryType:@(YMHomePageCategoryTypeSameCity) // }]; // } // return _sameCityVM; //} // //- (YMHomePageListViewModel *)recommendForMaleVM{ // if (!_recommendForMaleVM) { // _recommendForMaleVM = [[YMHomePageListViewModel alloc]initWithParams:@{ // ParamsCategoryType:@(YMHomePageCategoryTypeRecommendForMale) // }]; // } // return _recommendForMaleVM; //} - (YMHomePageListViewModel *)homeIndexVM { if (!_homeIndexVM) { _homeIndexVM = [[YMHomePageListViewModel alloc] initWithParams:@{ParamsCategoryType: @(YMHomePageCategoryTypeHomeIndex)}]; _homeIndexVM.tabTitle = @""; _homeIndexVM.tabURLStr = HomeIndex; } return _homeIndexVM; } - (YMHomePageListViewModel *)homeSkillAnchorsVM { if (!_homeSkillAnchorsVM) { _homeSkillAnchorsVM = [[YMHomePageListViewModel alloc] initWithParams:@{ParamsCategoryType: @(YMHomePageCategoryTypeHomeSkillAnchors)}]; _homeSkillAnchorsVM.tabTitle = @""; _homeSkillAnchorsVM.tabURLStr = HomeSkillAnchors; } return _homeSkillAnchorsVM; } - (YMHomePageListViewModel *)homeRecommendAnchorsVM { if (!_homeRecommendAnchorsVM) { _homeRecommendAnchorsVM = [[YMHomePageListViewModel alloc] initWithParams:@{ParamsCategoryType: @(YMHomePageCategoryTypeHomeRecommendAnchors)}]; _homeRecommendAnchorsVM.tabTitle = @""; _homeRecommendAnchorsVM.tabURLStr = HomeRecommendAnchors; } return _homeRecommendAnchorsVM; } - (YMHomePageListViewModel *)homeRecommendVM { if (!_homeRecommendVM) { _homeRecommendVM = [[YMHomePageListViewModel alloc] initWithParams:@{ParamsCategoryType: @(YMHomePageCategoryTypeHomeRecommend)}]; _homeRecommendVM.tabTitle = @""; _homeRecommendVM.tabURLStr = HomeRecommend; } return _homeRecommendVM; } - (YMHomePageListViewModel *)homeWCWVM { if (!_homeWCWVM) { _homeWCWVM = [[YMHomePageListViewModel alloc] initWithParams:@{ParamsCategoryType: @(YMHomePageCategoryTypeHomeWCW)}]; _homeWCWVM.tabTitle = @""; _homeWCWVM.tabURLStr = HomeWCW; } return _homeWCWVM; } - (YMHomePageListViewModel *)homeOnlineListVM { if (!_homeOnlineListVM) { _homeOnlineListVM = [[YMHomePageListViewModel alloc] initWithParams:@{ParamsCategoryType: @(YMHomePageCategoryTypeHomeOnlineList)}]; _homeOnlineListVM.tabTitle = @""; _homeOnlineListVM.tabURLStr = HomeOnlineList; } return _homeOnlineListVM; } - (YMHomePageListViewModel *)homeOnlineVM { if (!_homeOnlineVM) { _homeOnlineVM = [[YMHomePageListViewModel alloc] initWithParams:@{ParamsCategoryType: @(YMHomePageCategoryTypeHomeOnline)}]; _homeOnlineVM.tabTitle = @""; _homeOnlineVM.tabURLStr = HomeOnline; } return _homeOnlineVM; } - (YMHomePageListViewModel *)homeGetDesignatedVM { if (!_homeGetDesignatedVM) { _homeGetDesignatedVM = [[YMHomePageListViewModel alloc] initWithParams:@{ParamsCategoryType: @(YMHomePageCategoryTypeHomeGetDesignated)}]; _homeGetDesignatedVM.tabTitle = @""; _homeGetDesignatedVM.tabURLStr = HomeGetDesignated; } return _homeGetDesignatedVM; } - (YMHomePageListViewModel *)homeGetSameCityUserVM { if (!_homeGetSameCityUserVM) { _homeGetSameCityUserVM = [[YMHomePageListViewModel alloc] initWithParams:@{ParamsCategoryType: @(YMHomePageCategoryTypeHomeGetSameCityUser)}]; _homeGetSameCityUserVM.tabTitle = @""; _homeGetSameCityUserVM.tabURLStr = HomeGetSameCityUser; } return _homeGetSameCityUserVM; } - (YMHomePageListViewModel *)homeActiveAnchorsVM { if (!_homeActiveAnchorsVM) { _homeActiveAnchorsVM = [[YMHomePageListViewModel alloc] initWithParams:@{ParamsCategoryType: @(YMHomePageCategoryTypeHomeActiveAnchors)}]; _homeActiveAnchorsVM.tabTitle = @""; _homeActiveAnchorsVM.tabURLStr = HomeActiveAnchors; } return _homeActiveAnchorsVM; } - (YMHomePageListViewModel *)homeNewAnchorsVM { if (!_homeNewAnchorsVM) { _homeNewAnchorsVM = [[YMHomePageListViewModel alloc] initWithParams:@{ParamsCategoryType: @(YMHomePageCategoryTypeHomeNewAnchors)}]; _homeNewAnchorsVM.tabTitle = @""; _homeNewAnchorsVM.tabURLStr = HomeNewAnchors; } return _homeNewAnchorsVM; } - (YMHomePageListViewModel *)homeCityAnchorsVM { if (!_homeCityAnchorsVM) { _homeCityAnchorsVM = [[YMHomePageListViewModel alloc] initWithParams:@{ParamsCategoryType: @(YMHomePageCategoryTypeHomeCityAnchors)}]; _homeCityAnchorsVM.tabTitle = @""; _homeCityAnchorsVM.tabURLStr = HomeCityAnchors; } return _homeCityAnchorsVM; } - (YMHomePageListViewModel *)homeBannerVM { if (!_homeBannerVM) { _homeBannerVM = [[YMHomePageListViewModel alloc] initWithParams:@{ParamsCategoryType: @(YMHomePageCategoryTypeHomeBanner)}]; _homeBannerVM.tabTitle = @""; _homeBannerVM.tabURLStr = HomeBanner; } return _homeBannerVM; } @end