new_list.auto_cache.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2016/10/13
  6. * Time: 15:29
  7. */
  8. class new_list_auto_cache extends auto_cache
  9. {
  10. private $key = "new:list";
  11. public function load($param)
  12. {
  13. if ($param['change'] == 1) {
  14. $sql = "SELECT
  15. v.id AS room_id,
  16. v.sort_num,
  17. v.group_id,
  18. v.user_id,
  19. v.city,
  20. v.title,
  21. v.cate_id,
  22. v.live_in,
  23. v.video_type,
  24. v.room_type,
  25. v.room_title,
  26. (v.robot_num + v.virtual_watch_number + v.watch_number) AS watch_number,
  27. v.head_image,
  28. v.thumb_head_image,
  29. v.xpoint,
  30. v.ypoint,
  31. u.v_type,
  32. u.v_icon,
  33. u.nick_name,
  34. u.user_level
  35. FROM
  36. " . DB_PREFIX . "video v
  37. LEFT JOIN
  38. " . DB_PREFIX . "user u ON u.id = v.user_id
  39. WHERE
  40. v.live_in IN (1 , 3) AND v.room_type = 3 and UNIX_TIMESTAMP(NOW())-from_unixtime(u.create_time) < 30*24*60
  41. ORDER BY RAND() , u.create_time DESC
  42. LIMIT 6";
  43. $list = $GLOBALS['db']->getAll($sql, true, true);
  44. foreach ($list as $k => $v) {
  45. $list[$k]['live_image'] = get_live_image($v);
  46. $list[$k]['head_image'] = get_spec_image($v['head_image'],40,40);
  47. $list[$k]['video_url'] = get_video_url($v['room_id'], $v['live_in']);
  48. if ($v['thumb_head_image'] == ''){
  49. $list[$k]['thumb_head_image'] = get_spec_image($v['head_image'],40,40);
  50. }else{
  51. $list[$k]['thumb_head_image'] = get_spec_image($v['thumb_head_image'],40,40);
  52. }
  53. }
  54. } else {
  55. $key_bf = $this->key . '_bf';
  56. $list = $GLOBALS['cache']->get($this->key, true);
  57. $page_size = 6;
  58. $page = $param['page'];
  59. if ($page <= 0) {
  60. $page = 1;
  61. }
  62. if ($list === false) {
  63. $is_ok = $GLOBALS['cache']->set_lock($this->key);
  64. if (!$is_ok) {
  65. $list = $GLOBALS['cache']->get($key_bf, true);
  66. } else {
  67. $limit = (($page - 1) * $page_size) . "," . $page_size;
  68. $sql = "SELECT
  69. v.id AS room_id,
  70. v.sort_num,
  71. v.group_id,
  72. v.user_id,
  73. v.city,
  74. v.title,
  75. v.cate_id,
  76. v.live_in,
  77. v.video_type,
  78. v.room_type,
  79. (v.robot_num + v.virtual_watch_number + v.watch_number) AS watch_number,
  80. v.live_image,
  81. v.head_image,
  82. v.thumb_head_image,
  83. v.xpoint,
  84. v.ypoint,
  85. u.v_type,
  86. u.v_icon,
  87. u.nick_name,
  88. u.user_level
  89. FROM
  90. " . DB_PREFIX . "video v
  91. LEFT JOIN
  92. " . DB_PREFIX . "user u ON u.id = v.user_id
  93. WHERE
  94. v.live_in IN (1 , 3) AND v.room_type = 3 and UNIX_TIMESTAMP(NOW())-from_unixtime(u.create_time) < 30*24*60
  95. ORDER BY u.create_time DESC
  96. LIMIT " . $limit;
  97. $list = $GLOBALS['db']->getAll($sql, true, true);
  98. foreach ($list as $k => $v) {
  99. $list[$k]['live_image'] = get_live_image($v);
  100. $list[$k]['head_image'] = get_spec_image($v['head_image'],40,40);
  101. $list[$k]['video_url'] = get_video_url($v['room_id'], $v['live_in']);
  102. if ($v['thumb_head_image'] == ''){
  103. $list[$k]['thumb_head_image'] = get_spec_image($v['head_image'],40,40);
  104. }else{
  105. $list[$k]['thumb_head_image'] = get_spec_image($v['thumb_head_image'],40,40);
  106. }
  107. }
  108. $GLOBALS['cache']->set($this->key, $list, 10, true);
  109. $GLOBALS['cache']->set($key_bf, $list, 86400, true);//备份
  110. }
  111. }
  112. }
  113. if ($list == false) $list = array();
  114. return $list;
  115. }
  116. public function rm()
  117. {
  118. $GLOBALS['cache']->clear_by_name($this->key);
  119. }
  120. public function clear_all()
  121. {
  122. $GLOBALS['cache']->clear_by_name($this->key);
  123. }
  124. }