YOUPAILZBigCastChargeSettingVC.m 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. //
  2. // YOUPAILZBigCastChargeSettingVC.m
  3. // MSYOUPAI
  4. //
  5. // Created by CY on 2022/3/9.
  6. // Copyright © 2022 MS. All rights reserved.
  7. //
  8. #import "YOUPAILZBigCastChargeSettingVC.h"
  9. #import "YOUPAIMineNickNameCell.h"
  10. #import "YOUPAIZYSettingCell.h"
  11. #import "YOUPAILZBigCastSetPriceModel.h"
  12. #import "YOUPAILZBigCastSetSelectedPricePickerVC.h"
  13. @interface YOUPAILZBigCastChargeSettingVC ()<UITableViewDelegate,UITableViewDataSource,UITextViewDelegate>
  14. @property (nonatomic, weak)UITableView *youpaiptableView;
  15. @property (nonatomic, strong)NSArray *youpaipdataSource;
  16. @property (nonatomic, strong) NSString *youpaipvideo_price; // 视频价格
  17. @property (nonatomic, strong) NSString *youpaipmsg_price; // 消息价格
  18. @property (nonatomic, assign) BOOL youpaipopen_video_status; // 是否开启视频 0关闭 1开启
  19. @property (nonatomic, strong) NSMutableArray <YOUPAILZBigCastSetPriceModel *>* youpaipchatPrices;
  20. @property (nonatomic, strong) NSMutableArray <YOUPAILZBigCastSetPriceModel *>* youpaipvideoPrices;
  21. @property (nonatomic, strong) NSString *youpaipanchorStarlevelUrl;
  22. @end
  23. @implementation YOUPAILZBigCastChargeSettingVC
  24. - (void)viewDidLoad {
  25. [super viewDidLoad];
  26. self.view.backgroundColor = [UIColor whiteColor];
  27. self.title = @"收费设置";
  28. [self youpaifRequestGetAnchorSettingWithShowPick:0];
  29. [self youpaifinitData];
  30. [self youpaifloadAnchorStarlevel];
  31. }
  32. - (void)youpaifinitUI{
  33. UITableView *tableView = [[UITableView alloc]initWithFrame:CGRectMake(0,NavBarHeight, KScreenWidth, KScreenHeight-NavBarHeight) style:UITableViewStyleGrouped];
  34. tableView.showsVerticalScrollIndicator = NO;
  35. tableView.rowHeight = 54.0f;
  36. tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  37. tableView.backgroundColor = [UIColor whiteColor];
  38. tableView.estimatedSectionHeaderHeight = 0;
  39. tableView.estimatedSectionFooterHeight = 0;
  40. tableView.dataSource = self;
  41. tableView.delegate = self;
  42. [self.view addSubview:tableView];
  43. self.youpaiptableView = tableView;
  44. UIView *footerV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 150.0f)];
  45. self.youpaiptableView.tableFooterView = footerV;
  46. NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
  47. [paragraphStyle setLineSpacing:6];
  48. NSString *text = @"收费设置说明\n对方主动给你发消息,扣费依据本页设定;同性之间聊天不收费\n\n双方亲密度达到一定数值后,相互关注发消息免费\n星级越高,可设置的价格越高,查看如何提高星级";
  49. NSMutableAttributedString *str = [[NSMutableAttributedString alloc]initWithString:text];
  50. [str addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [text length])];
  51. [str addAttribute:NSLinkAttributeName value:@"upgradeLevel://" range:[text rangeOfString:@"如何提高星级"]];
  52. UITextView * textview = [[UITextView alloc]init];
  53. textview.editable = NO;
  54. textview.scrollEnabled = NO;
  55. textview.delegate = self;
  56. textview.backgroundColor = [UIColor clearColor];
  57. textview.font = LCFont(12);
  58. textview.attributedText = str;
  59. textview.textColor = LZA3AABEColor;
  60. textview.linkTextAttributes = @{NSForegroundColorAttributeName:LZ7C69FEColor,
  61. NSUnderlineStyleAttributeName:[NSNumber numberWithInt:NSUnderlineStyleNone]
  62. };
  63. [footerV addSubview:textview];
  64. [textview mas_makeConstraints:^(MASConstraintMaker *make) {
  65. make.left.mas_equalTo(14);
  66. make.width.mas_equalTo(KScreenWidth - 28.0f);
  67. make.top.offset(30.0f);
  68. make.height.offset(120.0f);
  69. }];
  70. }
  71. - (void)youpaifloadAnchorStarlevel{
  72. @weakify(self);
  73. [LCHttpHelper requestWithURLString:UserCenter parameters:nil needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  74. @strongify(self);
  75. NSDictionary* dict = (NSDictionary*)responseObject;
  76. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  77. if (code==0) {//成功
  78. if ([[[dict objectForKey:@"data"] allKeys] containsObject:@"webUrl"]) {
  79. self.youpaipanchorStarlevelUrl = [NSString stringWithFormat:@"%@",[[[dict objectForKey:@"data"]objectForKey:@"webUrl"] objectForKey:@"anchorStarlevel"]];
  80. }
  81. }
  82. } failure:^(NSError *error) {
  83. }];
  84. }
  85. #pragma mark --UITextViewDelegate
  86. - (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange interaction:(UITextItemInteraction)interaction{
  87. if ([[URL scheme]isEqualToString:@"upgradeLevel"]) {// 如何提高星级
  88. ZCBaseWebVC * vc = [[ZCBaseWebVC alloc]init];
  89. vc.contentUrl = self.youpaipanchorStarlevelUrl;
  90. vc.needHideNav = YES;
  91. [self.navigationController pushViewController:vc animated:YES];
  92. return NO;
  93. }
  94. return YES;
  95. }
  96. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  97. return self.youpaipdataSource.count;
  98. }
  99. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  100. NSDictionary *sectionModel = self.youpaipdataSource[section];
  101. NSArray *rows = [sectionModel objectForKey:@"rows"];
  102. return rows.count;
  103. }
  104. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  105. NSDictionary *sectionModel = self.youpaipdataSource[indexPath.section];
  106. NSArray *rows = [sectionModel objectForKey:@"rows"];
  107. NSDictionary *cellModel = rows[indexPath.row];
  108. NSString *cellName = [cellModel objectForKey:@"cellName"];
  109. if ([cellName isEqual:@"YOUPAILZBigCastMoneySettingCell"]) {
  110. YOUPAILZBigCastMoneySettingCell *cell = [tableView dequeueReusableCellWithIdentifier:cellName];
  111. if (cell == nil) {
  112. cell = [[YOUPAILZBigCastMoneySettingCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName];
  113. }
  114. cell.titleLab.text = [cellModel objectForKey:@"title"];
  115. if ([[cellModel objectForKey:@"type"] isEqual:@"message_price"]) {
  116. cell.vlaueLab.text = self.youpaipmsg_price;
  117. }else if ([[cellModel objectForKey:@"type"] isEqual:@"video_price"]){
  118. cell.vlaueLab.text = self.youpaipvideo_price;
  119. }
  120. return cell;
  121. }else if([cellName isEqual:@"YOUPAIZYSettingCell"]){
  122. YOUPAIZYSettingCell *cell = [tableView dequeueReusableCellWithIdentifier:cellName];
  123. if (cell == nil) {
  124. cell = [[YOUPAIZYSettingCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName];
  125. }
  126. NSString *title = cellModel[@"title"];
  127. cell.youpaipheadLabel.text = title;
  128. cell.youpaiprightSwitch.hidden = NO;
  129. cell.youpaiparrowImgView.hidden = YES;
  130. cell.youpaiprightSwitch.selected = self.youpaipopen_video_status;
  131. [cell.youpaiprightSwitch addTarget:self action:@selector(youpaifopenVideoBtnClick:) forControlEvents:UIControlEventTouchUpInside];
  132. return cell;
  133. }
  134. return [UITableViewCell new];
  135. }
  136. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
  137. return CGFLOAT_MIN;
  138. }
  139. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
  140. NSDictionary *sectionModel = self.youpaipdataSource[section];
  141. if ([[sectionModel objectForKey:@"hasFooter"] boolValue]) {
  142. return 6.0f;
  143. }
  144. return CGFLOAT_MIN;
  145. }
  146. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  147. NSDictionary *sectionModel = self.youpaipdataSource[indexPath.section];
  148. NSArray *rows = [sectionModel objectForKey:@"rows"];
  149. NSDictionary *cellModel = rows[indexPath.row];
  150. if ([[cellModel objectForKey:@"type"] isEqual:@"message_price"]) {
  151. [self youpaifshowChatPricePick];
  152. }else if ([[cellModel objectForKey:@"type"] isEqual:@"video_price"]){
  153. [self youpaifshowVideoPricePick];
  154. }
  155. }
  156. - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
  157. NSDictionary *sectionModel = self.youpaipdataSource[section];
  158. if ([[sectionModel objectForKey:@"hasFooter"] boolValue]) {
  159. UIView *footerV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 6)];
  160. footerV.backgroundColor = LZF7F8FAColor;
  161. return footerV;
  162. }
  163. return nil;
  164. }
  165. - (void)youpaifopenVideoBtnClick:(UIButton *)sender{
  166. sender.selected = !sender.selected;
  167. NSInteger status = 0;
  168. if (sender.selected == NO) {//将状态置为1空闲
  169. status = 0;
  170. }else{
  171. status = 1;
  172. }
  173. @weakify(self);
  174. [LCHttpHelper requestWithURLString:BigCastSetVideoStatus parameters:@{@"status":@(status)} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  175. @strongify(self);
  176. NSDictionary* dict = (NSDictionary*)responseObject;
  177. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  178. if (code==0) {
  179. if (status==1) {
  180. [LCSaveData saveVideoOpenStatu:YES];
  181. self.youpaipopen_video_status = YES;
  182. }else{
  183. [LCSaveData saveVideoOpenStatu:NO];
  184. self.youpaipopen_video_status = NO;
  185. }
  186. }
  187. [self.youpaiptableView reloadData];
  188. } failure:^(NSError *error) {
  189. }];
  190. }
  191. - (void)youpaifinitData{
  192. @weakify(self);
  193. [LCHttpHelper requestWithURLString:AnchorGetPrice parameters:@{} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  194. @strongify(self);
  195. NSDictionary* dict = (NSDictionary*)responseObject;
  196. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  197. if (code == 0) {
  198. self.youpaipvideo_price = [[dict objectForKey:@"data"] objectForKey:@"video_price"];
  199. self.youpaipmsg_price = [[dict objectForKey:@"data"] objectForKey:@"msg_price"];
  200. self.youpaipopen_video_status = [[[dict objectForKey:@"data"] objectForKey:@"open_video_status"] boolValue];
  201. self.youpaipdataSource = @[
  202. @{@"hasFooter":@(YES),@"rows":@[@{@"cellName":@"YOUPAILZBigCastMoneySettingCell",@"title":@"消息价格",@"type":@"message_price"}]},
  203. @{@"hasFooter":@(NO),@"rows":@[
  204. @{@"cellName":@"YOUPAIZYSettingCell",@"title":@"视频接听",@"type":@"video_call"},
  205. @{@"cellName":@"YOUPAILZBigCastMoneySettingCell",@"title":@"视频价格设置",@"type":@"video_price"},
  206. ]},
  207. ];
  208. [self youpaifinitUI];
  209. }
  210. } failure:^(NSError *error) {
  211. }];
  212. }
  213. - (void)youpaifshowChatPricePick{
  214. if (self.youpaipchatPrices.count != 0) {
  215. YOUPAILZBigCastSetSelectedPricePickerVC *vc = [[YOUPAILZBigCastSetSelectedPricePickerVC alloc] init];
  216. vc.dataSouce = self.youpaipchatPrices;
  217. @weakify(self);
  218. [vc setConfirmBtnClickBlock:^(YOUPAILZBigCastSetPriceModel * _Nonnull model) {
  219. @strongify(self);
  220. [self youpaifSettingPriceWithModel:model type:@"5"];
  221. }];
  222. [self TFPresentVC:vc completion:nil];
  223. }else{
  224. [self youpaifRequestGetAnchorSettingWithShowPick:1];
  225. }
  226. }
  227. - (void)youpaifshowVideoPricePick{
  228. if (self.youpaipvideoPrices.count != 0) {
  229. YOUPAILZBigCastSetSelectedPricePickerVC *vc = [[YOUPAILZBigCastSetSelectedPricePickerVC alloc] init];
  230. vc.dataSouce = self.youpaipvideoPrices;
  231. @weakify(self);
  232. [vc setConfirmBtnClickBlock:^(YOUPAILZBigCastSetPriceModel * _Nonnull model) {
  233. @strongify(self);
  234. [self youpaifSettingPriceWithModel:model type:@"2"];
  235. }];
  236. [self TFPresentVC:vc completion:nil];
  237. }else{
  238. [self youpaifRequestGetAnchorSettingWithShowPick:2];
  239. }
  240. }
  241. - (void)youpaifSettingPriceWithModel:(YOUPAILZBigCastSetPriceModel *)model type:(NSString *)type{
  242. @weakify(self);
  243. [LCHttpHelper requestWithURLString:SetSkillPrice parameters:@{@"price_id":model.youpaipid,@"type":type} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  244. @strongify(self);
  245. NSDictionary* dict = (NSDictionary*)responseObject;
  246. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  247. if (code==0) {//成功
  248. [ZCHUDHelper showTitle:@"价格设置成功"];
  249. if ([type isEqual:@"5"]) { // 文字
  250. self.youpaipmsg_price = [NSString stringWithFormat:@"%@%@/条",model.youpaipcoins,model.youpaipcontent];
  251. }else if ([type isEqual:@"2"]) { // 视频
  252. self.youpaipvideo_price = [NSString stringWithFormat:@"%@%@/分钟",model.youpaipcoins,model.youpaipcontent];
  253. }
  254. [self.youpaiptableView reloadData];
  255. }
  256. } failure:^(NSError *error) {
  257. }];
  258. }
  259. - (void)youpaifRequestGetAnchorSettingWithShowPick:(NSInteger)showPick{
  260. @weakify(self);
  261. [LCHttpHelper requestWithURLString:GetAnchorSetting parameters:@{} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  262. @strongify(self);
  263. NSDictionary* dict = (NSDictionary*)responseObject;
  264. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  265. if (code == 0) {
  266. self.youpaipchatPrices = [YOUPAILZBigCastSetPriceModel mj_objectArrayWithKeyValuesArray:[[dict objectForKey:@"data"] objectForKey:@"chat"]];
  267. self.youpaipvideoPrices = [YOUPAILZBigCastSetPriceModel mj_objectArrayWithKeyValuesArray:[[dict objectForKey:@"data"] objectForKey:@"video"]];
  268. if (showPick == 1) {
  269. [self youpaifshowChatPricePick];
  270. }else if (showPick == 2){
  271. [self youpaifshowVideoPricePick];
  272. }
  273. }
  274. } failure:^(NSError *error) {
  275. }];
  276. }
  277. @end