NYLoginBindViewController.m 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. //
  2. // NYLoginBindViewController.m
  3. // jiaPei
  4. //
  5. // Created by Ning.ge on 2025/3/31.
  6. // Copyright © 2025 JCZ. All rights reserved.
  7. //
  8. #import "NYLoginBindViewController.h"
  9. #import "RQPhoneView.h"
  10. #import "RQPasswordView.h"
  11. @interface NYLoginBindViewController ()
  12. @property (nonatomic, readonly, strong) NYLoginBindViewModel *viewModel;
  13. @property (strong, readwrite, nonatomic) RQPhoneView *phoneView;
  14. @property (strong, readwrite, nonatomic) RQPasswordView *passwordView;
  15. @property (weak, nonatomic) IBOutlet UIView *containerView;
  16. @property (weak, nonatomic) IBOutlet UIButton *submit_btn;
  17. @end
  18. @implementation NYLoginBindViewController
  19. @dynamic viewModel;
  20. - (void)viewDidLoad {
  21. [super viewDidLoad];
  22. /// 设置
  23. [self rq_setup];
  24. [self setupSubViews];
  25. }
  26. #pragma mark - 设置子控件
  27. - (void)setupSubViews {
  28. @weakify(self)
  29. /// 手机号码
  30. RQPhoneView *phoneView = [RQPhoneView loginCodeView];
  31. self.phoneView = phoneView;
  32. [self.containerView addSubview:phoneView];
  33. /// 密码
  34. RQPasswordView *passwordView = [RQPasswordView passwordView];
  35. self.passwordView = passwordView;
  36. [self.containerView addSubview:passwordView];
  37. /// 布局
  38. [phoneView mas_makeConstraints:^(MASConstraintMaker *make) {
  39. @strongify(self)
  40. make.top.mas_equalTo(self.containerView);
  41. make.left.mas_equalTo(self.containerView).mas_offset(16.f);
  42. make.right.mas_equalTo(self.containerView).mas_offset(-16.f);
  43. make.height.mas_offset(RQ_FIT_HORIZONTAL(44.f));
  44. phoneView.layer.cornerRadius = RQ_FIT_HORIZONTAL(44.f) / 2.f;
  45. }];
  46. [passwordView mas_makeConstraints:^(MASConstraintMaker *make) {
  47. @strongify(self)
  48. make.top.mas_equalTo(self.phoneView.mas_bottom).mas_offset(16.f);
  49. make.left.mas_equalTo(self.containerView).mas_offset(16.f);
  50. make.right.mas_equalTo(self.containerView).mas_offset(-16.f);
  51. make.height.mas_offset(RQ_FIT_HORIZONTAL(44.f));
  52. passwordView.layer.cornerRadius = RQ_FIT_HORIZONTAL(44.f) / 2.f;
  53. }];
  54. }
  55. #pragma mark - 初始化
  56. - (void)rq_setup {
  57. if(self.viewModel.isBind){
  58. [self.submit_btn setTitle:@"解除绑定" forState:UIControlStateNormal];
  59. }else{
  60. [self.submit_btn setTitle:@"立即绑定" forState:UIControlStateNormal];
  61. }
  62. }
  63. //立即绑定
  64. - (IBAction)loginBinddo:(id)sender {
  65. NSString *logincode = self.phoneView.loginCodeTextField.text;
  66. NSString *password = self.passwordView.passwordTextField.text;
  67. if(RQStringIsEmpty(logincode)){
  68. ShowMsg(@"请输入账号");
  69. return;
  70. }
  71. if(RQStringIsEmpty(password)){
  72. ShowMsg(@"请输入密码");
  73. return;
  74. }
  75. /// 存储登录账号
  76. [SAMKeychain setRawLogin:logincode];
  77. [SAMKeychain setRawLoginPassword:password];
  78. if(self.viewModel.isBind){
  79. //解除绑定
  80. [MBProgressHUD rq_showProgressHUD:@""];
  81. NSDictionary *dict = @{
  82. @"logincode": logincode,
  83. @"password": [password md5String]
  84. };
  85. [jiaPeiManager NYRequestAnythingDataWithURL:RQ_POST_UnBindGzptUser contentType:@"application/json" parameters:dict completion:^(NSDictionary *dict) {
  86. if([dict[@"code"] intValue]==200){
  87. RQUserModel *user = [RQUserModel yy_modelWithDictionary:[RQ_USER_MANAGER.currentUser yy_modelToJSONObject]];
  88. user.openId = nil;
  89. /// 存储用户数据
  90. [RQ_USER_MANAGER loginUser:user];
  91. ShowMsg(@"解绑成功");
  92. [self.navigationController popViewControllerAnimated:YES];
  93. }else{
  94. ShowMsg(dict[@"msg"]);
  95. }
  96. [MBProgressHUD rq_hideHUD];
  97. }];
  98. }else{
  99. //立即绑定
  100. //提交-web
  101. [MBProgressHUD rq_showProgressHUD:@""];
  102. NSDictionary *dict = @{
  103. @"logincode": logincode,
  104. @"openid": self.viewModel.openid,
  105. @"password": [password md5String]
  106. };
  107. [jiaPeiManager NYRequestAnythingDataWithURL:RQ_POST_BindGzptUser contentType:@"application/json" parameters:dict completion:^(NSDictionary *dict) {
  108. if([dict[@"code"] intValue]==200){
  109. if (myDelegate.isLogin) {//已经登录提示-绑定成功
  110. RQUserModel *user = [RQUserModel yy_modelWithDictionary:[RQ_USER_MANAGER.currentUser yy_modelToJSONObject]];
  111. user.openId = self.viewModel.openid;
  112. /// 存储用户数据
  113. [RQ_USER_MANAGER loginUser:user];
  114. ShowMsg(@"绑定成功");
  115. [self.navigationController popViewControllerAnimated:YES];
  116. }else{
  117. //绑定成功-登录
  118. RQUserModel *user = [RQUserModel yy_modelWithDictionary:dict[@"data"]];
  119. /// 存储用户数据
  120. [RQ_USER_MANAGER loginUser:user];
  121. // //通知登录
  122. // [RQNotificationCenter postNotificationName:RQWeBanindOnRespNotification object:user];
  123. [RQ_VIP_Module isActiveWithCcomplete:^(RQActivationModel * _Nullable activationModel, BOOL isSuccess) {}];
  124. [[RQ_HTTP_Service getMyScoreWithSubject:RQHomePageSubjectType_SubjectOne] subscribeNext:^(NSArray *examResultModelArr) {
  125. RQ_COMMON_MANAGER.myExamOneCount = examResultModelArr.count;
  126. RQ_COMMON_MANAGER.examResultOneListArr = examResultModelArr;
  127. }];
  128. [[RQ_HTTP_Service getMyScoreWithSubject:RQHomePageSubjectType_SubjectFour] subscribeNext:^(NSArray *examResultModelArr) {
  129. RQ_COMMON_MANAGER.myExamFourCount = examResultModelArr.count;
  130. RQ_COMMON_MANAGER.examResultFourListArr = examResultModelArr;
  131. }];
  132. if (user.channel == RQUserLoginChannelTypePhone) {
  133. /// 切换更控制器
  134. dispatch_async(dispatch_get_main_queue(), ^{
  135. /// 发通知
  136. [[NSNotificationCenter defaultCenter] postNotificationName:RQSwitchRootViewControllerNotification object:nil userInfo:@{RQSwitchRootViewControllerUserInfoKey:@(RQSwitchRootViewControllerFromTypeLogin)}];
  137. });
  138. }
  139. }
  140. }else{
  141. ShowMsg(dict[@"msg"]);
  142. }
  143. [MBProgressHUD rq_hideHUD];
  144. }];
  145. }
  146. }
  147. @end