svideo_select_weibo_recommend.auto_cache.php 7.8 KB

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