selectpc_video.auto_cache.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. class selectpc_video_auto_cache extends auto_cache{
  3. private $key = "selectpc:video:";
  4. public function load($param)
  5. {
  6. $is_recommend = intval($param['is_recommend']);//推荐
  7. $index_recommend=intval($param['index_recommend']);//推荐主播
  8. $is_hot = intval($param['is_hot']);//热门
  9. $is_new = intval($param['is_new']);//最新
  10. $update = intval($param['update']);
  11. $is_family_hot = intval($param['is_family_hot']);//家族热门
  12. $has_private = intval($param['has_private']);//1:包括私密直播
  13. $page=$param['page']>0?$param['page']:1;
  14. $page_size=$param['page_size']>0?$param['page_size']:8;
  15. $limit = (($page-1) * $page_size) . "," . $page_size;
  16. if ($is_recommend){
  17. $this->key .= 'is_recommend';
  18. }
  19. if ($is_hot){
  20. $this->key .= 'is_hot';
  21. }
  22. if ($is_new){
  23. $this->key .= 'is_new';
  24. }
  25. if ($is_family_hot){
  26. $this->key .= 'is_family_hot';
  27. }
  28. if($param['pc']){ //主页读取
  29. $this->key .= $this->key.'_pc';
  30. }
  31. $key_bf = $this->key.'_bf';
  32. $list = $GLOBALS['cache']->get($this->key,true);
  33. if ($list === false || $update == 1) {
  34. // $is_ok = $GLOBALS['cache']->set_lock($this->key);
  35. // if(!$is_ok){
  36. // $list = $GLOBALS['cache']->get($key_bf,true);
  37. // }else{
  38. $m_config = load_auto_cache("m_config");//初始化手机端配置
  39. $has_is_authentication = intval($m_config['has_is_authentication'])?1:0;
  40. if($has_is_authentication&&$m_config['ios_check_version'] == ''){
  41. $sql = "SELECT v.id AS room_id, v.channelid, v.begin_time, v.create_time, v.play_url, v.play_flv, v.play_hls, v.sort_num, v.group_id, v.user_id, v.city, v.title, v.cate_id, v.live_in, v.video_type, v.room_type,
  42. (v.robot_num + v.virtual_watch_number + v.watch_number) as watch_number, v.live_image, v.head_image,v.thumb_head_image, v.xpoint,v.ypoint,
  43. u.v_type, u.v_icon, u.nick_name,u.user_level FROM ".DB_PREFIX."video v
  44. LEFT JOIN ".DB_PREFIX."user u ON u.id = v.user_id where v.live_in in (1,3) and u.is_authentication = 2 ";
  45. }elseif($is_family_hot){
  46. $sql = " SELECT v.id AS room_id, v.channelid, v.begin_time, v.create_time, v.play_url, v.play_flv, v.play_hls, v.sort_num, v.group_id, v.user_id, v.city, v.title, v.cate_id, v.live_in, v.video_type, v.room_type,
  47. (v.robot_num + v.virtual_watch_number + v.watch_number) as watch_number, v.live_image, v.head_image,v.thumb_head_image, v.xpoint,v.ypoint,
  48. u.v_type, u.v_icon, u.nick_name,u.user_level,f.id FROM ".DB_PREFIX."family as f , ".DB_PREFIX."video v LEFT JOIN ".DB_PREFIX."user u ON u.id = v.user_id where u.family_id = f.id and u.family_id >0 and f.status=1 and v.live_in in (1,3) ";
  49. }elseif($param['cate_id']){
  50. $sql = "SELECT v.id AS room_id, v.channelid, v.begin_time, v.create_time, v.play_url, v.play_flv, v.play_hls, v.sort_num, v.group_id, v.user_id, v.city, v.title, v.cate_id, v.live_in, v.video_type, v.room_type,
  51. (v.robot_num + v.virtual_watch_number + v.watch_number) as watch_number, v.live_image, v.head_image,v.thumb_head_image, v.xpoint,v.ypoint,
  52. u.v_type, u.v_icon, u.nick_name,u.user_level FROM ".DB_PREFIX."video v
  53. LEFT JOIN ".DB_PREFIX."user u ON u.id = v.user_id where v.live_in in (1,3) and v.cate_id =" . $param['cate_id'];
  54. }else{
  55. $sql = "SELECT v.id AS room_id, v.channelid, v.begin_time, v.create_time, v.play_url, v.play_flv, v.play_hls, v.sort_num, v.group_id, v.user_id, v.city, v.title, v.cate_id, v.live_in, v.video_type, v.room_type,
  56. (v.robot_num + v.virtual_watch_number + v.watch_number) as watch_number, v.live_image, v.head_image,v.thumb_head_image, v.xpoint,v.ypoint,
  57. u.v_type, u.v_icon, u.nick_name,u.user_level FROM ".DB_PREFIX."video v
  58. LEFT JOIN ".DB_PREFIX."user u ON u.id = v.user_id where v.live_in in (1,3) ";
  59. }
  60. if($index_recommend){
  61. $sql .= ' and v.user_id ='.$index_recommend;
  62. }
  63. if ($has_private == 1){
  64. $sql .= ' and v.room_type in (1,3)'; //1:私密直播;3:直播
  65. }else{
  66. $sql .= ' and v.room_type = 3'; //1:私密直播;3:直播
  67. }
  68. if($is_recommend){
  69. $sql .= ' and v.is_recommend = '.$is_recommend;
  70. $sql .= " order by v.is_recommend desc,v.sort desc,v.sort_num desc";
  71. }elseif ($is_hot){
  72. $sql .= " order by watch_number desc,v.sort_num desc,v.sort desc";
  73. }elseif ($is_new){
  74. $sql .= " order by v.create_time desc,v.sort_num desc,v.sort desc ";
  75. }elseif ($is_family_hot){
  76. $sql .= " order by v.watch_number desc,v.sort_num desc,v.sort desc ";
  77. }else{
  78. $sql .= " order by v.sort_num desc,v.sort desc";
  79. }
  80. $sql .=" limit ". $limit;
  81. $list = $GLOBALS['db']->getAll($sql,true,true);
  82. foreach($list as $k=>$v){
  83. if ($v['thumb_head_image'] == ''){
  84. $list[$k]['thumb_head_image'] = get_spec_image($v['head_image'],40,40);
  85. }else{
  86. $list[$k]['thumb_head_image'] = get_spec_image($v['thumb_head_image'],40,40);
  87. }
  88. if(empty($v['live_image'])) {
  89. $list[$k]['live_image'] = get_spec_image($v['head_image'],320,180,1);
  90. }else{
  91. $list[$k]['live_image']=get_spec_image($v['live_image'],320,180,1);
  92. }
  93. $list[$k]['head_image'] = get_spec_image($v['head_image'],40,40);
  94. $list[$k]['video_url'] = get_video_url($v['room_id'], $v['live_in']);
  95. if ($v['live_in'] == 3) {
  96. $file_info = load_auto_cache('video_file', array(
  97. 'id' => $v['room_id'],
  98. 'video_type' => $v['video_type'],
  99. 'channelid' => $v['channelid'],
  100. 'begin_time' => $v['begin_time'],
  101. 'create_time' => $v['create_time'],
  102. ));
  103. $list[$k]['fileid'] = $file_info['file_id'];
  104. $list[$k]['play_url'] = $file_info['play_url'];
  105. $list[$k]['urls'] = $file_info['urls'];
  106. }
  107. }
  108. $GLOBALS['cache']->set($this->key, $list, 10, true);
  109. $GLOBALS['cache']->set($key_bf, $list, 86400, true);//备份
  110. }
  111. // }
  112. if ($list == false) $list = array();
  113. return $list;
  114. }
  115. public function rm()
  116. {
  117. $GLOBALS['cache']->clear_by_name($this->key);
  118. }
  119. public function clear_all()
  120. {
  121. $GLOBALS['cache']->clear_by_name($this->key);
  122. }
  123. }
  124. ?>