From 21828423322067533cb263fb8361f8fc6b5fc92c Mon Sep 17 00:00:00 2001 From: wangxinglong <2371974647@qq.com> Date: Thu, 27 Jan 2022 14:02:28 +0800 Subject: [PATCH] setter --- app/controller/api/Dictionary.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/app/controller/api/Dictionary.php b/app/controller/api/Dictionary.php index d6da49f..2c1d09e 100644 --- a/app/controller/api/Dictionary.php +++ b/app/controller/api/Dictionary.php @@ -62,7 +62,7 @@ class Dictionary extends Base $order["id"] = "desc"; $items = DictionaryRepository::getInstance()->getAllBusinessCircleList($field,$order); - $items->each(function ($item) { + $items->each(function ($item)use($lat,$lng) { $areaText = ''; if (!empty($item['province_text'])) { $areaText = $item['province_text'].'·'; @@ -79,6 +79,18 @@ class Dictionary extends Base $item['name_text'] = $item['name'] . '「'.$areaText.'」'; } + if($lng && $lat){ + $distance = get_distance($lat,$lng,$item['lat'],$item['lng']); + if($distance>=1000){ + $distance = round($distance/1000,2)."Km"; + }else{ + $distance.="m"; + } + $item['distance_text'] = $distance; + }else{ + $item['distance_text'] = ''; + } + return $item; }); return $this->json(0, 'success', $items);