HJMyWalletViewController.m 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. //
  2. // HJMyWalletViewController.m
  3. // HappyJob
  4. //
  5. // Created by 张晓光 on 2019/9/5.
  6. // Copyright © 2019 Bob. All rights reserved.
  7. //
  8. #import "HJMyWalletViewController.h"
  9. #import "HJMyWalletDetailViewController.h"//明细
  10. #import "HJMyWalletWithdrawalViewController.h"//提现
  11. #import "HJMyWalletView.h"
  12. #import "HJMyWalletAPI.h"
  13. #import "HJApproveStatusAPIManager.h"
  14. #import "HJMyWalletModel.h"
  15. #import "HJAuthViewController.h"//认证
  16. #import "HJAuthingViewController.h"//认证中
  17. #import "HJAuthFailedViewController.h"//认证失败
  18. @interface HJMyWalletViewController ()
  19. <
  20. UIGestureRecognizerDelegate,
  21. FBAPIManagerDelegate,
  22. FBAPIManagerInterceptor
  23. >
  24. @property (nonatomic, strong) HJMyWalletView *walletView;
  25. @property (nonatomic, strong) HJMyWalletAPI *walletAPI;//钱包余额
  26. @property (nonatomic, strong) HJApproveStatusAPIManager *approveStatusAPI;//认证状态的
  27. @property (nonatomic, assign) HJAuthStatusType authStatus;//实名认证状态
  28. @property (nonatomic, strong) HJConfirmPanelSingleView *confirmPanelView;
  29. @end
  30. @implementation HJMyWalletViewController
  31. #pragma mark - life cycle
  32. - (void)viewWillAppear:(BOOL)animated {
  33. [super viewWillAppear:animated];
  34. [self.navigationController setNavigationBarHidden:YES animated:animated];
  35. self.navigationController.interactivePopGestureRecognizer.delegate = self;
  36. [self.view.errorView.refreshButton addTarget:self
  37. action:@selector(refreshButtonClicked:)
  38. forControlEvents:UIControlEventTouchUpInside];
  39. }
  40. - (void)viewDidLoad {
  41. [super viewDidLoad];
  42. [self initSubViews];
  43. [self.walletAPI start];
  44. }
  45. #pragma mark - init
  46. - (void)initSubViews {
  47. [self.view addSubview:self.walletView];
  48. [self.walletView mas_makeConstraints:^(MASConstraintMaker *make) {
  49. make.left.top.right.bottom.equalTo(self.view).offset(0);
  50. }];
  51. }
  52. #pragma mark - FBAPIManagerInterceptor
  53. - (BOOL)manager:(FBBaseAPIManager *)manager shouldStartCallAPIWithParams:(NSDictionary *)params {
  54. [self.view fb_showLoading];
  55. return YES;
  56. }
  57. - (void)managerShouldFinishCallAPI:(FBBaseAPIManager *)manager {
  58. [self.view fb_dismiss];
  59. }
  60. #pragma mark - FBAPIManagerDelegate
  61. - (void)managerCallAPIDidSuccess:(FBBaseAPIManager *)manager {
  62. if (manager == self.walletAPI)
  63. {
  64. [self.view dismissErrorView];
  65. id fetchData = [manager fetchDataWithBox:nil];
  66. if ([fetchData isKindOfClass:[NSDictionary class]])
  67. {
  68. HJMyWalletModel *model = [HJMyWalletModel yy_modelWithDictionary:fetchData[@"data"][@"MpMemberAccountAPI"]];
  69. self.walletView.moneyLabel.text = [NSString stringWithFormat:@"¥%@",[HJAppService thousandSeparatorStringWithNumber:model.moneyBalance]];
  70. }
  71. }
  72. if (manager == self.approveStatusAPI)
  73. {
  74. self.authStatus = (HJAuthStatusType)[[[manager fetchDataWithBox:nil] valueForKeyPath:@"data.approveStatus"] integerValue];
  75. if (self.authStatus == HJAuthStatusTypeAuthSuccess)
  76. {//认证成功(提现)
  77. HJMyWalletWithdrawalViewController *vc = [[HJMyWalletWithdrawalViewController alloc]init];
  78. [self.navigationController pushViewController:vc animated:YES];
  79. }
  80. if (self.authStatus == HJAuthStatusTypeNoAuth)
  81. {//没有认证
  82. self.confirmPanelView.titleLabel.text = @"为了保证资金安全, 请先进行实名认证。";
  83. [self.confirmPanelView ShowConfirmPanelSingleView];
  84. }
  85. else if (self.authStatus == HJAuthStatusTypeAuthing)
  86. {//认证中
  87. self.confirmPanelView.titleLabel.text = @"实名认证正在审核中,请耐心等待。";
  88. [self.confirmPanelView ShowConfirmPanelSingleView];
  89. }
  90. else if (self.authStatus == HJAuthStatusTypeAuthFailed)
  91. {//失败
  92. self.confirmPanelView.titleLabel.text = @"实名认证失败,请重新提交认证。";
  93. [self.confirmPanelView ShowConfirmPanelSingleView];
  94. }
  95. }
  96. }
  97. - (void)managerCallAPIDidFailed:(FBBaseAPIManager *)manager {
  98. FBAPIManagerErrorType type = manager.errorType;
  99. if (manager == self.walletAPI)
  100. {
  101. NSLog(@"------------------");
  102. [self.view showErrorView];
  103. }
  104. if (type == FBAPIManagerErrorTypeNoContent)
  105. {
  106. id fetchData = [manager fetchDataWithBox:nil];
  107. if ([fetchData isKindOfClass:[NSDictionary class]])
  108. {
  109. [self.view fb_showFailureWithStatus:fetchData[@"errmsg"]];
  110. }
  111. }
  112. else
  113. {
  114. [self.view fb_showFailureWithStatus:manager.errorMessage];
  115. }
  116. }
  117. #pragma mark - event response
  118. /* 错误刷新 */
  119. - (void)refreshButtonClicked:(UIButton *)btn {
  120. [self.walletAPI start];
  121. }
  122. /* 返回 */
  123. - (void)backButtonClick:(UIButton *)btn {
  124. [self.navigationController popViewControllerAnimated:YES];
  125. }
  126. /* 明细 */
  127. - (void)detailButtonClick:(UIButton *)btn {
  128. HJMyWalletDetailViewController *vc = [[HJMyWalletDetailViewController alloc]init];
  129. [self.navigationController pushViewController:vc animated:YES];
  130. }
  131. /* 提现 */
  132. - (void)withdrawalButtonClick:(UIButton *)btn {
  133. [self.approveStatusAPI start];
  134. }
  135. /* 好的*/
  136. - (void)confirmButtonClick:(UIButton *)btn {
  137. self.confirmPanelView = nil;
  138. if (self.authStatus == HJAuthStatusTypeNoAuth)
  139. {//没有认证
  140. HJAuthViewController *authVC = [[HJAuthViewController alloc] init];
  141. [self.navigationController pushViewController:authVC animated:YES];
  142. }
  143. else if (self.authStatus == HJAuthStatusTypeAuthing)
  144. {//认证中
  145. HJAuthingViewController *authingVC = [[HJAuthingViewController alloc] init];
  146. [self.navigationController pushViewController:authingVC animated:YES];
  147. }
  148. else if (self.authStatus == HJAuthStatusTypeAuthFailed)
  149. {//失败
  150. HJAuthFailedViewController *authFailedVC = [[HJAuthFailedViewController alloc] init];
  151. [self.navigationController pushViewController:authFailedVC animated:YES];
  152. }
  153. }
  154. #pragma mark - setter and getter
  155. - (HJMyWalletView *)walletView {
  156. if (_walletView == nil)
  157. {
  158. _walletView = [[HJMyWalletView alloc]init];
  159. [_walletView.backBtn addTarget:self action:@selector(backButtonClick:) forControlEvents:UIControlEventTouchUpInside];
  160. [_walletView.detailBtn addTarget:self action:@selector(detailButtonClick:) forControlEvents:UIControlEventTouchUpInside];
  161. [_walletView.withdrawalBtn addTarget:self action:@selector(withdrawalButtonClick:) forControlEvents:UIControlEventTouchUpInside];
  162. }
  163. return _walletView;
  164. }
  165. - (HJMyWalletAPI *)walletAPI {
  166. if (_walletAPI == nil)
  167. {
  168. _walletAPI = [[HJMyWalletAPI alloc]init];
  169. _walletAPI.APIManagerDelegate = self;
  170. _walletAPI.APIManagerInterceptor = self;
  171. }
  172. return _walletAPI;
  173. }
  174. - (HJApproveStatusAPIManager *)approveStatusAPI {
  175. if (_approveStatusAPI == nil)
  176. {
  177. _approveStatusAPI = [[HJApproveStatusAPIManager alloc]init];
  178. _approveStatusAPI.APIManagerDelegate = self;
  179. _approveStatusAPI.APIManagerInterceptor = self;
  180. }
  181. return _approveStatusAPI;
  182. }
  183. - (HJConfirmPanelSingleView *)confirmPanelView {
  184. if (_confirmPanelView == nil)
  185. {
  186. _confirmPanelView = [[HJConfirmPanelSingleView alloc]init];
  187. [_confirmPanelView.confirmButton setTitle:@"好的" forState:UIControlStateNormal];
  188. [_confirmPanelView.confirmButton addTarget:self action:@selector(confirmButtonClick:) forControlEvents:UIControlEventTouchUpInside];
  189. }
  190. return _confirmPanelView;
  191. }
  192. /*
  193. #pragma mark - Navigation
  194. // In a storyboard-based application, you will often want to do a little preparation before navigation
  195. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  196. // Get the new view controller using [segue destinationViewController].
  197. // Pass the selected object to the new view controller.
  198. }
  199. */
  200. @end