panda 1 năm trước cách đây
mục cha
commit
57aa875ec3
1 tập tin đã thay đổi với 178 bổ sung0 xóa
  1. 178 0
      application/api/controller/Index.php

+ 178 - 0
application/api/controller/Index.php

@@ -559,6 +559,184 @@ class Index extends Api
         $this->success('筛选年龄段', $list);
     }
 
+    public function nearUserNew()
+    {
+        //        if(empty($this->auth->longitude) || empty($this->auth->latitude)){
+//            // $this->success('success',[]);
+//            $this->error('请先开启定位');
+//        }
+
+//        $type = input('type', 0, 'intval'); //类型: 0附近 1缘分
+        $type = input('type', 0, 'intval'); //类型: 0推荐 1附近 2新人
+        $age_id = input('age_id', 0, 'intval'); //年龄段
+//        $agemin = input('agemin', 0, 'intval'); //最小年龄
+//        $agemax = input('agemax', 100, 'intval'); //最大年龄
+
+        //经过地图测算和公式推算,经度纬度 0.1即为11公里
+        $map = [
+            'user.status' => 1,
+            ////'user.cityname' => $this->auth->cityname,
+            'user.id' => ['neq',$this->auth->id],
+            'user.is_kefu' => 0,
+//            'user.longitude' => ['between',[$this->auth->longitude - 0.1,$this->auth->longitude + 0.1]],
+//            'user.latitude' => ['between',[$this->auth->latitude - 0.1,$this->auth->latitude + 0.1]],
+            // 'user.is_online|user.is_livebc' => 1, //完全不考虑直播与语聊的权重,只用活跃做排序
+//            'user.active_time' => ['gt',time()-86400],
+        ];
+
+        //排序
+        $order = 'user.is_active desc, user.active_time desc';
+        if (in_array($type,[0,1])) {
+            if ($this->auth->gender == 1) {
+                $order = 'user.is_active desc, user.active_time desc, uw.get_money desc';
+//                $order = 'user.is_active desc, user.active_time desc';
+            } else {
+                $order = 'user.is_active desc, user.active_time desc, uw.pay_money desc';
+//                $order = 'user.is_active desc, user.active_time desc';
+            }
+        }
+        if ($type == 0) {
+//            $map['user.cityname'] = $this->auth->cityname; //同城
+            if ($this->auth->gender == 1) {
+                $map['user.is_recommend'] = 1;
+            }
+            //$order = 'user.is_active desc, uw.pay_money desc,uw.get_money desc';
+        } elseif ($type == 1) {
+//            $map['user.longitude'] = ['between',[$this->auth->longitude - 0.1,$this->auth->longitude + 0.1]];
+//            $map['user.latitude'] = ['between',[$this->auth->latitude - 0.1,$this->auth->latitude + 0.1]];
+        } else {
+            $map['user.createtime'] = ['egt', time() - 86400 * 30];
+//            $order = 'user.createtime desc';
+        }
+
+        if($this->auth->gender == 1){
+            $map['user.gender'] = 0;
+        } else {
+            $map['user.gender'] = 1;
+        }
+
+        if ($age_id > 0 && $age_id < 8) {
+            if ($age_id == 1) {
+                $agemin = 18;
+                $agemax = 25;
+            } elseif ($age_id == 2) {
+                $agemin = 25;
+                $agemax = 30;
+            } elseif ($age_id == 3) {
+                $agemin = 30;
+                $agemax = 35;
+            } elseif ($age_id == 4) {
+                $agemin = 35;
+                $agemax = 40;
+            } elseif ($age_id == 5) {
+                $agemin = 40;
+                $agemax = 45;
+            } elseif ($age_id == 6) {
+                $agemin = 45;
+                $agemax = 50;
+            } elseif ($age_id == 7) {
+                $agemin = 50;
+                $agemax = 200;
+            }
+
+            $map['user.birthday'] = ['between', [time() - $agemax * 31536000, time() - $agemin * 31536000]];
+        }
+
+        //dump($map);
+        $field = [
+            'user.id','user.nickname','user.birthday','user.height','user.longitude','user.latitude','user.avatar','user.bio','user.gender','user.idcard_status', 'user.real_status', 'user.job_id', 'user.is_active', 'user.wages_id', 'user.is_recommend', 'user.cityname', 'user.hometown_cityid', 'user.is_hideaddress'
+        ];
+
+        //$list = Db::name('user')->alias('user')->field($field)->where($map)->order($order)->autopage()->select();
+        $list = Db::name('user')->alias('user')->field($field)
+             ->join('user_wallet uw','uw.user_id = user.id','LEFT')
+            ->where($map)->order($order)->autopage()->select();
+        //dump($list);exit;
+
+        $list = list_domain_image($list,['avatar']);
+
+        $mt_enum_job = Db::name('enum_job'); //职业
+        $mt_enum_wages = Db::name('enum_wages'); //收入
+        $mt_user_wallet = Db::name('user_wallet'); //vip
+        $mt_user_greet = Db::name('user_greet'); //是否打过招呼
+        $mt_wealth_level = Db::name('wealth_level'); //财富等级
+        $mt_area = Db::name('area'); //城市
+        $time = time();
+
+        foreach($list as $key => &$v) {
+            if ($this->auth->gender == 1) { //用户是男的
+                $age = birthtime_to_age($v['birthday']);
+//                $job = $mt_enum_job->where(['id' => $v['job_id']])->value('name');
+
+//                $v['desc'] = $distance . ' · ' . $age . '岁';
+                $v['desc'] = '';
+                if ($age > 0) {
+                    $v['desc'] = $age . '岁';
+                } else {
+                    $v['desc'] = '18岁';
+                }
+                if ($v['height']) {
+                    $v['desc'] .= ' | ' . $v['height'];
+                }
+//                if ($job) {
+//                    $v['desc'] .= ' · ' . $job;
+//                }
+                if ($type == 1) {
+//                    $distance = $this->calc_map_distance([$this->auth->longitude, $this->auth->latitude], [$v['longitude'], $v['latitude']]);
+//                    $v['desc'] .= ' | ' . $distance;
+                    $v['desc'] .= ' | 10km+';
+                }
+            } else {
+                if ($type != 1) {
+                    $v['desc'] = $v['bio'] ?: '暂未设置个性签名';
+                } else {
+                    $age = birthtime_to_age($v['birthday']);
+//                    $wages = $mt_enum_wages->where(['id' => $v['wages_id']])->value('name');
+
+//                $v['desc'] = $distance . ' · ' . $age . '岁';
+                    $v['desc'] = '';
+                    if ($age > 0) {
+                        $v['desc'] = $age . '岁';
+                    } else {
+                        $v['desc'] = '18岁';
+                    }
+                    if ($v['hometown_cityid']) {
+                        $hometown_city = $mt_area->where('id',$v['hometown_cityid'])->value('name');
+                        $hometown_city = ($hometown_city && $v['is_hideaddress'] == 0) ? $hometown_city : '';
+                        if ($hometown_city) {
+                            $v['desc'] .= ' | ' . $hometown_city;
+                        }
+                    }
+//                    if ($wages) {
+//                        $v['desc'] .= ' · ' . $wages;
+//                    }
+                }
+            }
+            //查询是否打过招呼
+            $count = $mt_user_greet->where(['user_id' => $this->auth->id, 'user_to_id' => $v['id']])->count('id');
+            if ($count) {
+                $v['is_chat'] = 1; //是否打过招呼: 1是  0否
+            } else {
+                $v['is_chat'] = 0; //是否打过招呼: 1是  0否
+            }
+            $vip_endtime = $mt_user_wallet->where(['user_id' => $v['id']])->find();//->value('vip_endtime');
+            if ($vip_endtime['vip_endtime'] >= $time) {
+                $v['is_vip'] = 1; //是否是vip: 1是 0否
+            } else {
+                $v['is_vip'] = 0; //是否是vip: 1是 0否
+            }
+            //查询财富等级
+            $wealth_level = $mt_wealth_level->where(['value' => ['elt', $vip_endtime['pay_money']]])->order('id desc')->find();
+            if ($wealth_level) {
+                $v['wealth_level'] = $wealth_level['name'];
+            } else {
+                $v['wealth_level'] = '';
+            }
+        }
+
+        $this->success('success',$list);
+    }
+
     //推荐/附近/新人
     public function nearuser(){
 //        if(empty($this->auth->longitude) || empty($this->auth->latitude)){