rank_consumption.auto_cache.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. class rank_consumption_auto_cache extends auto_cache{
  3. private $key = "rank:consumption:";
  4. public function load($param)
  5. {
  6. $rank_name = strim($param['rank_name']);
  7. $table = strim($param['table']);
  8. $page = intval($param['page']);
  9. $page_size = intval($param['page_size']);
  10. $cache_time = strim($param['cache_time']);
  11. $limit = (($page - 1) * $page_size) . "," . $page_size;
  12. $this->key .= $rank_name . '_' . $page;
  13. $key_bf = $this->key.'_bf';
  14. $list = $GLOBALS['cache']->get($this->key,true);
  15. if ($list === false) {
  16. $is_ok = $GLOBALS['cache']->set_lock($this->key);
  17. if(!$is_ok){
  18. $list = $GLOBALS['cache']->get($key_bf,true);
  19. }else{
  20. if($rank_name=='day'){//day
  21. $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 ticket,u.is_authentication
  22. from ".$table." as v LEFT JOIN ".DB_PREFIX."user as u on u.id = v.to_user_id
  23. where u.is_effect=1 and v.create_ym=".to_date(NOW_TIME,'Ym')." and v.create_d=".to_date(NOW_TIME,'d')." and v.is_red_envelope = 0 GROUP BY v.to_user_id
  24. order BY sum(v.total_ticket) desc limit ".$limit;
  25. }elseif($rank_name=='month'){//month
  26. $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 ticket,u.is_authentication
  27. from ".$table." as v LEFT JOIN ".DB_PREFIX."user as u on u.id = v.to_user_id
  28. where u.is_effect=1 and v.create_ym=".to_date(NOW_TIME,'Ym')." and v.is_red_envelope = 0 GROUP BY v.to_user_id
  29. order BY sum(v.total_ticket) desc limit ".$limit;
  30. }else{//all
  31. $sql = "select u.id as user_id,u.nick_name,u.v_type,u.v_icon,u.head_image,u.sex,u.user_level,u.ticket as ticket,u.is_authentication
  32. from ".DB_PREFIX."user as u
  33. where u.is_effect=1 and u.ticket>0
  34. order BY u.ticket desc limit ".$limit;
  35. }
  36. $list=$GLOBALS['db']->getAll($sql,true,true);
  37. if($rank_name=='day'){
  38. $GLOBALS['cache']->set($this->key, $list, $cache_time, true);//缓存时间 1800秒
  39. $GLOBALS['cache']->set($key_bf, $list, 86400, true);//备份
  40. }elseif($rank_name=='month'){
  41. $GLOBALS['cache']->set($this->key, $list, $cache_time, true);//缓存时间 28800秒 8h
  42. $GLOBALS['cache']->set($key_bf, $list, 86400, true);//备份
  43. }else{
  44. $GLOBALS['cache']->set($this->key, $list, $cache_time, true);//缓存时间 86400秒 24h
  45. $GLOBALS['cache']->set($key_bf, $list, 86400, true);//备份
  46. }
  47. }
  48. }
  49. if ($list == false) $list = array();
  50. return $list;
  51. }
  52. public function rm()
  53. {
  54. $GLOBALS['cache']->clear_by_name($this->key);
  55. }
  56. public function clear_all()
  57. {
  58. $GLOBALS['cache']->clear_by_name($this->key);
  59. }
  60. }
  61. ?>