ASUserInfoManager.m 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. //
  2. // ASUserInfoManager.m
  3. // Asteria
  4. //
  5. // Created by iOS on 2023/11/27.
  6. //
  7. #import "ASUserInfoManager.h"
  8. #import "ASVipUrlTempModel.h"
  9. @interface ASUserInfoManager ()
  10. @end
  11. @implementation ASUserInfoManager
  12. + (instancetype)shared {
  13. static id sharedInstance = nil;
  14. static dispatch_once_t onceToken;
  15. dispatch_once(&onceToken, ^{
  16. sharedInstance = [[self alloc] init];
  17. });
  18. return sharedInstance;
  19. }
  20. - (instancetype)init
  21. {
  22. self = [super init];
  23. if (self) {
  24. }
  25. return self;
  26. }
  27. - (void)getInfo {
  28. [self baseInfoNet];
  29. [self vipInfoNet];
  30. }
  31. - (void)baseInfoNet {
  32. [ASNetTools.shared getWithPath:userinfoUrl param:@{} success:^(id _Nonnull json) {
  33. self.userInfo = [ASUserModel mj_objectWithKeyValues:json];
  34. [NSNotificationCenter.defaultCenter postNotificationName:UserInfoUpdate object:nil];
  35. NSLog(@"----userInfo:%@-----id:%@----issub:%u----address:%@----", self.userInfo, self.userInfo.Id, self.userInfo.is_subscribed, self.userInfo.addresses);
  36. } faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) {
  37. [Current_normalTool.currentNav.topViewController.view makeToast:msg];
  38. }];
  39. }
  40. - (void)vipInfoNet {
  41. [ASNetTools.shared getWithPath:vipInfoUrl param:@{} success:^(id _Nonnull json) {
  42. ASVipUrlTempModel *tempModel = [ASVipUrlTempModel mj_objectWithKeyValues:json];
  43. self.pointAmount = tempModel.amount;
  44. self.userPoints = tempModel.balanceAmount;
  45. NSMutableArray<ASVipModel *> *arr = [NSMutableArray array];
  46. ASVipModel *cur = [ASVipModel new];
  47. ASVipModel *next = [ASVipModel new];
  48. if (tempModel != nil && tempModel.membergrade.count != 0) {
  49. NSArray *keys = tempModel.membergrade.allKeys;
  50. NSMutableArray *sortedArr = [NSMutableArray array];
  51. for (NSString *key in keys) {
  52. if (sortedArr.count == 0) {
  53. [sortedArr addObject:key];
  54. continue;
  55. }
  56. for (int i=0; i<sortedArr.count; i++) {
  57. NSString *this = sortedArr[i];
  58. if (sortedArr.count > i+1) {
  59. NSString *nx = sortedArr[i+1];
  60. if (key.intValue >= this.intValue && key.intValue < nx.intValue) {
  61. [sortedArr insertObject:key atIndex:i+1];
  62. break;
  63. }
  64. } else {
  65. if (sortedArr.count == 1 && key.intValue <= this.intValue) {
  66. [sortedArr insertObject:key atIndex:i];
  67. } else {
  68. [sortedArr addObject:key];
  69. }
  70. break;
  71. }
  72. }
  73. }
  74. for (int i=0; i<sortedArr.count; i++) {
  75. ASVipModel *vipM = [ASVipModel mj_objectWithKeyValues: tempModel.membergrade[sortedArr[i]]];
  76. if (cur.level.intValue > 0 && next.level.intValue <= 0) {
  77. next = vipM;
  78. }
  79. if (vipM.is_cur) {
  80. cur = vipM;
  81. }
  82. if (cur.level.intValue > 0 && next.level.intValue <= 0 && i == sortedArr.count-1) {
  83. next = vipM;
  84. }
  85. [arr addObject:vipM];
  86. }
  87. }
  88. self.curVipInfo = cur;
  89. self.nextVipInfo = next;
  90. self.vipInfoArr = arr;
  91. [NSNotificationCenter.defaultCenter postNotificationName:UserInfoUpdate object:nil];
  92. } faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) {
  93. [Current_normalTool.currentNav.topViewController.view makeToast:msg];
  94. }];
  95. }
  96. - (BOOL)isLogin {
  97. NSString *token = [NSUserDefaults.standardUserDefaults stringForKey:TokenKey];
  98. return !(token == nil || [token isEqualToString:@""]);
  99. }
  100. @end