select_weibo_list.auto_cache.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. <?php
  2. class select_weibo_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. $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. $top_list = array();
  48. $sql_top = "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,w.price,w.type,w.create_time,w.city,w.province,w.address from ".DB_PREFIX."weibo as w
  49. left join ".DB_PREFIX."user as u on w.user_id = u.id where w.user_id = $user_id and w.status = 1 and is_top=1";
  50. $top_list = $GLOBALS['db']->getAll($sql_top,true,true);
  51. $top_keys = array();
  52. foreach($top_list as $k=>$v){
  53. $top_keys[] = $v['weibo_id'];
  54. }
  55. $where = '';
  56. if($top_keys){
  57. $where = " and w.id not in ( ".implode(',',$top_keys) .")";
  58. }
  59. $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,w.price,w.type,w.create_time,w.city,w.province,w.address from ".DB_PREFIX."weibo as w
  60. left join ".DB_PREFIX."user as u on w.user_id = u.id where w.user_id in ( ".implode(',',$ids) .") and w.status = 1 ".$where;
  61. $sql .= " order by w.id desc";
  62. $sql .= " limit " .$limit;
  63. $list = $GLOBALS['db']->getAll($sql,true,true);
  64. if($page==1) {
  65. if($top_list){
  66. $list = array_merge($top_list,$list);
  67. }
  68. }
  69. if(count($list)>0){
  70. foreach($list as $k=>$v){
  71. $list[$k]['is_show_weibo_report'] = 0;
  72. $list[$k]['is_show_user_report'] = 0;
  73. $list[$k]['is_show_user_black'] = 0;
  74. $list[$k]['is_show_top'] = 1;
  75. if($v['is_top']){
  76. $list[$k]['show_top_des'] = '取消置顶';
  77. }else{
  78. $list[$k]['show_top_des'] = '置顶动态';
  79. }
  80. if($user_id !=$v['user_id']){
  81. $list[$k]['is_top'] = 0;
  82. }
  83. $list[$k]['is_show_deal_weibo'] =1;
  84. if(in_array($v['weibo_id'],$diggs_array)){
  85. $list[$k]['has_digg'] = 1;
  86. }else{
  87. $list[$k]['has_digg'] = 0;
  88. }
  89. $list[$k]['left_time'] = $this->time_tran($v['create_time']);
  90. if($v['head_image']){
  91. $list[$k]['head_image'] = deal_weio_image($v['head_image'],'head_image');
  92. }
  93. if($v['photo_image']){
  94. $list[$k]['photo_image'] = deal_weio_image($v['photo_image'],$v['type']);
  95. }
  96. $list[$k]['images_count'] = 0;
  97. $list[$k]['goods_url'] = '';
  98. if($v['type']=='goods'){
  99. $list[$k]['goods_url'] = SITE_DOMAIN.'/wap/xr/index.html#/weiboGoodsInfo?weibo_id='.$v['weibo_id'];
  100. }
  101. $address_x = str_replace("福建省","",$v['address']);
  102. $address_x = str_replace("福州市","",$address_x);
  103. $list[$k]['weibo_place'] = $v['province'].$v['city'].$address_x;
  104. if($v['type']=='video'){
  105. $list[$k]['images'] = array();
  106. $url = $v['data'];
  107. $list[$k]['video_url'] = get_file_oss_url($url);
  108. }else{
  109. $images = unserialize($v['data']);
  110. $list[$k]['images'] = $images;
  111. //只针对 $to_user_id==$user_id
  112. $is_pay = 0;
  113. if(in_array($v['weibo_id'],$order_list_array)||$v['user_id']==$user_id){
  114. $is_pay =1;
  115. }
  116. $price = floatval($v['price']);
  117. if(count($images)>0){
  118. foreach($images as $k1=>$v1){
  119. if(is_object($v1)){
  120. $v1 = (array)$v1;
  121. }
  122. $images[$k1]['orginal_url'] = '';
  123. if($v1['url']){
  124. if($price>0){
  125. $is_model = $v1['is_model'];
  126. if($is_pay){
  127. $images[$k1]['url'] = deal_weio_image($v1['url']);
  128. $images[$k1]['is_model'] = 0;
  129. $images[$k1]['orginal_url'] = get_spec_image($v1['url']);
  130. }else{
  131. if($is_model){
  132. $images[$k1]['url'] = deal_weio_image($v1['url'],$v['type'],1);
  133. }else{
  134. $images[$k1]['url'] = deal_weio_image($v1['url']);
  135. $images[$k1]['orginal_url'] = get_spec_image($v1['url']);
  136. }
  137. }
  138. }else{
  139. $images[$k1]['url'] = deal_weio_image($v1['url']);
  140. $images[$k1]['is_model'] = 0;
  141. $images[$k1]['orginal_url'] = get_spec_image($v1['url']);
  142. }
  143. }
  144. }
  145. $list[$k]['images'] = $images;
  146. $list[$k]['images_count'] = count($images);
  147. }else{
  148. $list[$k]['images'] = array();
  149. }
  150. $list[$k]['video_url'] = '';
  151. }
  152. unset($list[$k]['data']);
  153. }
  154. }else{
  155. $list = array();
  156. }
  157. $GLOBALS['cache']->set($this->key, $list, 3, true);
  158. $GLOBALS['cache']->set($key_bf, $list, 86400, true);//备份
  159. //echo $this->key;
  160. }
  161. }
  162. if ($list == false) $list = array();
  163. return $list;
  164. }
  165. public function rm()
  166. {
  167. //$GLOBALS['cache']->clear_by_name($this->key);
  168. }
  169. public function clear_all()
  170. {
  171. //$GLOBALS['cache']->clear_by_name($this->key);
  172. }
  173. public function time_tran($the_time)
  174. {
  175. $now_time = to_date(NOW_TIME,"Y-m-d H:i:s");
  176. $now_time = to_timespan($now_time);
  177. $show_time = to_timespan($the_time);
  178. $dur = $now_time - $show_time;
  179. if ($dur < 0) {
  180. return to_date($show_time,"Y-m-d");
  181. } else {
  182. if ($dur < 60) {
  183. return $dur . '秒前';
  184. } else {
  185. if ($dur < 3600) {
  186. return floor($dur / 60) . '分钟前';
  187. } else {
  188. if ($dur < 86400) {
  189. return floor($dur / 3600) . '小时前';
  190. } else {
  191. if ($dur < 2592000) {//30天内
  192. return floor($dur / 86400) . '天前';
  193. } else {
  194. return to_date($show_time,"Y-m-d");
  195. }
  196. }
  197. }
  198. }
  199. }
  200. }
  201. }
  202. ?>