Browse Source

我的好友列表

lizhen_gitee 1 year ago
parent
commit
7d56e6ffba
2 changed files with 37 additions and 26 deletions
  1. 36 25
      application/api/controller/Userfollow.php
  2. 1 1
      application/common.php

+ 36 - 25
application/api/controller/Userfollow.php

@@ -86,38 +86,49 @@ class Userfollow extends Api
 
     //我的好友,拿粉丝列表改的
     public function my_friend_list(){
-        $list = Db::name('user_follow')
-            ->alias('follow')
-            ->join('user','follow.uid = user.id','LEFT')
-            ->join('user_wallet uw','user.id = uw.user_id','LEFT')
-            ->field('user.id,user.username,user.nickname,user.avatar,user.bio,user.birthday,user.gender,user.attribute,uw.vip_endtime')
-            ->where('follow.follow_uid',$this->auth->id)
-            ->group('follow.uid')
-            ->order('follow.id desc')->autopage()->select();
-
-        $list = list_domain_image($list,['avatar']);
-        $list = list_birthday_age($list);
-
         //我的关注uids
         $my_follow_uids = $this->my_follow_uids();
+        //我的粉丝uids
+        $my_fans_uids = $this->my_fans_uids();
+        //合集就是朋友
+        $friend_ids = array_intersect($my_follow_uids,$my_fans_uids);
+        //dump($friend_ids);
+        //好友列表
+        $list = Db::name('user')->alias('user')
+            ->field('user.id,user.nickname,user.avatar,a.requesttime')
+            ->join('user_active a','user.id = a.user_id','LEFT')
+            ->where('user.id','IN',$friend_ids)->autopage()->order('user.id asc')->select();
+        if(empty($list)){
+            $this->success(1,[]);
+        }
 
-        $new_rs = []; //另起
-        if(!empty($list)){
-            foreach($list as $key => &$val){
-                //用户vip
-                $val['is_vip'] = $val['vip_endtime'] > time() ? 1 : 0;
-                unset($val['vip_endtime']);
-                //是否关注
-                $val['is_follow'] = in_array($val['id'],$my_follow_uids) ? 1 : 0;
-                //我的粉丝,且是我的关注的,另起
-                if($val['is_follow'] == 1){
-                    $new_rs[] = $val;
+        //dump($list);
+
+        $list_ids = implode(',',array_column($list,'id'));
+        //dump($list_ids);
+
+        //亲密度列表
+        $intimacy = Db::name('user_intimacy')->where('(uid = '.$this->auth->id.' and other_uid in ('.$list_ids.')) or (uid in ('.$list_ids.') and other_uid = '.$this->auth->id.')')->select();
+        //dump($intimacy);
+
+        foreach($list as $key => &$val){
+
+            $val['intimacy'] = 0;
+            $val['requesttime_text'] = get_last_time($val['requesttime']);
+
+            foreach($intimacy as $k => $v){
+
+                if($v['uid'] == $this->auth->id && $v['other_uid'] == $val['id']){
+                    $val['intimacy'] = $v['value'];
+                }
+                if($v['uid'] == $val['id'] && $v['other_uid'] == $this->auth->id){
+                    $val['intimacy'] = $v['value'];
                 }
             }
-
         }
 
-        $this->success('success',$new_rs);
+        $this->success(1,$list);
+
     }
 
     //好友待审核列表。

+ 1 - 1
application/common.php

@@ -773,7 +773,7 @@ function get_last_time($time = NULL) {
     $t = $nowtime - $time; //时间差 (秒)
     $y = date('Y', $time)-date('Y', $nowtime);//是否跨年
     switch($t){
-        case $t == 0:
+        case 0:
             $text = '刚刚';
             break;
         case $t < 60: