pdf-report.blade.php 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774
  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. // 生成时间(格式:2026年01月30日 15:04:05)
  10. $generateDateTime = now()->format('Y年m月d日 H:i:s');
  11. @endphp
  12. <!DOCTYPE html>
  13. <html lang="zh-CN">
  14. <head>
  15. <meta charset="UTF-8">
  16. <title>学情报告 - {{ $paper['name'] ?? '试卷' }}</title>
  17. <link rel="stylesheet" href="/css/katex/katex.min.css">
  18. <style>
  19. @page {
  20. size: A4;
  21. margin: 2.2cm 2cm 2.3cm 2cm;
  22. @top-left {
  23. content: "知了数学·{{ $generateDateTime }}";
  24. font-size: 13px;
  25. color: #666;
  26. }
  27. @top-center {
  28. content: "{{ $student['name'] ?? '-' }}";
  29. font-size: 13px;
  30. color: #666;
  31. }
  32. @top-right {
  33. content: "{{ $reportCode }}";
  34. font-size: 19px;
  35. font-weight: 600;
  36. font-family: "Noto Sans", "Liberation Sans", "Nimbus Sans", sans-serif;
  37. letter-spacing: 0;
  38. padding-right: 3mm;
  39. padding-top: 1.8mm;
  40. color: #222;
  41. }
  42. @bottom-left {
  43. content: "{{ $reportCode }}";
  44. font-size: 11px;
  45. color: #666;
  46. }
  47. @bottom-right {
  48. content: counter(page) "/" counter(pages);
  49. font-size: 13px;
  50. color: #666;
  51. }
  52. }
  53. * { box-sizing: border-box; }
  54. body {
  55. font-family: "SimSun", "Songti SC", serif;
  56. margin: 0;
  57. padding: 0;
  58. color: #000;
  59. background: #fff;
  60. font-size: 12px;
  61. line-height: 1.6;
  62. }
  63. h1, h2, h3 { margin: 0; color: #000; }
  64. .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); }
  65. .header { text-align: center; margin-bottom: 1.5rem; border-bottom: 2px solid #000; padding-bottom: 1rem; }
  66. .paper-title { font-size: 22px; font-weight: bold; margin-bottom: 14px; }
  67. .grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }
  68. .tag { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; color: #374151; background: #e5e7eb; }
  69. .section-title { font-size: 16px; margin-bottom: 10px; display: flex; align-items: center; gap: 8px; }
  70. .pill { padding: 4px 10px; border-radius: 999px; font-size: 12px; }
  71. .pill.green { background: #ecfdf3; color: #15803d; }
  72. .pill.amber { background: #fef3c7; color: #b45309; }
  73. .pill.red { background: #fef2f2; color: #b91c1c; }
  74. table { width: 100%; border-collapse: collapse; font-size: 13px; }
  75. th, td { padding: 8px 10px; border-bottom: 1px solid #e5e7eb; text-align: left; vertical-align: top; }
  76. th { background: #f3f4f6; color: #111827; }
  77. .muted { color: #6b7280; font-size: 12px; }
  78. .progress-wrap { background: #f3f4f6; border-radius: 999px; overflow: hidden; height: 10px; }
  79. .progress-bar { height: 100%; background: linear-gradient(90deg, #4f46e5, #10b981); }
  80. .recommend-card { border: 1px dashed #cbd5e1; border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; background: #f8fafc; }
  81. .relation-board { margin: 6px 0 10px; padding: 10px 12px; border: 1px solid #e2e8f0; border-radius: 8px; background: #f8fafc; }
  82. .relation-block { margin-bottom: 10px; padding: 8px; border: 1px solid #dbeafe; border-radius: 8px; background: #fff; }
  83. .tree-cards { width: 100%; border-collapse: collapse; table-layout: fixed; }
  84. .tree-cards td { border: none; padding: 0; vertical-align: top; }
  85. .tree-left { width: 45%; padding-right: 10px; }
  86. .tree-right { width: 55%; padding-left: 10px; }
  87. .tree-parent {
  88. display: inline-block;
  89. margin-bottom: 6px;
  90. padding: 4px 8px;
  91. border-radius: 999px;
  92. border: 1px solid #93c5fd;
  93. background: #dbeafe;
  94. color: #1e3a8a;
  95. font-weight: 700;
  96. font-size: 12px;
  97. }
  98. .tree-lines { margin: 0; padding-left: 14px; border-left: 2px solid #cbd5e1; }
  99. .tree-line {
  100. font-size: 11px;
  101. color: #334155;
  102. margin-bottom: 3px;
  103. white-space: normal;
  104. overflow: visible;
  105. text-overflow: clip;
  106. word-break: break-all;
  107. line-height: 1.45;
  108. }
  109. .tree-line.hit { font-weight: 600; color: #1e40af; }
  110. .tree-line-badge { display: inline-block; margin-left: 6px; padding: 1px 5px; border-radius: 999px; font-size: 10px; border: 1px solid transparent; }
  111. .tree-line-badge.high,
  112. .tree-line-badge.mid,
  113. .tree-line-badge.low,
  114. .tree-line-badge.miss { background: #f8fafc; color: #64748b; border-color: #cbd5e1; }
  115. .detail-card {
  116. border: 1px solid #e2e8f0;
  117. border-radius: 6px;
  118. background: #f8fafc;
  119. padding: 6px 8px;
  120. margin-bottom: 5px;
  121. }
  122. .detail-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
  123. .detail-title { font-size: 11px; color: #0f172a; font-weight: 700; margin-bottom: 2px; }
  124. .detail-meta { font-size: 11px; color: #475569; margin-top: 3px; }
  125. .detail-mastery { font-size: 38px; color: #0f172a; font-weight: 700; line-height: 1; margin: 0; }
  126. .detail-mastery.high { color: #16a34a; }
  127. .detail-mastery.mid { color: #d97706; }
  128. .detail-mastery.low { color: #dc2626; }
  129. .node-tags { margin-top: 2px; }
  130. .node-tag {
  131. display: inline-block;
  132. margin: 0 6px 6px 0;
  133. padding: 1px 7px;
  134. border-radius: 999px;
  135. font-size: 10px;
  136. line-height: 1.4;
  137. color: #475569;
  138. background: #f1f5f9;
  139. border: 1px solid #cbd5e1;
  140. }
  141. .suggest-tags { display: inline; }
  142. .suggest-tag {
  143. display: inline-block;
  144. margin: 0 6px 6px 0;
  145. padding: 1px 7px;
  146. border-radius: 999px;
  147. font-size: 10px;
  148. line-height: 1.4;
  149. color: #334155;
  150. background: #f8fafc;
  151. border: 1px solid #d1d5db;
  152. }
  153. .weak-kp-tags { margin-top: 6px; }
  154. .weak-kp-tag {
  155. display: inline-block;
  156. margin: 0 6px 6px 0;
  157. padding: 1px 7px;
  158. border-radius: 999px;
  159. font-size: 10px;
  160. line-height: 1.45;
  161. color: #854d0e;
  162. background: #fef3c7;
  163. border: 1px solid #fcd34d;
  164. }
  165. .error-kp-tag {
  166. display: inline-block;
  167. margin: 0 6px 6px 0;
  168. padding: 1px 7px;
  169. border-radius: 999px;
  170. font-size: 10px;
  171. line-height: 1.45;
  172. color: #334155;
  173. background: #f8fafc;
  174. border: 1px solid #d1d5db;
  175. }
  176. .error-kp-tag.high-risk {
  177. color: #b91c1c;
  178. border-color: #fca5a5;
  179. background: #fff;
  180. font-weight: 600;
  181. }
  182. .detail-change-up { color: #16a34a; font-weight: 700; }
  183. .detail-change-down { color: #dc2626; font-weight: 700; }
  184. .aggregate-tip { font-size: 11px; color: #475569; margin-top: 6px; }
  185. .question-card { border:1px solid #e5e7eb; border-radius:8px; padding:6px 9px; margin-bottom:5px; background:#fff; page-break-inside: auto; break-inside: auto; }
  186. .question-block { margin-bottom: 5px; padding: 5px; border-radius: 4px; page-break-inside: auto; break-inside: auto; }
  187. .question-card,
  188. .question-card .math-content,
  189. .question-card .solution-content {
  190. font-size: 12px;
  191. line-height: 1.7;
  192. }
  193. .question-card .math-content img,
  194. .question-card img {
  195. max-width: 100% !important;
  196. width: auto !important;
  197. height: auto !important;
  198. object-fit: contain;
  199. display: block;
  200. margin: 6px auto;
  201. }
  202. .solution-content {
  203. display: block;
  204. line-height: 1.75;
  205. white-space: normal;
  206. word-break: break-word;
  207. overflow-wrap: anywhere;
  208. page-break-inside: auto;
  209. break-inside: auto;
  210. }
  211. </style>
  212. </head>
  213. <body>
  214. <div class="page">
  215. <div class="header">
  216. <h1 class="paper-title">学情分析报告</h1>
  217. @php
  218. $teacherName = trim((string) ($teacher['name'] ?? ''));
  219. $showTeacher = $teacherName !== '' && $teacherName !== '________' && $teacherName !== '未知老师';
  220. @endphp
  221. <div style="display:flex;justify-content:space-between;font-size:14px;margin-top:8px;">
  222. @if($showTeacher)
  223. <span>老师:{{ $teacherName }}</span>
  224. @endif
  225. <span>年级:@formatGrade($student['grade'] ?? '________')</span>
  226. @if(!empty($paper['assemble_type_label']) && $paper['assemble_type_label'] !== '未知类型')
  227. <span>类型:{{ $paper['assemble_type_label'] }}</span>
  228. @endif
  229. <span>姓名:{{ $student['name'] ?? '________' }}</span>
  230. <span>题目数:{{ $paper['total_questions'] ?? (is_array($questions ?? null) ? count($questions) : '-') }}</span>
  231. </div>
  232. </div>
  233. <div class="card">
  234. <div class="section-title">本次命中子知识点掌握度</div>
  235. @php
  236. // 先收集“本次命中”子知识点(用于区分:已作答0分 vs 未学习0分)
  237. $hitChildMeta = [];
  238. foreach (($parent_mastery_levels ?? []) as $pData) {
  239. foreach (($pData['children_all'] ?? []) as $child) {
  240. if (empty($child['is_hit'])) {
  241. continue;
  242. }
  243. $kpCode = (string) ($child['kp_code'] ?? '');
  244. if ($kpCode === '') {
  245. continue;
  246. }
  247. $hitChildMeta[$kpCode] = [
  248. 'kp_code' => $kpCode,
  249. 'kp_name' => $child['kp_name'] ?? $kpCode,
  250. 'mastery_level' => floatval($child['mastery_level'] ?? 0),
  251. 'is_hit' => true,
  252. ];
  253. }
  254. }
  255. // 过滤掉K-GENERAL等通用知识点:
  256. // - 掌握度>0 的正常显示
  257. // - 命中且0分(已作答)也显示,避免被误判为“未学习”
  258. $filteredMasteryItems = [];
  259. $filteredMasteryByCode = [];
  260. if (!empty($mastery['items'])) {
  261. foreach ($mastery['items'] as $item) {
  262. $kpCode = $item['kp_code'] ?? '';
  263. $masteryLevel = $item['mastery_level'] ?? 0;
  264. $isHit = isset($hitChildMeta[$kpCode]);
  265. if (!in_array($kpCode, ['K-GENERAL', 'GENERAL', 'DEFAULT']) && ($masteryLevel > 0 || $isHit)) {
  266. $item['is_hit'] = $isHit;
  267. $filteredMasteryItems[] = $item;
  268. $filteredMasteryByCode[$kpCode] = true;
  269. }
  270. }
  271. }
  272. // 补齐:如果命中子知识点没有出现在 mastery.items 中,也补一条0分记录用于展示和建议
  273. foreach ($hitChildMeta as $kpCode => $meta) {
  274. if (isset($filteredMasteryByCode[$kpCode])) {
  275. continue;
  276. }
  277. if (in_array($kpCode, ['K-GENERAL', 'GENERAL', 'DEFAULT'])) {
  278. continue;
  279. }
  280. $filteredMasteryItems[] = [
  281. 'kp_code' => $kpCode,
  282. 'kp_name' => $meta['kp_name'],
  283. 'mastery_level' => $meta['mastery_level'],
  284. 'mastery_change' => null,
  285. 'is_hit' => true,
  286. ];
  287. }
  288. @endphp
  289. @if(!empty($filteredMasteryItems))
  290. @foreach($filteredMasteryItems as $item)
  291. @php
  292. $pct = min(100, max(0, ($item['mastery_level'] ?? 0) * 100));
  293. $barColor = $pct >= 80 ? '#10b981' : ($pct >= 60 ? '#f59e0b' : '#ef4444');
  294. $delta = $item['mastery_change'] ?? null;
  295. $isHitItem = !empty($item['is_hit']);
  296. // 只有当有变化值时才显示变化信息
  297. $changeText = '';
  298. if ($delta !== null && $delta !== '' && abs($delta) > 0.001) {
  299. $changeText = ($delta > 0 ? '↑ ' : '↓ ') . number_format(abs($delta) * 100, 1) . '%';
  300. }
  301. @endphp
  302. <div style="margin-bottom:12px; padding: 8px; border: 1px solid #e5e7eb; border-radius: 6px;">
  303. <div style="display:flex; justify-content:space-between; align-items:center; margin-bottom: 6px;">
  304. <div style="font-weight: 600; font-size: 13px;">{{ $item['kp_name'] ?? $item['kp_code'] ?? '未知知识点' }}</div>
  305. <div style="font-weight: 600; color: {{ $barColor }}; font-size: 13px;">
  306. {{ number_format($pct, 1) }}%
  307. <span style="margin-left: 8px; color: #666; font-size: 11px;">{{ $changeText ? '子节点变化 ' . $changeText : '' }}</span>
  308. </div>
  309. </div>
  310. <div class="progress-wrap" style="height: 12px;">
  311. <div class="progress-bar" style="width: {{ $pct }}%; background: {{ $barColor }};"></div>
  312. </div>
  313. </div>
  314. @endforeach
  315. @else
  316. <div class="muted">暂无有效掌握度数据(已过滤通用知识点)</div>
  317. @endif
  318. </div>
  319. <div class="card">
  320. <div class="section-title">📊 知识点层级掌握度分析</div>
  321. @php
  322. $parentMasteryLevels = $parent_mastery_levels ?? [];
  323. $hasParentMastery = !empty($parentMasteryLevels);
  324. $childMasteryMap = [];
  325. foreach (($filteredMasteryItems ?? []) as $it) {
  326. $childMasteryMap[$it['kp_code']] = [
  327. 'level' => floatval($it['mastery_level'] ?? 0),
  328. 'delta' => isset($it['mastery_change']) ? floatval($it['mastery_change']) : null,
  329. ];
  330. }
  331. @endphp
  332. @if($hasParentMastery)
  333. <div class="relation-board">
  334. <div style="font-size:12px; color:#334155; margin-bottom:6px; font-weight:600;">父子知识点关系</div>
  335. @foreach($parentMasteryLevels as $parentData)
  336. @php
  337. $childrenAll = $parentData['children_all'] ?? [];
  338. $children = $parentData['children'] ?? []; // 命中子节点
  339. $childCount = count($childrenAll);
  340. $hitCount = count($children);
  341. $hitAvg = $parentData['children_hit_avg_mastery'] ?? null;
  342. $parentPct = number_format(floatval($parentData['mastery_percentage'] ?? 0), 1);
  343. $parentLevel = floatval($parentData['mastery_level'] ?? 0);
  344. $parentClass = $parentLevel >= 0.8 ? 'high' : ($parentLevel >= 0.6 ? 'mid' : 'low');
  345. $delta = $parentData['mastery_change'] ?? null;
  346. $hitNames = array_values(array_map(fn($c) => $c['kp_name'] ?? ($c['kp_code'] ?? ''), $children));
  347. $allChildrenPerfect = !empty($childrenAll) && count(array_filter($childrenAll, function ($c) {
  348. return floatval($c['mastery_level'] ?? 0) >= 0.999;
  349. })) === count($childrenAll);
  350. @endphp
  351. <div class="relation-block">
  352. <table class="tree-cards">
  353. <tr>
  354. <td class="tree-left">
  355. <div class="tree-parent">{{ $parentData['kp_name'] ?? $parentData['kp_code'] }}</div>
  356. @if(!empty($childrenAll))
  357. <div class="tree-lines">
  358. @foreach($childrenAll as $child)
  359. @php
  360. $isHit = !empty($child['is_hit']);
  361. $m = floatval($child['mastery_level'] ?? 0);
  362. $badgeClass = $m >= 0.8 ? 'high' : ($m >= 0.6 ? 'mid' : ($m > 0 ? 'low' : 'miss'));
  363. $badgeText = number_format($m * 100, 1) . '%';
  364. @endphp
  365. <div class="tree-line {{ $isHit ? 'hit' : '' }}">
  366. └─ {{ $child['kp_name'] }}
  367. <span class="tree-line-badge {{ $badgeClass }}">{{ $badgeText }}</span>
  368. </div>
  369. @endforeach
  370. </div>
  371. @else
  372. <div class="muted">无命中子知识点</div>
  373. @endif
  374. </td>
  375. <td class="tree-right">
  376. <div class="detail-card">
  377. <div class="detail-head">
  378. <div class="detail-title">{{ $parentData['kp_name'] ?? $parentData['kp_code'] }}</div>
  379. <div class="detail-mastery {{ $parentClass }}">{{ $parentPct }}%</div>
  380. </div>
  381. <div class="detail-meta">
  382. 父节点变化:
  383. @if($delta !== null)
  384. <span class="{{ $delta >= 0 ? 'detail-change-up' : 'detail-change-down' }}">
  385. {{ $delta >= 0 ? '↑ ' : '↓ ' }}{{ number_format(abs($delta) * 100, 1) }}%
  386. </span>
  387. @else
  388. -
  389. @endif
  390. </div>
  391. <div class="detail-meta" style="margin-top: 3px;">
  392. 本次重点子节点:
  393. @if($hitCount > 0)
  394. <span class="node-tags">
  395. @foreach($hitNames as $hitName)
  396. @if(!empty(trim($hitName)))
  397. <span class="node-tag">{{ $hitName }}</span>
  398. @endif
  399. @endforeach
  400. </span>
  401. @else
  402. @endif
  403. </div>
  404. <div class="detail-meta">
  405. 子节点总数 {{ $childCount }} 个,本次命中 {{ $hitCount }} 个,命中均值 {{ $hitAvg !== null ? number_format(floatval($hitAvg) * 100, 1) . '%' : '-' }}(命中表示本次覆盖,不等于已掌握)
  406. </div>
  407. </div>
  408. </td>
  409. </tr>
  410. </table>
  411. </div>
  412. @endforeach
  413. </div>
  414. @php
  415. $allParentPerfect = !empty($parentMasteryLevels) && count(array_filter($parentMasteryLevels, function ($p) {
  416. return floatval($p['mastery_level'] ?? 0) >= 0.999;
  417. })) === count($parentMasteryLevels);
  418. $allHitChildrenPerfect = !empty($filteredMasteryItems) && count(array_filter($filteredMasteryItems, function ($it) {
  419. return floatval($it['mastery_level'] ?? 0) >= 0.999;
  420. })) === count($filteredMasteryItems);
  421. $isAllPerfect = $allParentPerfect && $allHitChildrenPerfect;
  422. // 1) 优先:本次命中子知识点中的低掌握度(<60%)
  423. $hitWeakChildren = [];
  424. $hitWeakKeys = [];
  425. foreach (($filteredMasteryItems ?? []) as $hitItem) {
  426. $level = floatval($hitItem['mastery_level'] ?? 0);
  427. $name = trim((string) ($hitItem['kp_name'] ?? $hitItem['kp_code'] ?? ''));
  428. if ($name === '' || $level >= 0.6) {
  429. continue;
  430. }
  431. $key = (string) ($hitItem['kp_code'] ?? $name);
  432. $hitWeakChildren[$key] = [
  433. 'name' => $name,
  434. 'level' => $level,
  435. ];
  436. $hitWeakKeys[$key] = true;
  437. }
  438. $hitWeakChildren = array_values($hitWeakChildren);
  439. usort($hitWeakChildren, function ($a, $b) {
  440. return $a['level'] <=> $b['level'];
  441. });
  442. // 2) 兜底:若命中子知识点都 >=60%,再从其他低掌握度子知识点补
  443. $otherWeakChildren = [];
  444. foreach (($parentMasteryLevels ?? []) as $pData) {
  445. foreach (($pData['children_all'] ?? []) as $child) {
  446. $level = floatval($child['mastery_level'] ?? 0);
  447. $name = trim((string) ($child['kp_name'] ?? $child['kp_code'] ?? ''));
  448. if ($name === '' || $level >= 0.6) {
  449. continue;
  450. }
  451. $key = ($child['kp_code'] ?? $name);
  452. if (isset($hitWeakKeys[$key])) {
  453. continue;
  454. }
  455. $otherWeakChildren[$key] = [
  456. 'name' => $name,
  457. 'level' => $level,
  458. ];
  459. }
  460. }
  461. $otherWeakChildren = array_values($otherWeakChildren);
  462. usort($otherWeakChildren, function ($a, $b) {
  463. return $a['level'] <=> $b['level'];
  464. });
  465. // 3) 最终展示:总数不超过5
  466. $globalWeakChildren = [];
  467. if (!empty($hitWeakChildren)) {
  468. $globalWeakChildren = array_slice($hitWeakChildren, 0, 5);
  469. } else {
  470. $globalWeakChildren = array_slice($otherWeakChildren, 0, 5);
  471. }
  472. @endphp
  473. <div style="margin-top: 12px; padding: 8px; background: #fefce8; border-left: 4px solid #eab308; border-radius: 4px;">
  474. <div style="font-size: 12px; color: #854d0e; line-height: 1.6;">
  475. <strong>学习建议:</strong>
  476. @if($isAllPerfect)
  477. 本次学案表现非常出色,相关知识点掌握稳定且完整。建议继续进入新的知识点专题学习,优先选择同层级未覆盖内容或更高难度综合题,保持进阶节奏。
  478. @else
  479. 建议重点关注掌握度较低的知识点,通过专项练习提升整体学习水平。优先练习掌握度低于60%的知识点。
  480. @endif
  481. @if(!empty($globalWeakChildren))
  482. <div class="weak-kp-tags">
  483. @foreach($globalWeakChildren as $weakChild)
  484. <span class="weak-kp-tag">{{ $weakChild['name'] }}({{ number_format($weakChild['level'] * 100, 1) }}%)</span>
  485. @endforeach
  486. </div>
  487. @endif
  488. </div>
  489. </div>
  490. @else
  491. <div class="muted">暂无父节点掌握度数据</div>
  492. <div style="margin-top: 8px; font-size: 12px; color: #64748b;">
  493. 当前分析主要基于具体知识点掌握度。完整的层级掌握度分析需要在系统中建立完整的知识点层级关系。
  494. </div>
  495. @endif
  496. </div>
  497. @php
  498. $insightMap = [];
  499. foreach (($question_insights ?? []) as $insight) {
  500. $no = $insight['question_number'] ?? $insight['question_id'] ?? null;
  501. if ($no !== null) {
  502. $insightMap[$no] = $insight;
  503. }
  504. }
  505. $analysisWrongMap = [];
  506. foreach (($analysis_data['question_analysis'] ?? []) as $qa) {
  507. $qid = $qa['question_bank_id'] ?? $qa['question_id'] ?? null;
  508. if ($qid === null || $qid === '') {
  509. continue;
  510. }
  511. $rawCorrect = $qa['is_correct'] ?? null;
  512. $isWrongFromAnalysis = false;
  513. if (is_array($rawCorrect)) {
  514. $isWrongFromAnalysis = in_array(0, $rawCorrect, true);
  515. } elseif ($rawCorrect !== null) {
  516. $isWrongFromAnalysis = !boolval($rawCorrect);
  517. }
  518. if ($isWrongFromAnalysis) {
  519. $analysisWrongMap[(string)$qid] = true;
  520. }
  521. }
  522. $wrongQuestions = [];
  523. foreach (($questions ?? []) as $qItem) {
  524. $studentAnswerProbe = $qItem['student_answer'] ?? null;
  525. $correctAnswerProbe = $qItem['answer'] ?? ($qItem['correct_answer'] ?? null);
  526. $isCorrectProbe = $qItem['is_correct'] ?? null;
  527. if ($isCorrectProbe === null && !empty($studentAnswerProbe) && !empty($correctAnswerProbe)) {
  528. $isCorrectProbe = (trim((string)$studentAnswerProbe) === trim((string)$correctAnswerProbe)) ? 1 : 0;
  529. }
  530. $normalizedCorrect = $isCorrectProbe;
  531. if ($isCorrectProbe !== null) {
  532. $normalizedCorrect = is_bool($isCorrectProbe) ? ($isCorrectProbe ? 1 : 0) : intval($isCorrectProbe);
  533. }
  534. $qidProbe = (string)($qItem['question_bank_id'] ?? $qItem['question_id'] ?? '');
  535. $isWrongByAnalysis = ($qidProbe !== '' && isset($analysisWrongMap[$qidProbe]));
  536. if ($normalizedCorrect === 0 || $isWrongByAnalysis) {
  537. $wrongQuestions[] = $qItem;
  538. }
  539. }
  540. // 错题知识点聚合统计(同知识点错几题/共几题)
  541. $kpStats = [];
  542. foreach (($questions ?? []) as $qItem) {
  543. $kpName = trim((string)($qItem['knowledge_point_name'] ?? $qItem['knowledge_point'] ?? '未标注知识点'));
  544. if ($kpName === '') {
  545. $kpName = '未标注知识点';
  546. }
  547. if (!isset($kpStats[$kpName])) {
  548. $kpStats[$kpName] = ['total' => 0, 'wrong' => 0];
  549. }
  550. $kpStats[$kpName]['total']++;
  551. }
  552. foreach ($wrongQuestions as $qItem) {
  553. $kpName = trim((string)($qItem['knowledge_point_name'] ?? $qItem['knowledge_point'] ?? '未标注知识点'));
  554. if ($kpName === '') {
  555. $kpName = '未标注知识点';
  556. }
  557. if (!isset($kpStats[$kpName])) {
  558. $kpStats[$kpName] = ['total' => 0, 'wrong' => 0];
  559. }
  560. $kpStats[$kpName]['wrong']++;
  561. }
  562. $kpWrongStats = [];
  563. foreach ($kpStats as $kpName => $stat) {
  564. if (($stat['wrong'] ?? 0) <= 0) {
  565. continue;
  566. }
  567. $total = max(1, intval($stat['total'] ?? 0));
  568. $wrong = intval($stat['wrong'] ?? 0);
  569. $kpWrongStats[] = [
  570. 'kp_name' => $kpName,
  571. 'wrong' => $wrong,
  572. 'total' => $total,
  573. 'rate' => $wrong / $total,
  574. ];
  575. }
  576. usort($kpWrongStats, function ($a, $b) {
  577. if ($a['rate'] === $b['rate']) {
  578. return $b['wrong'] <=> $a['wrong'];
  579. }
  580. return $b['rate'] <=> $a['rate'];
  581. });
  582. @endphp
  583. @if(!empty($wrongQuestions))
  584. <div class="card">
  585. <div class="section-title">错题列表</div>
  586. @if(!empty($kpWrongStats))
  587. <div style="margin-bottom:8px; padding:8px; border:1px solid #e5e7eb; border-radius:6px; background:#f8fafc;">
  588. <div style="font-size:12px; font-weight:600; color:#111827; margin-bottom:6px;">知识点错误率</div>
  589. <div style="font-size:12px; color:#475569; line-height:1.7;">
  590. @foreach($kpWrongStats as $item)
  591. <span class="error-kp-tag {{ $item['rate'] > 0.5 ? 'high-risk' : '' }}">{{ $item['kp_name'] }}:{{ $item['wrong'] }}/{{ $item['total'] }}({{ number_format($item['rate'] * 100, 1) }}%)</span>
  592. @endforeach
  593. </div>
  594. </div>
  595. @endif
  596. @foreach($wrongQuestions as $q)
  597. @php
  598. // 【修复】从题目数据中获取学生答案、正确答案和判分结果
  599. $studentAnswer = $q['student_answer'] ?? $q['student_answer'] ?? null;
  600. $correctAnswer = $q['answer'] ?? $q['correct_answer'] ?? null;
  601. $isCorrect = $q['is_correct'] ?? null; // 1=正确,0=错误,null=未判
  602. // 如果未判分但有学生答案和正确答案,自动比较判断
  603. if ($isCorrect === null && !empty($studentAnswer) && !empty($correctAnswer)) {
  604. $isCorrect = (trim($studentAnswer) === trim($correctAnswer)) ? 1 : 0;
  605. }
  606. // 判分状态显示逻辑
  607. $statusText = '';
  608. $statusColor = '';
  609. if ($isCorrect === 1) {
  610. $statusText = '正确';
  611. $statusColor = '#10b981';
  612. } elseif ($isCorrect === 0) {
  613. $statusText = '错误';
  614. $statusColor = '#ef4444';
  615. }
  616. $showStatus = $statusText !== '';
  617. $insight = $insightMap[$q['question_number']] ?? ($insightMap[$q['display_number'] ?? null] ?? []);
  618. // 【修复】得分显示:答错显示实际得分,答对显示满分
  619. $fullScore = $insight['full_score'] ?? ($q['score'] ?? null);
  620. if ($isCorrect === 1) {
  621. // 答对了,显示满分
  622. $score = $fullScore;
  623. } elseif ($isCorrect === 0) {
  624. // 答错了,显示实际得分(可能为0分或其他分数)
  625. $score = $q['score_obtained'] ?? 0;
  626. } else {
  627. // 未判分或未答题,不显示得分
  628. $score = null;
  629. }
  630. $analysisRaw = $insight['analysis']
  631. ?? $insight['thinking_process']
  632. ?? $insight['feedback']
  633. ?? $insight['suggestions']
  634. ?? $insight['reason']
  635. ?? ($insight['correct_solution'] ?? null);
  636. // 若有下一步建议,追加
  637. if (empty($analysisRaw) && !empty($insight['next_steps'])) {
  638. $analysisRaw = '后续建议:' . (is_array($insight['next_steps']) ? implode(';', $insight['next_steps']) : $insight['next_steps']);
  639. }
  640. $analysis = is_array($analysisRaw) ? json_encode($analysisRaw, JSON_UNESCAPED_UNICODE) : $analysisRaw;
  641. if ($analysis === null || $analysis === '') {
  642. $analysis = '暂无解题思路,待补充';
  643. }
  644. $formatSolutionLikeGrading = function ($text) {
  645. if (!is_string($text) || trim($text) === '') {
  646. return $text;
  647. }
  648. $normalized = preg_replace('/\s*;\s*步骤\s*(\d+)/u', ";\n步骤$1", $text);
  649. $normalized = preg_replace('/\s*。\s*步骤\s*(\d+)/u', "。\n步骤$1", $normalized);
  650. $normalized = preg_replace('/(?<!^)(步骤\s*\d+\s*[::])/u', "\n$1", $normalized);
  651. $normalized = preg_replace('/(?<!^)(第\s*\d+\s*步\s*[::]?)/u', "\n$1", $normalized);
  652. $normalized = preg_replace('/\n{3,}/u', "\n\n", $normalized);
  653. // 去掉每行左侧缩进空白,避免出现“左边空好几个字符”
  654. $normalized = preg_replace('/^[\h\x{3000}]+/mu', '', $normalized);
  655. return trim($normalized);
  656. };
  657. $stepsRaw = $insight['steps'] ?? $insight['solution_steps'] ?? $insight['analysis_steps'] ?? null;
  658. $steps = [];
  659. if (is_array($stepsRaw)) {
  660. $steps = $stepsRaw;
  661. } elseif (is_string($stepsRaw) && trim($stepsRaw) !== '') {
  662. $steps = preg_split('/[\r\n]+/', trim($stepsRaw));
  663. }
  664. $typeMap = ['choice' => '选择题', 'fill' => '填空题', 'answer' => '解答题'];
  665. $typeLabel = $typeMap[$q['question_type'] ?? ''] ?? ($q['question_type'] ?? '题型未标注');
  666. $questionText = is_string($q['question_text']) ? $q['question_text'] : json_encode($q['question_text'], JSON_UNESCAPED_UNICODE);
  667. $solution = $q['solution'] ?? null;
  668. $solution = $formatSolutionLikeGrading($solution);
  669. $analysis = $formatSolutionLikeGrading($analysis);
  670. @endphp
  671. <div class="question-card">
  672. <div style="display:flex; justify-content:space-between; align-items:center; gap:8px; margin-bottom:4px;">
  673. <div style="display:flex; align-items:center; gap:8px; font-weight:600;">
  674. <span class="tag">题号 {{ $q['display_number'] ?? $q['question_number'] }} · {{ $typeLabel }}</span>
  675. @php
  676. $kpName = $q['knowledge_point_name'] ?? $q['knowledge_point'] ?? null;
  677. if (!empty($kpName) && $kpName !== '-' && $kpName !== '未标注') {
  678. echo '<span class="tag" style="background: #eef2ff; color:#4338ca;">' . e($kpName) . '</span>';
  679. }
  680. @endphp
  681. @if($showStatus)
  682. <span class="tag" style="background: {{ $statusColor }}; color:#fff;">{{ $statusText }}</span>
  683. @endif
  684. </div>
  685. @if($score !== null && $fullScore !== null)
  686. <div class="muted">得分 {{ $score }} / {{ $fullScore }}</div>
  687. @endif
  688. </div>
  689. <div class="math-content" style="margin-bottom:6px;">{!! $questionText !!}</div>
  690. {{-- 【修复】正确答案显示 --}}
  691. @if(!empty($correctAnswer))
  692. <div class="question-block" style="background:#f0fdf4; border-left:3px solid #10b981;">
  693. <div style="font-weight:600; font-size:12px; color:#111827; margin-bottom:3px;">正确答案</div>
  694. <div class="math-content" style="line-height:1.7; color:#374151;">
  695. {!! is_string($correctAnswer) ? $correctAnswer : json_encode($correctAnswer, JSON_UNESCAPED_UNICODE) !!}
  696. </div>
  697. </div>
  698. @endif
  699. {{-- 【修改】解题思路显示(优先显示solution,其次显示analysis) --}}
  700. @if(!empty($solution))
  701. <div class="question-block" style="margin-top:6px; background:#eff6ff; border-left:3px solid #3b82f6;">
  702. <div style="font-weight:600; font-size:12px; color:#111827; margin-bottom:4px;">解题思路</div>
  703. <div class="math-content solution-content" style="color:#374151;">
  704. {!! nl2br(e(is_array($solution) ? json_encode($solution, JSON_UNESCAPED_UNICODE) : (string) $solution)) !!}
  705. </div>
  706. </div>
  707. @elseif(!empty($analysis) && $analysis !== '暂无解题思路记录')
  708. <div class="question-block" style="margin-top:6px; background:#eff6ff; border-left:3px solid #3b82f6;">
  709. <div style="font-weight:600; font-size:12px; color:#111827; margin-bottom:4px;">解题思路</div>
  710. <div class="math-content solution-content" style="color:#374151;">{!! nl2br(e((string) $analysis)) !!}</div>
  711. </div>
  712. @endif
  713. {{-- 解题步骤(如果有) --}}
  714. @if(!empty($steps))
  715. <div style="margin-top:6px; font-size:12px;">
  716. <div style="font-weight:600; margin-bottom:3px;">解题步骤</div>
  717. <ol style="margin:0; padding-left:18px;">
  718. @foreach($steps as $s)
  719. <li style="margin-bottom:2px;">{!! nl2br(e(is_array($s) ? json_encode($s, JSON_UNESCAPED_UNICODE) : $s)) !!}</li>
  720. @endforeach
  721. </ol>
  722. </div>
  723. @endif
  724. </div>
  725. @endforeach
  726. </div>
  727. @endif
  728. </div> {{-- 闭合page div --}}
  729. <script src="/js/katex.min.js"></script>
  730. <script src="/js/auto-render.min.js"></script>
  731. <script>
  732. document.addEventListener('DOMContentLoaded', function() {
  733. try {
  734. renderMathInElement(document.body, {
  735. delimiters: [
  736. {left: "$$", right: "$$", display: true},
  737. {left: "$", right: "$", display: false},
  738. {left: "\\(", right: "\\)", display: false},
  739. {left: "\\[", right: "\\]", display: true}
  740. ],
  741. throwOnError: false,
  742. strict: false,
  743. trust: true
  744. });
  745. } catch (e) {}
  746. });
  747. </script>
  748. </body>
  749. </html>