newstar_rank.auto_cache.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2016/12/6
  6. * Time: 15:37
  7. */
  8. class newstar_rank_auto_cache extends auto_cache{
  9. private $key = "rank:new_star";
  10. public function load($param)
  11. {
  12. $key_bf = $this->key.'_bf';
  13. $list = $GLOBALS['cache']->get($this->key,true);
  14. if ($list === false||true) {
  15. $is_ok = $GLOBALS['cache']->set_lock($this->key);
  16. if(!$is_ok){
  17. $list = $GLOBALS['cache']->get($key_bf,true);
  18. }else{
  19. $m_config = load_auto_cache("m_config");//初始化手机端配置
  20. //缓存更新时间
  21. $rank_cache_time = intval($m_config['rank_cache_time'])>0?intval($m_config['rank_cache_time']):300;
  22. //数据处理
  23. $live_list = $this->get_live();
  24. $date = $this->newstar_ceil();
  25. //判断是否在直播
  26. $date['day'] = $this->is_live($date['day'],$live_list);
  27. $date['weeks'] = $this->is_live($date['weeks'],$live_list);
  28. $date['month'] = $this->is_live($date['month'],$live_list);
  29. $date['all']=$this->is_live($date['all'],$live_list);
  30. $list=array(
  31. 'day' => $date['day'],
  32. 'weeks' => $date['weeks'],
  33. 'month' => $date['month'],
  34. 'all'=>$date['all']
  35. );
  36. //数据处理结束
  37. $GLOBALS['cache']->set($this->key, $list, $rank_cache_time, true);
  38. $GLOBALS['cache']->set($key_bf, $list, 86400, true);//备份
  39. //echo $this->key;
  40. }
  41. }
  42. if ($list == false) $list = array();
  43. return $list;
  44. }
  45. //给榜单中正在直播中的主播添加直播链接
  46. public function is_live($data, $live_list)
  47. {
  48. foreach ($data as $k => $v) {
  49. foreach ($live_list as $kk => $vv) {
  50. if ($vv['user_id'] == $v['user_id']) {
  51. $data[$k]['live_in'] = $vv['live_in'];
  52. $data[$k]['room_id'] = $vv['room_id'];
  53. if($vv['live_in']==1){
  54. $data[$k]['video_url'] = "/".intval($vv['user_id']);
  55. break 1;
  56. }else{
  57. $data[$k]['video_url'] = get_video_url($vv['room_id'], $vv['live_in']);
  58. }
  59. }
  60. }
  61. if(empty($data[$k]['video_url']))
  62. {
  63. $data[$k]['video_url'] = "/".intval($v['user_id']);
  64. }
  65. $data[$k]['user_level_ico'] = get_spec_image("./public/images/rank/rank_" . $v['user_level'] . ".png");
  66. }
  67. return $data;
  68. }
  69. //当前直播
  70. public function get_live()
  71. {
  72. $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,
  73. (v.robot_num + v.virtual_watch_number + v.watch_number) as watch_number, v.head_image,v.thumb_head_image, v.xpoint,v.ypoint,
  74. u.v_type, u.v_icon, u.nick_name,u.user_level FROM " . DB_PREFIX . "video v
  75. LEFT JOIN " . DB_PREFIX . "user u ON u.id = v.user_id where v.live_in in (1,3) and v.room_type = 3 order by v.create_time desc,v.sort_num desc,v.sort desc";
  76. $live_list = $GLOBALS['db']->getAll($sql, true, true);
  77. return $live_list;
  78. }
  79. // 魅力排行榜数据
  80. public function newstar_ceil()
  81. {
  82. $table = createPropTable();
  83. $limit = " 0,10 ";//取前十
  84. $where=" u.is_effect=1 and";
  85. $where .= " v.create_d = day(curdate()) and is_red_envelope = 0";//日榜条件
  86. $sql = "select u.id as user_id ,u.nick_name,u.v_type,u.v_icon,u.head_image,u.sex,u.user_level,sum(v.total_ticket) as use_ticket ,u.is_authentication
  87. from " . DB_PREFIX . "user as u INNER JOIN " . $table. " as v on u.id = v.to_user_id
  88. where TO_DAYS(NOW())-TO_DAYS(FROM_UNIXTIME(u.create_time)) <=30 and " . $where . " GROUP BY to_user_id
  89. order BY sum(v.total_ticket) desc limit " . $limit;
  90. $root['day'] = $GLOBALS['db']->getAll($sql);
  91. $where = " v.create_ym=".to_date(NOW_TIME,'Ym')." and is_red_envelope = 0";//月榜条件
  92. $sql = "select u.id as user_id ,u.nick_name,u.v_type,u.v_icon,u.head_image,u.sex,u.user_level,sum(v.total_ticket) as use_ticket ,u.is_authentication
  93. from " . DB_PREFIX . "user as u INNER JOIN " . $table." as v on u.id = v.to_user_id
  94. where TO_DAYS(NOW())-TO_DAYS(FROM_UNIXTIME(u.create_time)) <=30 and " . $where . " GROUP BY to_user_id
  95. order BY sum(v.total_ticket) desc limit " . $limit;
  96. $root['month'] = $GLOBALS['db']->getAll($sql);
  97. $where = " v.create_w = week(curdate()) and is_red_envelope = 0";//周榜条件
  98. $sql = "select u.id as user_id ,u.nick_name,u.v_type,u.v_icon,u.head_image,u.sex,u.user_level,sum(v.total_ticket) as use_ticket ,u.is_authentication
  99. from " . DB_PREFIX . "user as u INNER JOIN " . $table. " as v on u.id = v.to_user_id
  100. where TO_DAYS(NOW())-TO_DAYS(FROM_UNIXTIME(u.create_time)) <=30 and " . $where . " GROUP BY to_user_id
  101. order BY sum(v.total_ticket) desc limit " . $limit;
  102. $root['weeks'] = $GLOBALS['db']->getAll($sql);
  103. //总榜
  104. $sql = "select u.id as user_id ,u.nick_name,u.v_type,u.v_icon,u.head_image,u.sex,u.user_level,sum(v.total_ticket) as use_ticket ,u.is_authentication
  105. from " . DB_PREFIX . "user as u INNER JOIN " . $table. " as v on u.id = v.to_user_id
  106. where u.is_effect=1 and TO_DAYS(NOW())-TO_DAYS(FROM_UNIXTIME(u.create_time)) <=30 and is_red_envelope = 0 GROUP BY to_user_id
  107. order BY sum(v.total_ticket) desc limit " . $limit;
  108. $root['all'] = $GLOBALS['db']->getAll($sql);
  109. return $root;
  110. }
  111. public function rm()
  112. {
  113. $GLOBALS['cache']->clear_by_name($this->key);
  114. }
  115. public function clear_all()
  116. {
  117. $GLOBALS['cache']->clear_by_name($this->key);
  118. }
  119. }