Browse Source

搜索用户接口

lizhen_gitee 6 months ago
parent
commit
409fa5b5d5
1 changed files with 39 additions and 1 deletions
  1. 39 1
      application/api/controller/Usercenter.php

+ 39 - 1
application/api/controller/Usercenter.php

@@ -48,7 +48,11 @@ class Usercenter extends Api
 
         $list = Db::name('user')->alias('user')
             ->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,uw.vip_endtime')
+            ->field([
+                'user.id','user.username','user.nickname','user.avatar','user.bio','user.birthday','user.gender','user.longitude','user.latitude','user.height','user.weight','user.cityname',
+                'uw.vip_endtime',
+                '(st_distance(point (' . $this->auth->longitude . ', ' . $this->auth->latitude . '),point(user.longitude,user.latitude))*111195) as distance',
+            ])
             ->where('user.username',$username)->order('is_active desc,id asc')->autopage()->select();
 
         $list = list_domain_image($list,['avatar']);
@@ -59,8 +63,42 @@ class Usercenter extends Api
                 //用户vip
                 $val['is_vip'] = $val['vip_endtime'] > time() ? 1 : 0;
                 unset($val['vip_endtime']);
+
+                $val['distance'] = bcdiv(intval($val['distance']),1000,1).'km';
+                if($this->auth->longitude == 0 || $val['longitude'] == 0){
+                    $val['distance'] = '未知';
+                }
+
+                //简单信息
+                $simple_info = '';
+                if(!empty($val['height'])){
+                    $simple_info .= $val['height'];
+                }
+                if(!empty($val['weight'])){
+                    if(!empty($simple_info)){
+                        $simple_info .= '|';
+                    }
+                    $simple_info .= $val['weight'];
+                }
+                if(!empty($val['cityname'])){
+                    if(!empty($simple_info)){
+                        $simple_info .= '|';
+                    }
+                    $simple_info .= $val['cityname'];
+                }
+                $val['simple_info'] = $simple_info;
+
                 //是否关注
                 $val['is_follow'] = $this->is_follow($this->auth->id,$val['id']);
+
+                //
+                unset($val['longitude']);
+                unset($val['latitude']);
+                unset($val['height']);
+                unset($val['weight']);
+                unset($val['cityname']);
+                unset($val['vip_endtime']);
+                unset($val['birthday']);
             }
         }