ASUserInfoManager.m 5.0 KB

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