xiaogang 3 年之前
父節點
當前提交
edb1bcc5c9
共有 1 個文件被更改,包括 20 次插入20 次删除
  1. 20 20
      app/Services/DynamicService.php

+ 20 - 20
app/Services/DynamicService.php

xqd
@@ -234,27 +234,27 @@ class DynamicService
         foreach ($dynamic['data'] as $k=>$v){
             $dynamic['data'][$k]['img_url'] = json_decode($v['img_url'],true);
 
-
+            dd($lat,$lng);
             //计算距离 如果设置了位置,使用设置位置  否则使用定位位置
-//            if(!$v['latitude']||!$v['longitude']){
-//                //没有设置位置  取用户位置
-//                $v_user = User::query()->where(['id'=>$v['user_id']])->first();
-//                if(!$v_user['latitude'] || !$v_user['longitude']){
-//                    $distance = 0;
-//                }else{
-//                    $distance = GetDistance($lat,$lng,$v_user['latitude'],$v_user['longitude']);
-//                }
-//            }else{
-//                $distance = GetDistance($lat,$lng,$v['latitude'],$v['longitude']);
-//            }
-//
-//            if($distance>=1){
-//                $distance = round($distance);
-//            }else{
-//                $distance = round($distance*1000);
-//            }
-//
-//            $dynamic['data'][$k]['distance'] = $distance;
+            if(!$v['latitude']||!$v['longitude']){
+                //没有设置位置  取用户位置
+                $v_user = User::query()->where(['id'=>$v['user_id']])->first();
+                if(!$v_user['latitude'] || !$v_user['longitude']){
+                    $distance = 0;
+                }else{
+                    $distance = GetDistance($lat,$lng,$v_user['latitude'],$v_user['longitude']);
+                }
+            }else{
+                $distance = GetDistance($lat,$lng,$v['latitude'],$v['longitude']);
+            }
+
+            if($distance>=1){
+                $distance = round($distance);
+            }else{
+                $distance = round($distance*1000);
+            }
+
+            $dynamic['data'][$k]['distance'] = $distance;
 
 
             $dynamic['data'][$k]['atime'] = uc_time_ago(strtotime($v['created_at']));