VideoPlaybackAction.class.php.bak 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784
  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 VideoPlaybackAction extends CommonAction{
  10. //回播列表
  11. public function playback_index() {
  12. $now=get_gmtime();
  13. if(strim($_REQUEST['nick_name'])!=''){//name
  14. $user=M("User")->where("nick_name like '%".strim($_REQUEST['nick_name'])."%' ")->findAll();
  15. $user_arr_id = array();
  16. foreach($user as $k=>$v){
  17. $user_arr_id[$k] =intval($v['id']);
  18. }
  19. //$user_str_id = implode(',',$user_arr_id);
  20. $map['user_id'] = array('in',$user_arr_id);
  21. }
  22. if(intval($_REQUEST['cate_id'])>0)
  23. {
  24. $map['cate_id'] = intval($_REQUEST['cate_id']);
  25. }
  26. if($_REQUEST['live_in']!='')
  27. {
  28. $map['live_in'] = intval($_REQUEST['live_in']);
  29. }
  30. if(intval($_REQUEST['room_id'])>0)
  31. {
  32. $map['id'] = intval($_REQUEST['room_id']);
  33. }
  34. if(intval($_REQUEST['user_id'])>0)
  35. {
  36. $map['user_id'] = intval($_REQUEST['user_id']);
  37. }
  38. $create_time_2=empty($_REQUEST['create_time_2'])?to_date($now,'Y-m-d'):strim($_REQUEST['create_time_2']);
  39. $create_time_2=to_timespan($create_time_2)+24*3600;
  40. if(trim($_REQUEST['create_time_1'])!='')
  41. {
  42. $map['create_time'] = array('between',array(to_timespan($_REQUEST['create_time_1']),$create_time_2));
  43. }
  44. $map['is_delete'] = 0;
  45. $map['is_del_vod'] = 0;
  46. $map['room_type'] = array('in',array(0,2,3));
  47. //$map['video_vid'] =array("neq",NULL);
  48. if (method_exists ( $this, '_filter' )) {
  49. $this->_filter ( $map );
  50. }
  51. //$name=$this->getActionName();
  52. $model = D ('VideoHistory');
  53. if (! empty ( $model )) {
  54. $this->_list ( $model, $map );
  55. }
  56. $list = $this->get("list");
  57. foreach($list as &$v){
  58. if(function_exists('time_len')) {
  59. $v['len_time'] = time_len(intval($v['len_time']));
  60. }
  61. $v['pay_editable'] = 0;
  62. if(defined('OPEN_LIVE_PAY')&&OPEN_LIVE_PAY==1){
  63. $v['pay_editable'] = 1;
  64. if($v['is_live_pay']==1&&$v['live_pay_type']==0){
  65. $v['pay_editable'] = 0;
  66. }
  67. }
  68. }
  69. $this->assign ( 'list', $list );
  70. if(defined('OPEN_LIVE_PAY')&&OPEN_LIVE_PAY==1&&intval(LIVE_PAY_SCENE)){
  71. $this->assign ( 'is_pay_live', 1 );
  72. }else{
  73. $this->assign ( 'is_pay_live', 0 );
  74. }
  75. $cate_list = M("VideoCate")->findAll();
  76. $this->assign("cate_list",$cate_list);
  77. //服务端开启类型
  78. $sql = "select val from ".DB_PREFIX."m_config where code= 'video_type'";
  79. $video_type = $GLOBALS['db']->getOne($sql);
  80. $this->assign("video_type",intval($video_type));
  81. $this->display ();
  82. }
  83. public function set_live_pay()
  84. {
  85. fanwe_require( APP_ROOT_PATH.'mapi/lib/redis/BaseRedisService.php');
  86. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/VideoRedisService.php');
  87. $video_id = intval($_REQUEST['id']);
  88. $video_redis = new VideoRedisService($video_id);
  89. $video = $video_redis->getRow_db($video_id,array('id','is_live_pay','live_fee'));
  90. $this->assign("video",$video);
  91. $this->display();
  92. }
  93. public function modify_live_pay(){
  94. $video_id = intval($_REQUEST['id']);
  95. $video['id'] = $video_id;
  96. $video['live_pay_type'] = 0;
  97. $video['live_fee'] = 0;
  98. $video['is_live_pay'] = intval($_REQUEST['is_live_pay']);//是否付费
  99. $live_fee = intval($_REQUEST['live_fee']);//观看费用
  100. if($video['is_live_pay']){
  101. $video['live_pay_type'] = 1;
  102. $video['live_fee'] = $live_fee;
  103. }
  104. if($video['live_fee'] && !preg_match('/^[0-9]*[1-9][0-9]*$/', $video['live_fee']))
  105. {
  106. $this->error("观看费用必须为大于0的整数");
  107. }
  108. $list=M("VideoHistory")->save ($video);
  109. if (false !== $list) {
  110. //redis同步
  111. require_once APP_ROOT_PATH."/mapi/lib/core/common.php";
  112. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/BaseRedisService.php');
  113. sync_video_to_redis($video_id, '*', false);
  114. save_log($video_id.L("UPDATE_SUCCESS"),1);
  115. $this->success(L("UPDATE_SUCCESS"));
  116. } else {
  117. //错误提示
  118. save_log($video_id.L("UPDATE_FAILED"),0);
  119. $this->error(L("UPDATE_SUCCESS"));
  120. }
  121. }
  122. /*public function play_bak(){
  123. require_once APP_ROOT_PATH."/mapi/lib/core/common.php";
  124. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/BaseRedisService.php');
  125. $m_config = load_auto_cache("m_config");//初始化手机端配置
  126. $app_id = $m_config['vodset_app_id'];
  127. $this->assign('app_id',$app_id);
  128. $id = $_REQUEST['id'];
  129. $condition['id'] = $id;
  130. $video = M('VideoHistory')->where($condition)->find();
  131. if(!empty($video)){
  132. $root = get_vodset_by_video_id($id);
  133. if(isset($root['vodset'])){
  134. $play_list = array();
  135. $vodset = $root['vodset'];
  136. foreach($vodset as $k=>$v){
  137. $playSet = $v['fileSet'];
  138. for($i=sizeof($playSet)-1;$i>=0;$i--){
  139. if($playSet[$i]['duration']>1){
  140. $play_list[] = $playSet[$i]['fileId'];
  141. }
  142. }
  143. }
  144. $this->assign("playlist",implode(',',$play_list));
  145. $this->assign("video_url",$play_list[0]);
  146. $this->assign("poster",$vodset[0]['fileSet'][sizeof($vodset[0]['fileSet'])-1]['image_url']);
  147. }else{
  148. $this->assign("error",$root['error']);
  149. }
  150. }
  151. $this->assign("video",$video);
  152. $this->display();
  153. }*/
  154. public function play(){
  155. require_once APP_ROOT_PATH."/mapi/lib/core/common.php";
  156. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/BaseRedisService.php');
  157. $m_config = load_auto_cache("m_config");//初始化手机端配置
  158. $app_id = $m_config['vodset_app_id'];
  159. $this->assign('app_id',$app_id);
  160. $id = $_REQUEST['id'];
  161. $condition['id'] = $id;
  162. $video = M('VideoHistory')->where($condition)->find();
  163. if(!empty($video)&&$video['play_url']==''){
  164. $root = get_vodset_by_video_id($id);
  165. if(isset($root['vodset'])){
  166. $play_list = array();
  167. $vodset = $root['vodset'];
  168. foreach($vodset as $k=>$v){
  169. $playSet = $v['fileSet'];
  170. for($i=sizeof($playSet)-1;$i>=0;$i--){
  171. $play_list[] = $playSet[$i]['fileId'];
  172. $play_url_list[] = $playSet[$i]['playSet'];
  173. }
  174. }
  175. foreach($play_url_list as $k2=>$v2){
  176. foreach($v2 as $kk=>$vv) {
  177. //mp4
  178. if ($vv['definition'] == 0&&strpos($vv['url'], '.mp4')) {//原画mp4 播放URL
  179. $video['mp4_url'] = $vv['url'];
  180. }
  181. if ($vv['definition'] == 10) {//手机mp4 播放URL
  182. $video['mp4_sj_url'] = $vv['url'];
  183. }
  184. if ($vv['definition'] == 20) {//标清mp4 播放URL
  185. $video['mp4_sd_url'] = $vv['url'];
  186. }
  187. if ($vv['definition'] == 40 || $vv['definition'] == 30) {//高清mp4 播放URL
  188. $video['mp4_hd_url'] = $vv['url'];
  189. }
  190. //m3u8
  191. if ($vv['definition'] == 0 &&strpos($vv['url'], '.m3u8')) {//原画m3u8 播放URL
  192. $video['m3u8_url'] = $vv['url'];
  193. }
  194. if (($vv['definition'] == 210)&&strpos($vv['url'], '.m3u8')) {//手机m3u8 播放URL
  195. $video['m3u8_url'] = $vv['url'];
  196. }
  197. if (($vv['definition'] == 220)&&strpos($vv['url'], '.m3u8')) {//标清m3u8 播放URL
  198. $video['m3u8_sd_url'] = $vv['url'];
  199. }
  200. if (($vv['definition'] == 230)&&strpos($vv['url'], '.m3u8')) {//高清m3u8 播放URL
  201. $video['m3u8_hd_url'] = $vv['url'];
  202. }
  203. //flv
  204. if (strpos($vv['url'], '.flv')&&$vv['definition'] == 0) {//原画flv 播放URL
  205. $video['flv_url'] = $vv['url'];
  206. }
  207. if (strpos($vv['url'], '.flv')&&$vv['definition'] == 0) {//手机flv 播放URL
  208. $video['flv_sj_url'] = $vv['url'];
  209. }
  210. if (strpos($vv['url'], '.flv')&&$vv['definition'] == 0) {//标清flv 播放URL
  211. $video['flv_sd_url'] = $vv['url'];
  212. }
  213. if (strpos($vv['url'], '.flv')&&$vv['definition'] == 0) {//高清flv 播放URL
  214. $video['flv_hd_url'] = $vv['url'];
  215. }
  216. //rtmp
  217. if (!strpos($vv['url'], '.flv')&&!strpos($vv['url'], '.mp4')&&!strpos($vv['url'], '.m3u8')&&$vv['definition'] == 0) {//原画rtmp 播放URL
  218. $video['rtmp_url'] = $vv['url'];
  219. }
  220. if (!strpos($vv['url'], '.flv')&&!strpos($vv['url'], '.mp4')&&!strpos($vv['url'], '.m3u8')&&$vv['definition'] == 0) {//手机rtmp 播放URL
  221. $video['rtmp_sj_url'] = $vv['url'];
  222. }
  223. if (!strpos($vv['url'], '.flv')&&!strpos($vv['url'], '.mp4')&&!strpos($vv['url'], '.m3u8')&&$vv['definition'] == 0) {//标清rtmp 播放URL
  224. $video['rtmp_sd_url'] = $vv['url'];
  225. }
  226. if (!strpos($vv['url'], '.flv')&&!strpos($vv['url'], '.mp4')&&!strpos($vv['url'], '.m3u8')&&$vv['definition'] == 0) {//高清rtmp 播放URL
  227. $video['rtmp_hd_url'] = $vv['url'];
  228. }
  229. }
  230. }
  231. $this->assign("poster",$vodset[0]['fileSet'][sizeof($vodset[0]['fileSet'])-1]['image_url']);
  232. }else{
  233. $this->assign("error",$root['error']);
  234. }
  235. }else{
  236. //直播
  237. $video['mp4_url'] = $video['play_mp4'];
  238. if($video['play_url']) $video['mp4_url'] = $video['play_url'];
  239. $video['m3u8_url'] = $video['play_hls'];
  240. $video['flv_url'] = $video['play_flv'];
  241. $video['rtmp_url'] = $video['play_rtmp'];
  242. }
  243. $this->assign("video",$video);
  244. $this->display();
  245. }
  246. //删除视频
  247. public function del_video(){
  248. require_once APP_ROOT_PATH."/mapi/lib/core/common.php";
  249. $ajax = intval($_REQUEST['ajax']);
  250. $id = $_REQUEST['id'];
  251. $result['status'] = 0;
  252. if (isset ( $id )) {
  253. $condition = array ('id' => array ('in', explode ( ',', $id ) ) );
  254. $rel_data = M('VideoHistory')->where($condition)->findAll();
  255. $success_info = array();
  256. $fail_info = array();
  257. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/BaseRedisService.php');
  258. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/VideoRedisService.php');
  259. $video_redis = new VideoRedisService();
  260. foreach($rel_data as $video)
  261. {
  262. if($video['live_in']==0){
  263. $root = del_vodset($video,true);
  264. $sql = "update ".DB_PREFIX."video_history set is_delete = 1 where id =".$video['id'];
  265. $GLOBALS['db']->query($sql);
  266. if($GLOBALS['db']->affected_rows()){
  267. $success_info[] = $video['id'];
  268. $user_id = intval($video['user_id']);
  269. $sql = "select count(*) as num from ".DB_PREFIX."video_history where is_delete = 0 and is_del_vod = 0 and user_id = '".$user_id."'";
  270. $video_count = $GLOBALS['db']->getOne($sql);
  271. $sql = "update ".DB_PREFIX."user set video_count = ".$video_count." where id = ".$user_id;
  272. $GLOBALS['db']->query($sql);
  273. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/UserRedisService.php');
  274. $user_redis = new UserRedisService();
  275. $user_data = array();
  276. $user_data['video_count'] = $video_count;
  277. $user_redis->update_db($user_id, $user_data);
  278. $result['status'] = 1;
  279. }else{
  280. $fail_info[] = $video['id'];
  281. }
  282. }else{
  283. $fail_info[] = $video['id'].':不是历史状态,不能删除';
  284. }
  285. }
  286. if($success_info) $success_info = implode(",",$success_info);
  287. if($fail_info) $fail_info = implode(",",$fail_info);
  288. if (!$fail_info) {
  289. save_log($success_info.l("FOREVER_DELETE_SUCCESS"),1);
  290. clear_auto_cache("get_help_cache");
  291. $result['info'] = '删除成功!';
  292. //$this->success (l("FOREVER_DELETE_SUCCESS"),$ajax);
  293. } else {
  294. if($success_info){
  295. save_log($success_info.l("FOREVER_DELETE_SUCCESS"),1);
  296. }
  297. save_log($fail_info.l("FOREVER_DELETE_FAILED"),0);
  298. $result['info'] = $fail_info.' 删除失败!';
  299. //$this->error (l($fail_info),$ajax);
  300. }
  301. } else {
  302. $result['status'] = 0;
  303. $result['info'] = '编号错误';
  304. //$this->error (l("INVALID_OPERATION"),$ajax);
  305. }
  306. admin_ajax_return($result);
  307. }
  308. //修改上线状态
  309. public function set_demand_video_status(){
  310. require_once APP_ROOT_PATH."/mapi/lib/core/common.php";
  311. $ajax = intval($_REQUEST['ajax']);
  312. $id = $_REQUEST['id'];
  313. $result['status'] = 0;
  314. if (isset ( $id )) {
  315. $condition = array ('id' => array ('in', explode ( ',', $id ) ) );
  316. $rel_data = M('VideoHistory')->where($condition)->findAll();
  317. $success_info = array();
  318. $fail_info = array();
  319. $live_pay_id = '';
  320. foreach($rel_data as $data)
  321. {
  322. if ($data['live_in'] == 0&&(($data['is_live_pay']==1&&$data['live_pay_type'] != 0)||$data['is_live_pay']==0)){
  323. //上架
  324. fanwe_require(APP_ROOT_PATH . 'mapi/lib/core/video_factory.php');
  325. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/BaseRedisService.php');
  326. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/VideoRedisService.php');
  327. $video_factory = new VideoFactory();
  328. /*if($data['video_type'] == 1 && $data['channelid']&& strpos($data['channelid'],'_'))
  329. {
  330. $ret = $video_factory->GetVodRecordFiles($data['channelid'], $data['create_time']);
  331. } else {
  332. $fileName = $data['id'] . '_' . to_date($data['begin_time'],'Y-m-d-H');
  333. if($data['video_type'] == 1){
  334. $fileName = 'live'.$data['id'] . '_' . to_date($data['begin_time'],'Y-m-d-H');
  335. }
  336. $ret = $video_factory->DescribeVodPlayInfo($fileName);
  337. }*/
  338. $ret = get_vodset_by_video_id($data['id']);
  339. if(defined('CHILD_ROOM') && CHILD_ROOM == 1) {
  340. fanwe_require(APP_ROOT_PATH.'mapi/lib/ChildRoom.class.php');
  341. $child = new child_room();
  342. }
  343. /*if ($ret['totalCount'] > 0){*/
  344. if ($ret['total_count'] > 0||$data['play_url']!=''){
  345. require_once(APP_ROOT_PATH.'system/tim/TimApi.php');
  346. $api = createTimAPI();
  347. $ret = $api->group_get_group_info2(array('0'=>$data['user_id']));
  348. if ($ret['GroupInfo'][0]['ErrorCode']){
  349. //重新创建聊天组
  350. $ret = $api->group_create_group('AVChatRoom', (string)$data['user_id'], (string)$data['user_id'], (string)$data['id']);
  351. if ($ret['ActionStatus'] == 'OK'){
  352. $sql = "update ".DB_PREFIX."video_history set destroy_group_status = 1,group_id=id where id =".$data['id'];
  353. $GLOBALS['db']->query($sql);
  354. }
  355. }
  356. $re = video_status($data['id'],0);
  357. } elseif ($ret['status'] == 0 && $child->is_child_room($data['id'])) {
  358. require_once(APP_ROOT_PATH.'system/tim/TimApi.php');
  359. $api = createTimAPI();
  360. $ret = $api->group_get_group_info2(array('0'=>$data['user_id']));
  361. if ($ret['GroupInfo'][0]['ErrorCode']) {
  362. //重新创建聊天组
  363. $ret = $api->group_create_group('AVChatRoom', (string)$data['user_id'], (string)$data['user_id'], (string)$data['id']);
  364. if ($ret['ActionStatus'] == 'OK'){
  365. $sql = "update ".DB_PREFIX."video_history set destroy_group_status = 1,group_id=id where id =".$data['id'];
  366. $GLOBALS['db']->query($sql);
  367. }
  368. }
  369. $re = video_status($data['id'],0);
  370. } else{
  371. $sql = "update ".DB_PREFIX."video_history set is_del_vod = 1 where id = ".$data['id'];
  372. $GLOBALS['db']->query($sql);
  373. $video_redis = new VideoRedisService();
  374. $n_data = array();
  375. $n_data['is_del_vod'] = 1;
  376. $video_redis->update_db($data['id'], $n_data);
  377. $result['status'] = 1;
  378. $result['info'] = '视频不存在';
  379. admin_ajax_return($result);
  380. }
  381. }else{
  382. $live_pay_id .= $data['id'].",";
  383. if($data['is_live_pay']==1&&$data['live_pay_type'] != 0){
  384. $fail_live_info = $live_pay_id."按时付费直播无法上线";
  385. }else{
  386. $fail_live_info = $live_pay_id."付费直播上线失败";
  387. }
  388. }
  389. $success_info[] = $data['id'];
  390. if($re){
  391. $result['status'] = 1;
  392. }else{
  393. $fail_info[] = $data['id'];
  394. }
  395. /*}else{
  396. $fail_info[] = $data['id'];
  397. }*/
  398. }
  399. if($success_info) $success_info = implode(",",$success_info);
  400. if($fail_info) $fail_info = implode(",",$fail_info);
  401. if ($re) {
  402. save_log($success_info.l("DEMAND_VIDEO_STATUS_SUCCESS"),1);
  403. $result['info'] = '修改成功!'.$fail_live_info;
  404. }else {
  405. if($success_info){
  406. save_log($success_info.l("DEMAND_VIDEO_STATUS_SUCCESS"),1);
  407. }
  408. save_log($fail_info.l("DEMAND_VIDEO_STATUS_FAILED"),0);
  409. $result['info'] = $fail_info.'修改失败!'.$fail_live_info;
  410. }
  411. } else {
  412. $result['status'] = 0;
  413. $result['info'] = '编号错误';
  414. }
  415. admin_ajax_return($result);
  416. }
  417. public function add_tecent_video(){
  418. if(!TECENT_VIDEO){
  419. admin_ajax_return(array(
  420. 'status' => 0,
  421. 'error' => "模块开关未打开"
  422. ));
  423. }
  424. $m_config = load_auto_cache("m_config");
  425. $this->assign('secret_id', $m_config['qcloud_secret_id']);
  426. $this->display();
  427. }
  428. /**
  429. * 上传视频签名接口
  430. *
  431. * @return 签名
  432. */
  433. public function sign()
  434. {
  435. $args = $_REQUEST['args'];
  436. fanwe_require(APP_ROOT_PATH . 'mapi/lib/core/video_factory.php');
  437. $video_factory = new VideoFactory();
  438. $result = $video_factory->Sign($args);
  439. $root = array('status' => 1, 'result' => $result);
  440. ajax_file_return($root);
  441. }
  442. /**
  443. * 新上传视频SDK签名接口
  444. *
  445. * @return 签名
  446. */
  447. public function new_sign(){
  448. fanwe_require(APP_ROOT_PATH . 'mapi/lib/core/video_factory.php');
  449. $video_factory = new VideoFactory();
  450. $result = $video_factory->NewSign();
  451. $root = array('status' => 1, 'signature' => $result);
  452. ajax_file_return($root);
  453. }
  454. public function insert_tecent_video(){
  455. if(!TECENT_VIDEO){
  456. admin_ajax_return(array(
  457. 'status' => 0,
  458. 'error' => "模块开关未打开"
  459. ));
  460. }
  461. $result = array('status'=>1,'error'=>'添加回播视频成功,视频转码需要几分钟,请耐心等待');
  462. $create_type = intval($_REQUEST['create_type']);
  463. $user_id = intval($_REQUEST['user_id']);
  464. $title = trim($_REQUEST['title']);
  465. $video_vid = trim($_REQUEST['file_id']);
  466. $live_image = trim($_REQUEST['live_image']);
  467. if($user_id == 0)
  468. {
  469. admin_ajax_return(array('status'=>'0','error'=>'请输入用户id'));
  470. }
  471. if(!check_empty($title))
  472. {
  473. admin_ajax_return(array('status'=>'0','error'=>'请输入话题'));
  474. }
  475. if(!check_empty($video_vid))
  476. {
  477. admin_ajax_return(array('status'=>'0','error'=>'请添加文件'));
  478. }
  479. $is_private = false;
  480. $monitor_time = to_date(NOW_TIME+3600,'Y-m-d H:i:s');
  481. $data = $this->create_video($user_id,$title,$is_private,$monitor_time);//视频信息写入user表
  482. fanwe_require(APP_ROOT_PATH . 'mapi/lib/core/video_factory.php');
  483. $video_factory = new VideoFactory();
  484. $ret = $video_factory->ModifyVodInfo($video_vid, $data);
  485. if(! $ret['status'])
  486. {
  487. admin_ajax_return($ret);
  488. }
  489. // 新上传的视频未生成地址
  490. $data['is_del_vod'] = 1;
  491. $data['video_vid'] = $video_vid;
  492. $data['live_in'] = 2;//定时器通过2判断是否是上传到腾讯云
  493. $data['live_image'] = $live_image;
  494. $data['create_type'] = $create_type;
  495. $list = $GLOBALS['db']->autoExecute(DB_PREFIX . "video_history", $data, 'INSERT');
  496. if ($list !== false){
  497. save_log("回播视频上传成功",1);
  498. }else{
  499. save_log("回播视频上传失败",0);
  500. }
  501. //同步到redis
  502. require_once APP_ROOT_PATH."/mapi/lib/core/common.php";
  503. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/BaseRedisService.php');
  504. sync_video_to_redis($data['id'],'*',false);
  505. admin_ajax_return($result);
  506. }
  507. public function create_video($user_id, $title, $is_private, $monitor_time, $cate_id = '', $province = '', $city = '', $share_type = '')
  508. {
  509. $condition['title'] = $title;
  510. if ($cate_id == 0 && $title != '') {
  511. $cate_id = M('video_cate')->where($condition)->getfield('id');
  512. if ($cate_id) {
  513. $is_newtitle = 0;
  514. } else {
  515. $is_newtitle = 1;
  516. }
  517. }
  518. if ($is_newtitle) {
  519. $data_cate = array();
  520. $data_cate['title'] = $title;
  521. $data_cate['is_effect'] = 1;
  522. $data_cate['is_delete'] = 0;
  523. $data_cate['create_time'] = NOW_TIME;
  524. M('video_cate')->add($data_cate);
  525. $cate_id = M('video_cate')->where($condition)->getfield('id');
  526. }
  527. if ($province == '') {
  528. $province = '火星';
  529. }
  530. if ($city == '') {
  531. $city = '火星';
  532. }
  533. fanwe_require(APP_ROOT_PATH . 'mapi/lib/core/common.php');
  534. $v_id = get_max_room_id(0);//视频ID
  535. $data = array();
  536. $data['id'] = $v_id;
  537. //room_type 房间类型 : 1私有群(Private),0公开群(Public),2聊天室(ChatRoom),3互动直播聊天室(AVChatRoom)
  538. $data['room_type'] = 3;
  539. $m_config = load_auto_cache("m_config");
  540. $data['virtual_number'] = intval($m_config['virtual_number']);
  541. $data['max_robot_num'] = intval($m_config['robot_num']);//允许添加的最大机器人数;
  542. $sql = "select sex,ticket,refund_ticket,user_level,fans_count,head_image,thumb_head_image from " . DB_PREFIX . "user where id = " . $user_id;
  543. $user = $GLOBALS['db']->getRow($sql, true, true);
  544. if (!$user){
  545. admin_ajax_return(array(
  546. 'status' => 0,
  547. 'error' =>'用户ID不存在'
  548. ));
  549. }
  550. $info = origin_image_info($user['head_image']);
  551. $data['head_image'] = get_spec_image($info['file_name']);
  552. $data['thumb_head_image'] = $user['thumb_head_image'];
  553. $data['sex'] = intval($user['sex']);//性别 0:未知, 1-男,2-女
  554. $data['video_type'] = 1;//0:腾讯云互动直播;1:腾讯云直播
  555. require_once(APP_ROOT_PATH . 'system/tim/TimApi.php');
  556. $api = createTimAPI();
  557. $ret = $api->group_create_group('AVChatRoom', (string)$user_id, (string)$user_id, (string)$v_id);
  558. if ($ret['ActionStatus'] != 'OK') {
  559. admin_ajax_return(array(
  560. 'status' => 0,
  561. 'error' => $ret['ErrorCode'] . $ret['ErrorInfo']
  562. ));
  563. }
  564. $data['group_id'] = $ret['GroupId'];
  565. $data['monitor_time'] = $monitor_time;
  566. $data['create_type'] = 0;// 0:APP端创建的直播;1:PC端创建的直播
  567. $data['push_url'] = '';//video_type=1;1:腾讯云直播推流地址
  568. $data['play_url'] = '';//video_type=1;1:腾讯云直播播放地址(rmtp,flv)
  569. $data['share_type'] = $share_type;
  570. $data['title'] = $title;
  571. $data['cate_id'] = $cate_id;
  572. $data['user_id'] = $user_id;
  573. $data['live_in'] = 0;//live_in:是否直播中 1-直播中 0-已停止;2:正在创建直播;
  574. $data['watch_number'] = '';//'当前观看人数';
  575. $data['vote_number'] = '';//'获得票数';
  576. $data['province'] = $province;//'省';
  577. $data['city'] = $city;//'城市';
  578. $data['create_time'] = NOW_TIME;//'创建时间';
  579. $data['begin_time'] = NOW_TIME;//'开始时间';
  580. $data['end_time'] = '';//'结束时间';
  581. $data['is_hot'] = 1;//'1热门; 0:非热门';
  582. $data['is_new'] = 1; //'1新的; 0:非新的,直播结束时把它标识为:0?'
  583. $data['online_status'] = 1;//主播在线状态;1:在线(默认); 0:离开
  584. //上传的回播视频强制显示直播状态ljz
  585. if(defined('OPEN_CLASSIFY_URL')||OPEN_CLASSIFY_URL){
  586. $data['is_gather'] = 1;
  587. }
  588. //sort_init(初始排序权重) = (用户可提现印票:fanwe_user.ticket - fanwe_user.refund_ticket) * 保留印票权重+ 直播/回看[回看是:0; 直播:9000000000 直播,需要排在最上面 ]+ fanwe_user.user_level * 等级权重+ fanwe_user.fans_count * 当前有的关注数权重
  589. $sort_init = (intval($user['ticket']) - intval($user['refund_ticket'])) * floatval($m_config['ticke_weight']);
  590. $sort_init += intval($user['user_level']) * floatval($m_config['level_weight']);
  591. $sort_init += intval($user['fans_count']) * floatval($m_config['focus_weight']);
  592. $data['sort_init'] = 200000000 + $sort_init;
  593. $data['sort_num'] = $data['sort_init'];
  594. return $data;
  595. }
  596. //合并视频
  597. public function vod_concatvideo(){
  598. $id = $_REQUEST['id'];
  599. $result['status'] = 0;
  600. if (isset ( $id )) {
  601. require_once APP_ROOT_PATH . "/mapi/lib/core/common.php";
  602. $condition = array ('id' => array ('in', explode ( ',', $id ) ) );
  603. $rel_data = M('VideoHistory')->where($condition)->findAll();
  604. $success_info = array();
  605. $fail_info = array();
  606. foreach($rel_data as $data) {
  607. $channel_id =$data['channelid'];
  608. $new_file_name = $data['channelid'].'99';
  609. if($data['is_concatvideo']==0){
  610. $result = Com_ConcatVideo($channel_id,$new_file_name);
  611. }else{
  612. $result['status'] = 1;
  613. $result['error'] = '视频已经合并,请勿重复操作';
  614. }
  615. //更新
  616. if(intval($result['status'])==1){
  617. $sql = "update ".DB_PREFIX."video_history set is_concatvideo = 1 where id =".$data['id'];
  618. $GLOBALS['db']->query($sql);
  619. $success_info[] = $data['id'];
  620. }else{
  621. $fail_info[] = $data['id'];
  622. }
  623. }
  624. $msg = '';
  625. if(!empty($success_info)){
  626. $success_info=implode(',',$success_info);
  627. }
  628. if(!empty($fail_info)){
  629. $fail_info=implode(',',$fail_info);
  630. }
  631. if(intval($result['status'])==1){
  632. if($result['error']==''){
  633. if($success_info!=''){
  634. $result['info'] = $success_info.'合并成功;';
  635. $msg = $result['info'];
  636. }
  637. }else{
  638. $result['info'] = $result['error'];
  639. }
  640. }else{
  641. if($fail_info!=''){
  642. $result['info'] = $fail_info.'合并失败';
  643. $msg .= $result['info'];
  644. }
  645. }
  646. save_log($msg,0);
  647. }else {
  648. $result['status'] = 0;
  649. $result['info'] = '编号错误';
  650. }
  651. admin_ajax_return($result);
  652. }
  653. public function add_video(){
  654. $this->assign('max_size', conf('MAX_IMAGE_SIZE') / 1000);
  655. $this->display();
  656. }
  657. //上传OSS
  658. function upload_oss(){
  659. $result = array('status'=>1,'error'=>'添加回播视频成功,视频转码需要几分钟,请耐心等待');
  660. $create_type = intval($_REQUEST['create_type']);
  661. $kefile_url = trim($_REQUEST['kefile_url']);
  662. $kefile_url = urldecode($kefile_url);
  663. $title = trim($_REQUEST['title']);
  664. $user_id = trim($_REQUEST['user_id']);
  665. $live_image = trim($_REQUEST['live_image']);
  666. if($user_id == 0)
  667. {
  668. admin_ajax_return(array('status'=>'0','error'=>'请输入用户id'));
  669. }
  670. if(!check_empty($title))
  671. {
  672. admin_ajax_return(array('status'=>'0','error'=>'请输入话题'));
  673. }
  674. if(!check_empty($kefile_url))
  675. {
  676. admin_ajax_return(array('status'=>'0','error'=>'文件链接不能为空'));
  677. }
  678. $is_private = false;
  679. $monitor_time = to_date(NOW_TIME+3600,'Y-m-d H:i:s');
  680. $data = $this->create_video($user_id,$title,$is_private,$monitor_time);//视频信息写入user表
  681. if($GLOBALS['distribution_cfg']['OSS_TYPE']&&$GLOBALS['distribution_cfg']['OSS_TYPE']=='ALI_OSS'){
  682. $file_url=get_spec_image($kefile_url);
  683. }else{
  684. $file_url=str_replace("./public/",file_domain()."/public/",$kefile_url);
  685. }
  686. // 新上传的视频未生成地址
  687. $data['is_del_vod'] = 0;
  688. $data['play_url'] = $file_url;
  689. $data['live_image'] = $live_image;
  690. //上传的回播视频强制显示直播状态ljz
  691. if(defined('OPEN_CLASSIFY_URL')||OPEN_CLASSIFY_URL){
  692. $data['is_gather'] = 1;
  693. }
  694. $list = $GLOBALS['db']->autoExecute(DB_PREFIX . "video_history", $data, 'INSERT');
  695. if ($list !== false){
  696. save_log("回播视频上传成功",1);
  697. }else{
  698. save_log("回播视频上传失败",0);
  699. }
  700. //同步到redis
  701. require_once APP_ROOT_PATH."/mapi/lib/core/common.php";
  702. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/BaseRedisService.php');
  703. sync_video_to_redis($data['id'],'*',false);
  704. admin_ajax_return($result);
  705. }
  706. }
  707. ?>