shish 3 лет назад
Родитель
Сommit
a47eb25992
2 измененных файлов с 61 добавлено и 2 удалено
  1. 23 1
      app-hd/controllers/PurchaseController.php
  2. 38 1
      biz-hd/purchase/classes/PurchaseClass.php

+ 23 - 1
app-hd/controllers/PurchaseController.php

@@ -348,8 +348,30 @@ class PurchaseController extends BaseController
         util::success($newParams);
     }
 
-    //运费计算  lqh 2021.4.12  暂时返回固定值
+    //计算运费 ssh 20221003
     public function actionFreight()
+    {
+        $get = Yii::$app->request->get();
+        $ghsId = $get['ghsId'] ?? 0;
+        $ghs = GhsClass::getById($ghsId, true);
+        if (empty($ghs)) {
+            util::fail('计算运费时没有找到供货商');
+        }
+        $ghsShopId = $ghs->shopId ?? 0;
+        $ghsShop = ShopClass::getById($ghsShopId, true);
+        if (empty($ghsShop)) {
+            util::fail('计算运费时没有找到供货商!');
+        }
+        $weight = $get['weight'] ?? 0;
+        if (empty($weight)) {
+            util::fail('计划运费时没有重量');
+        }
+        $respond = PurchaseClass::getDistanceFee($this->shop, $ghsShop, $weight);
+        util::success($respond);
+    }
+
+    //运费计算  lqh 2021.4.12  暂时返回固定值
+    public function actionFreight2()
     {
         //lqh 2021.6.25 运费固定返回0
         util::success(['sedCost' => 0]);

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

@@ -26,6 +26,7 @@ use bizHd\stat\classes\StatIncomeClass;
 use bizHd\wx\classes\WxOpenClass;
 use common\components\dict;
 use common\components\imgUtil;
+use common\components\mapUtil;
 use common\components\orderSn;
 use common\components\util;
 use bizHd\base\classes\BaseClass;
@@ -58,6 +59,42 @@ class PurchaseClass extends BaseClass
     const REFUND_NO = 1;
     const REFUND_YES = 2;
 
+    //计算距离和运费 ssh 20221003
+    public static function getDistanceFee($shop, $ghsShop, $weight)
+    {
+        $shopLat = isset($shop->lat) ? $shop->lat : '';
+        $shopLong = isset($shop->long) ? $shop->long : '';
+
+        $ghsShopLat = isset($ghsShop->lat) ? $ghsShop->lat : '';
+        $ghsShopLong = isset($ghsShop->long) ? $ghsShop->long : '';
+
+        //跑腿费用设置,基础费用8—10元,3—100公里每公里增加2元,超过5公斤,5—21公斤每公斤增加2元
+
+        //起步价
+        $baseFee = 9;
+        $distance = mapUtil::calculateDistance($shopLong, $shopLat, $ghsShopLong, $ghsShopLat);
+        //每公里增加多少元
+        $perKmFee = 2;
+        //每公斤增加多少元
+        $perKiloFee = 2;
+        //免费距离
+        $freeDistance = 2;
+        $freeKm = 5;
+
+        $addDistanceFee = 0;
+        if ($distance > $freeDistance * 1000) {
+            $addDistanceFee = ceil(($distance - $freeDistance * 1000) / 1000) * $perKmFee;
+        }
+        $addWeightFee = 0;
+        if ($weight > $freeKm) {
+            $addWeightFee = ceil(bcsub($weight, $freeKm, 2)) * $perKiloFee;
+        }
+        $addFee = bcadd($addDistanceFee, $addWeightFee, 2);
+        $totalFee = bcadd($baseFee, $addFee, 2);
+        $showDistance = sprintf("%.1f", ($distance / 1000));
+        return ['distance' => $distance, 'showDistance' => $showDistance, 'fee' => $totalFee];
+    }
+
     //到货之后 ssh 20220321
     public static function arrival($cg, $data)
     {
@@ -371,7 +408,7 @@ class PurchaseClass extends BaseClass
             $bigPrice = $price;
 
             if ($currentSmallNum > 0) {
-				//如果是小单位数量,则传过来的就是小单位价格,无需转换
+                //如果是小单位数量,则传过来的就是小单位价格,无需转换
                 if (empty($changePrice)) {
                     $ghsRatio = $currentProduct['ratio'] ?? 0;
                     $ghsSmallRatio = $currentProduct['smallRatio'] ?? 1;