YMIncomeBreakdownListViewModel.m 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. //
  2. // YMIncomeBreakdownListViewModel.m
  3. // MSYOUPAI
  4. //
  5. // Created by YoMi on 2024/3/3.
  6. // Copyright © 2024 MS. All rights reserved.
  7. //
  8. #import "YMIncomeBreakdownListViewModel.h"
  9. #import "YMPointsAndEarningsListModel.h"
  10. #import "YMWithdrawalRecordsListModel.h"
  11. @interface YMIncomeBreakdownListViewModel ()
  12. /// 当前数据数量
  13. @property (nonatomic, assign) NSInteger currentSize;
  14. /// 好友分类类型
  15. @property (nonatomic, assign, readwrite) YMIncomeBreakdownCategoryType categoryType;
  16. /// 金币和收益数据
  17. @property (nonatomic, strong, readwrite) NSMutableArray <YMIncomeBreakdownListPointsAndEarningsSectionViewModel*>*pointsAndEarningsDataArray;
  18. /// 金币和收益数据
  19. @property (nonatomic, strong, readwrite) NSMutableArray <YMIncomeBreakdownListWithdrawalRecordsCellModel*>*withdrawalRecordsDataArray;
  20. /// 更改收支明细日期
  21. @property (nonatomic, strong, readwrite) RACSubject *changeIncomeBreakdownDateSubject;
  22. /// 筛选Id 0全部 1充值 2提现 3视频 4礼物 5系统 6兑换 7私信
  23. @property (nonatomic, assign) NSInteger *screeningId;
  24. /// 筛选日期
  25. @property (nonatomic, copy) NSString *screeningDate;
  26. @end
  27. @implementation YMIncomeBreakdownListViewModel
  28. - (void)ym_initialize{
  29. [super ym_initialize];
  30. self.currentPage = 1;
  31. self.currentSize = 10;
  32. self.categoryType = [self.params integerValueForKey:ParamsCategoryType defaultValue:YMIncomeBreakdownCategoryTypePoints];
  33. @weakify(self)
  34. [[self.changeIncomeBreakdownDateSubject takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id _Nullable value) {
  35. @strongify(self)
  36. self.screeningDate = value;
  37. self.currentPage = 1;
  38. [self getIncomeBreakdownListData];
  39. }];
  40. }
  41. - (void)getIncomeBreakdownListData {
  42. switch (self.categoryType) {
  43. case YMIncomeBreakdownCategoryTypePoints:
  44. case YMIncomeBreakdownCategoryTypeEarnings:
  45. {
  46. [self getBillListData];
  47. }
  48. break;
  49. case YMIncomeBreakdownCategoryTypeWithdrawalRecords:
  50. {
  51. [self getWithdrawalRecordsListData];
  52. }
  53. break;
  54. default:
  55. break;
  56. }
  57. }
  58. - (void)getBillListData{
  59. @weakify(self)
  60. [ZCHUDHelper showWithStatus:@"加载中..."];
  61. [LCHttpHelper requestWithURLString:WalletBill parameters:@{
  62. @"page":@(self.currentPage),
  63. @"category":@(self.categoryType),
  64. @"type":@(0),
  65. @"new_type":@(self.categoryType),
  66. @"cate_id":@(0),
  67. @"date":self.screeningDate
  68. } needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  69. @strongify(self)
  70. NSDictionary* dict = (NSDictionary*)responseObject;
  71. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  72. if (code == 0) {
  73. [ZCHUDHelper dismiss];
  74. NSDictionary *data = [dict dictionaryValueForKey:@"data" defaultValue:@{}];
  75. NSArray <NSDictionary*>*newlist = [data arrayValueForKey:@"new_list" defaultValue:@[]];
  76. NSArray *result = [newlist.lastObject arrayValueForKey:@"list" defaultValue:@[]];
  77. if (self.currentPage == 1) {
  78. [self.pointsAndEarningsDataArray removeAllObjects];
  79. }
  80. NSArray *viewModelArr = [[NSArray yy_modelArrayWithClass:[YMPointsAndEarningsListModel class] json:newlist].rac_sequence map:^(YMPointsAndEarningsListModel * _Nullable model) {
  81. YMIncomeBreakdownListPointsAndEarningsSectionViewModel *viewModel = [[YMIncomeBreakdownListPointsAndEarningsSectionViewModel alloc]initWithParams:@{
  82. ParamsModel:model,
  83. ParamsCategoryType:@(self.categoryType)
  84. }];
  85. return viewModel;
  86. }].array;
  87. [self.pointsAndEarningsDataArray addObjectsFromArray:viewModelArr];
  88. if(self.currentPage > 0 && self.currentPage % 5 == 0){
  89. [[SDImageCache sharedImageCache] clearMemory];
  90. }
  91. [self.refreshUISubject sendNext:@(result.count < self.currentSize ? YMFooterRefresh_HasNoMoreData : YMFooterRefresh_HasMoreData)];
  92. }else{
  93. [ZCHUDHelper showTitle:[dict stringValueForKey:@"message" defaultValue:@""]];
  94. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  95. [self.refreshUISubject sendNext:@(YMRefreshError)];
  96. });
  97. }
  98. } failure:^(NSError *error) {
  99. if(self.currentPage != 1){
  100. self.currentPage--;
  101. }
  102. [ZCHUDHelper showTitle:error.localizedDescription];
  103. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  104. [self.refreshUISubject sendNext:@(YMRefreshError)];
  105. });
  106. }];
  107. }
  108. - (void)getWithdrawalRecordsListData{
  109. @weakify(self)
  110. [ZCHUDHelper showWithStatus:@"加载中..."];
  111. [LCHttpHelper requestWithURLString:WithdrawalRecordsInfo parameters:@{
  112. @"page":@(self.currentPage),
  113. @"date":self.screeningDate
  114. } needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  115. @strongify(self)
  116. NSDictionary* dict = (NSDictionary*)responseObject;
  117. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  118. if (code == 0) {
  119. [ZCHUDHelper dismiss];
  120. NSDictionary *data = [dict dictionaryValueForKey:@"data" defaultValue:@{}];
  121. NSArray *result = [data arrayValueForKey:@"list" defaultValue:@[]];
  122. if (self.currentPage == 1) {
  123. [self.withdrawalRecordsDataArray removeAllObjects];
  124. }
  125. NSArray *viewModelArr = [[NSArray yy_modelArrayWithClass:[YMWithdrawalRecordsListModel class] json:result].rac_sequence map:^(YMWithdrawalRecordsListModel * _Nullable model) {
  126. YMIncomeBreakdownListWithdrawalRecordsCellModel *viewModel = [[YMIncomeBreakdownListWithdrawalRecordsCellModel alloc]initWithParams:@{
  127. ParamsModel:model,
  128. ParamsCategoryType:@(self.categoryType)
  129. }];
  130. return viewModel;
  131. }].array;
  132. [self.withdrawalRecordsDataArray addObjectsFromArray:viewModelArr];
  133. if(self.currentPage > 0 && self.currentPage % 5 == 0){
  134. [[SDImageCache sharedImageCache] clearMemory];
  135. }
  136. [self.refreshUISubject sendNext:@(result.count < self.currentSize ? YMFooterRefresh_HasNoMoreData : YMFooterRefresh_HasMoreData)];
  137. }else{
  138. [ZCHUDHelper showTitle:[dict stringValueForKey:@"message" defaultValue:@""]];
  139. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  140. [self.refreshUISubject sendNext:@(YMRefreshError)];
  141. });
  142. }
  143. } failure:^(NSError *error) {
  144. if(self.currentPage != 1){
  145. self.currentPage--;
  146. }
  147. [ZCHUDHelper showTitle:error.localizedDescription];
  148. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  149. [self.refreshUISubject sendNext:@(YMRefreshError)];
  150. });
  151. }];
  152. }
  153. - (NSMutableArray<YMIncomeBreakdownListPointsAndEarningsSectionViewModel *> *)pointsAndEarningsDataArray{
  154. if (!_pointsAndEarningsDataArray) {
  155. _pointsAndEarningsDataArray = [NSMutableArray array];
  156. }
  157. return _pointsAndEarningsDataArray;
  158. }
  159. - (NSMutableArray<YMIncomeBreakdownListWithdrawalRecordsCellModel *> *)withdrawalRecordsDataArray{
  160. if (!_withdrawalRecordsDataArray) {
  161. _withdrawalRecordsDataArray = [NSMutableArray array];
  162. }
  163. return _withdrawalRecordsDataArray;
  164. }
  165. - (RACSubject *)changeIncomeBreakdownDateSubject{
  166. if (!_changeIncomeBreakdownDateSubject) {
  167. _changeIncomeBreakdownDateSubject = [RACSubject subject];
  168. }
  169. return _changeIncomeBreakdownDateSubject;
  170. }
  171. @end