pdf-report.blade.php 20 KB

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