YMMyEarningsViewModel.m 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. //
  2. // YMMyEarningsViewModel.m
  3. // MSYOUPAI
  4. //
  5. // Created by YoMi on 2024/2/27.
  6. // Copyright © 2024 MS. All rights reserved.
  7. //
  8. #import "YMMyEarningsViewModel.h"
  9. #import "YMWealthModel.h"
  10. #import "YMMyEarningsModel.h"
  11. @interface YMMyEarningsViewModel ()
  12. /// 用户剩余金币
  13. @property (nonatomic, assign, readwrite) CGFloat userRemainingPoints;
  14. /// 提现金额项目数据
  15. @property (nonatomic, strong, readwrite) NSArray <YMMyEarningsWithdrawalAmountCellViewModel*>*withdrawalAmountItemDataArray;
  16. /// 提现账号类型名
  17. @property (nonatomic, strong, readwrite) NSString *withdrawalAccountTypeName;
  18. /// 提现账号持有人
  19. @property (nonatomic, strong, readwrite) NSString *withdrawalAccountHolder;
  20. /// 提现账号
  21. @property (nonatomic, strong, readwrite) NSString *withdrawalAccount;
  22. /// 账户是否通过认证
  23. @property (nonatomic, assign, readwrite) NSInteger isVerify;
  24. /// 提现说明
  25. @property (nonatomic, strong, readwrite) NSAttributedString *withdrawalNotes;
  26. /// 获取提现金额
  27. @property (nonatomic, strong, readwrite) RACSubject *getWithdrawalAmountSubject;
  28. /// 提现金额
  29. @property (nonatomic, assign, readwrite) NSInteger withdrawalAmount;
  30. @end
  31. @implementation YMMyEarningsViewModel
  32. - (void)ym_initialize{
  33. [super ym_initialize];
  34. self.customNavTitle = @"我的收益";
  35. @weakify(self)
  36. [[self.getWithdrawalAmountSubject takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id _Nullable value) {
  37. @strongify(self)
  38. self.withdrawalAmount = [value intValue];
  39. }];
  40. }
  41. - (void)getMyEarningsInfoData{
  42. @weakify(self)
  43. [ZCHUDHelper showWithStatus:@"加载中..."];
  44. [LCHttpHelper requestWithURLString:WalletWithdraw parameters:@{} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  45. @strongify(self)
  46. NSDictionary* dict = (NSDictionary*)responseObject;
  47. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  48. if (code == 0) {
  49. [ZCHUDHelper dismiss];
  50. YMMyEarningsModel *model = [YMMyEarningsModel yy_modelWithJSON:[dict dictionaryValueForKey:@"data" defaultValue:@{}]];
  51. self.userRemainingPoints = [model.income_money doubleValue]*100;
  52. self.withdrawalAmountItemDataArray = [model.list.rac_sequence map:^id _Nullable(YMMyEarningsWithdrawalAmountModel * _Nullable model) {
  53. YMMyEarningsWithdrawalAmountCellViewModel *viewModel = [[YMMyEarningsWithdrawalAmountCellViewModel alloc]initWithParams:@{
  54. ParamsModel:model
  55. }];
  56. return viewModel;
  57. }].array;
  58. self.withdrawalAccountTypeName = stringFormat(@"%@账号",model.bank);
  59. self.withdrawalAccountHolder = model.alipay_name;
  60. self.withdrawalAccount = OCStringIsEmpty(model.alipay_account) ? @"请绑定账号" : model.alipay_account;
  61. NSMutableAttributedString *withdrawalNotesAttributed = [[NSMutableAttributedString alloc]initWithString:model.des];
  62. withdrawalNotesAttributed.yy_font = LCFont(11);
  63. withdrawalNotesAttributed.yy_color = HexColorFromRGB(0x9c9c9c);
  64. withdrawalNotesAttributed.yy_alignment = NSTextAlignmentLeft;
  65. withdrawalNotesAttributed.yy_lineSpacing = 5;
  66. self.withdrawalNotes = withdrawalNotesAttributed;
  67. [self.refreshUISubject sendNext:@(YMRefreshUI)];
  68. }else{
  69. [ZCHUDHelper showTitle:[dict stringValueForKey:@"message" defaultValue:@""]];
  70. }
  71. } failure:^(NSError *error) {
  72. [ZCHUDHelper showTitle:error.localizedDescription];
  73. }];
  74. }
  75. - (void)submitWithdrawalInfo{
  76. @weakify(self)
  77. [ZCHUDHelper showWithStatus:@"提交提现信息中..."];
  78. [LCHttpHelper requestWithURLString:GetWithdrawPrice parameters:@{
  79. @"money":@(self.withdrawalAmount)
  80. } needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  81. @strongify(self)
  82. NSDictionary* dict = (NSDictionary*)responseObject;
  83. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  84. if (code == 0) {
  85. [ZCHUDHelper dismiss];
  86. NSDictionary *data = [dict dictionaryValueForKey:@"data" defaultValue:@{}];
  87. NSInteger withdrawalAmount = [data integerValueForKey:@"withdraw_money" defaultValue:0] * 100;
  88. NSString *receiveAmount = [data stringValueForKey:@"receive_money" defaultValue:@""];
  89. NSString *withdrawalAccount = [data stringValueForKey:@"account" defaultValue:@""];
  90. NSString *withdrawalAccountHolder = [data stringValueForKey:@"account_name" defaultValue:@""];
  91. YMTipsPopupView *customView = [[YMTipsPopupView alloc]init];
  92. customView.titleText = @"申请提现";
  93. customView.cancelTitle = @"取消";
  94. customView.confirmTitle = @"提交";
  95. [customView configutationWithTips:stringFormat(@"提现 %ld 金币,实际到账 %@ 金额\n收款账号:%@(%@)",withdrawalAmount,receiveAmount,withdrawalAccount,withdrawalAccountHolder) TipsAlignment:NSTextAlignmentLeft IsHideTitle:NO IsHideSingleButton:YES];
  96. YMPopupView *popupView = [YMPopupView initWithCustomView:customView parentView:nil popStyle:YMPopupStyleFade dismissStyle:YMDismissStyleFade];
  97. popupView.priority = 999;
  98. popupView.cornerRadius = adapt(10);
  99. popupView.rectCorners = UIRectCornerAllCorners;
  100. popupView.positionStyle = YMPositionStyleCenter;
  101. popupView.isHideBg = NO;
  102. popupView.bgAlpha = 0.3;
  103. @weakify(popupView)
  104. customView.buttonBlock = ^(BOOL isConfirm) {
  105. @strongify(popupView)
  106. if (isConfirm) {
  107. [self applyWithdrawal];
  108. }
  109. [popupView dismissWithStyle:YMDismissStyleFade duration:2.0];
  110. };
  111. [popupView pop];
  112. }else{
  113. [ZCHUDHelper showTitle:[dict stringValueForKey:@"message" defaultValue:@""]];
  114. }
  115. } failure:^(NSError *error) {
  116. [ZCHUDHelper showTitle:error.localizedDescription];
  117. }];
  118. }
  119. - (void)applyWithdrawal{
  120. [ZCHUDHelper showWithStatus:@"申请提现中..."];
  121. [LCHttpHelper requestWithURLString:ApplyWithdrawal parameters:@{
  122. @"money":@(self.withdrawalAmount)
  123. } needToken:YES type:HttpRequestTypePost success:^(id responseObject) {
  124. NSDictionary* dict = (NSDictionary*)responseObject;
  125. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  126. if (code == 0) {
  127. [ZCHUDHelper showTitle:@"提现已申请成功,请耐心等待~" showtime:1.5];
  128. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  129. [[YMGlobalUtils getCurrentVC].navigationController popViewControllerAnimated:YES];
  130. });
  131. }else{
  132. [ZCHUDHelper showTitle:[dict stringValueForKey:@"message" defaultValue:@""]];
  133. }
  134. }failure:^(NSError *error) {
  135. [ZCHUDHelper showTitle:error.localizedDescription];
  136. }];
  137. }
  138. - (void)gotoIncomeBreakdown{
  139. YMIncomeBreakdownViewModel *incomeBreakdownVM = [[YMIncomeBreakdownViewModel alloc]initWithParams:@{}];
  140. [YMRouter openURL:stringFormat(@"%@%@", YM_ROUTER_URL_PREFIX, YM_ROUTER_INCOME_BREAKDOWN) withUserInfo:@{
  141. RouterViewModel:incomeBreakdownVM
  142. } completion:nil];
  143. }
  144. - (void)gotoBindWithdrawalAccount{
  145. if (![self.withdrawalAccount isEqualToString:@"请绑定账号"]) {
  146. YMWithdrawalAccountListViewModel *withdrawalAccountListVM = [[YMWithdrawalAccountListViewModel alloc]initWithParams:@{}];
  147. [YMRouter openURL:stringFormat(@"%@%@", YM_ROUTER_URL_PREFIX, YM_ROUTER_WITHDRAWAL_ACCOUNT_LIST) withUserInfo:@{
  148. RouterViewModel:withdrawalAccountListVM
  149. } completion:nil];
  150. } else {
  151. YMBindWithdrawalAccountViewModel *bindWithdrawalAccountVM = [[YMBindWithdrawalAccountViewModel alloc]initWithParams:@{
  152. ParamsCategoryType:@(YMBindWithdrawalAccountTypeAdd),
  153. }];
  154. WS(weakSelf)
  155. bindWithdrawalAccountVM.bindWithdrawalAccountBlock = ^{
  156. /// 添加绑定提现账号成功后回调之前的提现接口
  157. // [weakSelf submitWithdrawalInfo];
  158. };
  159. [YMRouter openURL:stringFormat(@"%@%@", YM_ROUTER_URL_PREFIX, YM_ROUTER_BIND_WITHDRAWAL_ACCOUNT) withUserInfo:@{
  160. RouterViewModel:bindWithdrawalAccountVM
  161. } completion:nil];
  162. }
  163. }
  164. - (RACSubject *)getWithdrawalAmountSubject{
  165. if (!_getWithdrawalAmountSubject) {
  166. _getWithdrawalAmountSubject = [RACSubject subject];
  167. }
  168. return _getWithdrawalAmountSubject;
  169. }
  170. @end