YBGetVideoObj.m 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. //
  2. // YBGetVideoObj.m
  3. // YBVideo
  4. //
  5. // Created by YB007 on 2019/11/21.
  6. // Copyright © 2019 cat. All rights reserved.
  7. //
  8. #import "YBGetVideoObj.h"
  9. #import "YBLookVideoVC.h"
  10. #import "YBVipVC.h"
  11. #import "YBRechargeVC.h"
  12. @implementation YBGetVideoObj
  13. static YBGetVideoObj*_lookManeger = nil;
  14. +(instancetype)lookManeger {
  15. static dispatch_once_t onceToken;
  16. dispatch_once(&onceToken, ^{
  17. _lookManeger = [[super allocWithZone:NULL]init];
  18. _lookManeger.playIndex = 0;
  19. _lookManeger.paging = 1;
  20. _lookManeger.baseUrl = @"";
  21. });
  22. return _lookManeger;
  23. }
  24. +(instancetype)allocWithZone:(struct _NSZone *)zone {
  25. return [self lookManeger];
  26. }
  27. -(void)goLookVC {
  28. if ([PublicObj checkNull:minstr(_fromWhere)]) {
  29. [MBProgressHUD showPop:YZMsg(@"请标记页面来源")];
  30. return;
  31. }
  32. if ([PublicObj checkNull:minstr(_videoID)]) {
  33. [MBProgressHUD showPop:YZMsg(@"请标记视频id")];
  34. return;
  35. }
  36. YBWeakSelf;
  37. [MBProgressHUD showMessage:@""];
  38. [YBNetworking postWithUrl:@"Video.getVideo" Dic:@{@"videoid":_videoID,@"mobileid":[PublicObj getDeviceUUID]} Suc:^(int code, id info, NSString *msg) {
  39. [MBProgressHUD hideHUD];
  40. if (code == 0) {
  41. NSDictionary *infoDic = [info firstObject];
  42. [weakSelf getInfo:infoDic];
  43. }else if (code == 1001){
  44. //需要登录
  45. [PublicObj warnLogin];
  46. }else if(code == 1002){
  47. //需要开通Vip
  48. [weakSelf limitPlayVideo:1 andMsg:msg];
  49. }else if (code == 1003){
  50. //需要支付
  51. [weakSelf limitPlayVideo:2 andMsg:msg];
  52. }else {
  53. [MBProgressHUD showPop:msg];
  54. }
  55. } Fail:^(id fail) {
  56. [MBProgressHUD hideHUD];
  57. }];
  58. }
  59. -(void)getInfo:(NSDictionary *)infoDic {
  60. if ([PublicObj checkNull:minstr(_baseUrl)] && _videoList.count<=0) {
  61. //为空代表进入的观看页面将不能上下滑动
  62. _videoList = @[infoDic].mutableCopy;
  63. }else{
  64. NSMutableDictionary *m_dic;
  65. int index = -1;
  66. for (int i = 0; i<_videoList.count; i++) {
  67. NSDictionary *listDic = _videoList[i];
  68. if ([[listDic valueForKey:@"id"]isEqual:[infoDic valueForKey:@"id"]]) {
  69. index = i;
  70. m_dic = [NSMutableDictionary dictionaryWithDictionary:listDic];
  71. [m_dic setObject:[infoDic valueForKey:@"islike"] forKey:@"islike"];
  72. [m_dic setObject:[infoDic valueForKey:@"likes"] forKey:@"likes"];
  73. [m_dic setObject:[infoDic valueForKey:@"comments"] forKey:@"comments"];
  74. [m_dic setObject:[infoDic valueForKey:@"isattent"] forKey:@"isattent"];
  75. [m_dic setObject:[infoDic valueForKey:@"shares"] forKey:@"shares"];
  76. break;
  77. }
  78. }
  79. if (index != -1) {
  80. NSDictionary *needChangeDic = [NSDictionary dictionaryWithDictionary:m_dic];
  81. [_videoList replaceObjectAtIndex:index withObject:needChangeDic];
  82. }
  83. }
  84. [self canLookVideo:_playIndex andList:_videoList andPage:_paging andUrl:_baseUrl];
  85. }
  86. -(void)limitPlayVideo:(int)limiteType andMsg:(NSString *)msg{
  87. //limiteType 1:vip 2:pay
  88. YBWeakSelf
  89. NSDictionary *contentDic = @{@"title":@"",@"msg":msg,@"left":YZMsg(@"取消"),@"right":(limiteType==1)?YZMsg(@"开通会员"):YZMsg(@"观看")};
  90. [YBAlertView showAlertView:contentDic complete:^(int eventType) {
  91. if (eventType == 1) {
  92. if ([[Config getOwnID] intValue]<=0) {
  93. [PublicObj warnLogin];
  94. return;
  95. }
  96. if ([YBYoungManager shareInstance].youngSwitch == 1) {
  97. [MBProgressHUD showError:YZMsg(@"青少年模式下不支持该功能")];
  98. return;
  99. }
  100. //确认按钮
  101. if (limiteType == 1) {
  102. //vip
  103. YBVipVC *vipVC = [[YBVipVC alloc]init];
  104. [[YBBaseAppDelegate sharedAppDelegate]pushViewController:vipVC animated:YES];
  105. }else {
  106. //付费观看
  107. [weakSelf goPay];
  108. }
  109. }
  110. }];
  111. }
  112. //可以播放
  113. -(void)canLookVideo:(int)row andList:(NSMutableArray *)videoList andPage:(int)page andUrl:(NSString *)baseUrl{
  114. YBLookVideoVC *ybLook = [[YBLookVideoVC alloc]init];
  115. ybLook.fromWhere = _fromWhere;
  116. ybLook.firstPush = YES;
  117. ybLook.pushPlayIndex = row;
  118. ybLook.sourceBaseUrl = baseUrl;
  119. ybLook.videoList = [videoList mutableCopy];
  120. ybLook.pages = page;
  121. [[YBBaseAppDelegate sharedAppDelegate]pushViewController:ybLook animated:YES];
  122. }
  123. #pragma mark -
  124. -(void)goPay {
  125. YBWeakSelf;
  126. [MBProgressHUD showMessage:@""];
  127. [YBNetworking postWithUrl:@"Video.setVideoPay" Dic:@{@"videoid":_videoID} Suc:^(int code, id info, NSString *msg) {
  128. [MBProgressHUD hideHUD];
  129. if (code == 0) {
  130. [weakSelf canLookVideo:_playIndex andList:_videoList andPage:_paging andUrl:_baseUrl];
  131. }else if (code == 1004){
  132. //余额不足
  133. [weakSelf noMoney:msg];
  134. }else {
  135. [MBProgressHUD showPop:msg];
  136. }
  137. } Fail:^(id fail) {
  138. [MBProgressHUD hideHUD];
  139. }];
  140. }
  141. //余额不足提示
  142. -(void)noMoney:(NSString *)msg {
  143. NSDictionary *contentDic = @{@"title":@"",@"msg":msg,@"left":YZMsg(@"取消"),@"right":YZMsg(@"去充值")};
  144. [YBAlertView showAlertView:contentDic complete:^(int eventType) {
  145. if (eventType == 1) {
  146. //确认按钮
  147. YBRechargeVC *chargeVC = [[YBRechargeVC alloc]init];
  148. [[YBBaseAppDelegate sharedAppDelegate]pushViewController:chargeVC animated:YES];
  149. }
  150. }];
  151. }
  152. @end