select_weibo_index.auto_cache.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. class select_weibo_index_auto_cache extends auto_cache{
  3. private $key = "select:weibo_index:";
  4. public function load($param)
  5. {
  6. fanwe_require(APP_ROOT_PATH.'mapi/xr/core/common.php');
  7. $this->key .= md5(serialize($param));
  8. $type = $param['type']; //type: photo or video
  9. $page=$param['page']>0?$param['page']:1;
  10. $page_size=$param['page_size']>0?$param['page_size']:20;
  11. $limit = (($page-1) * $page_size) . "," . $page_size;
  12. $key_bf = $this->key.'_bf';
  13. $list = $GLOBALS['cache']->get($this->key,true);
  14. if ($list === false) {
  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. $has_is_authentication = intval($m_config['has_is_authentication'])?1:0;
  21. if($has_is_authentication){
  22. $sql = "select w.user_id,w.id as weibo_id,u.nick_name,w.sort_num,w.photo_image as video_image ,u.city,u.user_level,w.data as video_url,w.xpoint,w.ypoint,w.content as vide_desc,u.head_image,w.video_count,u.show_image from ".DB_PREFIX."weibo as w
  23. left join ".DB_PREFIX."user as u on w.user_id = u.id where u.is_authentication = 2 and w.type = '".$type."' ";
  24. }else{
  25. $sql = "select w.user_id,w.id as weibo_id,u.nick_name,w.sort_num,w.photo_image as video_image,u.city,u.user_level,w.data as video_url,w.xpoint,w.ypoint,w.content as vide_desc,u.head_image,w.video_count,u.show_image from ".DB_PREFIX."weibo as w
  26. left join ".DB_PREFIX."user as u on w.user_id = u.id where w.type = '".$type."' ";
  27. }
  28. $sql .= " order by w.sort_num desc";
  29. $sql .= " limit " .$limit;
  30. $list = $GLOBALS['db']->getAll($sql,true,true);
  31. foreach($list as $k=>$v){
  32. //判断用户是否为今日创建的新用户,是:1,否:0
  33. if (date('Y-m-d') == date('Y-m-d',$list[$k]['user_create_time']+3600*8)){
  34. $list[$k]['today_create'] = 1;
  35. }else{
  36. $list[$k]['today_create'] = 0;
  37. }
  38. if($v['video_url']){
  39. $list[$k]['video_url'] = get_file_oss_url($v['video_url']);
  40. }
  41. $list[$k]['head_image'] = get_spec_image($v['head_image'],200,200,1);
  42. $list[$k]['video_image'] = get_spec_image($v['video_image'],200,200,1);
  43. if($type=='photo'){
  44. $list[$k]['head_image'] = get_spec_image($v['video_image'],200,200,1);
  45. $list[$k]['nick_name'] = $v['vide_desc'];
  46. }
  47. if($v['video_url']){
  48. $show_image_num = count(unserialize($v['video_url']));
  49. }else{
  50. $show_image_num = 0;
  51. }
  52. //写真照片数量
  53. $list[$k]['show_image_num'] = $show_image_num;
  54. }
  55. $GLOBALS['cache']->set($this->key, $list, 10, true);
  56. $GLOBALS['cache']->set($key_bf, $list, 86400, true);//备份
  57. //echo $this->key;
  58. }
  59. }
  60. if ($list == false) $list = array();
  61. return $list;
  62. }
  63. public function rm()
  64. {
  65. //$GLOBALS['cache']->clear_by_name($this->key);
  66. }
  67. public function clear_all()
  68. {
  69. //$GLOBALS['cache']->clear_by_name($this->key);
  70. }
  71. }
  72. ?>