shish 3 年 前
コミット
72c387648a

+ 80 - 14
app-mall/controllers/ExpressController.php

@@ -4,26 +4,92 @@ namespace mall\controllers;
 
 use bizMall\merchant\services\ExpressService;
 use bizMall\merchant\services\ShopService;
+use common\components\noticeUtil;
 use Yii;
 use yii\web\Controller;
 use common\components\util;
+use common\components\mapUtil;
 
 class ExpressController extends BaseController
 {
 
-	//计算客户距离和运费 ssh 2020.5.14
-	public function actionGetUserDistance()
-	{
-		//经度
-		$lng = Yii::$app->request->get('lng', '');
-		//纬度
-		$lat = Yii::$app->request->get('lat', '');
-		if (empty($lng) || empty($lat)) {
-			util::fail('经度或纬度不能为空');
-		}
-		$shopId = ShopService::getDefaultShopId($this->sj);
-		$respond = ExpressService::getUserDistance($lng, $lat, $shopId, $this->sjExtend);
-		util::success($respond);
-	}
+    //计算距离和运费【另外还有个地方要同步修改,关键词calc_freight_distance】 ssh 20221003
+    public function actionGetUserDistance()
+    {
+        $get = Yii::$app->request->get();
+        $lng = $get['lng'] ?? '';
+        $lat = $get['lat'] ?? '';
+        $weight = 1.5;
+        if (empty($lng) || empty($lat)) {
+            util::fail('请填写收花地址');
+        }
+        $shop = $this->shop;
+        $shopLong = $shop->long ?? '';
+        $shopLat = $shop->lat ?? '';
+        if (empty($shopLong) || empty($shopLat)) {
+            util::fail('门店地址有问题');
+        }
+
+        //基础配送费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元
+        //恶劣天气,下单高峰期会临时调整价格
+
+        //起步价
+        $baseFee = 8;
+        $distance = mapUtil::calculateDistance($shopLong, $shopLat, $lng, $lat);
+
+        //0-5公里,每公里+1元,5-100公里,6元起,每公里+2元
+        $formatDistance = ceil($distance / 1000);
+        $startKiloFee = 6;
+        if ($formatDistance < 5) {
+            $addDistanceFee = bcmul($formatDistance, 1);
+        } elseif ($formatDistance == 5) {
+            $addDistanceFee = $startKiloFee;
+        } else {
+            $overKilo = bcsub($formatDistance, 5);
+            $overFee = bcmul($overKilo, 2);
+            $addDistanceFee = bcadd($startKiloFee, $overFee);
+        }
+
+        //5-10公斤,2元起,每公斤+2元,10-15公斤,+12元,超过15公斤,+20元
+        $formatWeight = ceil($weight);
+        if ($formatWeight > 15) {
+            $addWeightFee = 20;
+        } elseif ($formatWeight >= 10 && $formatWeight <= 15) {
+            $addWeightFee = 12;
+        } elseif ($formatWeight >= 5 && $formatWeight < 10) {
+            $overWeight = bcsub($formatWeight, 4);
+            $addWeightFee = bcmul($overWeight, 2);
+        } else {
+            $addWeightFee = 0;
+        }
+
+        $addFee = bcadd($addDistanceFee, $addWeightFee, 2);
+        $totalFee = bcadd($baseFee, $addFee, 2);
+
+        //特殊时段费
+        $timeFee = 0;
+        $hour = date("G");
+        //22:00 - 24:00 +4元
+        if (in_array($hour, [22, 23])) {
+            $timeFee = 4;
+        }
+        //00:00 - 06:00 +6元
+        if (in_array($hour, [0, 1, 2, 3, 4, 5])) {
+            $timeFee = 6;
+        }
+        $totalFee = bcadd($totalFee, $timeFee, 2);
+
+        //恶劣天气和下单高峰费用
+        $weatherFee = 0;
+        $totalFee = bcadd($totalFee, $weatherFee, 2);
+
+        $showDistance = sprintf("%.1f", ($distance / 1000));
+
+        noticeUtil::push("商城订单 距离:{$distance} {$showDistance} 重量:{$weight} 费用:{$totalFee}", '15280215347');
+
+        return ['distance' => $distance, 'showDistance' => $showDistance, 'fee' => $totalFee];
+    }
 
 }

+ 1 - 1
biz-hd/purchase/classes/PurchaseClass.php

@@ -60,7 +60,7 @@ class PurchaseClass extends BaseClass
     const REFUND_NO = 1;
     const REFUND_YES = 2;
 
-    //计算距离和运费 ssh 20221003
+    //计算距离和运费【另外还有个地方要同步修改,关键词calc_freight_distance】 ssh 20221003
     public static function getDistanceFee($shop, $ghsShop, $weight)
     {
         $shopLat = isset($shop->lat) ? $shop->lat : '';