select_weibo_other_list.auto_cache.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <?php
  2. class select_weibo_other_list_auto_cache extends auto_cache{
  3. private $key = "select:list:";
  4. public function load($param)
  5. {
  6. fanwe_require(APP_ROOT_PATH.'mapi/xr/core/common.php');
  7. $to_user_id = intval($param['to_user_id']);
  8. $page=$param['page']>0?$param['page']:1;
  9. $page_size=$param['page_size']>0?$param['page_size']:20;
  10. $limit = (($page-1) * $page_size) . "," . $page_size;
  11. $this->key .= md5(serialize($param));
  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. $sql = "select w.user_id,w.id as weibo_id,u.head_image,u.is_authentication,w.content,w.red_count,w.digg_count,w.comment_count,w.video_count,w.data,u.nick_name,w.sort_num,w.photo_image,w.is_top ,u.city,w.price,w.type,w.create_time,w.city,w.province,w.address from ".DB_PREFIX."weibo as w
  20. left join ".DB_PREFIX."user as u on w.user_id = u.id where w.user_id = ".$to_user_id ." and w.status = 1 ";
  21. if (!empty($param['type'])) {
  22. if (!is_array($param['type'])) {
  23. $param['type'] = array($param['type']);
  24. }
  25. $type = implode("','", $param['type']);
  26. $sql .= " and w.type in ('{$type}')";
  27. }
  28. $sql .= " order by w.is_top desc, w.id desc";
  29. $sql .= " limit " .$limit;
  30. $list = $GLOBALS['db']->getAll($sql,true,true);
  31. if(count($list)>0){
  32. foreach($list as $k=>$v){
  33. $list[$k]['is_show_weibo_report'] = 1;
  34. $list[$k]['is_show_user_report'] = 1;
  35. $list[$k]['is_show_user_black'] = 1;
  36. $list[$k]['is_show_top'] = 0;
  37. $list[$k]['is_show_deal_weibo'] =0;
  38. $list[$k]['has_digg'] = 0;
  39. $list[$k]['left_time'] = $this->time_tran($v['create_time']);
  40. if($v['head_image']){
  41. $list[$k]['head_image'] = deal_weio_image($v['head_image'],'head_image');
  42. }
  43. if($v['photo_image']){
  44. $list[$k]['photo_image'] = deal_weio_image($v['photo_image'],$v['type']);
  45. }
  46. $list[$k]['images_count'] = 0;
  47. $list[$k]['goods_url'] = '';
  48. if($v['type']=='goods'){
  49. $list[$k]['goods_url'] = SITE_DOMAIN.'/wap/xr/index.html#/weiboGoodsInfo?weibo_id='.$v['weibo_id'];
  50. }
  51. $address_x = str_replace("福建省","",$v['address']);
  52. $address_x = str_replace("福州市","",$address_x);
  53. $list[$k]['weibo_place'] = $v['province'].$v['city'].$address_x;
  54. if($v['type']=='video'){
  55. $list[$k]['images'] = array();
  56. $url = $v['data'];
  57. $list[$k]['video_url'] = get_file_oss_url($url);;
  58. }else{
  59. $images = unserialize($v['data']);
  60. $list[$k]['images'] = $images;
  61. //只针对 $to_user_id==$user_id
  62. $is_pay =1;
  63. $price = floatval($v['price']);
  64. if(count($images)>0){
  65. foreach($images as $k1=>$v1){
  66. if(is_object($v1)){
  67. $v1 = (array)$v1;
  68. }
  69. $images[$k1]['orginal_url'] = '';
  70. if($v1['url']){
  71. $images[$k1]['url'] = deal_weio_image($v1['url']);
  72. //$images[$k1]['is_model'] = 0;
  73. $images[$k1]['orginal_url'] = get_spec_image($v1['url']);
  74. }
  75. }
  76. $list[$k]['images'] = $images;
  77. $list[$k]['images_count'] = count($images);
  78. }else{
  79. $list[$k]['images'] = array();
  80. }
  81. $list[$k]['video_url'] = '';
  82. }
  83. unset($list[$k]['data']);
  84. }
  85. }else{
  86. $list = array();
  87. }
  88. $GLOBALS['cache']->set($this->key, $list, 3, true);
  89. $GLOBALS['cache']->set($key_bf, $list, 86400, true);//备份
  90. //echo $this->key;
  91. }
  92. }
  93. if ($list == false) $list = array();
  94. return $list;
  95. }
  96. public function rm()
  97. {
  98. //$GLOBALS['cache']->clear_by_name($this->key);
  99. }
  100. public function clear_all()
  101. {
  102. //$GLOBALS['cache']->clear_by_name($this->key);
  103. }
  104. public function time_tran($the_time)
  105. {
  106. $now_time = to_date(NOW_TIME,"Y-m-d H:i:s");
  107. $now_time = to_timespan($now_time);
  108. $show_time = to_timespan($the_time);
  109. $dur = $now_time - $show_time;
  110. if ($dur < 0) {
  111. return to_date($show_time,"Y-m-d");
  112. } else {
  113. if ($dur < 60) {
  114. return $dur . '秒前';
  115. } else {
  116. if ($dur < 3600) {
  117. return floor($dur / 60) . '分钟前';
  118. } else {
  119. if ($dur < 86400) {
  120. return floor($dur / 3600) . '小时前';
  121. } else {
  122. if ($dur < 2592000) {//30天内
  123. return floor($dur / 86400) . '天前';
  124. } else {
  125. return to_date($show_time,"Y-m-d");
  126. }
  127. }
  128. }
  129. }
  130. }
  131. }
  132. }
  133. ?>