YMFeesSettingViewModel.m 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. //
  2. // YMFeesSettingViewModel.m
  3. // MSYOUPAI
  4. //
  5. // Created by YoMi on 2024/2/23.
  6. // Copyright © 2024 MS. All rights reserved.
  7. //
  8. #import "YMFeesSettingViewModel.h"
  9. #import "YMFeesSettingInfoModel.h"
  10. #import "YMFeesSettingPriceModel.h"
  11. @interface YMFeesSettingViewModel ()
  12. /// 列表数据
  13. @property (nonatomic, strong, readwrite) NSArray <YMFeesSettingCellViewModel*>*listDataArray;
  14. /// 说明提示
  15. @property (nonatomic, strong, readwrite) NSAttributedString *notesTipsAttributed;
  16. /// 收费设置功能操作
  17. @property (nonatomic, strong, readwrite) RACSubject *feesSettingFunctionsOperationSubject;
  18. /// 消息价格数组
  19. @property (nonatomic, strong) NSArray <YMFeesPriceModel*>*messagePriceArr;
  20. /// 语音价格数组
  21. @property (nonatomic, strong) NSArray <YMFeesPriceModel*>*voicePriceArr;
  22. /// 视频价格数组
  23. @property (nonatomic, strong) NSArray <YMFeesPriceModel*>*videoPriceArr;
  24. /// 选中价格
  25. @property (nonatomic, strong) YMFeesPriceModel *feesPriceModel;
  26. @end
  27. @implementation YMFeesSettingViewModel
  28. - (void)ym_initialize{
  29. [super ym_initialize];
  30. self.customNavTitle = @"收费设置";
  31. @weakify(self)
  32. [[self.feesSettingFunctionsOperationSubject takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id _Nullable value) {
  33. @strongify(self)
  34. switch ([value intValue]) {
  35. case YMFeesSettingFunctionsTypeMessagePrice:
  36. {
  37. [self openMessagePricePickerPopupView];
  38. }
  39. break;
  40. case YMFeesSettingFunctionsTypeVoicePrice:
  41. {
  42. [self openVoicePricePickerPopupView];
  43. }
  44. break;
  45. case YMFeesSettingFunctionsTypeVideoPrice:
  46. {
  47. [self openVideoPricePickerPopupView];
  48. }
  49. break;
  50. default:
  51. break;
  52. }
  53. }];
  54. }
  55. - (void)getFeesSettingBaseInfoData{
  56. @weakify(self)
  57. [ZCHUDHelper showWithStatus:@"加载中..."];
  58. [LCHttpHelper requestWithURLString:AnchorGetPrice parameters:@{} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  59. @strongify(self)
  60. NSDictionary* dict = (NSDictionary*)responseObject;
  61. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  62. if (code == 0) {
  63. [ZCHUDHelper dismiss];
  64. YMFeesSettingInfoModel *mdoel = [YMFeesSettingInfoModel yy_modelWithJSON:[dict dictionaryValueForKey:@"data" defaultValue:@{}]];
  65. self.listDataArray = [@[
  66. // @{
  67. // @"title":@"消息价格",
  68. // @"content":mdoel.msg_price,
  69. // ParamsCategoryType:@(YMFeesSettingFunctionsTypeMessagePrice),
  70. // },
  71. @{
  72. @"title":@"视频价格设置",
  73. @"content":mdoel.video_price,
  74. ParamsCategoryType:@(YMFeesSettingFunctionsTypeVideoPrice),
  75. },
  76. ].rac_sequence map:^(NSDictionary * _Nullable dic) {
  77. YMFeesSettingCellViewModel *viewModel = [[YMFeesSettingCellViewModel alloc]initWithParams:@{
  78. ParamsModel:dic
  79. }];
  80. return viewModel;
  81. }].array;
  82. NSString *notesTipsStr = @"收费设置说明:1、对方主动给你发文字消息或与你进行视频/语音通话,你的收费依据本页设置。2、互相关注后,双方发文字消息免费。3、星级越高,可设置的价格越高,查看如何提高星级";
  83. NSMutableAttributedString *notesTipsAttributed = [[NSMutableAttributedString alloc]initWithString:notesTipsStr];
  84. notesTipsAttributed.yy_font = LCFont(11);
  85. notesTipsAttributed.yy_color = HexColorFromRGB(0x9c9c9c);
  86. notesTipsAttributed.yy_lineSpacing = 3;
  87. notesTipsAttributed.yy_alignment = NSTextAlignmentLeft;
  88. //设置高亮色和点击事件
  89. [notesTipsAttributed yy_setTextHighlightRange:[notesTipsStr rangeOfString:@"如何提高星级"] color:HexColorFromRGB(0xB26AFD) backgroundColor:[UIColor clearColor] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
  90. YMWebArticleViewModel *webArticleVM = [[YMWebArticleViewModel alloc]initWithParams:@{
  91. ParamsUrl:[YMGlobalUtils shared].increaseStarRatingUrl
  92. }];
  93. [YMRouter openURL:stringFormat(@"%@%@", YM_ROUTER_URL_PREFIX, YM_ROUTER_WEB_ARTICLE) withUserInfo:@{
  94. RouterViewModel:webArticleVM
  95. } completion:nil];
  96. }];
  97. self.notesTipsAttributed = notesTipsAttributed;
  98. [self.refreshUISubject sendNext:@(YMRefreshUI)];
  99. }else{
  100. [ZCHUDHelper showTitle:[dict stringValueForKey:@"message" defaultValue:@""]];
  101. }
  102. } failure:^(NSError *error) {
  103. [ZCHUDHelper showTitle:error.localizedDescription];
  104. }];
  105. }
  106. - (void)getFeesSettingPriceInfoData{
  107. [LCHttpHelper requestWithURLString:GetAnchorSetting parameters:@{} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  108. NSDictionary* dict = (NSDictionary*)responseObject;
  109. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  110. if (code == 0) {
  111. YMFeesSettingPriceModel *model = [YMFeesSettingPriceModel yy_modelWithJSON:[dict dictionaryValueForKey:@"data" defaultValue:@{}]];
  112. self.messagePriceArr = model.chat;
  113. self.voicePriceArr = model.voice;
  114. self.videoPriceArr = model.video;
  115. }else{
  116. [ZCHUDHelper showTitle:[dict stringValueForKey:@"message" defaultValue:@""]];
  117. }
  118. } failure:^(NSError *error) {
  119. [ZCHUDHelper showTitle:error.localizedDescription];
  120. }];
  121. }
  122. - (void)settingFeesPriceDataWithPriceId:(NSInteger)priceId ofType:(NSInteger)type{
  123. ///1语音 2视频 5文字
  124. [LCHttpHelper requestWithURLString:SetSkillPrice parameters:@{
  125. @"price_id":@(priceId),
  126. @"type":@(type)
  127. } needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  128. NSDictionary* dict = (NSDictionary*)responseObject;
  129. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  130. if (code == 0) {
  131. [ZCHUDHelper showTitle:@"价格设置成功"];
  132. self.listDataArray = [self.listDataArray.rac_sequence map:^(YMFeesSettingCellViewModel * _Nullable viewModel) {
  133. if (type == 5 && viewModel.feesSettingFunctionsType == YMFeesSettingFunctionsTypeMessagePrice) {
  134. viewModel.feesSettingContent = stringFormat(@"%ld%@/条",self.feesPriceModel.coins,self.feesPriceModel.content);
  135. } else if (type == 1 && viewModel.feesSettingFunctionsType == YMFeesSettingFunctionsTypeVoicePrice) {
  136. viewModel.feesSettingContent = stringFormat(@"%ld%@/分钟",self.feesPriceModel.coins,self.feesPriceModel.content);
  137. }else if (type == 2 && viewModel.feesSettingFunctionsType == YMFeesSettingFunctionsTypeVideoPrice) {
  138. viewModel.feesSettingContent = stringFormat(@"%ld%@/分钟",self.feesPriceModel.coins,self.feesPriceModel.content);
  139. }
  140. return viewModel;
  141. }].array;
  142. [self.refreshUISubject sendNext:@(YMRefreshUI)];
  143. }else{
  144. [ZCHUDHelper showTitle:[dict stringValueForKey:@"message" defaultValue:@""]];
  145. }
  146. } failure:^(NSError *error) {
  147. [ZCHUDHelper showTitle:error.localizedDescription];
  148. }];
  149. }
  150. - (void)openMessagePricePickerPopupView{
  151. NSArray *tempMassagePriceArr = [self.messagePriceArr.rac_sequence map:^(YMFeesPriceModel * _Nullable value) {
  152. return @{
  153. @"rowId":@(value.price_id),
  154. @"rowName":stringFormat(@"%ld%@",value.coins,value.content)
  155. };
  156. }].array;
  157. YMPickerViewModel *messagePricePickerVM = [[YMPickerViewModel alloc]initWithParams:@{
  158. @"componentDataSource":@[
  159. @{
  160. @"componentName":@"消息价格",
  161. @"rowDataSource":tempMassagePriceArr
  162. }
  163. ]
  164. }];
  165. YMPickerPopupView *customView = [[YMPickerPopupView alloc]init];
  166. [customView ym_bindViewModel:messagePricePickerVM];
  167. customView.titleText = @"请选择消息价格";
  168. YMPopupView *popupView = [YMPopupView initWithCustomView:customView parentView:nil popStyle:YMPopupStyleSmoothFromBottom dismissStyle:YMDismissStyleSmoothToBottom];
  169. popupView.priority = 999;
  170. popupView.cornerRadius = adapt(10);
  171. popupView.rectCorners = UIRectCornerTopLeft|UIRectCornerTopRight;
  172. popupView.positionStyle = YMPositionStyleBottom;
  173. popupView.isClickBgDismiss = YES;
  174. popupView.isHideBg = NO;
  175. popupView.bgAlpha = 0.5;
  176. @weakify(popupView)
  177. customView.buttonBlock = ^(BOOL isConfirm, NSArray<NSDictionary *> * _Nonnull currentSelectedDataArray) {
  178. @strongify(popupView)
  179. if (isConfirm) {
  180. NSLog(@"选中消息价格值:%@",currentSelectedDataArray);
  181. NSInteger currentSelectedRowIndex = [currentSelectedDataArray[0] integerValueForKey:@"currentSelectedRowIndex" defaultValue:0];
  182. self.feesPriceModel = self.messagePriceArr[currentSelectedRowIndex];
  183. [self settingFeesPriceDataWithPriceId:self.feesPriceModel.price_id ofType:5];
  184. }
  185. [popupView dismissWithStyle:YMDismissStyleSmoothToBottom duration:2.0];
  186. };
  187. [popupView pop];
  188. }
  189. - (void)openVoicePricePickerPopupView{
  190. NSArray *tempVoicePriceArr = [self.voicePriceArr.rac_sequence map:^(YMFeesPriceModel * _Nullable value) {
  191. return @{
  192. @"rowId":@(value.price_id),
  193. @"rowName":stringFormat(@"%ld%@",value.coins,value.content)
  194. };
  195. }].array;
  196. YMPickerViewModel *voicePricePickerVM = [[YMPickerViewModel alloc]initWithParams:@{
  197. @"componentDataSource":@[
  198. @{
  199. @"componentName":@"语音价格",
  200. @"rowDataSource":tempVoicePriceArr
  201. }
  202. ]
  203. }];
  204. YMPickerPopupView *customView = [[YMPickerPopupView alloc]init];
  205. [customView ym_bindViewModel:voicePricePickerVM];
  206. customView.titleText = @"请选择语音价格";
  207. YMPopupView *popupView = [YMPopupView initWithCustomView:customView parentView:nil popStyle:YMPopupStyleSmoothFromBottom dismissStyle:YMDismissStyleSmoothToBottom];
  208. popupView.priority = 999;
  209. popupView.cornerRadius = adapt(10);
  210. popupView.rectCorners = UIRectCornerTopLeft|UIRectCornerTopRight;
  211. popupView.positionStyle = YMPositionStyleBottom;
  212. popupView.isClickBgDismiss = YES;
  213. popupView.isHideBg = NO;
  214. popupView.bgAlpha = 0.5;
  215. @weakify(popupView)
  216. customView.buttonBlock = ^(BOOL isConfirm, NSArray<NSDictionary *> * _Nonnull currentSelectedDataArray) {
  217. @strongify(popupView)
  218. if (isConfirm) {
  219. NSLog(@"选中语音价格值:%@",currentSelectedDataArray);
  220. NSInteger currentSelectedRowIndex = [currentSelectedDataArray[0] integerValueForKey:@"currentSelectedRowIndex" defaultValue:0];
  221. self.feesPriceModel = self.voicePriceArr[currentSelectedRowIndex];
  222. [self settingFeesPriceDataWithPriceId:self.feesPriceModel.price_id ofType:1];
  223. }
  224. [popupView dismissWithStyle:YMDismissStyleSmoothToBottom duration:2.0];
  225. };
  226. [popupView pop];
  227. }
  228. - (void)openVideoPricePickerPopupView{
  229. NSArray *tempVideoPriceArr = [self.videoPriceArr.rac_sequence map:^(YMFeesPriceModel * _Nullable value) {
  230. return @{
  231. @"rowId":@(value.price_id),
  232. @"rowName":stringFormat(@"%ld%@",value.coins,value.content)
  233. };
  234. }].array;
  235. YMPickerViewModel *videoPricePickerVM = [[YMPickerViewModel alloc]initWithParams:@{
  236. @"componentDataSource":@[
  237. @{
  238. @"componentName":@"视频价格",
  239. @"rowDataSource":tempVideoPriceArr
  240. }
  241. ]
  242. }];
  243. YMPickerPopupView *customView = [[YMPickerPopupView alloc]init];
  244. [customView ym_bindViewModel:videoPricePickerVM];
  245. customView.titleText = @"请选择视频价格";
  246. YMPopupView *popupView = [YMPopupView initWithCustomView:customView parentView:nil popStyle:YMPopupStyleSmoothFromBottom dismissStyle:YMDismissStyleSmoothToBottom];
  247. popupView.priority = 999;
  248. popupView.cornerRadius = adapt(10);
  249. popupView.rectCorners = UIRectCornerTopLeft|UIRectCornerTopRight;
  250. popupView.positionStyle = YMPositionStyleBottom;
  251. popupView.isClickBgDismiss = YES;
  252. popupView.isHideBg = NO;
  253. popupView.bgAlpha = 0.5;
  254. @weakify(popupView)
  255. customView.buttonBlock = ^(BOOL isConfirm, NSArray<NSDictionary *> * _Nonnull currentSelectedDataArray) {
  256. @strongify(popupView)
  257. if (isConfirm) {
  258. NSLog(@"选中视频价格值:%@",currentSelectedDataArray);
  259. NSInteger currentSelectedRowIndex = [currentSelectedDataArray[0] integerValueForKey:@"currentSelectedRowIndex" defaultValue:0];
  260. self.feesPriceModel = self.videoPriceArr[currentSelectedRowIndex];
  261. [self settingFeesPriceDataWithPriceId:self.feesPriceModel.price_id ofType:2];
  262. }
  263. [popupView dismissWithStyle:YMDismissStyleSmoothToBottom duration:2.0];
  264. };
  265. [popupView pop];
  266. }
  267. - (RACSubject *)feesSettingFunctionsOperationSubject{
  268. if (!_feesSettingFunctionsOperationSubject) {
  269. _feesSettingFunctionsOperationSubject = [RACSubject subject];
  270. }
  271. return _feesSettingFunctionsOperationSubject;
  272. }
  273. @end