VideoCommonAction.class.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Fanwe 方维直播系统
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2011 http://www.fanwe.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Author: 云淡风轻(1956838968@qq.com)
  8. // +----------------------------------------------------------------------
  9. //相同操作
  10. class VideoCommon extends CommonAction{
  11. //关闭房间
  12. function close_live($data,$get_result = false){
  13. $m_config = load_auto_cache("m_config");
  14. $system_user_id =$m_config['tim_identifier'];//系统消息
  15. $podcast_id = trim($data ['user_id']);
  16. $podcast = $GLOBALS['db']->getRow("select u.id as user_id,u.nick_name,u.head_image from ".DB_PREFIX."user as u where u.id=".$podcast_id);
  17. $room_id = trim($data ['room_id']);
  18. $ext = array();
  19. $ext['type'] = 17;
  20. $ext['desc'] = '违规直播,立即关闭直播';
  21. $ext['room_id'] = $room_id;
  22. #构造高级接口所需参数
  23. $msg_content = array();
  24. //创建array 所需元素
  25. $msg_content_elem = array(
  26. 'MsgType' => 'TIMCustomElem', //自定义类型
  27. 'MsgContent' => array(
  28. 'Data' => json_encode($ext),
  29. 'Desc' => '',
  30. // 'Ext' => $ext,
  31. // 'Sound' => '',
  32. )
  33. );
  34. //将创建的元素$msg_content_elem, 加入array $msg_content
  35. array_push($msg_content, $msg_content_elem);
  36. require_once(APP_ROOT_PATH.'system/tim/TimApi.php');
  37. $api = createTimAPI();
  38. $ret = $api->openim_send_msg2($system_user_id, $podcast_id, $msg_content);
  39. //结束直播
  40. $sql = "select id,user_id,max_watch_number,virtual_watch_number,robot_num,vote_number,group_id,room_type,begin_time,end_time,channelid,cate_id,video_vid,video_type from ".DB_PREFIX."video where id = ".$room_id." and user_id = ".$podcast_id;
  41. $video = $GLOBALS['db']->getRow($sql,true,true);
  42. //同时关闭子房间
  43. if(defined('CHILD_ROOM') && CHILD_ROOM == 1){
  44. $child_id = $GLOBALS['db']->getAll("SELECT child_id FROM " . DB_PREFIX . "child_room WHERE parent_id =".$room_id);
  45. }
  46. if($video&&$ret['ActionStatus'] == 'OK'){
  47. $result = admin_do_end_video($video,$video['video_vid'],0,$video['cate_id']);
  48. if($child_id){
  49. foreach($child_id as $item){
  50. $child_ids[] = $item['child_id'];
  51. }
  52. $child_ids = implode(',',$child_ids);
  53. $child_video = $GLOBALS['db']->getAll("SELECT id,user_id,max_watch_number,virtual_watch_number,robot_num,vote_number,group_id,room_type,begin_time,end_time,channelid,cate_id,video_vid,video_type FROM " . DB_PREFIX . "video WHERE id in (".$child_ids.")");
  54. if(!empty($child_video)){
  55. foreach($child_video as $value){
  56. $child_res = admin_do_end_video($value,$value['video_vid'],0,$value['cate_id']);
  57. }
  58. }
  59. }
  60. $room_id = $video['id'];
  61. if ($video['group_id'] != ''&&$result){
  62. //=========================================================
  63. //广播:直播结束
  64. $ext = array();
  65. $ext['type'] = 18; //18:直播结束(全体推送的,用于更新用户列表状态)
  66. $ext['room_id'] = $room_id;//直播ID 也是room_id;只有与当前房间相同时,收到消息才响应
  67. //发送广播:直播结束
  68. fanwe_require(APP_ROOT_PATH.'system/tim/TimApi.php');
  69. $api = createTimAPI();
  70. //18:直播结束(全体推送的,用于更新用户列表状态)
  71. $api->group_send_group_system_notification($m_config['on_line_group_id'],json_encode($ext),null);
  72. //=========================================================
  73. }
  74. if($get_result){
  75. return true;
  76. }
  77. $this->success ('操作成功',1);
  78. }
  79. if ($ret['ActionStatus'] == 'OK'){
  80. $result=M("Video")->where("id=".$room_id)->setField("live_in",0);
  81. if($child_id){
  82. foreach($child_id as $item){
  83. $child_ids[] = $item['child_id'];
  84. }
  85. $child_ids = implode(',',$child_ids);
  86. $result=M("Video")->where("id in (".$child_ids.")")->setField("live_in",0);
  87. }
  88. if ($video['video_type'] > 0){
  89. //0:腾讯云互动直播;1:腾讯云直播
  90. fanwe_require(APP_ROOT_PATH.'mapi/lib/core/video_factory.php');
  91. $video_factory = new VideoFactory();
  92. $video_factory->StopLVBChannel($video['channelid']);
  93. }
  94. save_log('管理员结束'.$podcast['nick_name'].'直播',1);
  95. if($get_result){
  96. return true;
  97. }
  98. $this->success ('操作成功',1);
  99. }else {
  100. if($result){
  101. save_log('管理员结束'.$podcast['nick_name'].'直播',1);
  102. if($get_result){
  103. return true;
  104. }
  105. $this->success ('操作成功',1);
  106. }else{
  107. save_log('管理员结束'.$podcast['nick_name'].'直播',0);
  108. if($get_result){
  109. return false;
  110. }
  111. $this->error ('操作失败',1);
  112. }
  113. }
  114. }
  115. }