123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194 |
- //
- // YMMyEarningsViewModel.m
- // MSYOUPAI
- //
- // Created by YoMi on 2024/2/27.
- // Copyright © 2024 MS. All rights reserved.
- //
- #import "YMMyEarningsViewModel.h"
- #import "YMWealthModel.h"
- #import "YMMyEarningsModel.h"
- @interface YMMyEarningsViewModel ()
- /// 用户剩余金币
- @property (nonatomic, assign, readwrite) CGFloat userRemainingPoints;
- /// 提现金额项目数据
- @property (nonatomic, strong, readwrite) NSArray <YMMyEarningsWithdrawalAmountCellViewModel*>*withdrawalAmountItemDataArray;
- /// 提现账号类型名
- @property (nonatomic, strong, readwrite) NSString *withdrawalAccountTypeName;
- /// 提现账号持有人
- @property (nonatomic, strong, readwrite) NSString *withdrawalAccountHolder;
- /// 提现账号
- @property (nonatomic, strong, readwrite) NSString *withdrawalAccount;
- /// 账户是否通过认证
- @property (nonatomic, assign, readwrite) NSInteger isVerify;
- /// 提现说明
- @property (nonatomic, strong, readwrite) NSAttributedString *withdrawalNotes;
- /// 获取提现金额
- @property (nonatomic, strong, readwrite) RACSubject *getWithdrawalAmountSubject;
- /// 提现金额
- @property (nonatomic, assign, readwrite) NSInteger withdrawalAmount;
- @end
- @implementation YMMyEarningsViewModel
- - (void)ym_initialize{
- [super ym_initialize];
-
- self.customNavTitle = @"我的收益";
-
- @weakify(self)
- [[self.getWithdrawalAmountSubject takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id _Nullable value) {
- @strongify(self)
- self.withdrawalAmount = [value intValue];
- }];
- }
- - (void)getMyEarningsInfoData{
- @weakify(self)
- [ZCHUDHelper showWithStatus:@"加载中..."];
- [LCHttpHelper requestWithURLString:WalletWithdraw parameters:@{} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
- @strongify(self)
- NSDictionary* dict = (NSDictionary*)responseObject;
- NSInteger code = [[dict objectForKey:@"code"] integerValue];
- if (code == 0) {
- [ZCHUDHelper dismiss];
- YMMyEarningsModel *model = [YMMyEarningsModel yy_modelWithJSON:[dict dictionaryValueForKey:@"data" defaultValue:@{}]];
- self.userRemainingPoints = [model.income_money doubleValue]*100;
- self.withdrawalAmountItemDataArray = [model.list.rac_sequence map:^id _Nullable(YMMyEarningsWithdrawalAmountModel * _Nullable model) {
- YMMyEarningsWithdrawalAmountCellViewModel *viewModel = [[YMMyEarningsWithdrawalAmountCellViewModel alloc]initWithParams:@{
- ParamsModel:model
- }];
- return viewModel;
- }].array;
-
- self.withdrawalAccountTypeName = stringFormat(@"%@账号",model.bank);
-
- self.withdrawalAccountHolder = model.alipay_name;
- self.withdrawalAccount = OCStringIsEmpty(model.alipay_account) ? @"请绑定账号" : model.alipay_account;
-
- NSMutableAttributedString *withdrawalNotesAttributed = [[NSMutableAttributedString alloc]initWithString:model.des];
- withdrawalNotesAttributed.yy_font = LCFont(11);
- withdrawalNotesAttributed.yy_color = HexColorFromRGB(0x9c9c9c);
- withdrawalNotesAttributed.yy_alignment = NSTextAlignmentLeft;
- withdrawalNotesAttributed.yy_lineSpacing = 5;
-
- self.withdrawalNotes = withdrawalNotesAttributed;
-
- [self.refreshUISubject sendNext:@(YMRefreshUI)];
-
- }else{
- [ZCHUDHelper showTitle:[dict stringValueForKey:@"message" defaultValue:@""]];
- }
- } failure:^(NSError *error) {
- [ZCHUDHelper showTitle:error.localizedDescription];
- }];
-
- }
- - (void)submitWithdrawalInfo{
- @weakify(self)
- [ZCHUDHelper showWithStatus:@"提交提现信息中..."];
- [LCHttpHelper requestWithURLString:GetWithdrawPrice parameters:@{
- @"money":@(self.withdrawalAmount)
- } needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
- @strongify(self)
- NSDictionary* dict = (NSDictionary*)responseObject;
- NSInteger code = [[dict objectForKey:@"code"] integerValue];
- if (code == 0) {
- [ZCHUDHelper dismiss];
-
- NSDictionary *data = [dict dictionaryValueForKey:@"data" defaultValue:@{}];
-
- NSInteger withdrawalAmount = [data integerValueForKey:@"withdraw_money" defaultValue:0] * 100;
- NSString *receiveAmount = [data stringValueForKey:@"receive_money" defaultValue:@""];
- NSString *withdrawalAccount = [data stringValueForKey:@"account" defaultValue:@""];
- NSString *withdrawalAccountHolder = [data stringValueForKey:@"account_name" defaultValue:@""];
-
- YMTipsPopupView *customView = [[YMTipsPopupView alloc]init];
- customView.titleText = @"申请提现";
- customView.cancelTitle = @"取消";
- customView.confirmTitle = @"提交";
- [customView configutationWithTips:stringFormat(@"提现 %ld 金币,实际到账 %@ 金额\n收款账号:%@(%@)",withdrawalAmount,receiveAmount,withdrawalAccount,withdrawalAccountHolder) TipsAlignment:NSTextAlignmentLeft IsHideTitle:NO IsHideSingleButton:YES];
- YMPopupView *popupView = [YMPopupView initWithCustomView:customView parentView:nil popStyle:YMPopupStyleFade dismissStyle:YMDismissStyleFade];
- popupView.priority = 999;
- popupView.cornerRadius = adapt(10);
- popupView.rectCorners = UIRectCornerAllCorners;
- popupView.positionStyle = YMPositionStyleCenter;
- popupView.isHideBg = NO;
- popupView.bgAlpha = 0.3;
- @weakify(popupView)
- customView.buttonBlock = ^(BOOL isConfirm) {
- @strongify(popupView)
- if (isConfirm) {
- [self applyWithdrawal];
- }
- [popupView dismissWithStyle:YMDismissStyleFade duration:2.0];
- };
- [popupView pop];
- }else{
- [ZCHUDHelper showTitle:[dict stringValueForKey:@"message" defaultValue:@""]];
- }
- } failure:^(NSError *error) {
- [ZCHUDHelper showTitle:error.localizedDescription];
- }];
- }
- - (void)applyWithdrawal{
- [ZCHUDHelper showWithStatus:@"申请提现中..."];
- [LCHttpHelper requestWithURLString:ApplyWithdrawal parameters:@{
- @"money":@(self.withdrawalAmount)
- } needToken:YES type:HttpRequestTypePost success:^(id responseObject) {
- NSDictionary* dict = (NSDictionary*)responseObject;
- NSInteger code = [[dict objectForKey:@"code"] integerValue];
- if (code == 0) {
- [ZCHUDHelper showTitle:@"提现已申请成功,请耐心等待~" showtime:1.5];
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- [[YMGlobalUtils getCurrentVC].navigationController popViewControllerAnimated:YES];
- });
-
- }else{
- [ZCHUDHelper showTitle:[dict stringValueForKey:@"message" defaultValue:@""]];
- }
- }failure:^(NSError *error) {
- [ZCHUDHelper showTitle:error.localizedDescription];
- }];
- }
- - (void)gotoIncomeBreakdown{
- YMIncomeBreakdownViewModel *incomeBreakdownVM = [[YMIncomeBreakdownViewModel alloc]initWithParams:@{}];
- [YMRouter openURL:stringFormat(@"%@%@", YM_ROUTER_URL_PREFIX, YM_ROUTER_INCOME_BREAKDOWN) withUserInfo:@{
- RouterViewModel:incomeBreakdownVM
- } completion:nil];
- }
- - (void)gotoBindWithdrawalAccount{
- if (![self.withdrawalAccount isEqualToString:@"请绑定账号"]) {
- YMWithdrawalAccountListViewModel *withdrawalAccountListVM = [[YMWithdrawalAccountListViewModel alloc]initWithParams:@{}];
- [YMRouter openURL:stringFormat(@"%@%@", YM_ROUTER_URL_PREFIX, YM_ROUTER_WITHDRAWAL_ACCOUNT_LIST) withUserInfo:@{
- RouterViewModel:withdrawalAccountListVM
- } completion:nil];
- } else {
- YMBindWithdrawalAccountViewModel *bindWithdrawalAccountVM = [[YMBindWithdrawalAccountViewModel alloc]initWithParams:@{
- ParamsCategoryType:@(YMBindWithdrawalAccountTypeAdd),
- }];
- WS(weakSelf)
- bindWithdrawalAccountVM.bindWithdrawalAccountBlock = ^{
- /// 添加绑定提现账号成功后回调之前的提现接口
- // [weakSelf submitWithdrawalInfo];
- };
- [YMRouter openURL:stringFormat(@"%@%@", YM_ROUTER_URL_PREFIX, YM_ROUTER_BIND_WITHDRAWAL_ACCOUNT) withUserInfo:@{
- RouterViewModel:bindWithdrawalAccountVM
- } completion:nil];
- }
- }
- - (RACSubject *)getWithdrawalAmountSubject{
- if (!_getWithdrawalAmountSubject) {
- _getWithdrawalAmountSubject = [RACSubject subject];
- }
- return _getWithdrawalAmountSubject;
- }
- @end
|