xiaogang 4 éve
szülő
commit
e53a7d0f89

+ 25 - 0
app/Helper/function.php

xqd
@@ -155,4 +155,29 @@ function look_log($user_id,$look_id){
     return true;
 }
 
+/**
+ * 根据经纬度算距离,返回结果单位是公里,先纬度,后经度
+ * @param $lat1
+ * @param $lng1
+ * @param $lat2
+ * @param $lng2
+ * @return float|int
+ */
+function GetDistance($lat1, $lng1, $lat2, $lng2)
+{
+    $EARTH_RADIUS = 6378.137;
+    $radLat1 = rad($lat1);
+    $radLat2 = rad($lat2);
+    $a = $radLat1 - $radLat2;
+    $b = rad($lng1) - rad($lng2);
+    $s = 2 * asin(sqrt(pow(sin($a / 2), 2) + cos($radLat1) * cos($radLat2) * pow(sin($b / 2), 2)));
+    $s = $s * $EARTH_RADIUS;
+    $s = round($s * 10000) / 10000;
+    return $s;
+}
+
+function rad($d)
+{
+    return $d * M_PI / 180.0;
+}
 

+ 5 - 0
app/Http/Controllers/Api/TestController.php

xqd xqd
@@ -108,6 +108,9 @@ class TestController
     }
 
     public function jg_auth(){
+        dd(GetDistance(30.714619,103.992323,30.714629,103.992323));
+
+        die;
         $token="asdasd";
         $exId="111111";
          $ret = JPushService::jgLoginTokenVerify($token,$exId);
@@ -115,4 +118,6 @@ class TestController
 
          $res = JPushService::jgOpensslPrivateDecrypt($ret['phone']);
     }
+
+
 }

+ 4 - 7
app/Services/DynamicService.php

xqd xqd
@@ -75,19 +75,15 @@ class DynamicService
         if($user){
             $lat = $user->latitude;
             $lng = $user->longitude;
-        }else{
-
         }
+
         $dynamic = DynamicModel::query();
         $dynamic = $dynamic->with(["user"=>function($query){
                 $query->select('id','sex','is_vip','tencent_im_user_id');
             },'user_info']);
         //查询条件
-        //类型  type 1全部  2关注  3附近
+        //类型  type 1全部  2附近
         if($where['type']==2){
-            //关注
-
-        }elseif ($where['type']==3){
             //附近
 
         }
@@ -123,8 +119,9 @@ class DynamicService
 
             }
             //计算距离 如果设置了位置,使用设置位置  否则使用定位位置
-
             $dynamic['data'][$k]['distance'] = 0;
+
+
             $dynamic['data'][$k]['atime'] = uc_time_ago(strtotime($v['created_at']));
             $dynamic['data'][$k]['tag'] = DB::table("dynamic_tag")->whereIn('id',explode(',',$v['tag']))->get();