pdf-report.blade.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. @php
  2. // 学情报告识别码:3开头 + 15位paper_id数字部分
  3. $rawPaperId = $paper['id'] ?? $paper['paper_id'] ?? 'unknown';
  4. preg_match('/paper_(\d{15})/', $rawPaperId, $matches);
  5. $paperIdNum = $matches[1] ?? preg_replace('/[^0-9]/', '', $rawPaperId);
  6. $reportCode = '3' . $paperIdNum;
  7. $averageMastery = isset($mastery['average']) ? number_format($mastery['average'] * 100, 1) . '%' : '无数据';
  8. // 【修复】从insights中获取AI分析结果(而不是从analysis_data)
  9. $questionAnalysis = $insights ?? [];
  10. @endphp
  11. <!DOCTYPE html>
  12. <html lang="zh-CN">
  13. <head>
  14. <meta charset="UTF-8">
  15. <title>学情报告 - {{ $paper['name'] ?? '试卷' }}</title>
  16. <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/katex.min.css">
  17. <style>
  18. @page {
  19. size: A4;
  20. margin: 1.5cm 1.5cm 2cm 1.5cm;
  21. @top-left {
  22. content: "知了数学";
  23. font-size: 10px;
  24. color: #666;
  25. }
  26. @top-right {
  27. content: "{{ $reportCode }}";
  28. font-size: 10px;
  29. color: #666;
  30. }
  31. @bottom-left {
  32. content: "{{ $reportCode }}";
  33. font-size: 10px;
  34. color: #666;
  35. }
  36. @bottom-right {
  37. content: counter(page) "/" counter(pages);
  38. font-size: 10px;
  39. color: #666;
  40. }
  41. }
  42. * { box-sizing: border-box; }
  43. body {
  44. font-family: "SimSun", "Songti SC", serif;
  45. margin: 0;
  46. padding: 0;
  47. color: #000;
  48. background: #fff;
  49. font-size: 12px;
  50. line-height: 1.6;
  51. }
  52. h1, h2, h3 { margin: 0; color: #000; }
  53. .card { background: #fff; border: 1px solid #e5e7eb; border-radius: 8px; padding: 12px 16px; margin-bottom: 12px; box-shadow: 0 2px 8px rgba(15, 23, 42, 0.04); }
  54. .header { text-align: center; margin-bottom: 1rem; border-bottom: 2px solid #000; padding-bottom: 0.5rem; }
  55. .school-name { font-size: 24px; font-weight: bold; margin-bottom: 10px; }
  56. .paper-title { font-size: 20px; font-weight: bold; margin-bottom: 15px; }
  57. .grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }
  58. .tag { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; color: #374151; background: #e5e7eb; }
  59. .section-title { font-size: 16px; margin-bottom: 10px; display: flex; align-items: center; gap: 8px; }
  60. .pill { padding: 4px 10px; border-radius: 999px; font-size: 12px; }
  61. .pill.green { background: #ecfdf3; color: #15803d; }
  62. .pill.amber { background: #fef3c7; color: #b45309; }
  63. .pill.red { background: #fef2f2; color: #b91c1c; }
  64. table { width: 100%; border-collapse: collapse; font-size: 13px; }
  65. th, td { padding: 8px 10px; border-bottom: 1px solid #e5e7eb; text-align: left; vertical-align: top; }
  66. th { background: #f3f4f6; color: #111827; }
  67. .muted { color: #6b7280; font-size: 12px; }
  68. .progress-wrap { background: #f3f4f6; border-radius: 999px; overflow: hidden; height: 10px; }
  69. .progress-bar { height: 100%; background: linear-gradient(90deg, #4f46e5, #10b981); }
  70. .recommend-card { border: 1px dashed #cbd5e1; border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; background: #f8fafc; }
  71. </style>
  72. </head>
  73. <body>
  74. <div class="page">
  75. <div class="header">
  76. <h1 class="paper-title">学情分析报告</h1>
  77. <div style="margin-top: 10px; font-size: 14px;">
  78. 试卷:{{ $paper['name'] ?? '-' }} | 学生:{{ $student['name'] ?? '-' }} | 年级:{{ $student['grade'] ?? '-' }}
  79. </div>
  80. <div style="margin-top: 6px; font-size: 14px;">
  81. 题目数:{{ is_array($questions ?? null) ? count($questions) : ($paper['total_questions'] ?? '-') }}
  82. </div>
  83. </div>
  84. <div class="card">
  85. <div class="section-title">知识点掌握度</div>
  86. @php
  87. // 【修复】过滤掉K-GENERAL等通用知识点,只显示有值的知识点
  88. $filteredMasteryItems = [];
  89. if (!empty($mastery['items'])) {
  90. foreach ($mastery['items'] as $item) {
  91. $kpCode = $item['kp_code'] ?? '';
  92. $masteryLevel = $item['mastery_level'] ?? 0;
  93. // 过滤条件:不是通用知识点,且掌握度>0
  94. if (!in_array($kpCode, ['K-GENERAL', 'GENERAL', 'DEFAULT']) && $masteryLevel > 0) {
  95. $filteredMasteryItems[] = $item;
  96. }
  97. }
  98. }
  99. @endphp
  100. @if(!empty($filteredMasteryItems))
  101. @foreach($filteredMasteryItems as $item)
  102. @php
  103. $pct = min(100, max(0, ($item['mastery_level'] ?? 0) * 100));
  104. $barColor = $pct >= 80 ? '#10b981' : ($pct >= 60 ? '#f59e0b' : '#ef4444');
  105. $delta = $item['mastery_change'] ?? null;
  106. // 只有当有变化值时才显示变化信息
  107. $changeText = '';
  108. if ($delta !== null && $delta !== '' && abs($delta) > 0.001) {
  109. $changeText = ($delta > 0 ? '↑ ' : '↓ ') . number_format(abs($delta) * 100, 1) . '%';
  110. }
  111. @endphp
  112. <div style="margin-bottom:12px; padding: 8px; border: 1px solid #e5e7eb; border-radius: 6px;">
  113. <div style="display:flex; justify-content:space-between; align-items:center; margin-bottom: 6px;">
  114. <div style="font-weight: 600; font-size: 14px;">{{ $item['kp_name'] ?? $item['kp_code'] ?? '未知知识点' }}</div>
  115. <div style="font-weight: 600; color: {{ $barColor }}; font-size: 14px;">
  116. {{ number_format($pct, 1) }}%
  117. <span style="margin-left: 8px; color: #666; font-size: 12px;">{{ $changeText }}</span>
  118. </div>
  119. </div>
  120. <div class="progress-wrap" style="height: 12px;">
  121. <div class="progress-bar" style="width: {{ $pct }}%; background: {{ $barColor }};"></div>
  122. </div>
  123. </div>
  124. @endforeach
  125. @else
  126. <div class="muted">暂无有效掌握度数据(已过滤通用知识点和零值)</div>
  127. @endif
  128. </div>
  129. <div class="card">
  130. <div class="section-title">📊 知识点层级掌握度分析</div>
  131. @php
  132. $parentMasteryLevels = $parent_mastery_levels ?? [];
  133. $hasParentMastery = !empty($parentMasteryLevels);
  134. @endphp
  135. @if($hasParentMastery)
  136. @foreach($parentMasteryLevels as $parentData)
  137. @php
  138. $pct = $parentData['mastery_percentage'] ?? 0;
  139. $barColor = $pct >= 80 ? '#10b981' : ($pct >= 60 ? '#f59e0b' : '#ef4444');
  140. $parentName = $parentData['kp_name'] ?? $parentData['kp_code'];
  141. $children = $parentData['children'] ?? [];
  142. $level = $parentData['level'] ?? 1;
  143. $delta = $parentData['mastery_change'] ?? null;
  144. // 只有当有变化值时才显示变化信息
  145. $changeText = '';
  146. if ($delta !== null && $delta !== '' && abs($delta) > 0.001) {
  147. $changeText = ($delta > 0 ? '↑ ' : '↓ ') . number_format(abs($delta) * 100, 1) . '%';
  148. }
  149. @endphp
  150. <div style="margin-bottom: 14px; padding: 10px; border: 1px solid #e0f2fe; border-radius: 6px; background: #f8fafc;">
  151. <div style="display:flex; justify-content:space-between; align-items:center; margin-bottom: 8px;">
  152. <div style="font-weight: 700; font-size: 15px; color: #0f172a;">
  153. 【第{{ $level }}级】{{ $parentName }}
  154. <span style="margin-left: 8px; font-size: 11px; color: #64748b; font-weight: 400;">
  155. ({{ $parentData['kp_code'] }})
  156. </span>
  157. </div>
  158. <div style="font-weight: 700; color: {{ $barColor }}; font-size: 15px;">
  159. {{ number_format($pct, 1) }}%
  160. @if(!empty($changeText))
  161. <span style="margin-left: 8px; color: #666; font-size: 12px;">{{ $changeText }}</span>
  162. @endif
  163. </div>
  164. </div>
  165. <div class="progress-wrap" style="height: 12px; margin-bottom: 8px;">
  166. <div class="progress-bar" style="width: {{ $pct }}%; background: {{ $barColor }};"></div>
  167. </div>
  168. @if(!empty($children))
  169. <div style="font-size: 12px; color: #475569;">
  170. <strong>包含子知识点({{ count($children) }}个):</strong>
  171. @foreach($children as $index => $child)
  172. @if($index < 8)
  173. <span style="display:inline-block; margin: 2px 4px; padding: 2px 6px; background: #e0f2fe; border-radius: 3px; font-size: 11px;">
  174. {{ $child['kp_name'] }}
  175. </span>
  176. @endif
  177. @endforeach
  178. @if(count($children) > 8)
  179. <span style="color: #64748b; font-style: italic;">...等{{ count($children) }}个知识点</span>
  180. @endif
  181. </div>
  182. @else
  183. <div style="font-size: 12px; color: #64748b;">
  184. <em>无直接子知识点或子知识点掌握度为0</em>
  185. </div>
  186. @endif
  187. </div>
  188. @endforeach
  189. <div style="margin-top: 12px; padding: 8px; background: #fefce8; border-left: 4px solid #eab308; border-radius: 4px;">
  190. <div style="font-size: 12px; color: #854d0e; line-height: 1.6;">
  191. <strong>学习建议:</strong>
  192. 建议重点关注掌握度较低的知识点,通过专项练习提升整体学习水平。优先练习掌握度低于60%的知识点。
  193. </div>
  194. </div>
  195. @else
  196. <div class="muted">暂无父节点掌握度数据</div>
  197. <div style="margin-top: 8px; font-size: 12px; color: #64748b;">
  198. 当前分析主要基于具体知识点掌握度。完整的层级掌握度分析需要在系统中建立完整的知识点层级关系。
  199. </div>
  200. @endif
  201. </div>
  202. <div class="card">
  203. <div class="section-title">题目列表</div>
  204. @php
  205. $insightMap = [];
  206. foreach (($question_insights ?? []) as $insight) {
  207. $no = $insight['question_number'] ?? $insight['question_id'] ?? null;
  208. if ($no !== null) {
  209. $insightMap[$no] = $insight;
  210. }
  211. }
  212. @endphp
  213. @foreach($questions as $q)
  214. @php
  215. // 【修复】从题目数据中获取学生答案、正确答案和判分结果
  216. $studentAnswer = $q['student_answer'] ?? $q['student_answer'] ?? null;
  217. $correctAnswer = $q['answer'] ?? $q['correct_answer'] ?? null;
  218. $isCorrect = $q['is_correct'] ?? null; // 1=正确,0=错误,null=未判
  219. // 如果未判分但有学生答案和正确答案,自动比较判断
  220. if ($isCorrect === null && !empty($studentAnswer) && !empty($correctAnswer)) {
  221. $isCorrect = (trim($studentAnswer) === trim($correctAnswer)) ? 1 : 0;
  222. }
  223. // 判分状态显示逻辑
  224. $showStatus = false;
  225. $statusText = '';
  226. $statusColor = '';
  227. if (!empty($studentAnswer)) {
  228. // 学生有答题,显示判分结果
  229. $showStatus = true;
  230. if ($isCorrect === 1) {
  231. $statusText = '正确';
  232. $statusColor = '#10b981';
  233. } elseif ($isCorrect === 0) {
  234. $statusText = '错误';
  235. $statusColor = '#ef4444';
  236. }
  237. }
  238. // 没答题的不显示状态
  239. $insight = $insightMap[$q['question_number']] ?? ($insightMap[$q['display_number'] ?? null] ?? []);
  240. // 【修复】得分显示:答错显示实际得分,答对显示满分
  241. $fullScore = $insight['full_score'] ?? ($q['score'] ?? null);
  242. if ($isCorrect === 1) {
  243. // 答对了,显示满分
  244. $score = $fullScore;
  245. } elseif ($isCorrect === 0) {
  246. // 答错了,显示实际得分(可能为0分或其他分数)
  247. $score = $q['score_obtained'] ?? 0;
  248. } else {
  249. // 未判分或未答题,不显示得分
  250. $score = null;
  251. }
  252. $analysisRaw = $insight['analysis']
  253. ?? $insight['thinking_process']
  254. ?? $insight['feedback']
  255. ?? $insight['suggestions']
  256. ?? $insight['reason']
  257. ?? ($insight['correct_solution'] ?? null);
  258. // 若有下一步建议,追加
  259. if (empty($analysisRaw) && !empty($insight['next_steps'])) {
  260. $analysisRaw = '后续建议:' . (is_array($insight['next_steps']) ? implode(';', $insight['next_steps']) : $insight['next_steps']);
  261. }
  262. $analysis = is_array($analysisRaw) ? json_encode($analysisRaw, JSON_UNESCAPED_UNICODE) : $analysisRaw;
  263. if ($analysis === null || $analysis === '') {
  264. $analysis = '暂无解题思路,待补充';
  265. }
  266. $stepsRaw = $insight['steps'] ?? $insight['solution_steps'] ?? $insight['analysis_steps'] ?? null;
  267. $steps = [];
  268. if (is_array($stepsRaw)) {
  269. $steps = $stepsRaw;
  270. } elseif (is_string($stepsRaw) && trim($stepsRaw) !== '') {
  271. $steps = preg_split('/[\r\n]+/', trim($stepsRaw));
  272. }
  273. $typeMap = ['choice' => '选择题', 'fill' => '填空题', 'answer' => '解答题'];
  274. $typeLabel = $typeMap[$q['question_type'] ?? ''] ?? ($q['question_type'] ?? '题型未标注');
  275. $questionText = is_string($q['question_text']) ? $q['question_text'] : json_encode($q['question_text'], JSON_UNESCAPED_UNICODE);
  276. $solution = $q['solution'] ?? null;
  277. @endphp
  278. <div style="border:1px solid #e5e7eb; border-radius:8px; padding:8px 12px; margin-bottom:8px; background:#fff; page-break-inside: avoid;">
  279. <div style="display:flex; justify-content:space-between; align-items:center; gap:8px; margin-bottom:4px;">
  280. <div style="display:flex; align-items:center; gap:8px; font-weight:600;">
  281. <span class="tag">题号 {{ $q['display_number'] ?? $q['question_number'] }}</span>
  282. @php
  283. $kpName = $q['knowledge_point_name'] ?? $q['knowledge_point'] ?? null;
  284. if (!empty($kpName) && $kpName !== '-' && $kpName !== '未标注') {
  285. echo '<span class="tag" style="background: #eef2ff; color:#4338ca;">' . e($kpName) . '</span>';
  286. }
  287. @endphp
  288. @if($showStatus)
  289. <span class="tag" style="background: {{ $statusColor }}; color:#fff;">{{ $statusText }}</span>
  290. @endif
  291. </div>
  292. @if($score !== null && $fullScore !== null)
  293. <div class="muted">得分 {{ $score }} / {{ $fullScore }}</div>
  294. @endif
  295. </div>
  296. {{-- 【新增】学生答案显示(如果有) --}}
  297. @if(!empty($studentAnswer))
  298. <div style="margin-bottom:6px; padding:6px; background:#fef2f2; border-left:3px solid #ef4444; border-radius:4px;">
  299. <div style="font-weight:600; font-size:12px; color:#111827; margin-bottom:3px;">学生答案</div>
  300. <div class="math-content" style="font-size:12px; line-height:1.5; color:#374151;">
  301. {!! nl2br(e($studentAnswer)) !!}
  302. </div>
  303. </div>
  304. @endif
  305. <div class="math-content" style="margin-bottom:6px; font-size:12px;">{!! $questionText !!}</div>
  306. <div class="muted" style="margin-bottom:6px; font-size:12px;">题型:{{ $typeLabel }}</div>
  307. {{-- 【修复】正确答案显示 --}}
  308. @if(!empty($correctAnswer))
  309. <div style="margin-bottom:6px; padding:6px; background:#f0fdf4; border-left:3px solid #10b981; border-radius:4px;">
  310. <div style="font-weight:600; font-size:12px; color:#111827; margin-bottom:3px;">正确答案</div>
  311. <div class="math-content" style="font-size:12px; line-height:1.5; color:#374151;">
  312. {!! nl2br(e($correctAnswer)) !!}
  313. </div>
  314. </div>
  315. @endif
  316. {{-- 【修改】解题思路显示(优先显示solution,其次显示analysis) --}}
  317. @if(!empty($solution))
  318. <div style="margin-top:6px; padding:6px; background:#eff6ff; border-left:3px solid #3b82f6; border-radius:4px;">
  319. <div style="font-weight:600; font-size:12px; color:#111827; margin-bottom:4px;">解题思路</div>
  320. <div class="math-content" style="font-size:12px; line-height:1.5; color:#374151;">
  321. {!! is_array($solution) ? json_encode($solution, JSON_UNESCAPED_UNICODE) : nl2br(e($solution)) !!}
  322. </div>
  323. </div>
  324. @elseif(!empty($analysis) && $analysis !== '暂无解题思路记录')
  325. <div style="margin-top:6px; padding:6px; background:#eff6ff; border-left:3px solid #3b82f6; border-radius:4px;">
  326. <div style="font-weight:600; font-size:12px; color:#111827; margin-bottom:4px;">解题思路</div>
  327. <div style="font-size:12px; line-height:1.5; color:#374151;">{!! nl2br(e($analysis)) !!}</div>
  328. </div>
  329. @endif
  330. {{-- 解题步骤(如果有) --}}
  331. @if(!empty($steps))
  332. <div style="margin-top:6px; font-size:12px;">
  333. <div style="font-weight:600; margin-bottom:3px;">解题步骤</div>
  334. <ol style="margin:0; padding-left:18px;">
  335. @foreach($steps as $s)
  336. <li style="margin-bottom:2px;">{!! nl2br(e(is_array($s) ? json_encode($s, JSON_UNESCAPED_UNICODE) : $s)) !!}</li>
  337. @endforeach
  338. </ol>
  339. </div>
  340. @endif
  341. </div>
  342. @endforeach
  343. </div>
  344. </div> {{-- 闭合page div --}}
  345. <script src="https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/katex.min.js"></script>
  346. <script src="https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/contrib/auto-render.min.js"></script>
  347. <script>
  348. document.addEventListener('DOMContentLoaded', function() {
  349. try {
  350. renderMathInElement(document.body, {
  351. delimiters: [
  352. {left: "$$", right: "$$", display: true},
  353. {left: "$", right: "$", display: false},
  354. {left: "\\(", right: "\\)", display: false},
  355. {left: "\\[", right: "\\]", display: true}
  356. ],
  357. throwOnError: false,
  358. strict: false,
  359. trust: true
  360. });
  361. } catch (e) {}
  362. });
  363. </script>
  364. </body>
  365. </html>