249 lines
9.2 KiB
Objective-C
249 lines
9.2 KiB
Objective-C
//
|
|
// MainPresenter.m
|
|
// YUMI
|
|
//
|
|
// Created by zu on 2021/9/8.
|
|
//
|
|
|
|
#import "MainPresenter.h"
|
|
#import "AccountInfoStorage.h"
|
|
#import "RechargeStorage.h"
|
|
#import "AccountModel.h"
|
|
#import "Api+Main.h"
|
|
#import "Api+Mine.h"
|
|
#import "MainProtocol.h"
|
|
#import "NSObject+MJExtension.h"
|
|
#import <NIMSDK/NIMSDK.h>
|
|
#import "InviteUserInfoModel.h"
|
|
#import "NewUserGreetModel.h"
|
|
#import "NewUserRechargeModel.h"
|
|
#import "XPTabAnchorCardModel.h"
|
|
#import "YYUtility.h"
|
|
#import "XPVersionUpdateModel.h"
|
|
|
|
static NSString * kUpdateVersionNum = @"kUpdateVersionNum";
|
|
|
|
@implementation MainPresenter
|
|
|
|
- (void)autoLogin {
|
|
AccountModel *accountModel = [[AccountInfoStorage instance] getCurrentAccountInfo];
|
|
if (accountModel == nil || accountModel.uid == nil || accountModel.access_token == nil) {
|
|
[[self getView] tokenInvalid];
|
|
return;
|
|
}
|
|
if ([[AccountInfoStorage instance] getTicket].length > 0) {
|
|
[[self getView] autoLoginSuccess];
|
|
return;
|
|
}
|
|
@kWeakify(self);
|
|
[Api requestTicket:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
|
|
@kStrongify(self);
|
|
NSArray *tickets = [data.data valueForKey:@"tickets"];
|
|
NSString *ticket = [tickets[0] valueForKey:@"ticket"];
|
|
[[AccountInfoStorage instance] saveTicket:ticket];
|
|
[[self getView] autoLoginSuccess];
|
|
} fail:^(NSInteger code, NSString * _Nullable msg) {
|
|
@kStrongify(self);
|
|
[self logout];
|
|
} errorToast:NO]
|
|
access_token:accountModel.access_token
|
|
issue_type:@"multi"];
|
|
}
|
|
|
|
- (void)loginNIM {
|
|
AccountModel *accountModel = [[AccountInfoStorage instance] getCurrentAccountInfo];
|
|
if (accountModel == nil) {
|
|
[[self getView] tokenInvalid];
|
|
return;
|
|
}
|
|
if (![NIMSDK sharedSDK].loginManager.isLogined) {
|
|
NIMAutoLoginData *data = [[NIMAutoLoginData alloc]init];
|
|
data.account = accountModel.uid;
|
|
data.token = accountModel.netEaseToken;
|
|
data.forcedMode = NO;
|
|
[[NIMSDK sharedSDK].loginManager autoLogin:data];
|
|
}
|
|
}
|
|
|
|
- (void)getUserInfo {
|
|
@kWeakify(self);
|
|
[Api getUserInfo:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
|
|
@kStrongify(self);
|
|
[[self getView] getUserInfoSuccess:[UserInfoModel modelWithDictionary:data.data]];
|
|
}] uid:[[AccountInfoStorage instance] getUid]];
|
|
}
|
|
|
|
- (void)checkTranscation {
|
|
NSString * uid = [AccountInfoStorage instance].getUid;
|
|
NSString * ticket = [AccountInfoStorage instance].getTicket;
|
|
NSArray * array = [RechargeStorage getAllReciptsWithUid:uid];
|
|
if (array == nil || array.count <= 0) {
|
|
return;
|
|
}
|
|
for (NSDictionary *transcation in array) {
|
|
NSString *orderId = transcation[@"orderId"];
|
|
NSString *transcationId = transcation[@"transcationId"];
|
|
///二次验证
|
|
[Api checkReceipt:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
|
|
if (code == 200) {
|
|
NSString * uid = [AccountInfoStorage instance].getUid;
|
|
[RechargeStorage delegateTranscationId:transcationId uid:uid];
|
|
}
|
|
|
|
} chooseEnv:@"true" chargeRecordId:orderId transcationId:transcationId uid:uid ticket:ticket];
|
|
}
|
|
|
|
}
|
|
|
|
|
|
/// 巨量广告
|
|
- (void)juliandAdCallBackApi {
|
|
[Api appInitObserverJuliangAd:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
|
|
///不需要回调
|
|
}];
|
|
}
|
|
|
|
|
|
///获取邀请人信息
|
|
- (void)checkInviteUserInfo:(NSString *)inviteCode {
|
|
[Api checkInviteUserInRoom:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
|
|
InviteUserInfoModel * info= [InviteUserInfoModel modelWithDictionary:data.data];
|
|
[[self getView] checkInviteUserInfoSuccess:info];
|
|
}] inviteCode:inviteCode];
|
|
}
|
|
|
|
///获取新用户打招呼信息
|
|
- (void)getNewUserGreetInfo {
|
|
[Api newUserGreetInfo:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
|
|
NewUserGreetModel * greetInfo = [NewUserGreetModel modelWithDictionary:data.data];
|
|
[[self getView] getNewUserGreetInfoSucces:greetInfo];
|
|
}];
|
|
}
|
|
|
|
/// 获取快捷推荐进房
|
|
- (void)getShortCutRecommendRoom {
|
|
NSString * uid = [AccountInfoStorage instance].getUid;
|
|
[Api shortCutRecommendRoom:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
|
|
NSString * roomUid = [data.data stringValue];
|
|
[[self getView] getShortCutRecommendRoomSuccces:roomUid];
|
|
}] uid:uid];
|
|
}
|
|
|
|
///获取新用户充值优惠
|
|
- (void)getNewUserRechargeList {
|
|
[Api requestNewUserRechargeList:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
|
|
NewUserRechargeModel *model = [NewUserRechargeModel modelWithDictionary:data.data];
|
|
[[self getView] getNewUserRechargeInfoSuccess:model];
|
|
}]];
|
|
}
|
|
|
|
///获取主播卡片信息
|
|
- (void)getAnchorCardInfo {
|
|
[Api requestAnchorCardInfo:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
|
|
XPTabAnchorCardModel *model = [XPTabAnchorCardModel modelWithDictionary:data.data];
|
|
[[self getView] getAnchorCardInfoSuccess:model];
|
|
} fail:^(NSInteger code, NSString * _Nullable msg) {
|
|
NSLog(@"%@", msg);
|
|
} errorToast:NO]];
|
|
}
|
|
|
|
///心跳接口,每 30 秒调用一次,用来更新用户在线状态
|
|
- (void)clientHeartBeat {
|
|
[Api requestClientHeartBrat:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
|
|
|
|
}];
|
|
}
|
|
///app 启动调用此接口 主要功能:给主播分流
|
|
- (void)clientStartApp {
|
|
[Api requestClientStartApp:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
|
|
|
|
}];
|
|
}
|
|
#pragma mark - 版本更新
|
|
-(void)getVersionUpdate{
|
|
NSString *appVersion = [YYUtility appVersion];
|
|
NSString *os = @"ios";
|
|
NSString *channel = [YYUtility getAppSource];
|
|
[Api requestVersionUpdate:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
|
|
XPVersionUpdateModel *model = [XPVersionUpdateModel modelWithDictionary:data.data];
|
|
if([MainPresenter isUpdateVersion:model] == NO) return;
|
|
[[self getView] getVersionUpdate:model];
|
|
} fail:^(NSInteger code, NSString * _Nullable msg) {
|
|
NSLog(@"%@", msg);
|
|
} errorToast:NO] appVersion:appVersion os:os channel:channel];
|
|
}
|
|
|
|
+(BOOL)isUpdateVersion:(XPVersionUpdateModel *)versionModel{
|
|
if(versionModel.updateStatus == 1 || versionModel.updateStatus == 2)return NO;
|
|
if(versionModel.updateStatus == 3)return YES;
|
|
NSString *appVersion = [YYUtility appVersion];
|
|
NSString *updateVersion = versionModel.updateVersion;
|
|
NSComparisonResult result = [appVersion compare:updateVersion options:NSNumericSearch];
|
|
if(result == NSOrderedSame || result == NSOrderedDescending){
|
|
return NO;
|
|
}
|
|
NSDictionary *appVersionDic = [[NSUserDefaults standardUserDefaults]valueForKey:kUpdateVersionNum];
|
|
if(appVersionDic == nil){
|
|
[self saveDataWithVersion:versionModel.updateVersion updateVersionList:@[]];
|
|
|
|
return YES;
|
|
};
|
|
NSMutableDictionary *getAppVersionDic = [[NSMutableDictionary alloc]initWithDictionary:appVersionDic];
|
|
NSArray *updateVersionDic = getAppVersionDic[versionModel.updateVersion];
|
|
if(updateVersionDic == nil){
|
|
[self saveDataWithVersion:versionModel.updateVersion updateVersionList:@[]];
|
|
return YES;
|
|
};
|
|
NSArray<XPVersionUpdateItemModel *> *itemModelList = [XPVersionUpdateItemModel modelsWithArray:updateVersionDic];
|
|
if(itemModelList.count >= 3)return NO;
|
|
BOOL isDayUpdate = NO;
|
|
for (XPVersionUpdateItemModel *itemModel in itemModelList){
|
|
if([itemModel.time isEqualToString:[MainPresenter GetCurrentTime]]){
|
|
isDayUpdate = YES;
|
|
break;
|
|
}
|
|
}
|
|
if(isDayUpdate == YES)return NO;
|
|
[self saveDataWithVersion:versionModel.updateVersion updateVersionList:updateVersionDic];
|
|
return YES;
|
|
|
|
}
|
|
|
|
+(void)saveDataWithVersion:(NSString *)version updateVersionList:(NSArray *)list{
|
|
if(version == nil)return;
|
|
XPVersionUpdateItemModel *itemModel = [XPVersionUpdateItemModel new];
|
|
itemModel.time = [MainPresenter GetCurrentTime];
|
|
itemModel.version = version;
|
|
itemModel.num = @"1";
|
|
NSMutableArray *getUpdateVersionList = [NSMutableArray arrayWithArray:list];
|
|
[getUpdateVersionList addObject:[itemModel model2dictionary]];
|
|
|
|
NSDictionary *appVersionDic = [[NSUserDefaults standardUserDefaults]valueForKey:kUpdateVersionNum];
|
|
NSMutableDictionary *saveDic;
|
|
if(appVersionDic == nil){
|
|
saveDic = [NSMutableDictionary dictionary];
|
|
}else{
|
|
saveDic = [NSMutableDictionary dictionaryWithDictionary:appVersionDic];
|
|
}
|
|
[saveDic setObject:getUpdateVersionList forKey:version];
|
|
[[NSUserDefaults standardUserDefaults]setObject:saveDic forKey:kUpdateVersionNum];
|
|
[[NSUserDefaults standardUserDefaults] synchronize];
|
|
}
|
|
|
|
+ (NSString *)GetCurrentTime{
|
|
NSDate *now = [NSDate date];
|
|
NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
|
|
formatter.dateFormat = @"yyyy-MM-dd";
|
|
NSString *dateStr = [formatter stringFromDate:now];
|
|
return dateStr;
|
|
}
|
|
-(void)getAuthorizationCodeInfo{
|
|
[Api requestAuthorizationCodeInfo:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
|
|
[[self getView]getAuthorizationCodeInfoWithPhoneSuccess:[data.data boolValue]];
|
|
} fail:^(NSInteger code, NSString * _Nullable msg) {
|
|
[[self getView]getAuthorizationCodeInfoWithPhonefail];
|
|
} errorToast:NO]];
|
|
}
|
|
|
|
@end
|