Pārlūkot izejas kodu

Merge commit '28814bc4eb0fd88cb0d9b0bb0dd85dfe3544f7f4' into dev

# Conflicts:
#	app/v1/logic/dataReport/UserLogLogic.php
ith5 5 mēneši atpakaļ
vecāks
revīzija
e1d752cbd2
2 mainītis faili ar 39 papildinājumiem un 15 dzēšanām
  1. 34 0
      app/functions.php
  2. 5 15
      app/v1/logic/dataReport/UserLogLogic.php

+ 34 - 0
app/functions.php

@@ -8,4 +8,38 @@ function isValidDate($date, $format = 'Y-m-d'): bool
 {
     $d = DateTime::createFromFormat($format, $date);
     return $d && $d->format($format) === $date;
+}
+
+/**
+ * 获取两个日期之间的所有月份(格式:202508)
+ *
+ * @param string $startDate 开始日期(格式:Y-m-d)
+ * @param string $endDate 结束日期(格式:Y-m-d)
+ * @return array 月份数组,格式为 ['202508', '202509', ...]
+ */
+function getMonthsBetweenDates($startDate, $endDate) {
+    $months = [];
+
+    // 转换为 DateTime 对象
+    $start = new DateTime($startDate);
+    $end = new DateTime($endDate);
+
+    // 确保开始日期不大于结束日期
+    if ($start > $end) {
+        return $months;
+    }
+
+    // 设置开始日期为当月的第一天
+    $start->modify('first day of this month');
+
+    // 循环直到超过结束日期
+    while ($start <= $end) {
+        // 添加当前月份到数组(格式:202508)
+        $months[] = $start->format('Ym');
+
+        // 增加一个月
+        $start->add(new DateInterval('P1M'));
+    }
+
+    return $months;
 }

+ 5 - 15
app/v1/logic/dataReport/UserLogLogic.php

@@ -25,18 +25,18 @@ class UserLogLogic extends BaseLogic
         // 公共处理完的where, 自然量ID, auth_id=0为自然量
         [$where, $whereRaw] = $this->getUlogCommonWhere($params);
         
-        $currentQuery = Db::connect('db_game_log');
+        $regLogQuery = Db::connect('db_game_log');
         foreach($tableNames as $index => $tableName){
             if($index === 0){
-                $currentQuery = $currentQuery->table($tableName);
+                $regLogQuery = $regLogQuery->table($tableName);
                 if($where){
-                    $currentQuery = $currentQuery->where($where);
+                    $regLogQuery = $regLogQuery->where($where);
                 }
                 if($whereRaw){
-                    $currentQuery = $currentQuery->whereRaw($whereRaw);
+                    $regLogQuery = $regLogQuery->whereRaw($whereRaw);
                 }
             }else{
-                $currentQuery = $currentQuery->unionAll(function($query) use ($tableName, $where, $whereRaw){
+                $regLogQuery = $regLogQuery->unionAll(function($query) use ($tableName, $where, $whereRaw){
                     $query = $query->table($tableName);
                     if($where){
                         $query = $query->where($where);
@@ -47,16 +47,6 @@ class UserLogLogic extends BaseLogic
                 });
             }
         }
-
-
-
-        echo $currentQuery->buildSql();
-        // exit;
-
-        
-
-
-        $regLogQuery = $currentQuery->select();
         // 分页
         return $regLogQuery->paginate($limit)->toArray();
     }