select_weibo_recommond.auto_cache.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <?php
  2. class select_weibo_recommond_auto_cache extends auto_cache{
  3. private $key = "select:weibo_recommond:";
  4. public function load($param)
  5. {
  6. fanwe_require(APP_ROOT_PATH.'mapi/xr/core/common.php');
  7. $this->key .= md5(serialize($param));
  8. $page=$param['page']>0?$param['page']:1;
  9. $user_id=$param['user_id'];
  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. $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.v_icon,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
  20. left join ".DB_PREFIX."user as u on w.user_id = u.id where is_recommend = 1 and 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.id desc";
  29. $sql .= " limit " .$limit;
  30. $list = $GLOBALS['db']->getAll($sql,true,true);
  31. if($user_id>0){
  32. $order_list = $GLOBALS['db']->getAll("select order_id from ".DB_PREFIX."payment_notice where user_id = ".$user_id." and type in (11,13,14)");
  33. if(count($order_list)>0){
  34. foreach($order_list as $k=>$v){
  35. $order_list_array[] = $v['order_id'];
  36. }
  37. }else{
  38. $order_list_array = array();
  39. }
  40. }else{
  41. $order_list_array = array();
  42. }
  43. if(count($list)>0){
  44. foreach($list as $k=>$v){
  45. $sql = "select count(id) as num from ".DB_PREFIX."black where black_user_id = ".$v['user_id']." and user_id = ".$user_id;
  46. if ($GLOBALS['db']->getOne($sql) > 0){
  47. $list[$k]['has_black'] = 1;//0:未黑名单;1:黑名单
  48. }else{
  49. $list[$k]['has_black'] = 0;
  50. }
  51. $list[$k]['is_show_weibo_report'] = 1;
  52. $list[$k]['is_show_user_report'] = 1;
  53. $list[$k]['is_show_user_black'] = 1;
  54. $list[$k]['is_show_top'] = 0;
  55. $list[$k]['is_show_deal_weibo'] =0;
  56. $list[$k]['left_time'] = $this->time_tran($v['create_time']);
  57. if($v['head_image']){
  58. $list[$k]['head_image'] = deal_weio_image($v['head_image'],'head_image');
  59. }
  60. if($v['photo_image']){
  61. $list[$k]['photo_image'] = deal_weio_image($v['photo_image'],$v['type']);
  62. }
  63. $address_x = str_replace("福建省","",$v['address']);
  64. $address_x = str_replace("福州市","",$address_x);
  65. $list[$k]['weibo_place'] = $v['province'].$v['city'].$address_x;
  66. $list[$k]['images_count'] = 0;
  67. if($v['type']=='video'){
  68. $list[$k]['images'] = array();
  69. $url = $v['data'];
  70. $list[$k]['video_url'] = get_file_oss_url($url);
  71. }else{
  72. $images = unserialize($v['data']);
  73. if(in_array($v['weibo_id'],$order_list_array)){
  74. $is_pay =1;
  75. }else{
  76. $is_pay =0;
  77. }
  78. if(count($images)>0){
  79. foreach($images as $k1=>$v1){
  80. if(is_object($v1)){
  81. $v1 = (array)$v1;
  82. }
  83. if($v1['url']){
  84. $is_model = $v1['is_model'];
  85. $images[$k1]['orginal_url'] = '';
  86. if($is_model){
  87. if($is_pay){
  88. $images[$k1]['url'] = deal_weio_image($v1['url']);
  89. $images[$k1]['is_model'] = 0;
  90. $images[$k1]['orginal_url'] = get_spec_image($v1['url']);
  91. }else{
  92. $images[$k1]['url'] = deal_weio_image($v1['url'],$v['type'],1);
  93. }
  94. }else{
  95. $images[$k1]['url'] = deal_weio_image($v1['url']);
  96. $images[$k1]['orginal_url'] = get_spec_image($v1['url']);
  97. }
  98. }
  99. }
  100. $list[$k]['images'] = $images;
  101. $list[$k]['images_count'] = count($images);
  102. }else{
  103. $list[$k]['images'] = array();
  104. }
  105. $list[$k]['video_url'] = '';
  106. }
  107. unset($list[$k]['data']);
  108. }
  109. }else{
  110. $list = array();
  111. }
  112. $GLOBALS['cache']->set($this->key, $list, 10, true);
  113. $GLOBALS['cache']->set($key_bf, $list, 86400, true);//备份
  114. //echo $this->key;
  115. }
  116. }
  117. if ($list == false) $list = array();
  118. return $list;
  119. }
  120. public function rm()
  121. {
  122. //$GLOBALS['cache']->clear_by_name($this->key);
  123. }
  124. public function clear_all()
  125. {
  126. //$GLOBALS['cache']->clear_by_name($this->key);
  127. }
  128. public function time_tran($the_time)
  129. {
  130. $now_time = to_date(NOW_TIME,"Y-m-d H:i:s");
  131. $now_time = to_timespan($now_time);
  132. $show_time = to_timespan($the_time);
  133. $dur = $now_time - $show_time;
  134. if ($dur < 0) {
  135. return to_date($show_time,"Y-m-d");
  136. } else {
  137. if ($dur < 60) {
  138. return $dur . '秒前';
  139. } else {
  140. if ($dur < 3600) {
  141. return floor($dur / 60) . '分钟前';
  142. } else {
  143. if ($dur < 86400) {
  144. return floor($dur / 3600) . '小时前';
  145. } else {
  146. if ($dur < 2592000) {//30天内
  147. return floor($dur / 86400) . '天前';
  148. } else {
  149. return to_date($show_time,"Y-m-d");
  150. }
  151. }
  152. }
  153. }
  154. }
  155. }
  156. }
  157. ?>