selectpc_live_video.auto_cache.php 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. class selectpc_live_video_auto_cache extends auto_cache
  3. {
  4. private $key = "selectpc:live:video:";
  5. public function load($param)
  6. {
  7. if (empty($param['index_recommend'])) {
  8. return array();
  9. }
  10. $this->key .= md5(serialize($param));
  11. $key_bf = $this->key . '_bf';
  12. $page = $param['page'] > 0 ? $param['page'] : 1;
  13. $page_size = $param['page_size'] > 0 ? $param['page_size'] : 10;
  14. $limit = (($page - 1) * $page_size) . "," . $page_size;
  15. $list = $GLOBALS['cache']->get($this->key, true);
  16. if ($list === false) {
  17. $is_ok = $GLOBALS['cache']->set_lock($this->key);
  18. if (!$is_ok) {
  19. $list = $GLOBALS['cache']->get($key_bf, true);
  20. } else {
  21. $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,
  22. (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,
  23. u.v_type, u.v_icon, u.nick_name,u.user_level FROM " . DB_PREFIX . "video v
  24. LEFT JOIN " . DB_PREFIX . "user u ON u.id = v.user_id where v.live_in = 1 ";
  25. $m_config = load_auto_cache("m_config");//初始化手机端配置
  26. $has_is_authentication = intval($m_config['has_is_authentication']) ? 1 : 0;
  27. if ($has_is_authentication && $m_config['ios_check_version'] == '') {
  28. $sql .= "and u.is_authentication = 2 ";
  29. }
  30. $recommend_user = explode(',', $param['index_recommend']);
  31. foreach ($recommend_user as &$item) {
  32. $item = intval($item);
  33. }
  34. unset($item);
  35. $sql .= ' and v.user_id in (' . implode(',', $recommend_user) . ')';
  36. $sql .= ' and v.room_type = 3'; //1:私密直播;3:直播
  37. $sql .= " order by v.sort_num desc,v.sort desc";
  38. $sql .= " limit " . $limit;
  39. $list = $GLOBALS['db']->getAll($sql, true, true);
  40. foreach ($list as $k => &$v) {
  41. $v['thumb_head_image'] = get_spec_image(empty($v['thumb_head_image']) ? $v['head_image'] : $v['thumb_head_image'],
  42. 40, 40);
  43. $v['live_image'] = get_spec_image(empty($v['live_image']) ? $v['head_image'] : $v['live_image'],
  44. 320, 180, 1);
  45. $v['head_image'] = get_spec_image($v['head_image'], 40, 40);
  46. $v['video_url'] = get_video_url($v['room_id'], $v['live_in']);
  47. }
  48. unset($v);
  49. $GLOBALS['cache']->set($this->key, $list, 10, true);
  50. $GLOBALS['cache']->set($key_bf, $list, 86400, true);//备份
  51. }
  52. }
  53. if ($list == false) {
  54. $list = array();
  55. }
  56. return $list;
  57. }
  58. public function rm()
  59. {
  60. $GLOBALS['cache']->clear_by_name($this->key);
  61. }
  62. public function clear_all()
  63. {
  64. $GLOBALS['cache']->clear_by_name($this->key);
  65. }
  66. }