Jelajahi Sumber

搜索加好友

lizhen_gitee 10 bulan lalu
induk
melakukan
a334e201a9
1 mengubah file dengan 22 tambahan dan 0 penghapusan
  1. 22 0
      application/api/controller/Friend.php

+ 22 - 0
application/api/controller/Friend.php

@@ -143,6 +143,28 @@ class Friend extends Api
         $list = Db::name('user')->field('id,nickname,mobile,avatar')->where('mobile',$keyword)->select();
         $list = list_domain_image($list,['avatar']);
 
+        if(!empty($list)){
+            foreach($list as $key => $val){
+                //是否申请过了
+                $val['is_apply'] = 0;
+                $check_apply = Db::name('friend_apply')->where('user_id',$this->auth->id)->where('to_user_id',$val['id'])->find();
+                if($check_apply){
+                    $val['is_apply'] = 1;
+                }
+
+                //是否是好友
+                $val['is_friend'] = 0;
+                $check_friend1 = Db::name('friend')->where('user_id',$this->auth->id)->where('to_user_id',$val['id'])->find();
+                $check_friend2 = Db::name('friend')->where('user_id',$val['id'])->where('to_user_id',$this->auth->id)->find();
+                if($check_friend1 || $check_friend2){
+                    $val['is_friend'] = 1;
+                }
+
+                //
+                $list[$key] = $val;
+            }
+        }
+
         $this->success(1,$list);
     }