select_weibo_mine_list.auto_cache.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <?php
  2. class select_weibo_mine_list_auto_cache extends auto_cache{
  3. private $key = "select:mine_list:";
  4. public function load($param)
  5. {
  6. fanwe_require(APP_ROOT_PATH.'mapi/xr/core/common.php');
  7. $user_id = intval($param['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. $order_list_array = array();
  20. $diggs_array = array();
  21. // $order_list = $GLOBALS['db']->getAll("select order_id from ".DB_PREFIX."payment_notice where user_id = ".$user_id." and type in (11,13,14) and is_paid =1");
  22. // if(count($order_list)>0){
  23. // foreach($order_list as $k=>$v){
  24. // $order_list_array[] = $v['order_id'];
  25. // }
  26. // }
  27. $diggs = $GLOBALS['db']->getAll("select weibo_id from ".DB_PREFIX."weibo_comment where user_id = ".$user_id." and type = 2");
  28. if(count($diggs)>0){
  29. foreach($diggs as $k=>$v){
  30. $diggs_array[] = $v['weibo_id'];
  31. }
  32. }
  33. // $sql_black = "select black_user_id from ".DB_PREFIX."black where user_id = ".$user_id;
  34. // $black_list = $GLOBALS['db']->getAll($sql_black,true,true);
  35. // if(count($black_list)>0){
  36. // foreach($black_list as $k=>$v){
  37. // $black_list_array[] = $v['black_user_id'];
  38. // }
  39. // }
  40. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/UserRedisService.php');
  41. // $userfollow_redis = new UserFollwRedisService($user_id);
  42. // $ids = $userfollow_redis->following();
  43. // $ids[] = $user_id;
  44. // if(count($black_list_array)>0){
  45. // $ids = array_unique(array_merge($ids,$black_list_array));
  46. // }
  47. $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 ,u.city,w.is_top,w.price,w.type,w.create_time,w.city,w.province,w.address from ".DB_PREFIX."weibo as w
  48. left join ".DB_PREFIX."user as u on w.user_id = u.id where w.user_id =$user_id and w.status = 1 ";
  49. $sql .= " order by w.is_top desc, w.id desc";
  50. $sql .= " limit " .$limit;
  51. $list = $GLOBALS['db']->getAll($sql,true,true);
  52. if($user_id){
  53. }
  54. if(count($list)>0){
  55. foreach($list as $k=>$v){
  56. $list[$k]['is_show_weibo_report'] = 0;
  57. $list[$k]['is_show_user_report'] = 0;
  58. $list[$k]['is_show_user_black'] = 0;
  59. $list[$k]['is_show_top'] = 1;
  60. if($v['is_top']){
  61. $list[$k]['show_top_des'] = '取消置顶';
  62. }else{
  63. $list[$k]['show_top_des'] = '置顶动态';
  64. }
  65. // if($user_id !=$v['user_id']){
  66. // $list[$k]['is_top'] = 0;
  67. // }
  68. $list[$k]['is_show_deal_weibo'] =1;
  69. if(in_array($v['weibo_id'],$diggs_array)){
  70. $list[$k]['has_digg'] = 1;
  71. }else{
  72. $list[$k]['has_digg'] = 0;
  73. }
  74. $list[$k]['left_time'] = $this->time_tran($v['create_time']);
  75. if($v['head_image']){
  76. $list[$k]['head_image'] = deal_weio_image($v['head_image'],'head_image');
  77. }
  78. if($v['photo_image']){
  79. $list[$k]['photo_image'] = deal_weio_image($v['photo_image'],$v['type']);
  80. }
  81. $list[$k]['images_count'] = 0;
  82. $list[$k]['goods_url'] = '';
  83. if($v['type']=='goods'){
  84. $list[$k]['goods_url'] = SITE_DOMAIN.'/wap/xr/index.html#/weiboGoodsInfo?weibo_id='.$v['weibo_id'];
  85. }
  86. $list[$k]['weibo_place'] = $v['province'].$v['city'].$v['address'];
  87. if($v['type']=='video'){
  88. $list[$k]['images'] = array();
  89. $url = $v['data'];
  90. $list[$k]['video_url'] = get_file_oss_url($url);;
  91. }else{
  92. $images = unserialize($v['data']);
  93. $list[$k]['images'] = $images;
  94. $is_pay =1;
  95. $price = floatval($v['price']);
  96. if(count($images)>0){
  97. foreach($images as $k1=>$v1){
  98. if(is_object($v1)){
  99. $v1 = (array)$v1;
  100. }
  101. $images[$k1]['orginal_url'] = '';
  102. if($v1['url']){
  103. if($price>0){
  104. $is_model = $v1['is_model'];
  105. if($is_pay){
  106. $images[$k1]['url'] = deal_weio_image($v1['url']);
  107. $images[$k1]['is_model'] = 0;
  108. $images[$k1]['orginal_url'] = get_spec_image($v1['url']);
  109. }else{
  110. if($is_model){
  111. $images[$k1]['url'] = deal_weio_image($v1['url'],$v['type'],1);
  112. }else{
  113. $images[$k1]['url'] = deal_weio_image($v1['url']);
  114. $images[$k1]['orginal_url'] = get_spec_image($v1['url']);
  115. }
  116. }
  117. }else{
  118. $images[$k1]['url'] = deal_weio_image($v1['url']);
  119. $images[$k1]['is_model'] = 0;
  120. $images[$k1]['orginal_url'] = get_spec_image($v1['url']);
  121. }
  122. }
  123. }
  124. $list[$k]['images'] = $images;
  125. $list[$k]['images_count'] = count($images);
  126. }else{
  127. $list[$k]['images'] = array();
  128. }
  129. $list[$k]['video_url'] = '';
  130. }
  131. unset($list[$k]['data']);
  132. }
  133. }else{
  134. $list = array();
  135. }
  136. $GLOBALS['cache']->set($this->key, $list, 3, true);
  137. $GLOBALS['cache']->set($key_bf, $list, 86400, true);//备份
  138. //echo $this->key;
  139. }
  140. }
  141. if ($list == false) $list = array();
  142. return $list;
  143. }
  144. public function rm()
  145. {
  146. //$GLOBALS['cache']->clear_by_name($this->key);
  147. }
  148. public function clear_all()
  149. {
  150. //$GLOBALS['cache']->clear_by_name($this->key);
  151. }
  152. public function time_tran($the_time)
  153. {
  154. $now_time = to_date(NOW_TIME,"Y-m-d H:i:s");
  155. $now_time = to_timespan($now_time);
  156. $show_time = to_timespan($the_time);
  157. $dur = $now_time - $show_time;
  158. if ($dur < 0) {
  159. return to_date($show_time,"Y-m-d");
  160. } else {
  161. if ($dur < 60) {
  162. return $dur . '秒前';
  163. } else {
  164. if ($dur < 3600) {
  165. return floor($dur / 60) . '分钟前';
  166. } else {
  167. if ($dur < 86400) {
  168. return floor($dur / 3600) . '小时前';
  169. } else {
  170. if ($dur < 2592000) {//30天内
  171. return floor($dur / 86400) . '天前';
  172. } else {
  173. return to_date($show_time,"Y-m-d");
  174. }
  175. }
  176. }
  177. }
  178. }
  179. }
  180. }
  181. ?>