ASUserInfoManager.m 4.7 KB

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