Kaynağa Gözat

fix: 按老板要求增加页眉信息(姓名+生成日期年月日)

yemeishu 1 hafta önce
ebeveyn
işleme
ad084cdd89

+ 5 - 3
app/Http/Controllers/ExamPdfController.php

@@ -1003,8 +1003,9 @@ class ExamPdfController extends Controller
         preg_match('/paper_(\d{15})/', (string) $rawPaperId, $matches);
         $examCode = $matches[1] ?? preg_replace('/[^0-9]/', '', (string) $rawPaperId);
 
-        // 生成日期
-        $generateDate = now()->locale('zh_CN')->isoFormat('M月D日');
+        $studentName = $this->getStudentInfo($paper->student_id)['name'] ?? ($paper->student_id ?? '________');
+        // 生成时间(格式:2026年01月30日 15:04:05)
+        $generateDateTime = now()->format('Y年m月d日 H:i:s');
 
         // 提取并去重知识点代码(优先 paper_questions.knowledge_point,缺失时回退到题库 kp_code)
         $paperQuestions = \App\Models\PaperQuestion::where('paper_id', $paper_id)->get();
@@ -1046,7 +1047,8 @@ class ExamPdfController extends Controller
         return view('pdf.exam-knowledge-explanation', [
             'paperId' => $paper_id,
             'examCode' => $examCode ?: $paper_id,
-            'generateDate' => $generateDate,
+            'studentName' => $studentName,
+            'generateDateTime' => $generateDateTime,
             'knowledgePoints' => $knowledgePoints,
         ]);
     }

+ 14 - 8
resources/views/pdf/exam-grading.blade.php

@@ -4,8 +4,9 @@
     $rawPaperId = $paper->paper_id ?? 'unknown';
     preg_match('/paper_(\d{15})/', $rawPaperId, $matches);
     $gradingCode = $matches[1] ?? preg_replace('/[^0-9]/', '', $rawPaperId);
-    // 生成日期(格式:1月24日)
-    $generateDate = now()->locale('zh_CN')->isoFormat('M月D日');
+    $studentName = $student['name'] ?? ($paper->student_id ?? '________');
+    // 生成时间(格式:2026年01月30日 15:04:05)
+    $generateDateTime = now()->format('Y年m月d日 H:i:s');
 @endphp
 <!DOCTYPE html>
 <html lang="zh-CN">
@@ -16,25 +17,30 @@
     <style>
         @page {
             size: A4;
-            margin: 2cm 2cm 2.5cm 2cm;
+            margin: 2.2cm 2cm 2.3cm 2cm;
             @top-left {
-                content: "知了数学·{{ $generateDate }}";
-                font-size: 12px;
+                content: "知了数学·{{ $generateDateTime }}";
+                font-size: 13px;
+                color: #666;
+            }
+            @top-center {
+                content: "{{ $studentName }}";
+                font-size: 13px;
                 color: #666;
             }
             @top-right {
                 content: "{{ $gradingCode }}";
-                font-size: 12px;
+                font-size: 13px;
                 color: #666;
             }
             @bottom-left {
                 content: "{{ $gradingCode }}";
-                font-size: 12px;
+                font-size: 13px;
                 color: #666;
             }
             @bottom-right {
                 content: counter(page) "/" counter(pages);
-                font-size: 12px;
+                font-size: 13px;
                 color: #666;
             }
         }

+ 14 - 8
resources/views/pdf/exam-paper.blade.php

@@ -9,31 +9,37 @@
         $rawPaperId = $paper->paper_id ?? 'unknown';
         preg_match('/paper_(\d{15})/', $rawPaperId, $matches);
         $examCode = $matches[1] ?? preg_replace('/[^0-9]/', '', $rawPaperId);
-        // 生成日期(格式:1月24日)
-        $generateDate = now()->locale('zh_CN')->isoFormat('M月D日');
+        $studentName = $student['name'] ?? ($paper->student_id ?? '________');
+        // 生成时间(格式:2026年01月30日 15:04:05)
+        $generateDateTime = now()->format('Y年m月d日 H:i:s');
     @endphp
     <style>
         @page {
             size: A4;
-            margin: 2cm 2cm 2.5cm 2cm;
+            margin: 2.2cm 2cm 2.3cm 2cm;
             @top-left {
-                content: "知了数学·{{ $generateDate }}";
-                font-size: 12px;
+                content: "知了数学·{{ $generateDateTime }}";
+                font-size: 13px;
+                color: #666;
+            }
+            @top-center {
+                content: "{{ $studentName }}";
+                font-size: 13px;
                 color: #666;
             }
             @top-right {
                 content: "{{ $examCode }}";
-                font-size: 12px;
+                font-size: 13px;
                 color: #666;
             }
             @bottom-left {
                 content: "{{ $examCode }}";
-                font-size: 12px;
+                font-size: 13px;
                 color: #666;
             }
             @bottom-right {
                 content: counter(page) "/" counter(pages);
-                font-size: 12px;
+                font-size: 13px;
                 color: #666;
             }
         }

+ 30 - 0
resources/views/pdf/partials/kp-explain-styles.blade.php

@@ -1,5 +1,35 @@
 {{-- 知识点讲解专用样式 --}}
 <style>
+    /* ========== PDF 页眉页脚(用于知识点讲解) ========== */
+    @page {
+        size: A4;
+        margin: 2.2cm 2cm 2.3cm 2cm;
+        @top-left {
+            content: "知了数学·{{ $generateDateTime }}";
+            font-size: 13px;
+            color: #666;
+        }
+        @top-center {
+            content: "{{ $studentName }}";
+            font-size: 13px;
+            color: #666;
+        }
+        @top-right {
+            content: "{{ $examCode }}";
+            font-size: 13px;
+            color: #666;
+        }
+        @bottom-left {
+            content: "{{ $examCode }}";
+            font-size: 13px;
+            color: #666;
+        }
+        @bottom-right {
+            content: counter(page) "/" counter(pages);
+            font-size: 13px;
+            color: #666;
+        }
+    }
     /* ========== 屏幕预览样式 ========== */
     @media screen {
         body {