focus_video.auto_cache.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2016/9/30
  6. * Time: 8:28
  7. */
  8. class focus_video_auto_cache extends auto_cache
  9. {
  10. private $key = "focus:video:";
  11. public function load($param)
  12. {
  13. $sex = intval($param['sex_type']);
  14. $city = strim($param['area_type']);
  15. $cate_id = intval($param['cate_id']);
  16. $has_private = intval($param['has_private']);//1:包括私密直播
  17. if ($city == '热门' || $city == 'null') {
  18. $city = '';
  19. }
  20. if ($sex == null || $sex == '') {
  21. $sex = 0;
  22. }
  23. $this->key .= $sex . '_' . $city . '_' . $cate_id . '_' . $has_private;
  24. $key_bf = $this->key . '_bf';
  25. $list = $GLOBALS['cache']->get($this->key, true);
  26. if ($list === false) {
  27. $m_config = load_auto_cache("m_config");//初始化手机端配置
  28. $has_is_authentication = intval($m_config['has_is_authentication']) ? 1 : 0;
  29. if ($has_is_authentication && $m_config['ios_check_version'] == '') {
  30. $sql = "SELECT v.id AS room_id, 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,v.private_key,
  31. (v.robot_num + v.virtual_watch_number + v.watch_number) as watch_number,v.live_image, u.head_image,u.thumb_head_image, v.xpoint,v.ypoint,
  32. u.v_type, u.v_icon, u.nick_name,u.user_level FROM " . DB_PREFIX . "video v
  33. LEFT JOIN " . DB_PREFIX . "user u ON u.id = v.user_id where v.live_in in (1,3) and u.is_authentication = 2 ";
  34. } else {
  35. $sql = "SELECT v.id AS room_id, 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,v.private_key,
  36. (v.robot_num + v.virtual_watch_number + v.watch_number) as watch_number,v.live_image, u.head_image,u.thumb_head_image, v.xpoint,v.ypoint,
  37. u.v_type, u.v_icon, u.nick_name,u.user_level FROM " . DB_PREFIX . "video v
  38. LEFT JOIN " . DB_PREFIX . "user u ON u.id = v.user_id where v.live_in in (1,3) ";
  39. }
  40. if ($has_private == 1) {
  41. $sql .= ' and v.room_type in (1,3)'; //1:私密直播;3:直播
  42. } else {
  43. $sql .= ' and v.room_type = 3'; //1:私密直播;3:直播
  44. }
  45. if ($sex == 1 || $sex == 2) {
  46. $sql .= ' and v.sex = ' . $sex;
  47. }
  48. if ($city != '') {
  49. $sql .= " and v.province = '" . $city . "'";
  50. }
  51. if ($cate_id > 0) {
  52. $sql .= " and v.cate_id = '" . $cate_id . "'";
  53. }
  54. $sql .= " order by v.live_in, v.sort_num desc,v.sort desc";
  55. $list = $GLOBALS['db']->getAll($sql, true, true);
  56. foreach ($list as $k => $v) {
  57. if(strpos($v['head_image'],'wx.qlogo.cn')){
  58. $list[$k]['thumb_head_image'] = strtr($v['head_image'],array('/96'=>'/46'));
  59. }else{
  60. if ($v['thumb_head_image'] == ''){
  61. $list[$k]['thumb_head_image'] = get_spec_image($v['head_image'],150,150);
  62. }else{
  63. //$list[$k]['thumb_head_image'] = get_abs_img_root($v['thumb_head_image']);
  64. $list[$k]['thumb_head_image'] = get_spec_image($v['thumb_head_image'],150,150);
  65. }
  66. }
  67. if(empty($v['live_image'])) {
  68. if(strpos($v['head_image'],'wx.qlogo.cn')){
  69. $list[$k]['live_image'] = strtr($v['headimgurl'],array('/96'=>'/0'));
  70. }elseif(strpos($v['head_image'],'http://q.qlogo.cn/')) {
  71. $list[$k]['live_image'] = strtr($v['headimgurl'],array('/40'=>'/100'));
  72. }else{
  73. $list[$k]['live_image'] = get_spec_image($v['head_image'],320,180,1);
  74. }
  75. }else{
  76. $list[$k]['live_image']=get_spec_image($v['live_image'],320,180,1);
  77. }
  78. $list[$k]['head_image'] = get_spec_image($v['head_image'],40,40,1);
  79. if($v['live_in']==3){
  80. $list[$k]['video_url']=url('live#show',array('room_id'=>$list[$k]['room_id'],'is_vod'=>1));
  81. }else{
  82. $list[$k]['video_url']=url('live#show',array('room_id'=>$list[$k]['room_id']));
  83. }
  84. $list[$k]['nick_name'] = emoji_decode($v['nick_name']);
  85. }
  86. $GLOBALS['cache']->set($this->key, $list, 10, true);
  87. $GLOBALS['cache']->set($key_bf, $list, 86400, true);//备份
  88. }
  89. if ($list == false) $list = array();
  90. return $list;
  91. }
  92. public function rm()
  93. {
  94. $GLOBALS['cache']->clear_by_name($this->key);
  95. }
  96. public function clear_all()
  97. {
  98. $GLOBALS['cache']->clear_by_name($this->key);
  99. }
  100. }
  101. ?>