Browse Source

获取视频用户的过滤方法

lizhen_gitee 3 years ago
parent
commit
e739994996
1 changed files with 109 additions and 16 deletions
  1. 109 16
      application/api/controller/Usercenter.php

+ 109 - 16
application/api/controller/Usercenter.php

@@ -10,22 +10,19 @@ use think\Db;
  */
 class Usercenter extends Api
 {
-    protected $noNeedLogin = [];
+    protected $noNeedLogin = ['test'];
     protected $noNeedRight = '*';
 
+    public function test(){
+        $a = [1,4,10,22,66,36,102,45,23,52,35,76,7];
+        $b = [1,10,7,102];
+        $c = [10,102];
 
-
-
-    public function test()
-    {
-        $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);
+        //dump(array_intersect($a,$b));
+        $data = array_merge($c,$b);
+        dump($data);
+        dump(array_flip(array_flip($data)));
+        dump(array_flip([]));
     }
 
     //同城
@@ -34,6 +31,10 @@ class Usercenter extends Api
         $agemin = input_post('agemin',0);
         $agemax = input_post('agemax',100);
 
+        if(empty($this->auth->cityname) || empty($this->auth->longitude) || empty($this->auth->latitude)){
+            $this->success('success',[]);
+        }
+
         $map = [
             'user.status' => 1,
             'user.cityname' => $this->auth->cityname,
@@ -73,12 +74,17 @@ class Usercenter extends Api
         $agemin = input_post('agemin',0);
         $agemax = input_post('agemax',100);
 
+        if(empty($this->auth->cityname) || empty($this->auth->longitude) || empty($this->auth->latitude)){
+            $this->success('success',[]);
+        }
+
+        //经过地图测算和公式推算,经度纬度 0.1即为11公里
         $map = [
             'user.status' => 1,
             //'user.cityname' => $this->auth->cityname,
             'user.id' => ['neq',$this->auth->id],
             'user.longitude' => ['between',[$this->auth->longitude - 0.1,$this->auth->longitude + 0.1]],
-            'user.latitude' => ['between',[$this->auth->latitude - 0.01,$this->auth->latitude + 0.01]],
+            'user.latitude' => ['between',[$this->auth->latitude - 0.1,$this->auth->latitude + 0.1]],
         ];
         if($gender != 'all'){
             $map['user.gender'] = $gender;
@@ -107,6 +113,81 @@ class Usercenter extends Api
 
     }
 
+    //视频匹配
+    public function getvideouser(){
+        $map = [
+            'status' =>1,
+            //'gender' => $this->auth->gender == 1 ? 0 : 1,
+            //'real_status' => 1,
+            //打开视频开关的
+            'id' => ['neq',$this->auth->id]
+
+        ];
+
+        $lists = Db::name('user')->field('id,cityname,status,gender,real_status,tag_ids')->where($map)->order('logintime desc')->page($this->page,100)->select();
+
+        $lists = $this->fliter_user($lists);
+        $this->success('success',$lists);
+    }
+
+    private function fliter_user($lists){
+
+        //预留全部
+        $result = array_column($lists,'id');
+
+        //提取同城的
+        $citydata = [];
+        foreach($lists as $key => $val){
+            if( !empty($this->auth->cityname) && $this->auth->cityname == $val['cityname'] ){
+                $citydata[] = $val['id'];
+            }
+        }
+
+        //有标签交集的
+        $tagdata = [];
+        foreach($lists as $key => $val){
+            if( !empty($this->auth->tag_ids) && !empty($val['tag_ids']) ){
+
+                $auth_tag_ids = explode(',',$this->auth->tag_ids);
+                $val_tag_ids  = explode(',',$val['tag_ids']);
+                if(count(array_intersect($auth_tag_ids,$val_tag_ids)) > 0){
+                    $tagdata[] = $val['id'];
+                }
+            }
+        }
+
+        //两个都满足
+        $double_data = [];
+        if(!empty($citydata) && !empty($tagdata)){
+            $double_data = array_intersect($citydata,$tagdata);
+        }
+
+        //两种条件合并,去重。空数组合并没影响
+        $merge_data = array_merge($citydata,$tagdata);
+        $merge_data = array_flip(array_flip($merge_data));
+
+        //最终结果
+
+        //双条件数量足够就return
+        if(count($double_data) >= 1){
+            //echo __LINE__;
+            return $double_data;
+        }
+
+        //不够就合并
+        $result_data = array_merge($double_data,$merge_data);
+        $result_data = array_flip(array_flip($result_data));
+        if(count($result_data) >= 1){
+            //echo __LINE__;
+            return $result_data;
+        }
+
+        //仍然不够,全合并
+        $all_data = array_merge($result_data,$result);
+        $all_data = array_flip(array_flip($all_data));
+        return $all_data;
+    }
+
 
     /**
      * calc_map_distance() , 根据地图上的两个点各自的x,y坐标,计算出2点之间的直线距离
@@ -115,7 +196,7 @@ class Usercenter extends Api
      * @param bool $calc_as_string 是否计算为字符串公里距离 , 如果未否返回数字
      * @return float | false | string
      */
-    public function calc_map_distance( $point_1=array(  ) , $point_2=array(  ) , $calc_as_string=false ) {
+    private function calc_map_distance( $point_1=array(  ) , $point_2=array(  ) , $calc_as_string=false ) {
         if( empty( $point_1 ) || empty( $point_2 ) ){
             return false;
         }
@@ -156,7 +237,7 @@ class Usercenter extends Api
 
     //地图api,根据两地坐标,获得两地距离,打卡用的
     //type=0直线,type=1开车
-    public function getmapjuli($start_lon,$start_lat,$end_lon,$end_lat,$type = 0){
+    private function getmapjuli($start_lon,$start_lat,$end_lon,$end_lat,$type = 0){
         $result = 0;
 
         $apiurl = 'https://restapi.amap.com/v3/distance?';
@@ -184,4 +265,16 @@ class Usercenter extends Api
         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);
+    }
+
 }