123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use think\Db;
- use app\common\model\wallet;
- use Redis;
- /**
- * 会员中心,不是个人中心
- */
- class Usercenter extends Api
- {
- protected $noNeedLogin = [];
- protected $noNeedRight = '*';
- protected $allowFields = [
- 'id',
- 'username',
- 'nickname',
- 'avatar',
- 'mobile',
- 'idcard_status',
- 'real_status',
- 'cityname',
- 'gender',
- 'height',
- 'weight',
- 'birthday',
- 'bio',
- 'audio_bio',
- 'audio_seconds',
- 'video_bio',
- 'photo_images',
- 'marital_id',
- 'job_id',
- 'suqiu_id',
- 'wages_id',
- 'tag_ids',
- 'hobby_ids',
- 'open_match_video',
- 'open_match_audio',
- 'match_video_price',
- 'match_audio_price',
- 'match_typing_price',
- 'wealth_level','charm_level',
- ];
- protected $allowFields_simple = [
- 'id',
- 'username',
- 'nickname',
- 'avatar',
- 'idcard_status',
- 'real_status',
- 'gender',
- 'open_match_video',
- 'open_match_audio',
- 'match_video_price',
- 'match_audio_price',
- 'match_typing_price',
- ];
- //获取他人用户信息
- public function getuserinfo_simple(){
- $uid = input_post('uid',0);
- $field = $this->allowFields_simple;
- $userinfo = Db::name('user')->field($field)->where('id',$uid)->find();
- if(!$userinfo){
- $this->error('不存在的用户');
- }
- //用户数据
- $userinfo = info_domain_image($userinfo,['avatar']);
- //是否喜欢和关注
- $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_black = Db::name('user_black')->where(['uid'=>$this->auth->id,'black_uid'=>$uid])->find();
- $userinfo['is_black'] = $is_black ? 1 : 0;
- //活跃,在线
- $userinfo['active_info'] = $this->user_activeinfo($uid);
- //此用户与我的亲密度 信息
- $userinfo['intimacy_info'] = $this->get_intimacy_info($uid);
- //我给他的备注
- $nickname_remark = Db::name('nickname_remark')->where(['uid'=>$this->auth->id,'to_uid'=>$uid])->value('nickname_remark');
- $userinfo['nickname_remark'] = !empty($nickname_remark) ? $nickname_remark : '';
- //登录用户的金币余额
- $userinfo['my_goldtotal'] = model('wallet')->getWallettotal($this->auth->id);
- $userinfo['my_wallet'] = Db::name('user_wallet')->field(['audio_sec','video_sec','typing_times'])->where('user_id',$this->auth->id)->find();
- //是否客服
- $userinfo['is_kefu'] = 0;
- $kefu_ids = config('site.kefu_user_ids');
- if(in_array($uid,explode(',',$kefu_ids))){
- $userinfo['is_kefu'] = 1;
- }
- $this->success('success',$userinfo);
- }
- //两个人的亲密度
- //api/match/intimacylevel
- private function get_intimacy_info($user_id){
- //$user_id = input('user_id', 0, 'intval'); //对方id
- if ($this->auth->id > $user_id) { //大的在后
- $where['uid'] = $user_id;
- $where['other_uid'] = $this->auth->id;
- } else { //小的在前
- $where['uid'] = $this->auth->id;
- $where['other_uid'] = $user_id;
- }
- $level = 0; //当前等级
- $level_name = ''; //当前等级名称
- $qinmi_sum = 0; //当前亲密度
- $level_info = [];
- $next_level_info = [];
- $next_level_diff = 0; //距下一等级亲密度差值
- $next_level_name = ''; //下一等级名称
- $next_level_value = 0;//下一等级亲密度值
- $user_intimacy_info = Db::name('user_intimacy')->where($where)->find();
- if ($user_intimacy_info) {
- //当前亲密度
- $qinmi_sum = $user_intimacy_info['value'];
- //当前等级信息
- $level_info = Db::name('intimacy_level')->where(['value' => ['elt', $user_intimacy_info['value']]])->order('level desc')->find();
- if ($level_info) {
- $level = $level_info['level'];
- $level_name = $level_info['name'];
- }
- //下一等级信息
- $next_level_info = Db::name('intimacy_level')->where(['value' => ['gt', $user_intimacy_info['value']]])->order('value')->find();
- if ($next_level_info) {
- $next_level_name = $next_level_info['name'];
- $next_level_value = $next_level_info['value'];
- $next_level_diff = bcsub($next_level_info['value'],$user_intimacy_info['value'],2);
- }
- }else{
- $level = 1; //当前等级
- $level_name = '初级'; //当前等级名称
- $qinmi_sum = 0; //当前亲密度
- $level_info = Db::name('intimacy_level')->where('level',1)->find();
- $next_level_info = Db::name('intimacy_level')->where('level',2)->find();
- $next_level_diff = $next_level_info['value'];
- $next_level_name = $next_level_info['name'];
- $next_level_value = $next_level_info['value'];
- }
- //如果客服,权限直接覆盖
- $kefu_ids = config('site.kefu_user_ids');
- if(in_array($user_id,explode(',',$kefu_ids)) || in_array($this->auth->id,explode(',',$kefu_ids))){
- $level_info['typing_switch'] = 1;
- $level_info['sound_switch'] = 1;
- $level_info['audio_switch'] = 0;
- $level_info['video_switch'] = 0;
- $level_info['image_switch'] = 1;
- }
- unset($level_info['id']);
- unset($level_info['name']);
- unset($level_info['level']);
- unset($level_info['value']);
- $data['level'] = $level; //当前等级
- $data['level_name'] = $level_name; //当前等级名称
- $data['qinmi_sum'] = $qinmi_sum; //当前亲密度
- $data['level_info'] = $level_info; //当前亲密度
- $data['next_level_diff'] = $next_level_diff; //距下一等级亲密度差值
- $data['next_level_name'] = $next_level_name; //下一等级名称
- $data['next_level_value'] = $next_level_value; //下一等级亲密度值
- return $data;
- }
- //获取他人用户信息,留下足迹
- public function getuserinfo(){
- $uid = input_post('uid',0);
- $field = $this->allowFields;
- $userinfo = Db::name('user')->field($field)->where('id',$uid)->find();
- if(!$userinfo){
- $this->error('不存在的用户');
- }
- //用户数据
- $userinfo = info_domain_image($userinfo,['avatar','photo_images','video_bio','audio_bio']);
- $new_data = [
- 'age' => birthtime_to_age($userinfo['birthday']),
- 'birthday' => date('Y-m-d',$userinfo['birthday']),
- ];
- //合并
- $userinfo = array_merge($userinfo,$new_data);
- //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_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->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);
- //用户权限
- $user_power = Db::name('user_power')->where('user_id',$uid)->find();
- //此用户与我的亲密度 信息
- $userinfo['intimacy_info'] = $this->get_intimacy_info($uid);
- //我给他的备注
- $nickname_remark = Db::name('nickname_remark')->where(['uid'=>$this->auth->id,'to_uid'=>$uid])->value('nickname_remark');
- $userinfo['nickname_remark'] = !empty($nickname_remark) ? $nickname_remark : '';
- //vip如果开了隐私保护,需要隐藏距离
- if($user_power['weizhi'] == 0){
- $userinfo['cityname'] = '';
- }
- //追加登录用户的头像
- $userinfo['my_avatar'] = localpath_to_netpath($this->auth->avatar);
- //此用户与我的亲密度 信息
- //api/match/intimacylevel
- //最新一条动态
- $last_dongtai = Db::name('topic_dongtai')->field('content,images')->where('user_id',$uid)->where('type',1)->where('auditstatus',1)->order('id desc')->find();
- $last_dongtai = info_domain_image($last_dongtai,['images']);
- $userinfo['last_dongtai'] = $last_dongtai;
- //礼物墙
- $userinfo['gift_wall'] = [];
- if($user_power['giftwall'] == 1){
- $gift_wall = Db::name('gift_user_typing')->alias('log')
- ->join('gift', 'gift.id = log.gift_id', 'LEFT')
- ->field('log.id,log.gift_name,sum(log.number) as number,gift.image')
- ->where(['log.user_to_id' => $uid])
- ->group('log.gift_id')
- ->order('gift.price desc')
- ->select();
- $gift_wall = list_domain_image($gift_wall,['image']);
- $userinfo['gift_wall'] = $gift_wall;
- }
- //价格显示开关
- $userinfo['usersite_matchinfo_switch'] = config('site.usersite_matchinfo_switch');
- //财富等级,魅力等级
- if($user_power['meili'] == 1){
- $userinfo['charm_image'] = Db::name('charm_level')->where('level',$userinfo['charm_level'])->value('image');
- }else{
- $userinfo['charm_image'] = '';
- $userinfo['charm_level'] = '';
- }
- if($user_power['caifu'] == 1){
- $userinfo['wealth_image'] = Db::name('wealth_level')->where('level',$userinfo['wealth_level'])->value('image');
- }else{
- $userinfo['wealth_image'] = '';
- $userinfo['wealth_level'] = '';
- }
- //是否客服
- $userinfo['is_kefu'] = 0;
- $kefu_ids = config('site.kefu_user_ids');
- if(in_array($uid,explode(',',$kefu_ids))){
- $userinfo['is_kefu'] = 1;
- }
- $this->success('success',$userinfo);
- }
- //给对方设置备注
- public function set_nickname_remark(){
- if($this->apiLimit(1,1000) == false){
- $this->error('操作频繁');
- }
- $user_id = input('user_id');
- $remark = input('nickname_remark','');
- $map = [
- 'uid' => $this->auth->id,
- 'to_uid' => $user_id,
- ];
- $check = Db::name('nickname_remark')->where($map)->find();
- if($check){
- Db::name('nickname_remark')->where($map)->update(['nickname_remark'=>$remark]);
- }else{
- $map['nickname_remark'] = $remark;
- Db::name('nickname_remark')->insertGetId($map);
- }
- $this->success('设置成功');
- }
- //搜索用户列表
- public function search_user_list(){
- $username = input('username','');
- if(!$username){
- $this->error();
- }
- $uid = Db::name('user')->where('username',$username)->value('id');
- if(empty($uid)){
- $this->error('不存在的用户');
- }
- $this->success('success',$uid);
- }
- /**
- * 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);
- }
- }
|