moonsflyer před 3 měsíci
rodič
revize
7de737d5ce

+ 51 - 57
app/shopapi/logic/Order/FreightLogic.php

@@ -46,90 +46,84 @@ class FreightLogic extends BaseLogic
         $expressPrice = 0;
         $templateList = [];
         $goodsExpressMoneys = [];
-        outFileLog($goods,'freight','$goods');
+
         // 配送方式配置, 如果配送方式-快递配送已关闭则不参与运费计算
         $expressConfig = ConfigService::get('delivery_type', 'is_express', 1);
 
         if (empty($userAddress) || $expressConfig == YesNoEnum::NO) {
-            return ['goods'=>$goods,'express_price'=>$expressPrice];
+            return ['goods' => $goods, 'express_price' => $expressPrice];
         }
-        $area_flag =  ConfigService::get('shop', 'area_flag');
+        $area_flag = ConfigService::get('shop', 'area_flag');
         foreach ($goods as &$good) {
-            outFileLog($expressPrice,'freight','$expressPrice');
-            $good['total_weight']   = $good['weight'] * $good['goods_num'];
-            $good['total_volume']   = $good['volume'] * $good['goods_num'];
-            
+
+            $good['total_weight'] = $good['weight'] * $good['goods_num'];
+            $good['total_volume'] = $good['volume'] * $good['goods_num'];
+
             // 统一邮费
             if ($good['express_type'] == 2) {
                 $good['express_price'] = round($good['express_money'] * $good['goods_num'], 2);
                 $expressPrice += $good['express_price'];
             }
-            
+
             // 指定运费模板
             if ($good['express_type'] == 3 && $good['express_template_id'] > 0) {
                 $templateList[$good['express_template_id']][] = $good;
             }
         }
-        outFileLog($area_flag,'freight','$area_flag');
-        if($area_flag == 1){
-            outFileLog($good,'freight','$good');
-            $expressPrice += isset($good['sub_price']) ?? 0;
-            outFileLog($expressPrice,'freight','$expressPrice2');
-        }else {
-
 
-            foreach ($templateList as $templateId => $templateGoods) {
 
-                $freight = FreightLogic::getFreightsByAddress($templateId, $userAddress);
+        foreach ($templateList as $templateId => $templateGoods) {
 
-                if (empty($freight)) {
-                    continue;
-                }
+            $freight = FreightLogic::getFreightsByAddress($templateId, $userAddress);
 
-                switch ($freight['charge_way']) {
-                    // 件数
-                    case FreightEnum::CHARGE_WAY_PIECE:
-                        $nums = array_sum(array_column($templateGoods, 'goods_num'));
-                        $real_count_field = 'goods_num';
-                        break;
-                    // 重量
-                    case FreightEnum::CHARGE_WAY_WEIGHT:
-                        $nums = array_sum(array_column($templateGoods, 'total_weight'));
-                        $real_count_field = 'total_weight';
-                        break;
-                    // 体积
-                    case FreightEnum::CHARGE_WAY_VOLUME:
-                        $nums = array_sum(array_column($templateGoods, 'total_volume'));
-                        $real_count_field = 'total_volume';
-                        break;
-                    default:
-                        continue 2;
-                }
+            if (empty($freight)) {
+                continue;
+            }
 
-                // 计算运费
-                if ($nums > $freight['first_unit'] && $freight['continue_unit'] > 0) {
-                    $left = ceil(($nums - $freight['first_unit']) / $freight['continue_unit']);
-                    $this_express_money = $freight['first_money'] + $left * $freight['continue_money'];
-                } else {
-                    $this_express_money = $freight['first_money'];
-                }
+            switch ($freight['charge_way']) {
+                // 件数
+                case FreightEnum::CHARGE_WAY_PIECE:
+                    $nums = array_sum(array_column($templateGoods, 'goods_num'));
+                    $real_count_field = 'goods_num';
+                    break;
+                // 重量
+                case FreightEnum::CHARGE_WAY_WEIGHT:
+                    $nums = array_sum(array_column($templateGoods, 'total_weight'));
+                    $real_count_field = 'total_weight';
+                    break;
+                // 体积
+                case FreightEnum::CHARGE_WAY_VOLUME:
+                    $nums = array_sum(array_column($templateGoods, 'total_volume'));
+                    $real_count_field = 'total_volume';
+                    break;
+                default:
+                    continue 2;
+            }
 
-                // 计算每个商品 所占运费金额
-                $goods_moneys = static::array_proportion($this_express_money, array_column($templateGoods, $real_count_field), 2, 'end');
+            // 计算运费
+            if ($nums > $freight['first_unit'] && $freight['continue_unit'] > 0) {
+                $left = ceil(($nums - $freight['first_unit']) / $freight['continue_unit']);
+                $this_express_money = $freight['first_money'] + $left * $freight['continue_money'];
+            } else {
+                $this_express_money = $freight['first_money'];
+            }
 
-                foreach ($templateGoods as $ko => $templateGood) {
-                    $goodsExpressMoneys[$templateGood['id']] = $goods_moneys['gets'][$ko] ?? 0;
-                }
+            // 计算每个商品 所占运费金额
+            $goods_moneys = static::array_proportion($this_express_money, array_column($templateGoods, $real_count_field), 2, 'end');
 
-                // 总的运费
-                $expressPrice += $this_express_money;
+            foreach ($templateGoods as $ko => $templateGood) {
+                $goodsExpressMoneys[$templateGood['id']] = $goods_moneys['gets'][$ko] ?? 0;
             }
 
-            foreach ($goods as &$good) {
-                $good['express_price'] = $goodsExpressMoneys[$good['id']] ?? $good['express_price'] ?? 0;
-            }
+            // 总的运费
+            $expressPrice += $this_express_money;
         }
-        return [ 'goods' => $goods, 'express_price' => $expressPrice ];
+
+        foreach ($goods as &$good) {
+            $good['express_price'] = $goodsExpressMoneys[$good['id']] ?? $good['express_price'] ?? 0;
+        }
+
+        return ['goods' => $goods, 'express_price' => $expressPrice];
     }
 
 

+ 5 - 1
app/shopapi/logic/Order/OrderLogic.php

@@ -171,7 +171,7 @@ class OrderLogic extends BaseLogic
             if ($is_address == 0) {
                 $userAddress = [];
             }
-
+            outFileLog($goodsLists,'freight','$goodsLists');
             //计算运费(自提订单不需要运费)
             if ($params['delivery_type'] == DeliveryEnum::SELF_DELIVERY) {
                 self::$orderPrice['express_price'] = 0;
@@ -179,6 +179,7 @@ class OrderLogic extends BaseLogic
                 $area_flag =  ConfigService::get('shop', 'area_flag');
                 if($area_flag==1){
 //                    $express_data = FreightLogic::calculateFreight($goodsLists, $userAddress);
+                    $new_express_price = self::getNewExpressPrice($goodsLists,$userAddress);
                     self::$orderPrice['express_price'] = 33;
                 }else{
                     $express_data = FreightLogic::calculateFreight($goodsLists, $userAddress);
@@ -323,6 +324,9 @@ class OrderLogic extends BaseLogic
         }
     }
 
+    public static function getNewExpressPrice($goods,$address){
+        return 13;
+    }
     /**
      * @notes 是否符合包邮活动条件
      */