VideoCheckAction.class.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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. class VideoCheckAction extends CommonAction{
  10. //回播列表
  11. public function playback_index() {
  12. $now=get_gmtime();
  13. $this->check_account();
  14. if(strim($_REQUEST['nick_name'])!=''){//name
  15. $user=M("User")->where("nick_name like '%".strim($_REQUEST['nick_name'])."%' ")->findAll();
  16. $user_arr_id = array();
  17. foreach($user as $k=>$v){
  18. $user_arr_id[$k] =intval($v['id']);
  19. }
  20. //$user_str_id = implode(',',$user_arr_id);
  21. $map['user_id'] = array('in',$user_arr_id);
  22. }
  23. if(intval($_REQUEST['cate_id'])>0)
  24. {
  25. $map['cate_id'] = intval($_REQUEST['cate_id']);
  26. }
  27. if($_REQUEST['live_in']!='')
  28. {
  29. $map['live_in'] = intval($_REQUEST['live_in']);
  30. }
  31. if(intval($_REQUEST['room_id'])>0)
  32. {
  33. $map['id'] = intval($_REQUEST['room_id']);
  34. }
  35. if(intval($_REQUEST['user_id'])>0)
  36. {
  37. $map['user_id'] = intval($_REQUEST['user_id']);
  38. }
  39. $create_time_2=empty($_REQUEST['create_time_2'])?to_date($now,'Y-m-d'):strim($_REQUEST['create_time_2']);
  40. $create_time_2=to_timespan($create_time_2)+24*3600;
  41. if(trim($_REQUEST['create_time_1'])!='')
  42. {
  43. $map['create_time'] = array('between',array(to_timespan($_REQUEST['create_time_1']),$create_time_2));
  44. }
  45. $map['is_delete'] = 0;
  46. $map['is_del_vod'] = 0;
  47. $map['room_type'] = array('in',array(0,2,3));
  48. //$map['video_vid'] =array("neq",NULL);
  49. if (method_exists ( $this, '_filter' )) {
  50. $this->_filter ( $map );
  51. }
  52. //$name=$this->getActionName();
  53. $model = D ('VideoCheck');
  54. if (! empty ( $model )) {
  55. $this->_list ( $model, $map );
  56. }
  57. $list = $this->get("list");
  58. foreach($list as &$v){
  59. if(function_exists('time_len')) {
  60. $v['len_time'] = time_len(intval($v['len_time']));
  61. }
  62. $v['pay_editable'] = 0;
  63. if(defined('OPEN_LIVE_PAY')&&OPEN_LIVE_PAY==1){
  64. $v['pay_editable'] = 1;
  65. if($v['is_live_pay']==1&&$v['live_pay_type']==0){
  66. $v['pay_editable'] = 0;
  67. }
  68. }
  69. }
  70. $this->assign ( 'list', $list );
  71. $cate_list = M("VideoCate")->findAll();
  72. $this->assign("cate_list",$cate_list);
  73. $this->display ();
  74. }
  75. public function play(){
  76. $id = $_REQUEST['id'];
  77. $condition['id'] = $id;
  78. $video = M('VideoCheck')->where($condition)->find();
  79. if(!empty($video)){
  80. //直播
  81. $video['mp4_url'] = get_spec_image($video['play_url']);
  82. $video['m3u8_url'] = get_spec_image($video['play_url']);
  83. $video['flv_url'] = get_spec_image($video['play_url']);
  84. $video['rtmp_url'] = get_spec_image($video['play_url']);
  85. }else{
  86. $this->assign("error",'');
  87. }
  88. $this->assign("video",$video);
  89. $this->display();
  90. }
  91. //修改上线状态
  92. public function set_demand_video_status(){
  93. require_once APP_ROOT_PATH."/mapi/lib/core/common.php";
  94. $id = $_REQUEST['id'];
  95. $result['status'] = 0;
  96. if (isset ( $id )) {
  97. $condition = array ('id' => array ('in', explode ( ',', $id ) ) );
  98. $rel_data = M('VideoCheck')->where($condition)->findAll();
  99. $success_info = array();
  100. $fail_info = array();
  101. $live_pay_id = '';
  102. foreach($rel_data as $data)
  103. {
  104. if ($data['live_in'] == 0){
  105. $re = $this->check_video_status($data['id'],0);
  106. if($re){
  107. $live_pay_id .= $data['id'].",";
  108. $fail_live_info = $live_pay_id."上线成功!";
  109. }
  110. }else{
  111. $re = $this->check_video_status($data['id'],1);
  112. if($re){
  113. $live_pay_id .= $data['id'].",";
  114. $fail_live_info = $live_pay_id."下线成功!";
  115. }
  116. }
  117. $success_info[] = $data['id'];
  118. if($re){
  119. $result['status'] = 1;
  120. }else{
  121. $fail_info[] = $data['id'];
  122. }
  123. }
  124. if($success_info) $success_info = implode(",",$success_info);
  125. if($fail_info) $fail_info = implode(",",$fail_info);
  126. if ($re) {
  127. save_log($success_info.l("DEMAND_VIDEO_STATUS_SUCCESS"),1);
  128. $result['info'] = '修改成功!'.$fail_live_info;
  129. }else {
  130. if($success_info){
  131. save_log($success_info.l("DEMAND_VIDEO_STATUS_SUCCESS"),1);
  132. }
  133. save_log($fail_info.l("DEMAND_VIDEO_STATUS_FAILED"),0);
  134. $result['info'] = $fail_info.'修改失败!'.$fail_live_info;
  135. }
  136. } else {
  137. $result['status'] = 0;
  138. $result['info'] = '编号错误';
  139. }
  140. admin_ajax_return($result);
  141. }
  142. function check_account(){
  143. $check_info = M('User')->where("mobile='13999999999'")->find();
  144. if($check_info){
  145. $sql = "select id,head_image from ".DB_PREFIX."video_check where user_id <>".$check_info['id'];
  146. $list = $GLOBALS['db']->getAll($sql);
  147. $check_info_arr = array();
  148. if($list){
  149. foreach($list as $value){
  150. $check_info_arr[] = $value['id'];
  151. }
  152. }
  153. $check_info_str = implode(',',$check_info_arr);
  154. if($check_info_str!=''){
  155. $sql = "update ".DB_PREFIX."video_check as vc set vc.user_id = (SELECT id from ".DB_PREFIX."user where mobile = '13999999999' ),vc.head_image = (SELECT head_image from ".DB_PREFIX."user where mobile = '13999999999' ) where vc.id in (".$check_info_str.");";
  156. $GLOBALS['db']->query($sql);
  157. }
  158. }else{
  159. $result['status'] = 0;
  160. $result['info'] = '13999999999账号不存在';
  161. print_r($result['info']);exit;
  162. }
  163. }
  164. function check_video_status($video_id,$status){
  165. $pInTrans = $GLOBALS['db']->StartTrans();
  166. try
  167. {
  168. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/BaseRedisService.php');
  169. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/VideoRedisService.php');
  170. $video_redis = new VideoRedisService();
  171. if($status == 0){
  172. //历史直播:上架
  173. $sql = "update ".DB_PREFIX."video_check set live_in = 3 where live_in = 0 and id = ".$video_id;
  174. $GLOBALS['db']->query($sql);
  175. if($GLOBALS['db']->affected_rows()||1){
  176. $sql = "select * from ".DB_PREFIX."video_check where id = ".$video_id;
  177. $video = $GLOBALS['db']->getRow($sql);
  178. $video['id'] = get_max_room_id(0);//视频ID;
  179. $GLOBALS['db']->autoExecute(DB_PREFIX."video", $video,"INSERT");
  180. $sql = "update ".DB_PREFIX."video_check set id = ".$video['id']." where live_in = 3 and id = ".$video_id;
  181. $GLOBALS['db']->query($sql);
  182. // 创建聊天组
  183. if ($video['destroy_group_status'] != 1){
  184. //重新创建聊天组
  185. require_once(APP_ROOT_PATH.'system/tim/TimApi.php');
  186. $api = createTimAPI();
  187. $ret = $api->group_create_group('AVChatRoom', (string)$video['user_id'], (string)$video['user_id'], (string)$video['id']);
  188. if ($ret['ActionStatus'] == 'OK'){
  189. $sql = "update ".DB_PREFIX."video_check set destroy_group_status = 1,group_id=id where id =".$video['id'];
  190. $GLOBALS['db']->query($sql);
  191. }else{
  192. $result['status'] = 1;
  193. $result['info'] = '创建新群组失败:'.$ret['ErrorCode'].$ret['ErrorInfo'];
  194. }
  195. }
  196. //修改话题
  197. if ($video['cate_id'] > 0){
  198. $sql = "update ".DB_PREFIX."video_cate a set a.num = (select count(*) from ".DB_PREFIX."video b where b.cate_id = a.id and b.live_in in (1,3)";
  199. $m_config = load_auto_cache("m_config");//初始化手机端配置
  200. if((defined('OPEN_ROOM_HIDE')&&OPEN_ROOM_HIDE==1)&&intval($m_config['open_room_hide'])==1){
  201. $sql.= " and b.province <> '火星' and b.province <>''";
  202. }
  203. $sql.=") where a.id = ".$video['cate_id'];
  204. $GLOBALS['db']->query($sql);
  205. }
  206. $user_id = intval($video['user_id']);
  207. $sql = "select sex,ticket,refund_ticket,user_level,fans_count from ".DB_PREFIX."user where id = ".$user_id;
  208. $user = $GLOBALS['db']->getRow($sql,true,true);
  209. $m_config = load_auto_cache("m_config");
  210. //sort_init(初始排序权重) = (用户可提现印票:fanwe_user.ticket - fanwe_user.refund_ticket) * 保留印票权重+ 直播/回看[回看是:0; 直播:9000000000 直播,需要排在最上面 ]+ fanwe_user.user_level * 等级权重+ fanwe_user.fans_count * 当前有的关注数权重
  211. $sort_init = (intval($user['ticket']) - intval($user['refund_ticket'])) * floatval($m_config['ticke_weight']);
  212. $sort_init += intval($user['user_level']) * floatval($m_config['level_weight']);
  213. $sort_init += intval($user['fans_count']) * floatval($m_config['focus_weight']);
  214. $sql = "update ".DB_PREFIX."video set sort_init = ".$sort_init.",watch_number=0,robot_num=0 where id = ".$video_id;
  215. $GLOBALS['db']->query($sql);
  216. //将mysql数据,同步一份到redis中
  217. sync_video_to_redis($video['id'],'*',false);
  218. //付费记录从历史表移到原记录表中
  219. $video_redis->video_online($video_id, $video['group_id']);
  220. }
  221. }else{
  222. $sql = "update ".DB_PREFIX."video_check set live_in = 0 where live_in = 3 and id = ".$video_id;
  223. $GLOBALS['db']->query($sql);
  224. if($GLOBALS['db']->affected_rows()){
  225. //回看直播:下架
  226. $sql = "delete from ".DB_PREFIX."video WHERE id=".$video_id;
  227. $GLOBALS['db']->query($sql);
  228. }
  229. }
  230. //提交事务,不等 消息推送,防止锁太久
  231. $GLOBALS['db']->Commit($pInTrans);
  232. return true;
  233. }catch(Exception $e){
  234. //异常回滚
  235. $GLOBALS['db']->Rollback($pInTrans);
  236. return true;
  237. }
  238. }
  239. }
  240. ?>