all_video.auto_cache.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2016/9/29
  6. * Time: 17:25
  7. */
  8. class all_video_auto_cache extends auto_cache
  9. {
  10. private $key = "all:video:";
  11. public function load($param)
  12. {
  13. $this->key .= md5(serialize($param));
  14. $key_bf = $this->key . '_bf';
  15. $list = $GLOBALS['cache']->get($this->key, true);
  16. $page=$param['page']>0?$param['page']:1;
  17. $page_size=$param['page_size']>0?$param['page_size']:12;
  18. $limit = (($page-1) * $page_size) . "," . $page_size;
  19. $has_private=$param['has_private'];
  20. $is_hot_cate=$param['is_hot_cate'];
  21. if ($list===false) {
  22. $is_ok = $GLOBALS['cache']->set_lock($this->key);
  23. if (!$is_ok) {
  24. $list = $GLOBALS['cache']->get($key_bf, true);
  25. } else {
  26. if ($param['cate_id'] != '') {
  27. $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,
  28. (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,
  29. u.v_type, u.v_icon, u.nick_name,u.user_level FROM " . DB_PREFIX . "video v
  30. 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'] ;
  31. } elseif($is_hot_cate){
  32. $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,
  33. (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,
  34. u.v_type, u.v_icon, u.nick_name,u.user_level FROM " . DB_PREFIX . "video v
  35. LEFT JOIN " . DB_PREFIX . "user u ON u.id = v.user_id LEFT JOIN " . DB_PREFIX . "video_cate vc on vc.id=v.cate_id where v.live_in in (1,3) ";
  36. }else {
  37. $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,
  38. (v.robot_num + v.virtual_watch_number + v.watch_number) as watch_number, v.head_image,v.thumb_head_image,v.live_image, v.xpoint,v.ypoint,
  39. u.v_type, u.v_icon, u.nick_name,u.user_level FROM " . DB_PREFIX . "video v
  40. LEFT JOIN " . DB_PREFIX . "user u ON u.id = v.user_id where v.live_in in (1,3) ";
  41. }
  42. if ($has_private == 1){
  43. $sql .= ' and v.room_type in (1,3)'; //1:私密直播;3:直播
  44. }else{
  45. $sql .= ' and v.room_type = 3'; //1:私密直播;3:直播
  46. }
  47. if($is_hot_cate){
  48. $sql .=" order by vc.num desc";
  49. }else{
  50. $sql .=" order by v.sort_num desc";
  51. }
  52. $sql .= " limit " .$limit;
  53. $list = $GLOBALS['db']->getAll($sql, true, true);
  54. foreach ($list as $k => $v) {
  55. if ($v['thumb_head_image'] == '') {
  56. $list[$k]['thumb_head_image'] = get_spec_image($v['head_image'],40,40);
  57. } else {
  58. $list[$k]['thumb_head_image'] = get_spec_image($v['thumb_head_image'],40,40);
  59. }
  60. if(empty($v['live_image'])) {
  61. $list[$k]['live_image'] = get_spec_image($v['head_image'],320,180,1);;
  62. }else{
  63. $list[$k]['live_image']=get_spec_image($v['live_image'],320,180,1);
  64. }
  65. $list[$k]['head_image'] = get_spec_image($v['head_image'],40,40);
  66. if($v['live_in']==3){
  67. $list[$k]['video_url']=url('live#show',array('room_id'=>$list[$k]['room_id'],'is_vod'=>1));
  68. }else{
  69. $list[$k]['video_url']=url('live#show',array('room_id'=>$list[$k]['room_id']));
  70. }
  71. }
  72. $GLOBALS['cache']->set($this->key, $list, 10, true);
  73. $GLOBALS['cache']->set($key_bf, $list, 86400, true);//备份
  74. }
  75. }
  76. if ($list == false) $list = array();
  77. $res = array('list' => $list);
  78. return $res;
  79. }
  80. public function rm()
  81. {
  82. $GLOBALS['cache']->clear_by_name($this->key);
  83. }
  84. public function clear_all()
  85. {
  86. $GLOBALS['cache']->clear_by_name($this->key);
  87. }
  88. }
  89. ?>