edu_select_weibo_list.auto_cache.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. <?php
  2. class edu_select_weibo_list_auto_cache extends auto_cache
  3. {
  4. private $key = "select:list:";
  5. public function load($param)
  6. {
  7. fanwe_require(APP_ROOT_PATH . 'mapi/xr/core/common.php');
  8. $user_id = intval($param['user_id']);
  9. $page = $param['page'] > 0 ? $param['page'] : 1;
  10. $page_size = $param['page_size'] > 0 ? $param['page_size'] : 20;
  11. $limit = (($page - 1) * $page_size) . "," . $page_size;
  12. $this->key .= md5(serialize($param));
  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. $order_list_array = array();
  21. $diggs_array = array();
  22. $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");
  23. if (count($order_list) > 0) {
  24. foreach ($order_list as $k => $v) {
  25. $order_list_array[] = $v['order_id'];
  26. }
  27. }
  28. $diggs = $GLOBALS['db']->getAll("select weibo_id from " . DB_PREFIX . "weibo_comment where user_id = " . $user_id . " and type = 2");
  29. if (count($diggs) > 0) {
  30. foreach ($diggs as $k => $v) {
  31. $diggs_array[] = $v['weibo_id'];
  32. }
  33. }
  34. $sql_black = "select black_user_id from " . DB_PREFIX . "black where user_id = " . $user_id;
  35. $black_list = $GLOBALS['db']->getAll($sql_black, true, true);
  36. if (count($black_list) > 0) {
  37. foreach ($black_list as $k => $v) {
  38. $black_list_array[] = $v['black_user_id'];
  39. }
  40. }
  41. $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
  42. 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";
  43. $top_list = $GLOBALS['db']->getAll($sql_top, true, true);
  44. $top_keys = array();
  45. foreach ($top_list as $k => $v) {
  46. $top_keys[] = $v['weibo_id'];
  47. }
  48. $where = '';
  49. if ($top_keys) {
  50. $where = " and w.id not in ( " . implode(',', $top_keys) . ")";
  51. }
  52. if (!empty($param['type'])) {
  53. if (!is_array($param['type'])) {
  54. $param['type'] = array($param['type']);
  55. }
  56. $type = implode("','", $param['type']);
  57. $where .= " and w.type in ('{$type}')";
  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 = {$user_id} 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) {
  163. $list = array();
  164. }
  165. return $list;
  166. }
  167. public function rm()
  168. {
  169. //$GLOBALS['cache']->clear_by_name($this->key);
  170. }
  171. public function clear_all()
  172. {
  173. //$GLOBALS['cache']->clear_by_name($this->key);
  174. }
  175. public function time_tran($the_time)
  176. {
  177. $now_time = to_date(NOW_TIME, "Y-m-d H:i:s");
  178. $now_time = to_timespan($now_time);
  179. $show_time = to_timespan($the_time);
  180. $dur = $now_time - $show_time;
  181. if ($dur < 0) {
  182. return to_date($show_time, "Y-m-d");
  183. } else {
  184. if ($dur < 60) {
  185. return $dur . '秒前';
  186. } else {
  187. if ($dur < 3600) {
  188. return floor($dur / 60) . '分钟前';
  189. } else {
  190. if ($dur < 86400) {
  191. return floor($dur / 3600) . '小时前';
  192. } else {
  193. if ($dur < 2592000) {//30天内
  194. return floor($dur / 86400) . '天前';
  195. } else {
  196. return to_date($show_time, "Y-m-d");
  197. }
  198. }
  199. }
  200. }
  201. }
  202. }
  203. }
  204. ?>