cqp 2 месяцев назад
Родитель
Сommit
ebbd8948e3
1 измененных файлов с 16 добавлено и 5 удалено
  1. 16 5
      app/Service/StatisticService.php

+ 16 - 5
app/Service/StatisticService.php

@@ -521,15 +521,26 @@ class StatisticService extends Service
             }
         }
 
-        if (!isset($data['month_start'])) $month_start = date('Y-01-01');
-        else $month_start = date('Y-m-01', strtotime($data['month_start']));
-        if (!isset($data['month_end'])) $month_end = date('Y-01-01', strtotime('+1 year', strtotime($month_start)));
-        else {
+        // 确定起始时间:默认当年 1 月 1 日
+        if (!isset($data['month_start'])) {
+            $month_start = date('Y-01-01 00:00:00');
+        } else {
+            $month_start = date('Y-m-01 00:00:00', strtotime($data['month_start']));
+        }
+
+        // 确定结束时间
+        if (!isset($data['month_end'])) {
+            $month_end = date('Y-12-31 23:59:59', strtotime($month_start));
+        } else {
             $start_year = date('Y', strtotime($month_start));
             $end_year = date('Y', strtotime($data['month_end']));
+
             if ($start_year != $end_year) return [false, "查询不得跨年!", ""];
-            $month_end = date('Y-m-01', strtotime($data['month_end'] . ' +1 month'));
+
+            // 取传入月份的最后一天最后一秒
+            $month_end = date('Y-m-t 23:59:59', strtotime($data['month_end']));
         }
+
         return [true, strtotime($month_start), strtotime($month_end)];
     }