rank_game.auto_cache.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. class rank_game_auto_cache extends auto_cache{
  3. private $key = "rank:game:";
  4. public function load($param)
  5. {
  6. $rank_name = strim($param['rank_name']);
  7. $game_id = intval($param['game_id']);
  8. $table = strim($param['table']);
  9. $page = intval($param['page']);
  10. $page_size = intval($param['page_size']);
  11. $cache_time = strim($param['cache_time']);
  12. $limit = (($page - 1) * $page_size) . "," . $page_size;
  13. $this->key .= $rank_name . '_' . $page;
  14. $key_bf = $this->key.'_bf';
  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. if($rank_name=='day'){//day
  22. $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.money) as ticket,u.is_authentication
  23. from ".$table." as v LEFT JOIN ".DB_PREFIX."user as u on u.id = v.user_id
  24. where u.is_effect=1 and v.type = 2 and v.create_time>".(NOW_TIME-86400)." and v.game_log_id in ( select id FROM ".DB_PREFIX."game_log_history where game_id=".$game_id.") GROUP BY v.user_id
  25. order BY ticket desc limit ".$limit;
  26. }elseif($rank_name=='month'){//month
  27. $sql = "";
  28. }else{//all
  29. /*$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
  30. from ".DB_PREFIX."user as u
  31. where u.is_effect=1 and u.ticket>0
  32. order BY u.ticket desc limit ".$limit;*/
  33. $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.money) as ticket,u.is_authentication
  34. from ".$table." as v LEFT JOIN ".DB_PREFIX."user as u on u.id = v.user_id
  35. where u.is_effect=1 and v.type = 2 and v.game_log_id in ( select id FROM ".DB_PREFIX."game_log_history where game_id=".$game_id.") GROUP BY v.user_id
  36. order BY ticket desc limit ".$limit;
  37. }
  38. $list=$GLOBALS['db']->getAll($sql,true,true);
  39. if($rank_name=='day'){
  40. $GLOBALS['cache']->set($this->key, $list, $cache_time, true);//缓存时间 1800秒
  41. $GLOBALS['cache']->set($key_bf, $list, 86400, true);//备份
  42. }elseif($rank_name=='month'){
  43. $GLOBALS['cache']->set($this->key, $list, $cache_time, true);//缓存时间 28800秒 8h
  44. $GLOBALS['cache']->set($key_bf, $list, 86400, true);//备份
  45. }else{
  46. $GLOBALS['cache']->set($this->key, $list, $cache_time, true);//缓存时间 86400秒 24h
  47. $GLOBALS['cache']->set($key_bf, $list, 86400, true);//备份
  48. }
  49. }
  50. }
  51. if ($list == false) $list = array();
  52. return $list;
  53. }
  54. public function rm()
  55. {
  56. $GLOBALS['cache']->clear_by_name($this->key);
  57. }
  58. public function clear_all()
  59. {
  60. $GLOBALS['cache']->clear_by_name($this->key);
  61. }
  62. }
  63. ?>