Browse Source

生活圈

Panda 2 weeks ago
parent
commit
33e8f9903c

+ 22 - 0
application/api/controller/OfflineShop.php

@@ -65,6 +65,28 @@ class OfflineShop extends Api
         }
 
         $list = $model->getList(params: $params,orderBy: array_merge($orderBy,['weigh' => 'desc']),select: $select);
+        foreach ($list as &$item) {
+            [$distance,$unit] = \app\utils\Common::distanceTo($item['distance']);
+            $item['distance'] = "{$distance}{$unit}";
+        }
         return $this->success('success',$list);
     }
+
+    // 商铺列表
+    public function info()
+    {
+        $params = $this->request->param();
+        $userLng = $this->auth->lng;
+        $userLat = $this->auth->lat;
+        $model = new OfflineShopModel();
+        $select = ['*'];
+        if (!empty($userLng) && !empty($userLat)) {
+            $select[] = Db::raw("(st_distance(point ({$userLng}, {$userLat}),point(lng,lat))*111195) as distance");
+        }
+        $info = $model->getDetail(params: $params,select: $select);
+        if (!empty($info)) {
+            $info['images'] = explode(',',$info['image']);
+        }
+        return $this->success('success',$info);
+    }
 }

+ 1 - 1
application/common/model/BaseModel.php

@@ -120,7 +120,7 @@ class BaseModel extends Model
         count($with) > 0 && $query->with($with);
 
         // 规避 禁用 和 删除 数据
-        $this->is_status_search === 1 && $query->where('status', 'normal');
+        $this->is_status_search === 1 && $query->where('status', 1);
         $this->is_delete_search === 1 && $query->whereNull('deletetime');
 
         $detail = $query->find();

+ 1 - 1
application/common/model/OfflineShopModel.php

@@ -20,7 +20,7 @@ class OfflineShopModel extends BaseModel
     protected $createTime = 'createtime';
     protected $updateTime = 'updatetime';
 
-    protected int $is_status_search = 1;// 默认使用 status = 1 筛选
+    protected int $is_status_search = 0;// 默认使用 status = 1 筛选
     protected int $is_delete_search = 0;// 默认使用 is_delete = 0 筛选
 
     /**

+ 19 - 0
application/utils/Common.php

@@ -189,6 +189,25 @@ class Common
         return round($s, $decimal);
     }
 
+    public static function distanceTo($distance,$len_type = 2,$decimal = 2)
+    {
+        // 单位
+        $unit = 'm';
+        // 1 kilometer / 2 meter
+        if ($len_type == 1) {
+            $distance    /= 1000;
+            $unit = 'km';
+        }
+        // 自动转换
+        if ($len_type == 2) {
+            if ($distance >= 1000) {
+                $distance    /= 1000;
+                $unit = 'km';
+            }
+        }
+        return [round($distance, $decimal), $unit];
+    }
+
     /**
      * 获取随机昵称
      * @return string