family_rank_all.auto_cache.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2016/10/26
  6. * Time: 17:45
  7. */
  8. class family_rank_all_auto_cache extends auto_cache{
  9. private $key = "family_rank:";
  10. public function load($params = array())
  11. {
  12. $sort = $params['sort'] ? $params['sort'] : 'user_count';
  13. $limit = $params['limit'] ? $params['limit'] : 10;
  14. $this->key .= "{$sort}_{$limit}";
  15. $key_bf = $this->key.'_bf';
  16. $type=$params['type'];
  17. $list = $GLOBALS['cache']->get($this->key,true);
  18. if ($list === false) {
  19. $is_ok = $GLOBALS['cache']->set_lock($this->key);
  20. if(!$is_ok){
  21. $list = $GLOBALS['cache']->get($key_bf,true);
  22. }else{
  23. $list=array();
  24. $list = $this->family_ceil($sort, $limit);
  25. if($type=='all'){
  26. //数据处理
  27. $list['day']= $this->family_ceil($sort, $limit,"day");
  28. $list['weeks'] = $this->family_ceil($sort, $limit,"weeks");
  29. $list['month']= $this->family_ceil($sort, $limit,"month");
  30. $list['all'] = $this->family_ceil($sort, $limit);
  31. }
  32. $m_config = load_auto_cache("m_config");//初始化手机端配置
  33. //缓存更新时间
  34. $rank_cache_time = intval($m_config['rank_cache_time'])>0?intval($m_config['rank_cache_time']):300;
  35. $GLOBALS['cache']->set($this->key, $list, $rank_cache_time, true);
  36. $GLOBALS['cache']->set($key_bf, $list, 86400, true);//备份
  37. }
  38. }
  39. if ($list == false) $list = array();
  40. return $list;
  41. }
  42. //家族排行数据来源
  43. public function family_ceil($sort = 'user_count', $limit = 10,$type)
  44. {
  45. $where = " f.user_id = u.id AND f.status = 1 ";
  46. if ($type == 'day') {
  47. $where .= " and create_d = day(CURDATE()) ";
  48. }
  49. if ($type == 'weeks') {
  50. $where .= " and create_w = week(CURDATE()) ";
  51. }
  52. if ($type == 'month') {
  53. $where .= " and create_m = month(CURDATE()) ";
  54. }
  55. $sql = "
  56. SELECT
  57. f.id AS family_id,
  58. f.logo AS family_logo,
  59. f.name AS family_name,
  60. f.user_id,
  61. u.nick_name,
  62. f.create_time,
  63. f.user_count
  64. FROM
  65. " . DB_PREFIX . "family AS f,
  66. " . DB_PREFIX . "user AS u
  67. WHERE
  68. {$where}
  69. ORDER BY {$sort} DESC, f.contribution desc, f.video_time desc, f.create_time desc
  70. LIMIT {$limit}";
  71. $family = $GLOBALS['db']->getAll($sql);
  72. foreach ($family as $k => $v) {
  73. $family[$k]['family_url'] = url("family#info", array("family_id" => $v['family_id']));
  74. $family[$k]['v_icon'] = get_domain().'/public/images/rank/rank_'.$v["family_level"].'.png';
  75. }
  76. return $family;
  77. }
  78. public function rm()
  79. {
  80. $GLOBALS['cache']->clear_by_name($this->key);
  81. }
  82. public function clear_all()
  83. {
  84. $GLOBALS['cache']->clear_by_name($this->key);
  85. }
  86. }
  87. ?>