shish hace 1 año
padre
commit
074fc34d1f
Se han modificado 2 ficheros con 10 adiciones y 6 borrados
  1. 0 2
      biz-mall/order/classes/OrderClass.php
  2. 10 4
      common/components/mapUtil.php

+ 0 - 2
biz-mall/order/classes/OrderClass.php

@@ -62,8 +62,6 @@ class OrderClass extends BaseClass
     public static function getDistanceFee($userLat, $userLong, $shopLat, $shopLong, $weight)
     {
 
-        return ['distance' => 0, 'showDistance' => 0, 'fee' => 0];
-
         //基础配送费8元,0-5公里,每公里+1元,5-100公里,6元起,每公里+2元
         //5-10公斤,2元起,每公斤+2元,10-15公斤,+12元,超过15公斤,+20元
         //00:00 - 06:00 +6元,22:00-24:00 +4元

+ 10 - 4
common/components/mapUtil.php

@@ -19,7 +19,7 @@ class mapUtil
     {
         if (getenv('YII_ENV') == 'production') {
             $url = "https://restapi.amap.com/v3/assistant/inputtips?city={$region}&keywords={$keyword}&key=" . self::$thirdMapKey;
-        }else{
+        } else {
             $url = "http://restapi.amap.com/v3/assistant/inputtips?city={$region}&keywords={$keyword}&key=" . self::$thirdMapKey;
         }
         $curl = new curl\Curl();
@@ -30,13 +30,19 @@ class mapUtil
     //计算距离 lng经度 lat纬度 ssh 2020.5.14
     public static function calculateDistance($fromLnt, $fromLat, $toLnt, $toLat)
     {
-        $url = "https://apis.map.qq.com/ws/distance/v1/matrix/?mode=driving&from={$fromLat},{$fromLnt}&to={$toLat},{$toLnt}&key=" . self::$thirdMapKey;
+        if (getenv('YII_ENV') == 'production') {
+            $url = "https://restapi.amap.com/v5/direction/electrobike?key=" . self::$thirdMapKey . '&origin=' . $fromLnt . ',' . $fromLat . '&destination=' . $toLnt . ',' . $toLat;
+        } else {
+            $url = "http://restapi.amap.com/v5/direction/electrobike?key=" . self::$thirdMapKey . '&origin=' . $fromLnt . ',' . $fromLat . '&destination=' . $toLnt . ',' . $toLat;
+        }
         $curl = new curl\Curl();
         $result = $curl->get($url);
         $result = Json::decode($result);
         $distance = 0;
-        if (isset($result['status']) && $result['status'] == 0) {
-            $distance = isset($result['result']['rows'][0]['elements'][0]['distance']) ? $result['result']['rows'][0]['elements'][0]['distance'] : 0;
+        if (!empty($result['status']) && $result['status'] == 1) {
+            $path = $result['route']['paths'] ?? [];
+            $current = $path[0] ?? [];
+            $distance = $current['distance'] ?? 0;
         }
         return $distance;
     }