ASUserInfoManager.m 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. }];
  30. [self vipInfoNet];
  31. [self birthInfoNet];
  32. }
  33. - (void)baseInfoNet:(void(^)(void))comp {
  34. [ASNetTools.shared getWithPath:userinfoUrl param:@{} success:^(id _Nonnull json) {
  35. self.userInfo = [ASUserModel mj_objectWithKeyValues:json];
  36. [NSNotificationCenter.defaultCenter postNotificationName:UserInfoUpdate object:nil];
  37. NSLog(@"----userInfo:%@-----id:%@----issub:%u----address:%@----", self.userInfo, self.userInfo.Id, self.userInfo.is_subscribed, self.userInfo.addresses);
  38. comp();
  39. } faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) {
  40. [Current_normalTool.currentNav.topViewController.view makeToast:msg];
  41. comp();
  42. }];
  43. }
  44. - (void)birthInfoNet {
  45. [ASNetTools.shared getWithPath:userBirthUrl param:@{} success:^(id _Nonnull json) {
  46. self.birthDay = [NSString stringWithFormat:@"%@", json[@"birthDay"]];
  47. self.birthStatus = [NSString stringWithFormat:@"%@", json[@"status"]];
  48. self.amount = [NSString stringWithFormat:@"%@", json[@"amount"]];
  49. self.code = [NSString stringWithFormat:@"%@", json[@"code"]];
  50. self.typeId = [NSString stringWithFormat:@"%@", json[@"typeid"]];
  51. } faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) {
  52. [Current_normalTool.currentNav.topViewController.view makeToast:msg];
  53. }];
  54. }
  55. - (void)vipInfoNet {
  56. [ASNetTools.shared getWithPath:vipInfoUrl param:@{} success:^(id _Nonnull json) {
  57. ASVipUrlTempModel *tempModel = [ASVipUrlTempModel mj_objectWithKeyValues:json];
  58. self.pointAmount = tempModel.amount;
  59. self.userPoints = tempModel.balanceAmount;
  60. NSMutableArray<ASVipModel *> *arr = [NSMutableArray array];
  61. ASVipModel *cur = [ASVipModel new];
  62. ASVipModel *next = [ASVipModel new];
  63. if (tempModel != nil && tempModel.membergrade.count != 0) {
  64. NSArray *keys = tempModel.membergrade.allKeys;
  65. NSMutableArray *sortedArr = [NSMutableArray array];
  66. for (NSString *key in keys) {
  67. if (sortedArr.count == 0) {
  68. [sortedArr addObject:key];
  69. continue;
  70. }
  71. for (int i=0; i<sortedArr.count; i++) {
  72. NSString *this = sortedArr[i];
  73. if (sortedArr.count > i+1) {
  74. NSString *nx = sortedArr[i+1];
  75. if (key.intValue >= this.intValue && key.intValue < nx.intValue) {
  76. [sortedArr insertObject:key atIndex:i+1];
  77. break;
  78. }
  79. } else {
  80. if (sortedArr.count == 1 && key.intValue <= this.intValue) {
  81. [sortedArr insertObject:key atIndex:i];
  82. } else {
  83. [sortedArr addObject:key];
  84. }
  85. break;
  86. }
  87. }
  88. }
  89. for (int i=0; i<sortedArr.count; i++) {
  90. ASVipModel *vipM = [ASVipModel mj_objectWithKeyValues: tempModel.membergrade[sortedArr[i]]];
  91. if (i+1<sortedArr.count) {
  92. ASVipModel *tempNext = [ASVipModel mj_objectWithKeyValues: tempModel.membergrade[sortedArr[i+1]]];
  93. vipM.nextExppoints = tempNext.exppoints;
  94. }
  95. if (cur.level.intValue > 0 && next.level.intValue <= 0) {
  96. next = vipM;
  97. }
  98. if (vipM.is_cur) {
  99. cur = vipM;
  100. }
  101. if (cur.level.intValue > 0 && next.level.intValue <= 0 && i == sortedArr.count-1) {
  102. next = vipM;
  103. }
  104. [arr addObject:vipM];
  105. }
  106. }
  107. self.curVipInfo = cur;
  108. self.nextVipInfo = next;
  109. self.vipInfoArr = arr;
  110. [NSNotificationCenter.defaultCenter postNotificationName:UserInfoUpdate object:nil];
  111. } faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) {
  112. [Current_normalTool.currentNav.topViewController.view makeToast:msg];
  113. }];
  114. }
  115. - (BOOL)isLogin {
  116. NSString *token = [DataUtil loginToken];
  117. return !(token == nil || [token isEqualToString:@""]);
  118. }
  119. @end