YMRegisterViewModel.m 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. //
  2. // YMRegisterViewModel.m
  3. // MSYOUPAI
  4. //
  5. // Created by YoMi on 2024/2/5.
  6. // Copyright © 2024 MS. All rights reserved.
  7. //
  8. #import "YMRegisterViewModel.h"
  9. @interface YMRegisterViewModel ()
  10. /// 注册按钮有效性
  11. @property (nonatomic, strong, readwrite) RACSignal *validRegisterSignal;
  12. @end
  13. @implementation YMRegisterViewModel
  14. - (void)ym_initialize{
  15. [super ym_initialize];
  16. /// 注册按钮有效性
  17. self.validRegisterSignal = [[[RACSignal combineLatest:@[
  18. RACObserve(self, mobile),
  19. RACObserve(self, verifyCode),
  20. RACObserve(self, password)
  21. ] reduce:^(NSString *mobile, NSString *verifyCode, NSString *password ) {
  22. //是否不为空
  23. return @(!OCStringIsEmpty(mobile) && !OCStringIsEmpty(verifyCode) &&!OCStringIsEmpty(password));
  24. }] distinctUntilChanged] takeUntil:self.rac_willDeallocSignal];
  25. }
  26. /// 获取验证码
  27. - (void)getVerifyCodeWithCaptcha:(id)captcha handler:(void(^)(NSDictionary *dic, NSError * _Nullable error))handler {
  28. NSMutableDictionary *dictm = [NSMutableDictionary dictionary];
  29. dictm[@"mobile"] = self.mobile;
  30. dictm[@"type"] = @"register";
  31. if ([captcha isKindOfClass:[NSString class]]) {
  32. dictm[@"captcha"] = captcha;
  33. }
  34. if ([captcha isKindOfClass:[NSDictionary class]]) {
  35. [dictm addEntriesFromDictionary:captcha];
  36. }
  37. @weakify(self)
  38. [ZCHUDHelper showWithStatus:@"获取验证码中"];
  39. [LCHttpHelper requestWithURLString:PhoneCode parameters:dictm needToken:NO type:HttpRequestTypePost success:^(id responseObject) {
  40. @strongify(self)
  41. NSDictionary* dict = (NSDictionary*)responseObject;
  42. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  43. if (code == 0) {
  44. [ZCHUDHelper showTitle:@"验证码已发送"];
  45. handler(dict?:@{},nil);
  46. }else{
  47. [ZCHUDHelper showTitle:[dict stringValueForKey:@"message" defaultValue:@""]];
  48. }
  49. } failure:^(NSError *error) {
  50. [ZCHUDHelper showTitle:error.localizedDescription];
  51. }];
  52. }
  53. - (void)registerRequest{
  54. NSMutableDictionary *params = [NSMutableDictionary dictionary];
  55. [params setObject:self.mobile?:@"" forKey:@"mobile"];
  56. [params setObject:self.verifyCode?:@"" forKey:@"phone_code"];
  57. [params setObject:self.password?:@"" forKey:@"password"];
  58. [params setObject:@"1" forKey:@"agreement"];
  59. @weakify(self)
  60. [ZCHUDHelper showWithStatus:@"注册中"];
  61. [LCHttpHelper requestWithURLString:PhoneRegister parameters:params needToken:NO type:HttpRequestTypePost success:^(id responseObject) {
  62. @strongify(self)
  63. NSDictionary* dict = (NSDictionary*)responseObject;
  64. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  65. if (code == 0) {
  66. [ZCHUDHelper dismiss];
  67. YOUPAILCUserModel* userModel = [YOUPAILCUserModel mj_objectWithKeyValues:[dict objectForKey:@"data"]];
  68. [LCSaveModel saveUserModel:userModel];
  69. [LCSaveData saveTokenString:userModel.youpaipuserinfo.youpaiptoken];//保存token
  70. [LCSaveData saveLoginMark:YES];
  71. [LCHttpHelper requestWithURLString:GiftConfig parameters:@{} needToken:YES type:HttpRequestTypePost success:^(id responseObject) {
  72. NSDictionary* dict = (NSDictionary*)responseObject;
  73. NSLog(@"GiftConfig == %@",dict);
  74. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  75. if (code==0) {//成功
  76. NSMutableArray *giftArray = [NSMutableArray array];
  77. giftArray = [YOUPAILCGiftModel mj_objectArrayWithKeyValuesArray:[[dict objectForKey:@"data"]objectForKey:@"gift_list"]];
  78. for (int i = 0; i<giftArray.count; i++) {
  79. YOUPAILCGiftModel *model = giftArray[i];
  80. if (model.youpaipsvga.length > 0 ) {
  81. [LCTools giftSVGAWithSvgaUrlStr:model.youpaipsvga];
  82. }
  83. }
  84. }else{
  85. [ZCHUDHelper showTitle:[dict stringValueForKey:@"message" defaultValue:@""]];
  86. }
  87. } failure:^(NSError *error) {
  88. [ZCHUDHelper showTitle:error.localizedDescription];
  89. }];
  90. if (userModel.youpaipuserinfo.youpaiptype == 2) {
  91. //是特殊用户
  92. [LCSaveData saveIsspecial:YES];
  93. }
  94. //未完善资料,进入完善资料页面
  95. if (userModel.youpaipuserinfo.youpaipfinish_status == 0) {
  96. YMImproveInfoViewModel *improveInfoVM = [[YMImproveInfoViewModel alloc]initWithParams:@{}];
  97. [YMRouter openURL:stringFormat(@"%@%@", YM_ROUTER_URL_PREFIX, YM_ROUTER_IMPROVE_INFO) withUserInfo:@{
  98. RouterViewModel:improveInfoVM
  99. } completion:nil];
  100. }else{
  101. //已经完善资料
  102. [[YOUPAILCIMLoginManager sharedCenter]IMLogin:[LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id token:[LCSaveModel getUserModel].youpaipuserinfo.youpaipim_token];
  103. [LCTools changeRootToTabbar];
  104. }
  105. }else{
  106. [ZCHUDHelper showTitle:[dict stringValueForKey:@"message" defaultValue:@""]];
  107. }
  108. } failure:^(NSError *error) {
  109. [ZCHUDHelper showTitle:error.localizedDescription];
  110. }];
  111. }
  112. @end