cqp 2 周之前
父节点
当前提交
18d1d600a6
共有 2 个文件被更改,包括 12 次插入87 次删除
  1. 11 87
      app/Service/StatisticsService.php
  2. 1 0
      config/header/75.php

+ 11 - 87
app/Service/StatisticsService.php

@@ -539,7 +539,7 @@ class StatisticsService extends Service
                 if ($f['business_type_id'] == FreightFee::businessTypeNormal) {
                     $k = $f['order_time'] . $f['area_hs'];
                     $time_amount[$k]['amount'] = isset($time_amount[$k]['amount'])
-                        ? bcadd($f['freight_amount'], $time_amount[$k]['amount'], 2)
+                        ? bcadd($f['freight_amount'], $time_amount[$k]['amount'], 4)
                         : $f['freight_amount'];
                     $time_amount[$k]['is_use'] = $time_amount[$k]['is_use'] ?? 0;
                 }
@@ -549,7 +549,7 @@ class StatisticsService extends Service
             $valueTotal = 0;
             foreach ($fees as $f) {
                 $f = $this->calculateFreightFeeRow($f, $time_amount);
-                $valueTotal = bcadd($valueTotal, $f['total_amount'], 2);
+                $valueTotal = bcadd($valueTotal, $f['total_amount'], 4);
             }
 
             $data['data'][$key]['total_amount'] = $valueTotal;
@@ -562,84 +562,6 @@ class StatisticsService extends Service
         return $data;
     }
 
-//    public function statisticsFreightFeeDetail($data, $user){
-//        if(empty($data['order_time'])) return [false, '单据日期不能为空'];
-//
-//        $fee = FreightFee::where('del_time',0)
-//            ->where('order_time', $data['order_time'])
-//            ->get()->toArray();
-//        if(empty($fee)) return [false, '单据日期下暂无数据'];
-//
-//        //同一天 同一个地区 非退货的配送费总金额
-//        $time_amount = [];
-//        foreach ($fee as $value){
-//            if($value['business_type_id'] == FreightFee::businessTypeNormal){
-//                $key = $value['order_time'] . $value['area_hs'];
-//                if(isset($time_amount[$key])){
-//                    $freight_amount = bcadd($value['freight_amount'], $time_amount[$key]['amount'],2);
-//                    $time_amount[$key]['amount'] = $freight_amount;
-//                }else{
-//                    $time_amount[$key] = [
-//                        'is_use' => 0,
-//                        'amount' => $value['freight_amount'],
-//                    ];
-//                }
-//            }
-//        }
-//
-//        $return = [];
-//        foreach ($fee as $value){
-//            //结算金额
-//            $js_amount = 0;
-//            $key = $value['order_time'] . $value['area_hs'];
-//            if($value['business_type_id'] == FreightFee::businessTypeNormal){
-//                $tmp_total_arr = $time_amount[$key];
-//                if($tmp_total_arr['amount'] < $value['min_freight_amount']){
-//                    if(! $time_amount[$key]['is_use']){
-//                        $js_amount = $value['min_freight_amount'];
-//                        $time_amount[$key]['is_use'] = 1;
-//                    }
-//                }else{
-//                    $js_amount = $value['js_single_amount'];
-//                }
-//                $value['js_amount'] = $js_amount;
-//                //加急费
-//                $jj_fee = 0;
-//                if($value['delivery_mode'] == FreightFee::deliveryModeRightNow) $jj_fee = bcmul($js_amount, 0.5,2);
-//                $value['jj_fee'] = $jj_fee;
-//                //总金额
-//                $total_amount = bcadd($js_amount,$value['customer_store_zx_fee'],2);
-//                $total_amount = bcadd($total_amount,$value['sl_fee'],2);
-//                $total_amount = bcadd($total_amount,$jj_fee,2);
-//                $total_amount = bcadd($total_amount,$value['dh_fee'],2);
-//                $value['total_amount'] = $total_amount;
-//                $return[FreightFee::businessTypeNormal][$key][] = $value;
-//            }else{
-//                $js_amount = $value['js_single_amount'];
-//                $value['js_amount'] = $js_amount;
-//                $jj_fee = 0;
-//                if($value['delivery_mode'] == FreightFee::deliveryModeRightNow) $jj_fee = bcmul($js_amount, 0.5,2);
-//                //加急费
-//                $value['jj_fee'] = $jj_fee;
-//                //总金额
-//                $total_amount = bcadd($js_amount,$value['customer_store_zx_fee'],2);
-//                $total_amount = bcadd($total_amount,$value['sl_fee'],2);
-//                $total_amount = bcadd($total_amount,$jj_fee,2);
-//                $total_amount = bcadd($total_amount,$value['dh_fee'],2);
-//                $value['total_amount'] = $total_amount;
-//                $return[FreightFee::businessTypeReturn][$key][] = $value;
-//            }
-//        }
-//
-//        $result = [];
-//        foreach ($return as $value){
-//            foreach (array_values($value) as $val){
-//                $result[] = $val;
-//            }
-//        }
-//        dd($result);
-//    }
-
     public function statisticsFreightFeeDetail($data, $user)
     {
         if (empty($data['order_time'])) {
@@ -662,7 +584,7 @@ class StatisticsService extends Service
             if ($value['business_type_id'] == FreightFee::businessTypeNormal) {
                 $key = $value['order_time'] . $value['area_hs'];
                 $time_amount[$key]['amount'] = isset($time_amount[$key]['amount'])
-                    ? bcadd($value['freight_amount'], $time_amount[$key]['amount'], 2)
+                    ? bcadd($value['freight_amount'], $time_amount[$key]['amount'], 4)
                     : $value['freight_amount'];
                 $time_amount[$key]['is_use'] = $time_amount[$key]['is_use'] ?? 0;
             }
@@ -678,6 +600,7 @@ class StatisticsService extends Service
         $result = [];
         // 需要合计的字段
         $sumFields = ['xs', 'weight', 'freight_amount', 'js_amount', 'customer_store_zx_fee', 'jj_fee', 'dh_fee', 'total_amount'];
+        $sumFields_map = ['freight_amount' => 4, 'js_amount' => 4,'customer_store_zx_fee' => 4, 'jj_fee' => 4, 'dh_fee' => 4, 'total_amount' => 4];
 
         // 业务类型 日期 地区 算一张表算运费
         foreach ($return as $g => $group) {
@@ -695,8 +618,9 @@ class StatisticsService extends Service
                     $val[$key]['delivery_mode_show'] = $delivery_mode_show;
                     $val[$key]['area_range_show'] = $row['area_range'] == 1 ? '1~5吨' : '5吨以上';
                     foreach ($sumFields as $field) {
+                        $decimals = $sumFields_map[$field] ?? 2;
                         $sumRow[$field] = isset($sumRow[$field])
-                            ? bcadd($sumRow[$field], $row[$field], 2)
+                            ? bcadd($sumRow[$field], $row[$field], $decimals)
                             : $row[$field];
                     }
                 }
@@ -745,15 +669,15 @@ class StatisticsService extends Service
         // 加急费
         $jj_fee = 0;
         if ($value['delivery_mode'] == FreightFee::deliveryModeRightNow) {
-            $jj_fee = bcmul($js_amount, 0.5, 2);
+            $jj_fee = bcmul($js_amount, 0.5, 4);
         }
         $value['jj_fee'] = $jj_fee;
 
         // 总金额
-        $total_amount = bcadd($js_amount, $value['customer_store_zx_fee'], 2);
-        $total_amount = bcadd($total_amount, $value['sl_fee'], 2);
-        $total_amount = bcadd($total_amount, $jj_fee, 2);
-        $total_amount = bcadd($total_amount, $value['dh_fee'], 2);
+        $total_amount = bcadd($js_amount, $value['customer_store_zx_fee'], 4);
+        $total_amount = bcadd($total_amount, $value['sl_fee'], 4);
+        $total_amount = bcadd($total_amount, $jj_fee, 4);
+        $total_amount = bcadd($total_amount, $value['dh_fee'], 4);
         $value['total_amount'] = $total_amount;
 
         return $value;

+ 1 - 0
config/header/75.php

@@ -14,5 +14,6 @@ return [
         'key' =>'total_amount',
         'value' => '运费总金额',
         'sum' => 1,
+        'decimals' => 4,
     ],
 ];