error(); } $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,user.attribute,uw.vip_endtime') ->where('user.username',$username)->order('is_active desc,id asc')->autopage()->select(); $list = list_domain_image($list,['avatar']); $list = list_birthday_age($list); 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'] = $this->is_follow($this->auth->id,$val['id']); } } $this->success('success',$list); } //获取他人用户信息 public function getuserinfo_simple(){ $uid = input_post('uid',0); $field = $this->allowFields; $field[] = 'longitude'; $field[] = '(st_distance(point (' . $this->auth->longitude . ', ' . $this->auth->latitude . '),point(longitude,latitude))*111195) as distance'; $userinfo = Db::name('user')->field($field)->where('id',$uid)->find(); if(!$userinfo){ $this->error('不存在的用户'); } //用户数据 $userinfo = info_domain_image($userinfo,['avatar','photo_images']); $new_data = [ 'age' => birthtime_to_age($userinfo['birthday']), 'truename' => '', ]; //合并 $userinfo = array_merge($userinfo,$new_data); //枚举 $userinfo['tag'] = Db::name('enum_tag')->where('id','IN',$userinfo['tag_ids'])->field(['id','name','color'])->select(); //vip $userinfo['vip_endtime'] = Db::name('user_wallet')->where('user_id',$uid)->value('vip_endtime'); $userinfo['is_vip'] = $userinfo['vip_endtime'] > time() ? 1 : 0; //是否喜欢和关注 $userinfo['is_follow'] = $this->is_follow($this->auth->id,$uid); $userinfo['is_fans'] = $this->is_follow($uid,$this->auth->id); $userinfo['is_friend'] = ($userinfo['is_follow'] && $userinfo['is_fans']) ? 1 : 0; // $is_like = Db::name('user_like')->where(['uid'=>$this->auth->id,'like_uid'=>$uid])->find(); // $userinfo['is_like'] = $is_like ? 1 : 0; //是否拉黑 $is_black = Db::name('user_black')->where(['uid'=>$this->auth->id,'black_uid'=>$uid])->find(); $userinfo['is_black'] = $is_black ? 1 : 0; //关注人数,粉丝人数 $follow_num = Db::name('user_follow')->where(['uid'=>$uid])->count('id'); $fans_num = Db::name('user_follow')->where(['follow_uid'=>$uid])->count('id'); $userinfo['follow_num'] = $follow_num; $userinfo['fans_num'] = $fans_num; //活跃,在线 $userinfo['active_info'] = $this->user_activeinfo($uid); //装扮 $userheader = ""; // 获取用户头像框信息 $map = [ 'a.user_id' => $uid, 'a.is_using' => 1, 'a.end_time' => ['gt',time()], ]; $backResult = Db::name('user_decorate')->alias('a') ->field('a.id,a.decorate_type,b.base_image,b.play_image') ->join('decorate b', 'a.decorate_id = b.id') ->where($map)->order('a.id desc')->select(); $backResult = list_domain_image($backResult,['base_image','play_image']); if ($backResult) { foreach ($backResult as $k => $v) { $v['decorate_type'] == 2 && $userheader = $v['play_image']; } } $userinfo['userheader'] = $userheader; //用户权限 $userinfo['power'] = Db::name('user_power')->where('user_id',$uid)->find(); $userinfo['distance'] = bcdiv(intval($userinfo['distance']),1000,1).'km'; if($this->auth->longitude == 0 || $userinfo['longitude'] == 0){ unset($userinfo['longitude']); $userinfo['distance'] = '未知'; } //vip如果开了隐私保护,需要隐藏距离 $yinsi = $this->user_power($userinfo['id'],'yinsi'); if($yinsi == 1){ $userinfo['distance'] = ''; $userinfo['cityname'] = ''; } $this->success('success',$userinfo); } //获取他人用户信息,留下足迹 public function getuserinfo(){ $uid = input_post('uid',0); $field = $this->allowFields; $field[] = 'longitude'; $field[] = '(st_distance(point (' . $this->auth->longitude . ', ' . $this->auth->latitude . '),point(longitude,latitude))*111195) as distance'; $userinfo = Db::name('user')->field($field)->where('id',$uid)->find(); if(!$userinfo){ $this->error('不存在的用户'); } //用户数据 $userinfo = info_domain_image($userinfo,['avatar','photo_images']); // $idcard_confirm = Db::name('user_idconfirm')->where('user_id',$uid)->find(); $new_data = [ 'age' => birthtime_to_age($userinfo['birthday']), // 'truename' => ($userinfo['idcard_status'] == 1 && isset($idcard_confirm['truename'])) ? $idcard_confirm['truename'] : '', 'truename' => '', ]; //合并 $userinfo = array_merge($userinfo,$new_data); //枚举 $userinfo['tag'] = Db::name('enum_tag')->where('id','IN',$userinfo['tag_ids'])->field(['id','name','color'])->select(); //vip $userinfo['vip_endtime'] = Db::name('user_wallet')->where('user_id',$uid)->value('vip_endtime'); $userinfo['is_vip'] = $userinfo['vip_endtime'] > time() ? 1 : 0; //是否喜欢和关注 $userinfo['is_follow'] = $this->is_follow($this->auth->id,$uid); $userinfo['is_fans'] = $this->is_follow($uid,$this->auth->id); $userinfo['is_friend'] = ($userinfo['is_follow'] && $userinfo['is_fans']) ? 1 : 0; // $is_like = Db::name('user_like')->where(['uid'=>$this->auth->id,'like_uid'=>$uid])->find(); // $userinfo['is_like'] = $is_like ? 1 : 0; //是否拉黑 $is_black = Db::name('user_black')->where(['uid'=>$this->auth->id,'black_uid'=>$uid])->find(); $userinfo['is_black'] = $is_black ? 1 : 0; //关注人数,粉丝人数 $follow_num = Db::name('user_follow')->where(['uid'=>$uid])->count('id'); $fans_num = Db::name('user_follow')->where(['follow_uid'=>$uid])->count('id'); $userinfo['follow_num'] = $follow_num; $userinfo['fans_num'] = $fans_num; //查看别人信息,就要留下痕迹 if($this->user_power($this->auth->id,'wuhen') != 1){ if($this->apiLimit(1,1000) == true){ $data = [ 'uid' => $this->auth->id, 'to_uid' => $uid, ]; $check = Db::name('user_visit')->where($data)->find(); if($check){ Db::name('user_visit')->where($data)->update(['number'=>$check['number']+1,'updatetime'=>time()]); }else{ $data['number'] = 1; $data['updatetime'] = time(); Db::name('user_visit')->insertGetId($data); } } } //活跃,在线 $userinfo['active_info'] = $this->user_activeinfo($uid); //装扮 $userheader = ""; // 获取用户头像框信息 $map = [ 'a.user_id' => $uid, 'a.is_using' => 1, 'a.end_time' => ['gt',time()], ]; $backResult = Db::name('user_decorate')->alias('a') ->field('a.id,a.decorate_type,b.base_image,b.play_image') ->join('decorate b', 'a.decorate_id = b.id') ->where($map)->order('a.id desc')->select(); $backResult = list_domain_image($backResult,['base_image','play_image']); if ($backResult) { foreach ($backResult as $k => $v) { $v['decorate_type'] == 2 && $userheader = $v['play_image']; } } $userinfo['userheader'] = $userheader; //用户权限 $userinfo['power'] = Db::name('user_power')->where('user_id',$uid)->find(); $userinfo['distance'] = bcdiv(intval($userinfo['distance']),1000,1).'km'; if($this->auth->longitude == 0 || $userinfo['longitude'] == 0){ unset($userinfo['longitude']); $userinfo['distance'] = '未知'; } //vip如果开了隐私保护,需要隐藏距离 $yinsi = $this->user_power($userinfo['id'],'yinsi'); if($yinsi == 1){ $userinfo['distance'] = ''; $userinfo['cityname'] = ''; } $this->success('success',$userinfo); } //获取他人主页,简版 public function getuserinfo_domain(){ $uid = input_post('uid',0); $field = $this->allowFields; $field[] = 'longitude'; $field[] = '(st_distance(point (' . $this->auth->longitude . ', ' . $this->auth->latitude . '),point(longitude,latitude))*111195) as distance'; $userinfo = Db::name('user')->field($field)->where('id',$uid)->find(); if(!$userinfo){ $this->error('不存在的用户'); } //用户数据 $userinfo = info_domain_image($userinfo,['avatar','photo_images']); //是否关注 $userinfo['is_follow'] = $this->is_follow($this->auth->id,$uid); $userinfo['is_vip'] = $this->is_vip($uid); //是否拉黑 $is_black = Db::name('user_black')->where(['uid'=>$this->auth->id,'black_uid'=>$uid])->find(); $userinfo['is_black'] = $is_black ? 1 : 0; //关注人数,粉丝人数 $follow_num = Db::name('user_follow')->where(['uid'=>$uid])->count('id'); $fans_num = Db::name('user_follow')->where(['follow_uid'=>$uid])->count('id'); $userinfo['follow_num'] = $follow_num; $userinfo['fans_num'] = $fans_num; //查看别人信息,就要留下痕迹 if($this->user_power($this->auth->id,'wuhen') != 1){ if($this->apiLimit(1,1000) == true){ $data = [ 'uid' => $this->auth->id, 'to_uid' => $uid, ]; $check = Db::name('user_visit')->where($data)->find(); if($check){ Db::name('user_visit')->where($data)->update(['number'=>$check['number']+1,'updatetime'=>time()]); }else{ $data['number'] = 1; $data['updatetime'] = time(); Db::name('user_visit')->insertGetId($data); } } } //活跃,在线 $userinfo['active_info'] = $this->user_activeinfo($uid); $userinfo['distance'] = bcdiv(intval($userinfo['distance']),1000,1).'km'; if($this->auth->longitude == 0 || $userinfo['longitude'] == 0){ unset($userinfo['longitude']); $userinfo['distance'] = '未知'; } //vip如果开了隐私保护,需要隐藏距离 $yinsi = $this->user_power($userinfo['id'],'yinsi'); if($yinsi == 1){ $userinfo['distance'] = ''; $userinfo['cityname'] = ''; } $this->success('success',$userinfo); } public function getuserinfo_domain2(){ $uid = input_post('uid',0); $field = $this->allowFields; $userinfo = Db::name('user')->field($field)->where('id',$uid)->find(); if(!$userinfo){ $this->error('不存在的用户'); } $new_data = [ 'age' => birthtime_to_age($userinfo['birthday']), ]; //合并 $userinfo = array_merge($userinfo,$new_data); //枚举 $userinfo['tag'] = Db::name('enum_tag')->where('id','IN',$userinfo['tag_ids'])->field(['id','name','color'])->select(); //vip如果开了隐私保护,需要隐藏距离 $yinsi = $this->user_power($userinfo['id'],'yinsi'); if($yinsi == 1){ $userinfo['cityname'] = ''; } $this->success('success',$userinfo); } /** * calc_map_distance() , 根据地图上的两个点各自的x,y坐标,计算出2点之间的直线距离 * @param array $point_1 第1个点的x,y坐标 array( 101 , 202 ) * @param array $point_2 第2个点的x,y坐标 array( 101 , 202 ) * @param bool $calc_as_string 是否计算为字符串公里距离 , 如果未否返回数字 * @return float | false | string */ private function calc_map_distance( $point_1=array( ) , $point_2=array( ) , $calc_as_string=false ) { if( empty( $point_1 ) || empty( $point_2 ) ){ return false; } // 经纬度不存在,或者经纬度超过最大范围 +-180 , +-90 ,返回false $p1_x = $point_1[0]; $p1_y = $point_1[1]; $p2_x = $point_2[0]; $p2_y = $point_2[1]; if( $p1_x < -180 || $p1_x > 180 || $p2_x < -180 || $p2_x > 180 || $p1_y < -90 || $p1_y > 90 || $p2_y < -90 || $p2_y > 90 ){ return '0公里'; } // 根据2点各自的坐标,计算2点之间直线距离的公式 $distance = round(6378.138*2*asin(sqrt(pow(sin(( $p1_x *pi()/180-$p2_x*pi()/180)/2),2)+cos( $p1_x *pi()/180)*cos($p2_x*pi()/180)* pow(sin(( $p1_y *pi()/180-$p2_y*pi()/180)/2),2)))*1000); // 是否计算为字符串公里距离 if( !$calc_as_string ){ return (string)round( $distance / 1000 , 1 ) . '公里'; } // 如果计算为字符串公里距离 if( $distance / 1000 > 1 ){ $k = (string)round( $distance / 1000 , 1 ); $m = (string)$distance % 1000 ; $distance = "{$k}公里{$m}米"; } else{ $distance = "{$distance}米"; } return $distance; } //地图api,根据两地坐标,获得两地距离,打卡用的 //type=0直线,type=1开车 private function getmapjuli($start_lon,$start_lat,$end_lon,$end_lat,$type = 0){ $result = 0; $apiurl = 'https://restapi.amap.com/v3/distance?'; $param = [ 'key' => '398c424811d1a59beac2f915323d334e', 'origins' => $start_lon.','.$start_lat, 'destination' => $end_lon.','.$end_lat, 'type' => $type, 'output' => 'json', ]; $apiurl .= http_build_query($param); $request_rs = json_decode(curl_get($apiurl),true); if(isset($request_rs['status']) && $request_rs['status'] == 1){ if(isset($request_rs['results'][0]['distance'])) { $result = $request_rs['results'][0]['distance']; } } //dump($result); return $result; } public function distance() { $a = $this->calc_map_distance([118.339282,35.028445],[118.437399,35.017438]); dump($a); $a = $this->calc_map_distance([118.339282,35.028445],[118.437399,35.017438],true); dump($a); $b = $this->getmapjuli(118.339282,35.028445,118.437399,35.017438,1); dump($b); $b = $this->getmapjuli(118.339282,35.028445,118.437399,35.017438,0); dump($b); } }