Просмотр исходного кода

Merge branch 'master' into dev

shish 2 дней назад
Родитель
Сommit
48d3bf4ab5
1 измененных файлов с 34 добавлено и 31 удалено
  1. 34 31
      app-ghs/controllers/StatItemController.php

+ 34 - 31
app-ghs/controllers/StatItemController.php

@@ -70,9 +70,10 @@ class StatItemController extends BaseController
         $timeType = isset($get['timeType']) ? strval($get['timeType']) : 'bill';
         $saleTimeField = ($timeType === 'send') ? 'sendTime' : 'payTime';
         $where[$saleTimeField] = ['between', [$currentStartTime, $currentEndTime]];
+        // includeNextDay=1(默认)计入跨天售后通过日扣减;=0 不含售后历史
+        $includeNextDay = !isset($get['includeNextDay']) || intval($get['includeNextDay']) === 1;
 
         $staffId = $get['staffId'] ?? 0;
-
         $list = OrderClass::getAllByCondition($where, null, '*');
         $productInfo = ProductClass::getAllByCondition(['mainId' => $this->mainId], null, 'id,name,py,cgStaffId', 'id');
         $stat = [];
@@ -151,37 +152,39 @@ class StatItemController extends BaseController
 
         // 通过日:退货扣数量+金额;仅退款只扣金额;无当日销量的花材也建负行
         $nextDayDeduct = '0.00';
-        $deductMaps = [
-            NextDayRefundClass::sumItemByProduct($this->mainId, $currentStartTime, $currentEndTime),
-            NextDayRefundClass::sumMoneyOnlyAmountByProduct($this->mainId, $currentStartTime, $currentEndTime),
-        ];
-        foreach ($deductMaps as $deductMap) {
-            foreach ($deductMap as $pid => $row) {
-                if (!empty($staffId)) {
-                    $currentCgStaffId = $productInfo[$pid]['cgStaffId'] ?? 0;
-                    if ($staffId != $currentCgStaffId) {
-                        continue;
+        if ($includeNextDay) {
+            $deductMaps = [
+                NextDayRefundClass::sumItemByProduct($this->mainId, $currentStartTime, $currentEndTime),
+                NextDayRefundClass::sumMoneyOnlyAmountByProduct($this->mainId, $currentStartTime, $currentEndTime),
+            ];
+            foreach ($deductMaps as $deductMap) {
+                foreach ($deductMap as $pid => $row) {
+                    if (!empty($staffId)) {
+                        $currentCgStaffId = $productInfo[$pid]['cgStaffId'] ?? 0;
+                        if ($staffId != $currentCgStaffId) {
+                            continue;
+                        }
                     }
+                    if (!isset($stat[$pid])) {
+                        $stat[$pid] = [
+                            'productId' => $pid,
+                            'name' => $productInfo[$pid]['name'] ?? '',
+                            'py' => $productInfo[$pid]['py'] ?? '',
+                            'num' => '0.00',
+                            'amount' => '0.00',
+                            'gross' => '0.00',
+                        ];
+                    }
+                    $subNum = (string)($row['num'] ?? '0');
+                    $subAmt = (string)($row['amount'] ?? '0');
+                    $stat[$pid]['num'] = bcsub((string)$stat[$pid]['num'], $subNum, 2);
+                    $stat[$pid]['amount'] = bcsub((string)$stat[$pid]['amount'], $subAmt, 2);
+                    $stat[$pid]['gross'] = bcsub((string)$stat[$pid]['gross'], $subAmt, 2);
+                    $totalNum = bcsub((string)$totalNum, $subNum, 2);
+                    $totalAmount = bcsub((string)$totalAmount, $subAmt, 2);
+                    $totalMl = bcsub((string)$totalMl, $subAmt, 2);
+                    $nextDayDeduct = bcadd($nextDayDeduct, $subAmt, 2);
                 }
-                if (!isset($stat[$pid])) {
-                    $stat[$pid] = [
-                        'productId' => $pid,
-                        'name' => $productInfo[$pid]['name'] ?? '',
-                        'py' => $productInfo[$pid]['py'] ?? '',
-                        'num' => '0.00',
-                        'amount' => '0.00',
-                        'gross' => '0.00',
-                    ];
-                }
-                $subNum = (string)($row['num'] ?? '0');
-                $subAmt = (string)($row['amount'] ?? '0');
-                $stat[$pid]['num'] = bcsub((string)$stat[$pid]['num'], $subNum, 2);
-                $stat[$pid]['amount'] = bcsub((string)$stat[$pid]['amount'], $subAmt, 2);
-                $stat[$pid]['gross'] = bcsub((string)$stat[$pid]['gross'], $subAmt, 2);
-                $totalNum = bcsub((string)$totalNum, $subNum, 2);
-                $totalAmount = bcsub((string)$totalAmount, $subAmt, 2);
-                $totalMl = bcsub((string)$totalMl, $subAmt, 2);
-                $nextDayDeduct = bcadd($nextDayDeduct, $subAmt, 2);
             }
         }
 
@@ -282,4 +285,4 @@ class StatItemController extends BaseController
         util::success(['list' => $stat]);
     }
 
-}
+}