Explorar el Código

fix(finance): 修复周统计时间范围计算问题

- 使用 ISO-8601 标准获取正确的年份和周数
- 添加本周一开始时间和下周一时间的准确计算
- 修正周统计查询条件以使用标准周范围
- 移除旧的错误周时间计算逻辑
- 确保统计数据按标准周进行准确分组
shichen hace 4 meses
padre
commit
5268b5a263
Se han modificado 1 ficheros con 14 adiciones y 1 borrados
  1. 14 1
      app/common/repositories/finance/FinanceRepository.php

+ 14 - 1
app/common/repositories/finance/FinanceRepository.php

@@ -483,10 +483,23 @@ class FinanceRepository extends BaseRepository
483 483
         $sWeekWhere = " 1=1";
484 484
         $weekWhere = " 1=1";
485 485
         $dayWhere = " 1=1";
486
+
487
+        // 获取当前 ISO 年份和周数
488
+        $year = $today->format('o'); // ISO-8601 年份
489
+        $week = $today->format('W'); // ISO-8601 周数(周一为周起始)
490
+
491
+        // 本周一:setISODate(年份, 周数, 1) 参数 1 表示周一
492
+        $thisMonday = new \DateTime();
493
+        $thisMonday->setISODate($year, $week, 1);
494
+
495
+        // 下周一:周数加1
496
+        $nextMonday = new \DateTime();
497
+        $nextMonday->setISODate($year, $week + 1, 1);
498
+
486 499
         //上周时间条件
487 500
         $sWeekWhere .= " and DATE(create_time) >= '" . $startDate . "' and DATE(create_time) <= '" . $endDate . "'";
488 501
         //周时间条件
489
-        $weekWhere .= " and DATE(create_time) >= '" . $oneWeekAgoFormatted . "' and DATE(create_time) <= '" . $todayFormatted . "'";
502
+        $weekWhere .= " and DATE(create_time) >= '" . $thisMonday->format('Y-m-d') . "' and DATE(create_time) <= '" . $nextMonday->format('Y-m-d') . "'";
490 503
         //今日时间条件
491 504
         $dayWhere .= " and DATE(create_time) = '" . $todayFormatted . "'";
492 505
         $sharedUserCount = Db::name('shared_prosperity_user')->count(); //共富会员总人数