cqp 1 月之前
父节点
当前提交
a052871ea3
共有 1 个文件被更改,包括 10 次插入1 次删除
  1. 10 1
      app/Service/ExportFileService.php

+ 10 - 1
app/Service/ExportFileService.php

@@ -195,7 +195,7 @@ class ExportFileService extends Service
         ];
 
         // 获取该月所有天数
-        $daysInMonth = cal_days_in_month(CAL_GREGORIAN, $mon, $year);
+        $daysInMonth = $this->get_days_in_month($mon, $year);
         $dates = [];
         $weekdays = [];
         for($d=1;$d<=$daysInMonth;$d++){
@@ -260,6 +260,15 @@ class ExportFileService extends Service
         return $this->saveExportData($kqData, $header,'kq2');
     }
 
+    function get_days_in_month($month, $year) {
+        if (function_exists('cal_days_in_month')) {
+            return cal_days_in_month(CAL_GREGORIAN, $month, $year);
+        } else {
+            // 回退方案
+            return (int)date('t', mktime(0, 0, 0, $month, 1, $year));
+        }
+    }
+
     public function saveExportData($data, $headers, $type = 'default',$file_name = ''){
         if(empty($file_name)) $file_name = self::$filename . "_". date("Y-m-d") . "_". rand(1000,9999);
         $filename =  $file_name . '.' . 'xlsx';