sex_area.auto_cache.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. class sex_area_auto_cache extends auto_cache{
  3. private $key = "sex:area:";
  4. public function load($param)
  5. {
  6. $sex = intval($param['sex']);//性别 0:全部, 1-男,2-女
  7. $this->key .= $sex;
  8. $key_bf = $this->key.'_bf';
  9. $list = $GLOBALS['cache']->get($this->key);
  10. if($list === false)
  11. {
  12. $is_ok = $GLOBALS['cache']->set_lock($this->key);
  13. if(!$is_ok){
  14. $list = $GLOBALS['cache']->get($key_bf,true);
  15. }else{
  16. $m_config = load_auto_cache("m_config");//初始化手机端配置
  17. if ($sex == 0){
  18. $sql = "select v.province as city,count(v.province) as number from fanwe_video v LEFT JOIN fanwe_user u on u.id=v.user_id where v.live_in in (1,3) and u.is_hot_on =0 ";
  19. }else{
  20. $sql = "select v.province as city,count(v.province) as number from fanwe_video v LEFT JOIN fanwe_user u on u.id=v.user_id where v.live_in in (1,3) and u.is_hot_on =0 and v.sex = ".$sex;
  21. }
  22. if((defined('OPEN_ROOM_HIDE')&&OPEN_ROOM_HIDE==1)&&intval($m_config['open_room_hide'])==1){
  23. $sql.= " and v.province <> '火星' and v.province <>''";
  24. }
  25. $sql.=" group by v. province";
  26. $total_num = 0;
  27. $list = $GLOBALS['db']->getAll($sql,true,true);
  28. foreach($list as $k=>$v){
  29. $total_num = $total_num + $v['number'];
  30. }
  31. $hot = array();
  32. if($total_num>0){
  33. $hot[] = array(
  34. 'city'=>'热门',
  35. 'number'=>$total_num
  36. );
  37. $list = array_merge($hot,$list);
  38. }
  39. $GLOBALS['cache']->set($this->key,$list,10,true);
  40. $GLOBALS['cache']->set($key_bf, $list, 86400, true);//备份
  41. }
  42. }
  43. if ($list == false) $list = array();
  44. return $list;
  45. }
  46. public function rm($param)
  47. {
  48. $GLOBALS['cache']->clear_by_name($this->key);
  49. }
  50. public function clear_all()
  51. {
  52. $GLOBALS['cache']->clear_by_name($this->key);
  53. }
  54. }
  55. ?>