YMRegisterViewModel.m 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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)getVerifyCodeHandler:(void(^)(NSDictionary *dic, NSError * _Nullable error))handler{
  28. @weakify(self)
  29. [ZCHUDHelper showWithStatus:@"获取验证码中"];
  30. [LCHttpHelper requestWithURLString:PhoneCode parameters:@{
  31. @"mobile":self.mobile,
  32. @"type":@"register"
  33. } needToken:NO type:HttpRequestTypePost success:^(id responseObject) {
  34. @strongify(self)
  35. NSDictionary* dict = (NSDictionary*)responseObject;
  36. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  37. if (code == 0) {
  38. [ZCHUDHelper showTitle:@"验证码已发送"];
  39. handler(dict?:@{},nil);
  40. }else{
  41. [ZCHUDHelper showTitle:[dict stringValueForKey:@"message" defaultValue:@""]];
  42. }
  43. } failure:^(NSError *error) {
  44. [ZCHUDHelper showTitle:error.localizedDescription];
  45. }];
  46. }
  47. - (void)registerRequest{
  48. NSMutableDictionary *params = [NSMutableDictionary dictionary];
  49. [params setObject:self.mobile?:@"" forKey:@"mobile"];
  50. [params setObject:self.verifyCode?:@"" forKey:@"phone_code"];
  51. [params setObject:self.password?:@"" forKey:@"password"];
  52. [params setObject:@"1" forKey:@"agreement"];
  53. @weakify(self)
  54. [ZCHUDHelper showWithStatus:@"注册中"];
  55. [LCHttpHelper requestWithURLString:PhoneRegister parameters:params needToken:NO type:HttpRequestTypePost success:^(id responseObject) {
  56. @strongify(self)
  57. NSDictionary* dict = (NSDictionary*)responseObject;
  58. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  59. if (code == 0) {
  60. [ZCHUDHelper dismiss];
  61. YOUPAILCUserModel* userModel = [YOUPAILCUserModel mj_objectWithKeyValues:[dict objectForKey:@"data"]];
  62. [LCSaveModel saveUserModel:userModel];
  63. [LCSaveData saveTokenString:userModel.youpaipuserinfo.youpaiptoken];//保存token
  64. [LCSaveData saveLoginMark:YES];
  65. [LCHttpHelper requestWithURLString:GiftConfig parameters:@{} needToken:YES type:HttpRequestTypePost success:^(id responseObject) {
  66. NSDictionary* dict = (NSDictionary*)responseObject;
  67. NSLog(@"GiftConfig == %@",dict);
  68. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  69. if (code==0) {//成功
  70. NSMutableArray *giftArray = [NSMutableArray array];
  71. giftArray = [YOUPAILCGiftModel mj_objectArrayWithKeyValuesArray:[[dict objectForKey:@"data"]objectForKey:@"gift_list"]];
  72. for (int i = 0; i<giftArray.count; i++) {
  73. YOUPAILCGiftModel *model = giftArray[i];
  74. if (model.youpaipsvga.length > 0 ) {
  75. [LCTools giftSVGAWithSvgaUrlStr:model.youpaipsvga];
  76. }
  77. }
  78. }else{
  79. [ZCHUDHelper showTitle:[dict stringValueForKey:@"message" defaultValue:@""]];
  80. }
  81. } failure:^(NSError *error) {
  82. [ZCHUDHelper showTitle:error.localizedDescription];
  83. }];
  84. if (userModel.youpaipuserinfo.youpaiptype == 2) {
  85. //是特殊用户
  86. [LCSaveData saveIsspecial:YES];
  87. }
  88. //未完善资料,进入完善资料页面
  89. if (userModel.youpaipuserinfo.youpaipfinish_status == 0) {
  90. YMImproveInfoViewModel *improveInfoVM = [[YMImproveInfoViewModel alloc]initWithParams:@{}];
  91. [YMRouter openURL:stringFormat(@"%@%@", YM_ROUTER_URL_PREFIX, YM_ROUTER_IMPROVE_INFO) withUserInfo:@{
  92. RouterViewModel:improveInfoVM
  93. } completion:nil];
  94. }else{
  95. //已经完善资料
  96. [[YOUPAILCIMLoginManager sharedCenter]IMLogin:[LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id token:[LCSaveModel getUserModel].youpaipuserinfo.youpaipim_token];
  97. [LCTools changeRootToTabbar];
  98. }
  99. }else{
  100. [ZCHUDHelper showTitle:[dict stringValueForKey:@"message" defaultValue:@""]];
  101. }
  102. } failure:^(NSError *error) {
  103. [ZCHUDHelper showTitle:error.localizedDescription];
  104. }];
  105. }
  106. @end