shish 3 سال پیش
والد
کامیت
a3ce8071a9

+ 6 - 66
app-mall/controllers/ExpressController.php

@@ -2,13 +2,9 @@
 
 namespace mall\controllers;
 
-use bizMall\merchant\services\ExpressService;
-use bizMall\merchant\services\ShopService;
-use common\components\noticeUtil;
+use bizMall\order\classes\OrderClass;
 use Yii;
-use yii\web\Controller;
 use common\components\util;
-use common\components\mapUtil;
 
 class ExpressController extends BaseController
 {
@@ -29,67 +25,11 @@ class ExpressController extends BaseController
         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');
-
-        util::success(['distance' => $distance, 'showDistance' => $showDistance, 'fee' => $totalFee]);
+        $respond = OrderClass::getDistanceFee($lat, $lng, $shop, $weight);
+        $distance = $respond['distance']??0;
+        $showDistance = $respond['showDistance']??0;
+        $fee = $respond['fee']??0;
+        util::success(['distance' => $distance, 'showDistance' => $showDistance, 'fee' => $fee]);
     }
 
 }

+ 15 - 10
app-mall/controllers/OrderController.php

@@ -122,7 +122,7 @@ class OrderController extends BaseController
         $goodsId = isset($post['goodsId']) ? $post['goodsId'] : 0;
         $goodsStyleId = isset($post['goodsStyleId']) ? $post['goodsStyleId'] : 0;
         $goodsNum = isset($post['goodsNum']) && $post['goodsNum'] > 0 ? $post['goodsNum'] : 1;
-        $needSend = isset($post['needSend']) && is_numeric($post['needSend']) ? $post['needSend'] : 1;
+        $sendType = $post['sendType'] ?? dict::getDict('sendType', 'thirdSend');
         if (empty($goodsId)) {
             util::fail('请选择商品');
         }
@@ -135,8 +135,6 @@ class OrderController extends BaseController
         if ($stock <= 0 && $stockSet == 0) {
             util::fail('库存不足');
         }
-        //运费计算方式
-        $freightType = isset($goodsInfo['freightType']) ? $goodsInfo['freightType'] : 0;
         //事务处理
         $connection = Yii::$app->db;
         $transaction = $connection->beginTransaction();
@@ -165,15 +163,22 @@ class OrderController extends BaseController
             $post['payWay'] = $this->isWx == true ? 0 : 1;
 
             //计算运费
-            $post['sendDistance'] = isset($post['sendDistance']) ? $post['sendDistance'] : 0;
+            $sendDistance = 0;
             $sendCost = 0;
-            //按距离计算运费并且客户要求送的
-            if ($freightType == 0 && $needSend == 1) {
-                $lat = $post['latitude'];//收货人纬度
-                $lng = $post['longitude'];//收货人经度
-                $respond = ExpressService::getUserDistance($lng, $lat, $this->shopId, $this->sjExtend);
-                $sendCost = isset($respond['fee']) ? $respond['fee'] : 0;
+            $shop = $this->shop;
+            if ($sendType == dict::getDict('sendType', 'thirdSend')) {
+                $lat = $post['latitude'] ?? '';
+                $lng = $post['longitude'] ?? '';
+                if (empty($lat) || empty($lng)) {
+                    util::fail('请填写收花地址');
+                }
+                //花束重量默认1.5
+                $weight = 1.5;
+                $disRespond = OrderClass::getDistanceFee($lat, $lng, $shop, $weight);
+                $sendCost = $disRespond['fee'] ?? 0;
+                $sendDistance = $disRespond['distance'] ?? 0;
             }
+            $post['sendDistance'] = $sendDistance;
             $post['sendCost'] = $sendCost;
             $post['sjId'] = $this->sjId;
             $post['shopId'] = $this->shopId;

+ 1 - 8
biz-mall/order/classes/OrderClass.php

@@ -59,15 +59,8 @@ class OrderClass extends BaseClass
     ];
 
     //计算运费,请搜索关键词calc_freight,二个方法要合一起 ssh 20221014
-    public static function getDistanceFee($user, $shop, $weight)
+    public static function getDistanceFee($userLat,$userLong, $shop, $weight)
     {
-        $userLat = isset($user->lat) ? $user->lat : '';
-        $userLong = isset($user->long) ? $user->long : '';
-
-        if (empty($userLat) || empty($userLong)) {
-            util::fail('请完善门店地址');
-        }
-
         $shopLat = isset($shop->lat) ? $shop->lat : '';
         $shopLong = isset($shop->long) ? $shop->long : '';
         if (empty($shopLat) || empty($shopLong)) {

+ 1 - 1
common/components/dict.php

@@ -49,7 +49,7 @@ class dict
             'big' => 0,
             'small' => 1,
         ],
-        //配送方式,0出车取货 1到店自取 2发快递
+        //配送方式,0出车取货 1到店自取 2请跑腿送
         'sendType' => [
             'carGet' => 0,
             'shopGet' => 1,