BGLivePayManager.m 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  1. //
  2. // BGLivePayManager.m
  3. // BuguLive
  4. //
  5. // Created by 丁凯 on 2017/8/16.
  6. // Copyright © 2017年 xfg. All rights reserved.
  7. /*
  8. 付费直播流程
  9. 1主播:主播通过心跳接口判断是否加价或者提档-->进行加价或者提档-->加价或者提档成功IM发送消息给观众-->IM消息接收之后规定时间进行付费(付费成功继续观看,否则无法观看直播页面以及关闭直播声音)
  10. 2观众:进入直播通过get_video判断直播间是否进行收费-->收费直播就进行收费操作,且无法观看直播页面以及关闭直播声音(不需要就继续观看)
  11. */
  12. #import "BGLivePayManager.h"
  13. #import "LivePayLeftPromptV.h"
  14. @implementation BGLivePayManager
  15. #pragma mark =============================主播================================
  16. - (id)initWithLiveView:(TCShowLiveView *)liveView andRoomId:(int)roomId andhostDict:(NSDictionary *)hostDict andpayType:(NSInteger)payType
  17. {
  18. if (self = [super init])
  19. {
  20. self.roomId = roomId;
  21. self.httpsManager = [NetHttpsManager manager];
  22. self.BuguLive = [GlobalVariables sharedInstance];
  23. self.buttomFunctionType = payType;
  24. self.is_agree = NO;
  25. self.subLiving = liveView;
  26. self.hostDict = hostDict;
  27. self.hostLeftPView = [[LivePayLeftPromptV alloc]init];
  28. self.hostLeftPView.frame = CGRectMake(kDefaultMargin,CGRectGetMaxY(self.subLiving.topView.otherContainerView.frame)+kStatusBarHeight, 0, kTicketContrainerViewHeight);
  29. [self.subLiving addSubview:self.hostLeftPView];
  30. [self creatViewWithDict:self.hostDict];
  31. }
  32. return self;
  33. }
  34. #pragma mark 心跳接口判断是否付费或者提档 主播和观众同时在直播间里面开始收费的流程
  35. - (void)creatViewWithDict:(NSDictionary *)dict
  36. {
  37. if ([[dict objectForKey:@"live"] toInt:@"allow_mention"] == 1)
  38. {
  39. self.is_mentionType = 1;
  40. SUS_WINDOW.isShowMention = YES;
  41. [self.subLiving.bottomView addLiveFunc:self.buttomFunctionType];
  42. }
  43. else
  44. {
  45. if (self.liveType != 40)//为了防止按场付费开启后没有分享等功能(和开启按时付费开启后多一个切换付费的功能)
  46. {
  47. if ([dict toInt:@"live_pay_type"] == 0 && self.subLiving.isHost)
  48. {
  49. SUS_WINDOW.isShowLivePay = YES;
  50. [self.subLiving.bottomView addLiveFunc:self.buttomFunctionType];
  51. }
  52. }
  53. }
  54. }
  55. #pragma mark 切换付费或者提档后的代理
  56. - (void)creatPriceViewWithCount:(int)count
  57. {
  58. if (count == 1)//按时付费ASLocalizedString(@"1<=价格<=100")
  59. {
  60. [FanweMessage alertInput:ASLocalizedString(@"按时付费定价")message:[NSString stringWithFormat:ASLocalizedString(@"请输入价格(%@/分钟)"),self.BuguLive.appModel.diamond_name] placeholder:[NSString stringWithFormat:ASLocalizedString(@"%ld<=价格<=%ld"),(long)self.BuguLive.appModel.live_pay_min,(long)self.BuguLive.appModel.live_pay_max] keyboardType:UIKeyboardTypeNumberPad destructiveTitle:nil destructiveAction:^(NSString *text)
  61. {
  62. if ([text longLongValue] > (long)self.BuguLive.appModel.live_pay_max || [text longLongValue] < (long)self.BuguLive.appModel.live_pay_min)
  63. {
  64. [FanweMessage alert:ASLocalizedString(@"请输入正确的价格")];
  65. return ;
  66. }
  67. [self hostComfirmChargerWithStr:text];
  68. } cancelTitle:nil cancelAction:^{
  69. }];
  70. }else if (count == 2)//提档
  71. {
  72. [FanweMessage alert:ASLocalizedString(@"按时付费提档")message:ASLocalizedString(@"确定要提档?")destructiveAction:^{
  73. [self hostComfirmChargerWithStr:nil];
  74. } cancelAction:^{
  75. }];
  76. }else if (count == 3)//按场次
  77. {
  78. [FanweMessage alertInput:ASLocalizedString(@"按场付费定价")message:[NSString stringWithFormat:ASLocalizedString(@"请输入该场价格(%@/场)"),self.BuguLive.appModel.diamond_name] placeholder:[NSString stringWithFormat:ASLocalizedString(@"%ld<=价格<=%ld"),(long)self.BuguLive.appModel.live_pay_scene_min,(long)self.BuguLive.appModel.live_pay_scene_max] keyboardType:UIKeyboardTypeNumberPad destructiveTitle:nil destructiveAction:^(NSString *text)
  79. {
  80. if ([text longLongValue] > (long)self.BuguLive.appModel.live_pay_scene_max || [text longLongValue] < (long)self.BuguLive.appModel.live_pay_scene_min)
  81. {
  82. [FanweMessage alert:ASLocalizedString(@"请输入正确的价格")];
  83. return ;
  84. }
  85. [self hostComfirmChargerWithStr:text];
  86. } cancelTitle:nil cancelAction:^{
  87. }];
  88. }
  89. }
  90. #pragma mark 主播提档或者切换付费之后确定的接口
  91. - (void)hostComfirmChargerWithStr:(NSString *)textStr
  92. {
  93. NSMutableDictionary *mDict = [NSMutableDictionary dictionary];
  94. [mDict setObject:@"live" forKey:@"ctl"];
  95. [mDict setObject:@"live_pay" forKey:@"act"];
  96. if (self.liveType == 40)
  97. {
  98. [mDict setObject:@"1" forKey:@"live_pay_type"];
  99. }else
  100. {
  101. [mDict setObject:@"0" forKey:@"live_pay_type"];
  102. }
  103. [mDict setObject:[NSString stringWithFormat:@"%d",(int)self.roomId] forKey:@"room_id"];
  104. if (self.is_mentionType == 1)
  105. {
  106. [mDict setObject:@"1" forKey:@"is_mention"];
  107. }else
  108. {
  109. [mDict setObject:@"0" forKey:@"is_mention"];
  110. if (textStr)
  111. {
  112. [mDict setObject:textStr forKey:@"live_fee"];
  113. }
  114. }
  115. [self.httpsManager POSTWithParameters:mDict SuccessBlock:^(NSDictionary *responseJson)
  116. {
  117. if ([responseJson toInt:@"status"] == 1)
  118. {
  119. SUS_WINDOW.isShowLivePay = NO;
  120. SUS_WINDOW.isShowMention = NO;
  121. [self.subLiving.bottomView addLiveFunc:self.buttomFunctionType];
  122. if (self.liveType == 40)
  123. {
  124. [self.hostLeftPView addFirstLabWithStr:[NSString stringWithFormat:ASLocalizedString(@"该直播%d%@/场"),[responseJson toInt:@"live_fee"],self.BuguLive.appModel.diamond_name]];
  125. [self.hostLeftPView addSecondLabWithStr:[NSString stringWithFormat:ASLocalizedString(@"直播间付费人数:%d"),[responseJson toInt:@"live_viewer"]]];
  126. }else
  127. {
  128. self.hostTimeCount = [[responseJson toString:@"count_down"] intValue];
  129. if (self.hostTimeCount > 0)
  130. {
  131. self.hostTimeCount = [[responseJson toString:@"count_down"] intValue];
  132. [self.hostLeftPView addFirstLabWithStr:[NSString stringWithFormat:ASLocalizedString(@"%d秒后付费开始"),(int)self.hostTimeCount]];
  133. if (!self.hostPayLiveTime)
  134. {
  135. self.hostPayLiveTime = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(HostTimeGo) userInfo:nil repeats:YES];
  136. [[NSRunLoop currentRunLoop] addTimer:self.hostPayLiveTime forMode:NSDefaultRunLoopMode];
  137. }
  138. [self.hostLeftPView addSecondLabWithStr:[NSString stringWithFormat:ASLocalizedString(@"%d%@/分钟"),[responseJson toInt:@"live_fee"],self.BuguLive.appModel.diamond_name]];
  139. [self.hostLeftPView addThreeLabWithStr:[NSString stringWithFormat:ASLocalizedString(@"直播间付费人数:%d"),[responseJson toInt:@"live_viewer"]]];
  140. }else
  141. {
  142. [self.hostLeftPView addSecondLabWithStr:[NSString stringWithFormat:ASLocalizedString(@"%d%@/分钟"),[responseJson toInt:@"live_fee"],self.BuguLive.appModel.diamond_name]];
  143. [self.hostLeftPView addThreeLabWithStr:[NSString stringWithFormat:ASLocalizedString(@"直播间付费人数:%d"),[responseJson toInt:@"live_viewer"]]];
  144. }
  145. }
  146. CGRect rect = self.hostLeftPView.frame;
  147. rect.origin.y = CGRectGetMaxY(self.subLiving.topView.vipBtn.frame)+kStatusBarHeight;
  148. self.hostLeftPView.frame = rect;
  149. self.subLiving.livewWishView.top = rect.origin.y+rect.size.height + kDefaultMargin;
  150. __weak __typeof(self)weakSelf = self;
  151. [self.subLiving.livewWishView addObserverBlockForKeyPath:@"hidden" block:^(id _Nonnull obj, id _Nullable oldVal, id _Nullable newVal) {
  152. weakSelf.subLiving.livewWishView.top = rect.origin.y+rect.size.height + kDefaultMargin;
  153. }];
  154. }
  155. } FailureBlock:^(NSError *error)
  156. {
  157. NSLog(@"error===%@",error);
  158. }];
  159. }
  160. #pragma mark 主播付费页面显示倒计时
  161. - (void)HostTimeGo
  162. {
  163. self.hostTimeCount --;
  164. if (self.hostTimeCount == 0)
  165. {
  166. [self.hostPayLiveTime invalidate];
  167. self.hostPayLiveTime = nil;
  168. [self.hostLeftPView removeFirstLabel];
  169. return;
  170. }
  171. [self.hostLeftPView addFirstLabWithStr:[NSString stringWithFormat:ASLocalizedString(@"%d秒后付费开始"),(int)self.hostTimeCount]];
  172. }
  173. #pragma mark 主播异常后再次可以进入原来自己的付费直播
  174. - (void)hostEnterLiveAgainWithMDict:(NSDictionary *)responseJson
  175. {
  176. if ([responseJson toInt:@"live_pay_type"] == 1)//按场收费
  177. {
  178. self.liveType = 40;
  179. [self.hostLeftPView addFirstLabWithStr:[NSString stringWithFormat:ASLocalizedString(@"该直播%d%@/场"),[responseJson toInt:@"live_fee"],self.BuguLive.appModel.diamond_name]];
  180. [self.hostLeftPView addSecondLabWithStr:[NSString stringWithFormat:ASLocalizedString(@"直播间付费人数:%d"),[responseJson toInt:@"live_viewer"]]];
  181. }else //按时付费
  182. {
  183. self.hostTimeCount = [[responseJson toString:@"count_down"] intValue];
  184. if (self.hostTimeCount > 0)
  185. {
  186. self.hostTimeCount = [[responseJson toString:@"count_down"] intValue];
  187. [self.hostLeftPView addFirstLabWithStr:[NSString stringWithFormat:ASLocalizedString(@"%d秒后付费开始"),(int)self.hostTimeCount]];
  188. if (!self.hostPayLiveTime)
  189. {
  190. self.hostPayLiveTime = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(HostTimeGo) userInfo:nil repeats:YES];
  191. [[NSRunLoop currentRunLoop] addTimer:self.hostPayLiveTime forMode:NSDefaultRunLoopMode];
  192. }
  193. [self.hostLeftPView addSecondLabWithStr:[NSString stringWithFormat:ASLocalizedString(@"%d%@/分钟"),[responseJson toInt:@"live_fee"],self.BuguLive.appModel.diamond_name]];
  194. [self.hostLeftPView addThreeLabWithStr:[NSString stringWithFormat:ASLocalizedString(@"直播间付费人数:%d"),[responseJson toInt:@"live_viewer"]]];
  195. }else
  196. {
  197. [self.hostLeftPView addSecondLabWithStr:[NSString stringWithFormat:ASLocalizedString(@"%d%@/分钟"),[responseJson toInt:@"live_fee"],self.BuguLive.appModel.diamond_name]];
  198. [self.hostLeftPView addThreeLabWithStr:[NSString stringWithFormat:ASLocalizedString(@"直播间付费人数:%d"),[responseJson toInt:@"live_viewer"]]];
  199. }
  200. }
  201. }
  202. #pragma mark ==================================观众========================================
  203. - (id)initWithController:(UIViewController *)controller andLiveView:(TCShowLiveView *)liveView andRoomId:(int)roomId andAudienceDict:(NSDictionary *)audienceDict andButton:(UIButton *)closeBtn
  204. {
  205. if (self = [super init])
  206. {
  207. self.roomId = roomId;
  208. self.httpsManager = [NetHttpsManager manager];
  209. self.BuguLive = [GlobalVariables sharedInstance];
  210. self.closeButton = closeBtn;
  211. self.is_agree = NO;
  212. self.subLiving = liveView;
  213. self.livController = controller;
  214. self.audienceDict = audienceDict;
  215. self.audienceLeftPView = [[LivePayLeftPromptV alloc]init];
  216. self.audienceLeftPView.frame = CGRectMake(kDefaultMargin,self.subLiving.topView.vipBtn.bottom, 0, kTicketContrainerViewHeight);
  217. [self.subLiving addSubview:self.audienceLeftPView];
  218. }
  219. return self;
  220. }
  221. #pragma mark 观众进入直播间后是否需要付费 观众1
  222. - (void)creatAudienceWithDict:(NSDictionary *)dict
  223. {
  224. if (!self.payLiveTime)
  225. {
  226. self.payLiveTime = [NSTimer scheduledTimerWithTimeInterval:30.0 target:self selector:@selector(ChargeTimeGo) userInfo:nil repeats:YES];
  227. [[NSRunLoop currentRunLoop] addTimer:self.payLiveTime forMode:NSDefaultRunLoopMode];
  228. [self enterMoneyMode];//请求接口
  229. }
  230. }
  231. #pragma mark 按场付费直播观众在主播开启付费之后进入直播间变灰
  232. - (void)AudienceBecomeshadowView
  233. {
  234. self.liveType = 40;
  235. [self creatTwoPromptView];//切换付费
  236. }
  237. #pragma mark 观众在收费直播间IM收到收费的通知 typeTag = 40 为按场次付费
  238. - (void)AudienceGetVedioViewWithType:(int)typeTag
  239. {
  240. [self creatShadowView];
  241. self.liveType = typeTag;
  242. if (typeTag == 40) //按场次付费
  243. {
  244. self.shadowView.hidden = NO;
  245. [self enterMoneyMode];
  246. [self sentNotice:0];
  247. }else //按时间付费
  248. {
  249. [self goToCountDownTime];
  250. [self enterMoneyMode];
  251. if (!self.payLiveTime)
  252. {
  253. self.payLiveTime = [NSTimer scheduledTimerWithTimeInterval:30 target:self selector:@selector(ChargeTimeGo) userInfo:nil repeats:YES];
  254. [[NSRunLoop currentRunLoop] addTimer:self.payLiveTime forMode:NSDefaultRunLoopMode];
  255. }
  256. }
  257. }
  258. #pragma mark 观众倒计时方法的调用
  259. - (void)goToCountDownTime
  260. {
  261. self.downTimeType = 1;
  262. if (!self.countDownTime)
  263. {
  264. self.countDownTime = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(moneyCountDownTimeGo) userInfo:nil repeats:YES];
  265. self.timeCount = self.BuguLive.appModel.live_pay_count_down;
  266. [[NSRunLoop currentRunLoop] addTimer:self.countDownTime forMode:NSDefaultRunLoopMode];
  267. }
  268. }
  269. #pragma mark 观众倒计时
  270. - (void)moneyCountDownTimeGo
  271. {
  272. self.timeCount --;
  273. if (self.downTimeType == 1)
  274. {
  275. if (self.timeCount == 0)
  276. {
  277. [self.countDownTime invalidate];
  278. self.countDownTime = nil;
  279. [self.audienceLeftPView.threeLabel removeFromSuperview];
  280. if (self.is_agree)
  281. {
  282. [self enterMoneyMode];
  283. }else
  284. {
  285. [self closeYY];
  286. self.shadowView.hidden = NO;
  287. [self sentNotice:0];
  288. }
  289. return;
  290. }
  291. }else
  292. {
  293. if (self.timeCount == 0)
  294. {
  295. [self.countDownTime invalidate];
  296. self.countDownTime = nil;
  297. [self.audienceLeftPView.threeLabel removeFromSuperview];
  298. if (self.is_agree)
  299. {
  300. [self enterMoneyMode];
  301. }else
  302. {
  303. [self closeYY];
  304. self.shadowView.hidden = NO;
  305. [self sentNotice:0];
  306. }
  307. return;
  308. }
  309. }
  310. [self.audienceLeftPView addThreeLabWithStr:[NSString stringWithFormat:ASLocalizedString(@"%d秒后付费开始"),(int)self.timeCount]];
  311. }
  312. #pragma mark 阴影部分的创建
  313. - (void)creatShadowView
  314. {
  315. if (!self.shadowView)//覆盖直播间的view
  316. {
  317. self.shadowView = [[UIView alloc]initWithFrame:CGRectMake(-3*kScreenW, 0, 5*kScreenW, kScreenH)];
  318. self.shadowView.backgroundColor = kLightGrayColor;
  319. self.shadowView.hidden = YES;
  320. self.closeButton.hidden = NO;
  321. [self.livController.view addSubview:self.shadowView];
  322. [self.livController.view bringSubviewToFront:self.closeButton];
  323. }
  324. }
  325. #pragma mark 30秒循环定时器
  326. - (void)ChargeTimeGo
  327. {
  328. [self enterMoneyMode];
  329. }
  330. #pragma mark 观众点击确定进入收费模式
  331. - (void)enterMoneyMode
  332. {
  333. NSMutableDictionary *mDict = [NSMutableDictionary dictionary];
  334. [mDict setObject:@"live" forKey:@"ctl"];
  335. [mDict setObject:@"live_pay_deduct" forKey:@"act"];
  336. [mDict setObject:[NSString stringWithFormat:@"%d",self.is_agree] forKey:@"is_agree"];
  337. [mDict setObject:[NSString stringWithFormat:@"%d",(int)self.roomId] forKey:@"room_id"];
  338. FWWeakify(self)
  339. [self.httpsManager POSTWithParameters:mDict SuccessBlock:^(NSDictionary *responseJson)
  340. {
  341. FWStrongify(self)
  342. if ([responseJson toInt:@"status"] == 1)
  343. {
  344. self.isEnterPayLive = 1;
  345. [[IMAPlatform sharedInstance].host setDiamonds:[NSString stringWithFormat:@"%ld",(long)[responseJson toInt:@"diamonds"]]];
  346. [self.subLiving.giftView setDiamondsLabelTxt:[NSString stringWithFormat:@"%ld",(long)[responseJson toInt:@"diamonds"]]];
  347. self.audienceDict = responseJson;
  348. if (self.BuguLive.appModel.open_diamond_game_module == 1)
  349. {
  350. //更新游戏的余额
  351. [[NSNotificationCenter defaultCenter]postNotificationName:@"updateCoin" object:nil];
  352. }
  353. if ([responseJson toInt:@"is_live_pay"]== 1)//是否收费,1是 0 否
  354. {
  355. self.subLiving.topView.ticketNumLabel.text =[NSString stringWithFormat:@"%d",[responseJson toInt:@"ticket"]];
  356. [self.subLiving.topView relayoutOtherContainerViewFrame];
  357. if (self.liveType == 40)
  358. {
  359. [self.audienceLeftPView addFirstLabWithStr:[NSString stringWithFormat:ASLocalizedString(@"该直播%d%@/场"),[responseJson toInt:@"live_fee"],self.BuguLive.appModel.diamond_name]];
  360. if (self.is_agree == 0)
  361. {
  362. [self creatTwoPromptView];
  363. }else
  364. {
  365. [self getAudienceStateWithDict:self.audienceDict];
  366. }
  367. }else
  368. {
  369. [self creatAudienceWithDict:self.audienceDict];
  370. [self.audienceLeftPView addFirstLabWithStr:[NSString stringWithFormat:ASLocalizedString(@"%d%@/分钟"),[responseJson toInt:@"live_fee"],self.BuguLive.appModel.diamond_name]];
  371. [self.audienceLeftPView addSecondLabWithStr:[NSString stringWithFormat:ASLocalizedString(@"已观看:%d分钟"),[responseJson toInt:@"total_time"]/60]];
  372. if ([responseJson toInt:@"count_down"])
  373. {
  374. self.timeCount = [responseJson toInt:@"count_down"];
  375. [self.audienceLeftPView addThreeLabWithStr:[NSString stringWithFormat:ASLocalizedString(@"%d秒后付费开始"),[responseJson toInt:@"count_down"]]];
  376. if (!self.countDownTime)
  377. {
  378. self.countDownTime = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(moneyCountDownTimeGo) userInfo:nil repeats:YES];
  379. [[NSRunLoop currentRunLoop] addTimer:self.countDownTime forMode:NSDefaultRunLoopMode];
  380. }
  381. }
  382. if (self.is_agree == 1)//是否同意,1同意 0不同意
  383. {
  384. [self getAudienceStateWithDict:self.audienceDict];
  385. }else
  386. {
  387. if ([responseJson toInt:@"on_live_pay"] == 1)//是否收费中 1是 0否
  388. {
  389. self.shadowView.hidden = NO;
  390. // [self sentNotice:0];
  391. }
  392. [self creatTwoPromptView];
  393. }
  394. }
  395. }else
  396. {
  397. NSLog(@"not need to do");
  398. }
  399. }
  400. } FailureBlock:^(NSError *error)
  401. {
  402. NSLog(@"error===%@",error);
  403. }];
  404. }
  405. #pragma mark 判断观众现在的状态,钱为0,钱不够5分钟,钱足够 观众3
  406. - (void)getAudienceStateWithDict:(NSDictionary *)dict
  407. {
  408. if ([dict toInt:@"is_diamonds_low"] == 1 && [dict toInt:@"is_recharge"] == 0)//余额很少
  409. {
  410. [BGUtils closeKeyboard]; // 关闭键盘
  411. if (self.payDelegate)//加载直播间视频的代理
  412. {
  413. if ([self.payDelegate respondsToSelector:@selector(livePayLoadVedioIsComfirm:)])
  414. {
  415. [self.payDelegate livePayLoadVedioIsComfirm:YES];
  416. }
  417. }
  418. FWWeakify(self)
  419. if (!self.myAlertView2)
  420. {
  421. self.myAlertView2 = [FanweMessage alert:ASLocalizedString(@"温馨提示")message:[NSString stringWithFormat:ASLocalizedString(@"账户余额:%d%@"),[dict toInt:@"diamonds"],self.BuguLive.appModel.diamond_name] destructiveAction:^{
  422. FWStrongify(self)
  423. self.block(@"1");
  424. [self.myAlertView2 removeFromSuperview];
  425. self.myAlertView2 = nil;
  426. } cancelAction:^{
  427. [self.myAlertView2 removeFromSuperview];
  428. self.myAlertView2 = nil;
  429. }];
  430. }
  431. if (self.shadowView)
  432. {
  433. [self.shadowView removeFromSuperview];
  434. self.shadowView = nil;
  435. }
  436. [self sentNotice:1];
  437. }else if ([dict toInt:@"is_diamonds_low"] == 1 && [dict toInt:@"is_recharge"] == 1)//余额为不足
  438. {
  439. // 关闭键盘
  440. [BGUtils closeKeyboard];
  441. [self creatShadowView];//没钱就要加上阴影
  442. if (self.timeCount < 1)
  443. {
  444. [self closeYY];
  445. self.shadowView.hidden = NO;
  446. }
  447. FWWeakify(self)
  448. if (!self.myAlertView3)
  449. {
  450. self.myAlertView3 = [FanweMessage alert:ASLocalizedString(@"温馨提示")message:[NSString stringWithFormat:ASLocalizedString(@"账户余额:%d%@"),[dict toInt:@"diamonds"],self.BuguLive.appModel.diamond_name] destructiveAction:^{
  451. FWStrongify(self)
  452. self.block(@"1");
  453. [self.myAlertView3 removeFromSuperview];
  454. self.myAlertView3 = nil;
  455. } cancelAction:^{
  456. FWStrongify(self)
  457. if (self.payDelegate)//加载或者不加载直播间视频的代理
  458. {
  459. if ([self.payDelegate respondsToSelector:@selector(livePayLoadVedioIsComfirm:)])
  460. {
  461. [self.payDelegate livePayLoadVedioIsComfirm:NO];
  462. }
  463. }
  464. [self.myAlertView3 removeFromSuperview];
  465. self.myAlertView3 = nil;
  466. }];
  467. }
  468. [self sentNotice:0];
  469. }else
  470. {
  471. if (self.payDelegate)//加载直播间视频的代理
  472. {
  473. if ([self.payDelegate respondsToSelector:@selector(livePayLoadVedioIsComfirm:)])
  474. {
  475. [self.payDelegate livePayLoadVedioIsComfirm:YES];
  476. }
  477. }
  478. if (self.shadowView)
  479. {
  480. [self.shadowView removeFromSuperview];
  481. self.shadowView = nil;
  482. }
  483. [self sentNotice:1];
  484. }
  485. }
  486. #pragma mark 创建TwoPromptView
  487. - (void)creatTwoPromptView
  488. {
  489. if (!self.myAlertView1)
  490. {
  491. NSString *promptStr;
  492. if (self.liveType == 40)
  493. {
  494. promptStr = [NSString stringWithFormat:ASLocalizedString(@"主播开启了付费直播,%d%@/场,是否进入?"),[self.audienceDict toInt:@"live_fee"],self.BuguLive.appModel.diamond_name];
  495. }else
  496. {
  497. promptStr = [NSString stringWithFormat:ASLocalizedString(@"主播开启了付费直播,%d%@/分钟,是否进入?"),[self.audienceDict toInt:@"live_fee"],self.BuguLive.appModel.diamond_name];
  498. }
  499. self.myAlertView1 = [FanweMessage alert:ASLocalizedString(@"付费直播")message:promptStr destructiveAction:^{
  500. self.is_agree = YES;
  501. [self enterMoneyMode];
  502. [self.myAlertView1 removeFromSuperview];
  503. self.myAlertView1 = nil;
  504. } cancelAction:^{
  505. [self.myAlertView1 removeFromSuperview];
  506. self.myAlertView1 = nil;
  507. if (self.payDelegate)//加载或者不加载直播间视频的代理
  508. {
  509. if ([self.payDelegate respondsToSelector:@selector(livePayLoadVedioIsComfirm:)])
  510. {
  511. [self.payDelegate livePayLoadVedioIsComfirm:NO];
  512. }
  513. }
  514. }];
  515. }
  516. }
  517. #pragma mark 发送通知来关闭云直播间的声音
  518. - (void)sentNotice:(int)type
  519. {
  520. NSMutableDictionary *dict = [[NSMutableDictionary alloc]init];
  521. [dict setObject:[NSString stringWithFormat:@"%d",type] forKey:@"type"];
  522. [[NSNotificationCenter defaultCenter]postNotificationName:@"closeAndOpenVoice" object:dict];
  523. }
  524. #pragma mark 观众直播间有连麦,付费直播后不能看直播就关闭连麦
  525. - (void)closeYY
  526. {
  527. NSString *controlRole;
  528. if (![BGUtils isBlankString:_BuguLive.appModel.spear_normal])
  529. {
  530. controlRole = self.BuguLive.appModel.spear_normal;
  531. }
  532. else
  533. {
  534. controlRole = @"NormalGuest";
  535. }
  536. }
  537. #pragma mark ===========共用==================
  538. - (void)changeLeftViewFrameWithIsHost:(BOOL)isHost andAuctionView:(UIView *)auctionView andBankerView:(UIView *)bankerView
  539. {
  540. if (isHost == YES)//是主播
  541. {
  542. if (bankerView.hidden)
  543. {
  544. if (auctionView.hidden)
  545. {
  546. CGRect rect = self.hostLeftPView.frame;
  547. rect.origin.y = CGRectGetMaxY(self.subLiving.topView.vipBtn.frame)+kStatusBarHeight;
  548. self.hostLeftPView.frame = rect;
  549. self.subLiving.livewWishView.top = rect.origin.y+rect.size.height;
  550. }
  551. else
  552. {
  553. CGRect rect = self.hostLeftPView.frame;
  554. rect.origin.y = CGRectGetMaxY(self.subLiving.topView.vipBtn.frame)+auctionView.height+8+kStatusBarHeight;
  555. self.hostLeftPView.frame = rect;
  556. }
  557. self.hostLeftPView.right = kDefaultMargin;
  558. }
  559. else
  560. {
  561. if (auctionView.hidden)
  562. {
  563. CGRect rect = self.hostLeftPView.frame;
  564. rect.origin.y = CGRectGetMaxY(self.subLiving.topView.vipBtn.frame)+bankerView.height+8+kStatusBarHeight;
  565. // self.subLiving.livewWishView.top = rect.origin.y+rect.size.height;
  566. }
  567. else
  568. {
  569. CGRect rect = self.hostLeftPView.frame;
  570. rect.origin.y = CGRectGetMaxY(self.subLiving.topView.vipBtn.frame)+bankerView.height+auctionView.height+8+8+kStatusBarHeight;
  571. self.hostLeftPView.frame = rect;
  572. }
  573. }
  574. }else//是观众
  575. {
  576. if (bankerView.hidden)
  577. {
  578. if (auctionView.hidden)
  579. {
  580. CGRect rect = self.audienceLeftPView.frame;
  581. rect.origin.y = CGRectGetMaxY(self.subLiving.topView.vipBtn.frame)+kStatusBarHeight;
  582. self.audienceLeftPView.frame = rect;
  583. }
  584. else
  585. {
  586. CGRect rect = self.audienceLeftPView.frame;
  587. rect.origin.y = CGRectGetMaxY(self.subLiving.topView.vipBtn.frame)+auctionView.height+8+kStatusBarHeight;
  588. self.audienceLeftPView.frame = rect;
  589. }
  590. }
  591. else
  592. {
  593. if (auctionView.hidden)
  594. {
  595. CGRect rect = self.audienceLeftPView.frame;
  596. rect.origin.y = CGRectGetMaxY(self.subLiving.topView.otherContainerView.frame)+bankerView.height+8+kStatusBarHeight;
  597. self.audienceLeftPView.frame = rect;
  598. }
  599. else
  600. {
  601. CGRect rect = self.audienceLeftPView.frame;
  602. rect.origin.y = CGRectGetMaxY(self.subLiving.topView.otherContainerView.frame)+bankerView.height+auctionView.height+8+8+kStatusBarHeight;
  603. self.audienceLeftPView.frame = rect;
  604. }
  605. }
  606. }
  607. // self.hostLeftPView.right = kScreenW - kDefaultMargin;
  608. // self.audienceLeftPView.left = kScreenW / 2 - kRealValue(15);
  609. }
  610. @end