// // ASUserInfoManager.m // Asteria // // Created by iOS on 2023/11/27. // #import "ASUserInfoManager.h" #import "ASVipUrlTempModel.h" @interface ASUserInfoManager () @end @implementation ASUserInfoManager + (instancetype)shared { static id sharedInstance = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ sharedInstance = [[self alloc] init]; }); return sharedInstance; } - (instancetype)init { self = [super init]; if (self) { } return self; } - (void)getInfo:(void(^)(void))completeBlock { [self baseInfoNet:^{ if (completeBlock) { completeBlock(); } }]; [self vipInfoNet]; [self birthInfoNet]; } - (void)getInfo { [self baseInfoNet:^{ }]; [self vipInfoNet]; [self birthInfoNet]; } - (void)baseInfoNet:(void(^)(void))comp { [ASNetTools.shared getWithPath:userinfoUrl param:@{} success:^(id _Nonnull json) { self.userInfo = [ASUserModel mj_objectWithKeyValues:json]; [NSNotificationCenter.defaultCenter postNotificationName:UserInfoUpdate object:nil]; NSLog(@"----userInfo:%@-----id:%@----issub:%u----address:%@----", self.userInfo, self.userInfo.Id, self.userInfo.is_subscribed, self.userInfo.addresses); comp(); } faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) { [Current_normalTool.currentNav.topViewController.view makeToast:msg]; comp(); }]; } - (void)birthInfoNet { [ASNetTools.shared getWithPath:userBirthUrl param:@{} success:^(id _Nonnull json) { self.birthDay = [NSString stringWithFormat:@"%@", json[@"birthDay"]]; self.birthStatus = [NSString stringWithFormat:@"%@", json[@"status"]]; self.amount = [NSString stringWithFormat:@"%@", json[@"amount"]]; self.code = [NSString stringWithFormat:@"%@", json[@"code"]]; self.typeId = [NSString stringWithFormat:@"%@", json[@"typeid"]]; } faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) { [Current_normalTool.currentNav.topViewController.view makeToast:msg]; }]; } - (void)vipInfoNet { [ASNetTools.shared getWithPath:vipInfoUrl param:@{} success:^(id _Nonnull json) { ASVipUrlTempModel *tempModel = [ASVipUrlTempModel mj_objectWithKeyValues:json]; self.pointAmount = tempModel.amount; self.userPoints = tempModel.balanceAmount; NSMutableArray *arr = [NSMutableArray array]; ASVipModel *cur = [ASVipModel new]; ASVipModel *next = [ASVipModel new]; if (tempModel != nil && tempModel.membergrade.count != 0) { NSArray *keys = tempModel.membergrade.allKeys; NSMutableArray *sortedArr = [NSMutableArray array]; for (NSString *key in keys) { if (sortedArr.count == 0) { [sortedArr addObject:key]; continue; } for (int i=0; i i+1) { NSString *nx = sortedArr[i+1]; if (key.intValue >= this.intValue && key.intValue < nx.intValue) { [sortedArr insertObject:key atIndex:i+1]; break; } } else { if (sortedArr.count == 1 && key.intValue <= this.intValue) { [sortedArr insertObject:key atIndex:i]; } else { [sortedArr addObject:key]; } break; } } } for (int i=0; i 0 && next.level.intValue <= 0) { next = vipM; } if (vipM.is_cur) { cur = vipM; } if (cur.level.intValue > 0 && next.level.intValue <= 0 && i == sortedArr.count-1) { next = vipM; } [arr addObject:vipM]; } } self.curVipInfo = cur; self.nextVipInfo = next; self.vipInfoArr = arr; [NSNotificationCenter.defaultCenter postNotificationName:UserInfoUpdate object:nil]; } faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) { [Current_normalTool.currentNav.topViewController.view makeToast:msg]; }]; } - (BOOL)isLogin { NSString *token = [DataUtil loginToken]; return !(token == nil || [token isEqualToString:@""]); } @end