| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 |
- <?php
- class select_weibo_recommond_auto_cache extends auto_cache{
- private $key = "select:weibo_recommond:";
- public function load($param)
- {
- fanwe_require(APP_ROOT_PATH.'mapi/xr/core/common.php');
- $this->key .= md5(serialize($param));
- $page=$param['page']>0?$param['page']:1;
- $user_id=$param['user_id'];
- $page_size=$param['page_size']>0?$param['page_size']:20;
- $limit = (($page-1) * $page_size) . "," . $page_size;
-
- $key_bf = $this->key.'_bf';
-
- $list = $GLOBALS['cache']->get($this->key,true);
- if ($list === false) {
- $is_ok = $GLOBALS['cache']->set_lock($this->key);
- if(!$is_ok){
- $list = $GLOBALS['cache']->get($key_bf,true);
- }else{
- $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
- left join ".DB_PREFIX."user as u on w.user_id = u.id where is_recommend = 1 and status = 1 ";
- if (!empty($param['type'])) {
- if (!is_array($param['type'])) {
- $param['type'] = array($param['type']);
- }
- $type = implode("','", $param['type']);
- $sql .= " and w.type in ('{$type}')";
- }
- $sql .= " order by w.id desc";
- $sql .= " limit " .$limit;
- $list = $GLOBALS['db']->getAll($sql,true,true);
- if($user_id>0){
- $order_list = $GLOBALS['db']->getAll("select order_id from ".DB_PREFIX."payment_notice where user_id = ".$user_id." and type in (11,13,14)");
- if(count($order_list)>0){
- foreach($order_list as $k=>$v){
- $order_list_array[] = $v['order_id'];
- }
- }else{
- $order_list_array = array();
- }
- }else{
- $order_list_array = array();
- }
- if(count($list)>0){
- foreach($list as $k=>$v){
-
- $sql = "select count(id) as num from ".DB_PREFIX."black where black_user_id = ".$v['user_id']." and user_id = ".$user_id;
- if ($GLOBALS['db']->getOne($sql) > 0){
- $list[$k]['has_black'] = 1;//0:未黑名单;1:黑名单
- }else{
- $list[$k]['has_black'] = 0;
- }
- $list[$k]['is_show_weibo_report'] = 1;
- $list[$k]['is_show_user_report'] = 1;
- $list[$k]['is_show_user_black'] = 1;
- $list[$k]['is_show_top'] = 0;
- $list[$k]['is_show_deal_weibo'] =0;
- $list[$k]['left_time'] = $this->time_tran($v['create_time']);
- if($v['head_image']){
- $list[$k]['head_image'] = deal_weio_image($v['head_image'],'head_image');
- }
- if($v['photo_image']){
- $list[$k]['photo_image'] = deal_weio_image($v['photo_image'],$v['type']);
- }
- $address_x = str_replace("福建省","",$v['address']);
- $address_x = str_replace("福州市","",$address_x);
- $list[$k]['weibo_place'] = $v['province'].$v['city'].$address_x;
- $list[$k]['images_count'] = 0;
- if($v['type']=='video'){
- $list[$k]['images'] = array();
- $url = $v['data'];
- $list[$k]['video_url'] = get_file_oss_url($url);
- }else{
- $images = unserialize($v['data']);
- if(in_array($v['weibo_id'],$order_list_array)){
- $is_pay =1;
- }else{
- $is_pay =0;
- }
- if(count($images)>0){
- foreach($images as $k1=>$v1){
- if(is_object($v1)){
- $v1 = (array)$v1;
- }
- if($v1['url']){
- $is_model = $v1['is_model'];
- $images[$k1]['orginal_url'] = '';
- if($is_model){
- if($is_pay){
- $images[$k1]['url'] = deal_weio_image($v1['url']);
- $images[$k1]['is_model'] = 0;
- $images[$k1]['orginal_url'] = get_spec_image($v1['url']);
- }else{
- $images[$k1]['url'] = deal_weio_image($v1['url'],$v['type'],1);
- }
- }else{
- $images[$k1]['url'] = deal_weio_image($v1['url']);
- $images[$k1]['orginal_url'] = get_spec_image($v1['url']);
- }
- }
- }
- $list[$k]['images'] = $images;
- $list[$k]['images_count'] = count($images);
- }else{
- $list[$k]['images'] = array();
- }
- $list[$k]['video_url'] = '';
- }
- unset($list[$k]['data']);
- }
- }else{
- $list = array();
- }
-
- $GLOBALS['cache']->set($this->key, $list, 10, true);
-
- $GLOBALS['cache']->set($key_bf, $list, 86400, true);//备份
- //echo $this->key;
- }
- }
-
- if ($list == false) $list = array();
-
- return $list;
- }
-
- public function rm()
- {
- //$GLOBALS['cache']->clear_by_name($this->key);
- }
-
- public function clear_all()
- {
-
- //$GLOBALS['cache']->clear_by_name($this->key);
- }
- public function time_tran($the_time)
- {
- $now_time = to_date(NOW_TIME,"Y-m-d H:i:s");
- $now_time = to_timespan($now_time);
- $show_time = to_timespan($the_time);
- $dur = $now_time - $show_time;
- if ($dur < 0) {
- return to_date($show_time,"Y-m-d");
- } else {
- if ($dur < 60) {
- return $dur . '秒前';
- } else {
- if ($dur < 3600) {
- return floor($dur / 60) . '分钟前';
- } else {
- if ($dur < 86400) {
- return floor($dur / 3600) . '小时前';
- } else {
- if ($dur < 2592000) {//30天内
- return floor($dur / 86400) . '天前';
- } else {
- return to_date($show_time,"Y-m-d");
- }
- }
- }
- }
- }
- }
- }
- ?>
|