123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311 |
- //
- // YMFeesSettingViewModel.m
- // MSYOUPAI
- //
- // Created by YoMi on 2024/2/23.
- // Copyright © 2024 MS. All rights reserved.
- //
- #import "YMFeesSettingViewModel.h"
- #import "YMFeesSettingInfoModel.h"
- #import "YMFeesSettingPriceModel.h"
- @interface YMFeesSettingViewModel ()
- /// 列表数据
- @property (nonatomic, strong, readwrite) NSArray <YMFeesSettingCellViewModel*>*listDataArray;
- /// 说明提示
- @property (nonatomic, strong, readwrite) NSAttributedString *notesTipsAttributed;
- /// 收费设置功能操作
- @property (nonatomic, strong, readwrite) RACSubject *feesSettingFunctionsOperationSubject;
- /// 消息价格数组
- @property (nonatomic, strong) NSArray <YMFeesPriceModel*>*messagePriceArr;
- /// 语音价格数组
- @property (nonatomic, strong) NSArray <YMFeesPriceModel*>*voicePriceArr;
- /// 视频价格数组
- @property (nonatomic, strong) NSArray <YMFeesPriceModel*>*videoPriceArr;
- /// 选中价格
- @property (nonatomic, strong) YMFeesPriceModel *feesPriceModel;
- @end
- @implementation YMFeesSettingViewModel
- - (void)ym_initialize{
- [super ym_initialize];
-
- self.customNavTitle = @"收费设置";
-
- @weakify(self)
- [[self.feesSettingFunctionsOperationSubject takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id _Nullable value) {
- @strongify(self)
- switch ([value intValue]) {
- case YMFeesSettingFunctionsTypeMessagePrice:
- {
- [self openMessagePricePickerPopupView];
- }
- break;
- case YMFeesSettingFunctionsTypeVoicePrice:
- {
- [self openVoicePricePickerPopupView];
- }
- break;
- case YMFeesSettingFunctionsTypeVideoPrice:
- {
- [self openVideoPricePickerPopupView];
- }
- break;
- default:
- break;
- }
- }];
-
- }
- - (void)getFeesSettingBaseInfoData{
- @weakify(self)
- [ZCHUDHelper showWithStatus:@"加载中..."];
- [LCHttpHelper requestWithURLString:AnchorGetPrice parameters:@{} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
- @strongify(self)
- NSDictionary* dict = (NSDictionary*)responseObject;
- NSInteger code = [[dict objectForKey:@"code"] integerValue];
- if (code == 0) {
- [ZCHUDHelper dismiss];
-
- YMFeesSettingInfoModel *mdoel = [YMFeesSettingInfoModel yy_modelWithJSON:[dict dictionaryValueForKey:@"data" defaultValue:@{}]];
-
- self.listDataArray = [@[
- // @{
- // @"title":@"消息价格",
- // @"content":mdoel.msg_price,
- // ParamsCategoryType:@(YMFeesSettingFunctionsTypeMessagePrice),
- // },
- @{
- @"title":@"视频价格设置",
- @"content":mdoel.video_price,
- ParamsCategoryType:@(YMFeesSettingFunctionsTypeVideoPrice),
- },
- ].rac_sequence map:^(NSDictionary * _Nullable dic) {
- YMFeesSettingCellViewModel *viewModel = [[YMFeesSettingCellViewModel alloc]initWithParams:@{
- ParamsModel:dic
- }];
-
- return viewModel;
- }].array;
-
- NSString *notesTipsStr = @"收费设置说明:1、对方主动给你发文字消息或与你进行视频/语音通话,你的收费依据本页设置。2、互相关注后,双方发文字消息免费。3、星级越高,可设置的价格越高,查看如何提高星级";
-
- NSMutableAttributedString *notesTipsAttributed = [[NSMutableAttributedString alloc]initWithString:notesTipsStr];
- notesTipsAttributed.yy_font = LCFont(11);
- notesTipsAttributed.yy_color = HexColorFromRGB(0x9c9c9c);
- notesTipsAttributed.yy_lineSpacing = 3;
- notesTipsAttributed.yy_alignment = NSTextAlignmentLeft;
- //设置高亮色和点击事件
- [notesTipsAttributed yy_setTextHighlightRange:[notesTipsStr rangeOfString:@"如何提高星级"] color:HexColorFromRGB(0xB26AFD) backgroundColor:[UIColor clearColor] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
- YMWebArticleViewModel *webArticleVM = [[YMWebArticleViewModel alloc]initWithParams:@{
- ParamsUrl:[YMGlobalUtils shared].increaseStarRatingUrl
- }];
- [YMRouter openURL:stringFormat(@"%@%@", YM_ROUTER_URL_PREFIX, YM_ROUTER_WEB_ARTICLE) withUserInfo:@{
- RouterViewModel:webArticleVM
- } completion:nil];
- }];
-
- self.notesTipsAttributed = notesTipsAttributed;
-
- [self.refreshUISubject sendNext:@(YMRefreshUI)];
-
- }else{
- [ZCHUDHelper showTitle:[dict stringValueForKey:@"message" defaultValue:@""]];
- }
- } failure:^(NSError *error) {
- [ZCHUDHelper showTitle:error.localizedDescription];
- }];
-
- }
- - (void)getFeesSettingPriceInfoData{
-
- [LCHttpHelper requestWithURLString:GetAnchorSetting parameters:@{} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
- NSDictionary* dict = (NSDictionary*)responseObject;
- NSInteger code = [[dict objectForKey:@"code"] integerValue];
- if (code == 0) {
- YMFeesSettingPriceModel *model = [YMFeesSettingPriceModel yy_modelWithJSON:[dict dictionaryValueForKey:@"data" defaultValue:@{}]];
-
- self.messagePriceArr = model.chat;
-
- self.voicePriceArr = model.voice;
-
- self.videoPriceArr = model.video;
-
- }else{
- [ZCHUDHelper showTitle:[dict stringValueForKey:@"message" defaultValue:@""]];
- }
- } failure:^(NSError *error) {
- [ZCHUDHelper showTitle:error.localizedDescription];
- }];
- }
- - (void)settingFeesPriceDataWithPriceId:(NSInteger)priceId ofType:(NSInteger)type{
- ///1语音 2视频 5文字
- [LCHttpHelper requestWithURLString:SetSkillPrice parameters:@{
- @"price_id":@(priceId),
- @"type":@(type)
- } needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
- NSDictionary* dict = (NSDictionary*)responseObject;
- NSInteger code = [[dict objectForKey:@"code"] integerValue];
- if (code == 0) {
- [ZCHUDHelper showTitle:@"价格设置成功"];
-
- self.listDataArray = [self.listDataArray.rac_sequence map:^(YMFeesSettingCellViewModel * _Nullable viewModel) {
- if (type == 5 && viewModel.feesSettingFunctionsType == YMFeesSettingFunctionsTypeMessagePrice) {
- viewModel.feesSettingContent = stringFormat(@"%ld%@/条",self.feesPriceModel.coins,self.feesPriceModel.content);
- } else if (type == 1 && viewModel.feesSettingFunctionsType == YMFeesSettingFunctionsTypeVoicePrice) {
- viewModel.feesSettingContent = stringFormat(@"%ld%@/分钟",self.feesPriceModel.coins,self.feesPriceModel.content);
- }else if (type == 2 && viewModel.feesSettingFunctionsType == YMFeesSettingFunctionsTypeVideoPrice) {
- viewModel.feesSettingContent = stringFormat(@"%ld%@/分钟",self.feesPriceModel.coins,self.feesPriceModel.content);
- }
- return viewModel;
- }].array;
-
- [self.refreshUISubject sendNext:@(YMRefreshUI)];
-
- }else{
- [ZCHUDHelper showTitle:[dict stringValueForKey:@"message" defaultValue:@""]];
- }
- } failure:^(NSError *error) {
- [ZCHUDHelper showTitle:error.localizedDescription];
- }];
- }
- - (void)openMessagePricePickerPopupView{
- NSArray *tempMassagePriceArr = [self.messagePriceArr.rac_sequence map:^(YMFeesPriceModel * _Nullable value) {
- return @{
- @"rowId":@(value.price_id),
- @"rowName":stringFormat(@"%ld%@",value.coins,value.content)
- };
- }].array;
-
- YMPickerViewModel *messagePricePickerVM = [[YMPickerViewModel alloc]initWithParams:@{
- @"componentDataSource":@[
- @{
- @"componentName":@"消息价格",
- @"rowDataSource":tempMassagePriceArr
- }
- ]
- }];
- YMPickerPopupView *customView = [[YMPickerPopupView alloc]init];
- [customView ym_bindViewModel:messagePricePickerVM];
- customView.titleText = @"请选择消息价格";
-
- YMPopupView *popupView = [YMPopupView initWithCustomView:customView parentView:nil popStyle:YMPopupStyleSmoothFromBottom dismissStyle:YMDismissStyleSmoothToBottom];
- popupView.priority = 999;
- popupView.cornerRadius = adapt(10);
- popupView.rectCorners = UIRectCornerTopLeft|UIRectCornerTopRight;
- popupView.positionStyle = YMPositionStyleBottom;
- popupView.isClickBgDismiss = YES;
- popupView.isHideBg = NO;
- popupView.bgAlpha = 0.5;
- @weakify(popupView)
- customView.buttonBlock = ^(BOOL isConfirm, NSArray<NSDictionary *> * _Nonnull currentSelectedDataArray) {
- @strongify(popupView)
- if (isConfirm) {
- NSLog(@"选中消息价格值:%@",currentSelectedDataArray);
- NSInteger currentSelectedRowIndex = [currentSelectedDataArray[0] integerValueForKey:@"currentSelectedRowIndex" defaultValue:0];
- self.feesPriceModel = self.messagePriceArr[currentSelectedRowIndex];
- [self settingFeesPriceDataWithPriceId:self.feesPriceModel.price_id ofType:5];
- }
- [popupView dismissWithStyle:YMDismissStyleSmoothToBottom duration:2.0];
- };
- [popupView pop];
- }
- - (void)openVoicePricePickerPopupView{
- NSArray *tempVoicePriceArr = [self.voicePriceArr.rac_sequence map:^(YMFeesPriceModel * _Nullable value) {
- return @{
- @"rowId":@(value.price_id),
- @"rowName":stringFormat(@"%ld%@",value.coins,value.content)
- };
- }].array;
-
- YMPickerViewModel *voicePricePickerVM = [[YMPickerViewModel alloc]initWithParams:@{
- @"componentDataSource":@[
- @{
- @"componentName":@"语音价格",
- @"rowDataSource":tempVoicePriceArr
- }
- ]
- }];
- YMPickerPopupView *customView = [[YMPickerPopupView alloc]init];
- [customView ym_bindViewModel:voicePricePickerVM];
- customView.titleText = @"请选择语音价格";
-
- YMPopupView *popupView = [YMPopupView initWithCustomView:customView parentView:nil popStyle:YMPopupStyleSmoothFromBottom dismissStyle:YMDismissStyleSmoothToBottom];
- popupView.priority = 999;
- popupView.cornerRadius = adapt(10);
- popupView.rectCorners = UIRectCornerTopLeft|UIRectCornerTopRight;
- popupView.positionStyle = YMPositionStyleBottom;
- popupView.isClickBgDismiss = YES;
- popupView.isHideBg = NO;
- popupView.bgAlpha = 0.5;
- @weakify(popupView)
- customView.buttonBlock = ^(BOOL isConfirm, NSArray<NSDictionary *> * _Nonnull currentSelectedDataArray) {
- @strongify(popupView)
- if (isConfirm) {
- NSLog(@"选中语音价格值:%@",currentSelectedDataArray);
- NSInteger currentSelectedRowIndex = [currentSelectedDataArray[0] integerValueForKey:@"currentSelectedRowIndex" defaultValue:0];
- self.feesPriceModel = self.voicePriceArr[currentSelectedRowIndex];
- [self settingFeesPriceDataWithPriceId:self.feesPriceModel.price_id ofType:1];
- }
- [popupView dismissWithStyle:YMDismissStyleSmoothToBottom duration:2.0];
- };
- [popupView pop];
- }
- - (void)openVideoPricePickerPopupView{
- NSArray *tempVideoPriceArr = [self.videoPriceArr.rac_sequence map:^(YMFeesPriceModel * _Nullable value) {
- return @{
- @"rowId":@(value.price_id),
- @"rowName":stringFormat(@"%ld%@",value.coins,value.content)
- };
- }].array;
-
- YMPickerViewModel *videoPricePickerVM = [[YMPickerViewModel alloc]initWithParams:@{
- @"componentDataSource":@[
- @{
- @"componentName":@"视频价格",
- @"rowDataSource":tempVideoPriceArr
- }
- ]
- }];
- YMPickerPopupView *customView = [[YMPickerPopupView alloc]init];
- [customView ym_bindViewModel:videoPricePickerVM];
- customView.titleText = @"请选择视频价格";
-
- YMPopupView *popupView = [YMPopupView initWithCustomView:customView parentView:nil popStyle:YMPopupStyleSmoothFromBottom dismissStyle:YMDismissStyleSmoothToBottom];
- popupView.priority = 999;
- popupView.cornerRadius = adapt(10);
- popupView.rectCorners = UIRectCornerTopLeft|UIRectCornerTopRight;
- popupView.positionStyle = YMPositionStyleBottom;
- popupView.isClickBgDismiss = YES;
- popupView.isHideBg = NO;
- popupView.bgAlpha = 0.5;
- @weakify(popupView)
- customView.buttonBlock = ^(BOOL isConfirm, NSArray<NSDictionary *> * _Nonnull currentSelectedDataArray) {
- @strongify(popupView)
- if (isConfirm) {
- NSLog(@"选中视频价格值:%@",currentSelectedDataArray);
- NSInteger currentSelectedRowIndex = [currentSelectedDataArray[0] integerValueForKey:@"currentSelectedRowIndex" defaultValue:0];
- self.feesPriceModel = self.videoPriceArr[currentSelectedRowIndex];
- [self settingFeesPriceDataWithPriceId:self.feesPriceModel.price_id ofType:2];
- }
- [popupView dismissWithStyle:YMDismissStyleSmoothToBottom duration:2.0];
- };
- [popupView pop];
- }
- - (RACSubject *)feesSettingFunctionsOperationSubject{
- if (!_feesSettingFunctionsOperationSubject) {
- _feesSettingFunctionsOperationSubject = [RACSubject subject];
- }
- return _feesSettingFunctionsOperationSubject;
- }
- @end
|