moonsflyer 3 maanden geleden
bovenliggende
commit
9b7286e6de
2 gewijzigde bestanden met toevoegingen van 56 en 50 verwijderingen
  1. 54 49
      app/shopapi/logic/Order/FreightLogic.php
  2. 2 1
      app/shopapi/logic/Order/OrderLogic.php

+ 54 - 49
app/shopapi/logic/Order/FreightLogic.php

@@ -70,58 +70,63 @@ class FreightLogic extends BaseLogic
                 $templateList[$good['express_template_id']][] = $good;
             }
         }
-        
-        foreach ($templateList as $templateId => $templateGoods) {
-    
-            $freight = FreightLogic::getFreightsByAddress($templateId, $userAddress);
-            
-            if (empty($freight)) {
-                continue;
-            }
-            
-            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 ($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'];
+        $area_flag =  ConfigService::get('shop', 'area_flag');
+        if($area_flag == 1){
+            $expressPrice +=22;
+        }else {
+
+
+            foreach ($templateList as $templateId => $templateGoods) {
+
+                $freight = FreightLogic::getFreightsByAddress($templateId, $userAddress);
+
+                if (empty($freight)) {
+                    continue;
+                }
+
+                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 ($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'];
+                }
+
+                // 计算每个商品 所占运费金额
+                $goods_moneys = static::array_proportion($this_express_money, array_column($templateGoods, $real_count_field), 2, 'end');
+
+                foreach ($templateGoods as $ko => $templateGood) {
+                    $goodsExpressMoneys[$templateGood['id']] = $goods_moneys['gets'][$ko] ?? 0;
+                }
+
+                // 总的运费
+                $expressPrice += $this_express_money;
             }
-    
-            // 计算每个商品 所占运费金额
-            $goods_moneys = static::array_proportion($this_express_money, array_column($templateGoods, $real_count_field), 2, 'end');
-            
-            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;
-        }
-    
-        foreach ($goods as &$good) {
-            $good['express_price'] = $goodsExpressMoneys[$good['id']] ?? $good['express_price'] ?? 0;
         }
-       
         return [ 'goods' => $goods, 'express_price' => $expressPrice ];
     }
 

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

@@ -178,7 +178,8 @@ class OrderLogic extends BaseLogic
             } else {
                 $area_flag =  ConfigService::get('shop', 'area_flag');
                 if($area_flag==1){
-                    self::$orderPrice['express_price'] = 5;
+                    $express_data = FreightLogic::calculateFreight($goodsLists, $userAddress);
+                    self::$orderPrice['express_price'] = $express_data['express_price'];
                 }else{
                     $express_data = FreightLogic::calculateFreight($goodsLists, $userAddress);
                     self::$orderPrice['express_price'] = $express_data['express_price'];