Browse Source

我的好友列表,重写

lizhen_gitee 10 months ago
parent
commit
323aa7f00f
1 changed files with 38 additions and 38 deletions
  1. 38 38
      application/api/controller/Userfollow.php

+ 38 - 38
application/api/controller/Userfollow.php

@@ -76,51 +76,51 @@ class Userfollow extends Api
         $this->success('success',$list);
     }
 
-    //我的好友,拿粉丝列表改的
+    //我的好友,有亲密度就算是好友
     public function my_friend_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,[]);
-        }
-
-        //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'];
+        $intimacy = Db::name('user_intimacy')->alias('ui')
+            ->field(['ui.id','ui.uid','ui.other_uid','ui.value','ui.level','
+            u.nickname as u_nickname','u.avatar as u_avatar','ua.requesttime as ua_requesttime','
+            ou.nickname as ou_nickname','ou.avatar as ou_avatar','oua.requesttime as oua_requesttime'])
+            ->join('user u'         ,'ui.uid = u.id','LEFT')
+            ->join('user_active ua' ,'ui.uid = ua.user_id','LEFT')
+            ->join('user ou'        ,'ui.other_uid = ou.id','LEFT')
+            ->join('user_active oua','ui.other_uid = oua.user_id','LEFT')
+            ->where('(ui.uid = '.$this->auth->id.') or (ui.other_uid = '.$this->auth->id.')')
+            ->where('ui.value','gt','0.1')
+            ->order('ui.value desc, ui.id desc')->select();
+//        dump($intimacy);
+
+        $result = [];
+        if(!empty($intimacy)){
+            foreach($intimacy as $key => $val){
+                $newval = [];
+                if($val['uid'] == $this->auth->id){
+                    $newval = [
+                        'id'               => $val['other_uid'],
+                        'nickname'         => $val['ou_nickname'],
+                        'avatar'           => $val['ou_avatar'],
+                        'requesttime'      => $val['oua_requesttime'],
+                        'intimacy'         => $val['value'],
+                        'requesttime_text' => get_last_time($val['oua_requesttime']),
+                    ];
+                }else{
+                    $newval = [
+                        'id'               => $val['uid'],
+                        'nickname'         => $val['u_nickname'],
+                        'avatar'           => $val['u_avatar'],
+                        'requesttime'      => $val['ua_requesttime'],
+                        'intimacy'         => $val['value'],
+                        'requesttime_text' => get_last_time($val['ua_requesttime']),
+                    ];
                 }
+                $result[] = $newval;
             }
         }
 
-        $this->success(1,$list);
-
+        $this->success(1,$result);
     }