| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739 |
- @php
- $v3 = $v3 ?? [];
- $summary = $v3['summary'] ?? [];
- $radar = $v3['radar'] ?? [];
- $modules = $v3['modules'] ?? [];
- $paths = $v3['paths'] ?? ['keep' => [], 'boost' => [], 'key' => []];
- $overallPlan = $v3['overall_plan'] ?? [];
- $rawPaperId = $paper['id'] ?? $paper['paper_id'] ?? 'unknown';
- preg_match('/paper_(\d{15})/', $rawPaperId, $matches);
- $reportCode = $matches[1] ?? preg_replace('/[^0-9]/', '', (string) $rawPaperId);
- $generateDateTime = now()->format('Y年m月d日 H:i:s');
- $scoreObtained = $summary['score_obtained'] ?? null;
- $scoreTotal = $summary['score_total'] ?? null;
- $scoreRate = $summary['score_rate'] ?? null;
- $averageMastery = $summary['average_mastery'] ?? null;
- $overallLabel = $summary['overall_label'] ?? '待评估';
- $statusColor = function (string $status): string {
- return match ($status) {
- '良好' => '#16a34a',
- '一般' => '#f97316',
- '薄弱' => '#e11d48',
- default => '#64748b',
- };
- };
- $n = max(1, count($radar));
- $cx = 210;
- $cy = 155;
- $r = 108;
- $outer = [];
- $inner = [];
- for ($i = 0; $i < $n; $i++) {
- $angle = -M_PI / 2 + (2 * M_PI * $i / $n);
- $ox = $cx + $r * cos($angle);
- $oy = $cy + $r * sin($angle);
- $outer[] = [$ox, $oy];
- $value = isset($radar[$i]['value']) ? (float) $radar[$i]['value'] : 0.0;
- $ratio = max(0.0, min(1.0, $value / 5));
- $ix = $cx + $r * $ratio * cos($angle);
- $iy = $cy + $r * $ratio * sin($angle);
- $inner[] = [$ix, $iy];
- }
- $outerPoints = implode(' ', array_map(fn ($p) => round($p[0], 2).','.round($p[1], 2), $outer));
- $innerPoints = implode(' ', array_map(fn ($p) => round($p[0], 2).','.round($p[1], 2), $inner));
- $insightMap = [];
- foreach (($question_insights ?? []) as $insight) {
- $no = $insight['question_number'] ?? $insight['question_id'] ?? null;
- if ($no !== null) {
- $insightMap[$no] = $insight;
- }
- }
- $analysisWrongMap = [];
- foreach (($analysis_data['question_analysis'] ?? []) as $qa) {
- $qid = $qa['question_bank_id'] ?? $qa['question_id'] ?? null;
- if ($qid === null || $qid === '') {
- continue;
- }
- $rawCorrect = $qa['is_correct'] ?? null;
- $isWrongFromAnalysis = false;
- if (is_array($rawCorrect)) {
- $isWrongFromAnalysis = in_array(0, $rawCorrect, true);
- } elseif ($rawCorrect !== null) {
- $isWrongFromAnalysis = !boolval($rawCorrect);
- }
- if ($isWrongFromAnalysis) {
- $analysisWrongMap[(string) $qid] = true;
- }
- }
- $wrongQuestions = [];
- foreach (($questions ?? []) as $qItem) {
- $isCorrectProbe = $qItem['is_correct'] ?? null;
- $studentAnswerProbe = $qItem['student_answer'] ?? null;
- $correctAnswerProbe = $qItem['answer'] ?? ($qItem['correct_answer'] ?? null);
- if ($isCorrectProbe === null && !empty($studentAnswerProbe) && !empty($correctAnswerProbe)) {
- $isCorrectProbe = (trim((string) $studentAnswerProbe) === trim((string) $correctAnswerProbe)) ? 1 : 0;
- }
- $normalizedCorrect = $isCorrectProbe;
- if ($isCorrectProbe !== null) {
- $normalizedCorrect = is_bool($isCorrectProbe) ? ($isCorrectProbe ? 1 : 0) : intval($isCorrectProbe);
- }
- $qidProbe = (string) ($qItem['question_bank_id'] ?? $qItem['question_id'] ?? '');
- $isWrongByAnalysis = ($qidProbe !== '' && isset($analysisWrongMap[$qidProbe]));
- if ($normalizedCorrect === 0 || $isWrongByAnalysis) {
- $wrongQuestions[] = $qItem;
- }
- }
- $kpStats = [];
- foreach (($questions ?? []) as $qItem) {
- $kpName = trim((string) ($qItem['knowledge_point_name'] ?? $qItem['knowledge_point'] ?? '未标注知识点'));
- $kpName = $kpName === '' ? '未标注知识点' : $kpName;
- if (!isset($kpStats[$kpName])) {
- $kpStats[$kpName] = ['total' => 0, 'wrong' => 0];
- }
- $kpStats[$kpName]['total']++;
- }
- foreach ($wrongQuestions as $qItem) {
- $kpName = trim((string) ($qItem['knowledge_point_name'] ?? $qItem['knowledge_point'] ?? '未标注知识点'));
- $kpName = $kpName === '' ? '未标注知识点' : $kpName;
- if (!isset($kpStats[$kpName])) {
- $kpStats[$kpName] = ['total' => 0, 'wrong' => 0];
- }
- $kpStats[$kpName]['wrong']++;
- }
- $kpWrongStats = [];
- foreach ($kpStats as $kpName => $stat) {
- if (($stat['wrong'] ?? 0) <= 0) {
- continue;
- }
- $total = max(1, intval($stat['total'] ?? 0));
- $wrong = intval($stat['wrong'] ?? 0);
- $kpWrongStats[] = [
- 'kp_name' => $kpName,
- 'wrong' => $wrong,
- 'total' => $total,
- 'rate' => $wrong / $total,
- ];
- }
- usort($kpWrongStats, function ($a, $b) {
- if ($a['rate'] === $b['rate']) {
- return $b['wrong'] <=> $a['wrong'];
- }
- return $b['rate'] <=> $a['rate'];
- });
- @endphp
- <!DOCTYPE html>
- <html lang="zh-CN">
- <head>
- <meta charset="UTF-8">
- <title>学情分析报告</title>
- <link rel="stylesheet" href="/css/katex/katex.min.css">
- <style>
- @page {
- size: A4;
- margin: 2.2cm 2cm 2.3cm 2cm;
- @top-left { content: "知了数学·{{ $generateDateTime }}"; font-size: 13px; color: #666; }
- @top-center { content: "{{ $student['name'] ?? '-' }}"; font-size: 13px; color: #666; }
- @top-right {
- content: "{{ $reportCode }}";
- font-size: 19px;
- font-weight: 600;
- font-family: "Noto Sans", "Liberation Sans", "Nimbus Sans", sans-serif;
- color: #222;
- }
- @bottom-left { content: "{{ $reportCode }}"; font-size: 11px; color: #666; }
- @bottom-right { content: counter(page) "/" counter(pages); font-size: 13px; color: #666; }
- }
- * { box-sizing: border-box; }
- body { font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif; margin: 0; color: #0f172a; font-size: 13px; line-height: 1.65; }
- .page { page-break-after: auto; }
- .header { text-align: left; margin-bottom: 16px; }
- .paper-title { font-size: 30px; font-weight: 700; margin-bottom: 8px; color: #0b3a75; letter-spacing: 1px; }
- .meta-row { display: flex; justify-content: flex-start; gap: 16px; font-size: 13px; color: #475569; flex-wrap: wrap; }
- .section { margin-bottom: 14px; page-break-inside: auto; break-inside: auto; }
- .section-title { font-size: 20px; margin-bottom: 10px; font-weight: 700; color: #0b3a75; border-left: 5px solid #3b82f6; padding-left: 10px; line-height: 1.3; }
- .card { border: 1px solid #dbeafe; border-radius: 12px; padding: 14px; background: #f8fbff; }
- .summary-list { margin: 0; padding-left: 18px; }
- .summary-list li { margin: 6px 0; font-size: 13px; }
- .radar-center { text-align: center; }
- .legend { margin-top: 8px; font-size: 12px; color: #475569; }
- .legend span { margin: 0 8px; }
- .dot { display: inline-block; width: 10px; height: 10px; border-radius: 999px; margin-right: 4px; vertical-align: middle; }
- /* PDF 版优先上下结构,避免左右分栏导致拥挤 */
- .radar-split { display: block; width: 100%; }
- .radar-left { width: 100%; text-align: center; }
- .radar-right { width: 100%; padding-left: 0; margin-top: 10px; }
- .radar-desc { border: 1px solid #dbeafe; background: #f8fbff; border-radius: 12px; padding: 12px; text-align: left; }
- .radar-item { display: block; margin: 6px 0; font-size: 12px; }
- .kp-burst-card { margin-top: 10px; border: 1px solid #dbeafe; border-radius: 12px; padding: 10px; background: #fff; }
- .kp-burst-title { font-size: 13px; font-weight: 700; margin-bottom: 6px; color: #0b3a75; }
- .kp-burst-meta { font-size: 12px; color: #334155; margin-top: 6px; line-height: 1.6; }
- .kp-burst-list { margin-top: 6px; font-size: 11px; color: #334155; line-height: 1.5; }
- .kp-burst-list span { display: inline-block; margin-right: 10px; margin-bottom: 3px; }
- table { width: 100%; border-collapse: collapse; font-size: 12px; background: #fff; }
- th, td { border: 1px solid #d0d7e2; padding: 8px 10px; text-align: left; vertical-align: top; }
- th { background: #f1f5f9; color: #1e293b; font-weight: 700; }
- .badge { display: inline-block; padding: 2px 8px; border-radius: 999px; color: #fff; font-size: 11px; font-weight: 600; }
- .path-stack { display: block; }
- .path-box { border: 1px solid #e5e7eb; border-radius: 12px; padding: 12px 14px; margin-bottom: 10px; }
- .path-box.keep { background: #f0fdf4; border-color: #86efac; }
- .path-box.boost { background: #fff7ed; border-color: #fdba74; }
- .path-box.key { background: #fff1f2; border-color: #fda4af; }
- .path-title { font-size: 16px; font-weight: 700; margin-bottom: 6px; color: #111827; }
- .path-box ul { margin: 0; padding-left: 16px; }
- .path-box li { font-size: 13px; margin: 2px 0; }
- .plan { background: #eef4ff; border-left: 4px solid #3b82f6; border-radius: 12px; padding: 12px 14px; }
- .plan ol { margin: 0; padding-left: 18px; }
- .tag { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; color: #334155; background: #e5e7eb; }
- .error-kp-tag { display: inline-block; margin: 0 6px 6px 0; padding: 1px 7px; border-radius: 999px; font-size: 10px; color: #334155; background: #f8fafc; border: 1px solid #d1d5db; }
- .error-kp-tag.high-risk { color: #b91c1c; border-color: #fca5a5; background: #fff; font-weight: 600; }
- .question-card { border:1px solid #e5e7eb; border-radius:8px; padding:6px 9px; margin-bottom:5px; background:#fff; page-break-inside:auto; break-inside:auto; }
- .question-block { margin-bottom: 5px; padding: 5px; border-radius: 4px; page-break-inside: auto; break-inside: auto; }
- .question-card,
- .question-card .math-content,
- .question-card .solution-content { font-size: 12px; line-height: 1.7; }
- .question-card .question-stem svg,
- .question-card .math-content svg { max-width: 100%; height: auto; display: block; shape-rendering: geometricPrecision; text-rendering: geometricPrecision; }
- .question-card .question-stem svg text {
- font-family: "Noto Serif", "Noto Serif CJK SC", "Noto Sans CJK SC", "Noto Sans", "STSongti-SC", "PingFang SC", "Songti SC", serif !important;
- font-size: 13px !important;
- font-weight: bold;
- dominant-baseline: middle;
- text-anchor: middle;
- }
- .question-card .question-stem svg circle,
- .question-card .question-stem svg line,
- .question-card .question-stem svg polygon,
- .question-card .question-stem svg polyline { shape-rendering: geometricPrecision; }
- .question-card .question-stem img,
- .question-card .question-main img {
- display: block;
- max-width: 220px;
- max-height: 60mm;
- width: auto;
- height: auto;
- margin: 6px auto;
- box-sizing: border-box;
- object-fit: contain;
- -webkit-print-color-adjust: exact;
- print-color-adjust: exact;
- image-rendering: -webkit-optimize-contrast;
- }
- .question-card .question-stem .katex { font-size: 1em !important; vertical-align: 0; }
- .question-card .question-stem .katex-display { margin: 0.35em 0 !important; }
- .question-card .solution-content img,
- .question-card .report-answer-meta img {
- display: block;
- max-width: 220px;
- max-height: 60mm;
- width: auto;
- height: auto;
- margin: 6px auto;
- object-fit: contain;
- -webkit-print-color-adjust: exact;
- print-color-adjust: exact;
- }
- .solution-content {
- display: block;
- line-height: 1.75;
- white-space: normal;
- word-break: break-word;
- overflow-wrap: anywhere;
- page-break-inside: auto;
- break-inside: auto;
- }
- .report-options { margin-top: 6px; page-break-inside: auto; break-inside: auto; }
- .report-options.options-grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px 12px; }
- .report-options.options-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 20px; }
- .report-options.options-grid-1 { display: grid; grid-template-columns: 1fr; gap: 8px; }
- .report-options .option { display: flex; align-items: baseline; font-size: 12px; line-height: 1.6; page-break-inside: auto; break-inside: auto; }
- .report-options .option strong { margin-right: 4px; flex: 0 0 auto; }
- .report-options .option-value.option-short { white-space: nowrap; }
- .report-options .option-value.option-long { white-space: normal; word-break: break-word; }
- .report-options .option p, .report-options .option div { margin: 0; display: inline; }
- .report-options .option img { max-width: 100%; height: auto; vertical-align: middle; }
- .report-answer-meta { font-size: 12px; color: #2f2f2f; line-height: 1.75; margin-top: 6px; page-break-inside: auto; break-inside: auto; }
- .report-answer-meta .answer-line + .answer-line { margin-top: 4px; }
- .report-answer-meta .solution-content { display: inline; line-height: 1.75; }
- .muted { color: #6b7280; font-size: 12px; }
- </style>
- </head>
- <body>
- <div class="page">
- <div class="header">
- <h1 class="paper-title">学情分析报告</h1>
- <div class="meta-row">
- <span>学生姓名:{{ $student['name'] ?? '未知' }}</span>
- <span>报告日期:{{ now()->format('Y年n月j日') }}</span>
- </div>
- </div>
- <div class="section">
- <div class="section-title">一、总体评估</div>
- <div class="card">
- <ul class="summary-list">
- <li>本次诊断得分:
- @if($scoreObtained !== null && $scoreTotal !== null && $scoreTotal > 0)
- {{ rtrim(rtrim(number_format((float) $scoreObtained, 1), '0'), '.') }}/{{ rtrim(rtrim(number_format((float) $scoreTotal, 1), '0'), '.') }}
- @else
- 暂无得分数据
- @endif
- </li>
- <li>得分率:{{ $scoreRate !== null ? number_format((float) $scoreRate * 100, 1) . '%' : '暂无得分率' }}</li>
- <li>平均掌握度:{{ $averageMastery !== null ? number_format((float) $averageMastery * 100, 1) . '%' : '暂无掌握度' }}</li>
- <li>整体水平:{{ $overallLabel }}</li>
- </ul>
- </div>
- </div>
- <div class="section">
- <div class="section-title">二、知识点掌握雷达图</div>
- <div class="radar-split">
- <div class="radar-left">
- <svg width="430" height="320" viewBox="0 0 430 320">
- <polygon points="{{ $outerPoints }}" fill="#f8fafc" stroke="#cbd5e1" stroke-width="1"/>
- <polygon points="{{ $innerPoints }}" fill="rgba(59,130,246,0.28)" stroke="#3b82f6" stroke-width="2"/>
- @foreach($outer as $i => $p)
- <line x1="{{ $cx }}" y1="{{ $cy }}" x2="{{ round($p[0],2) }}" y2="{{ round($p[1],2) }}" stroke="#e2e8f0" stroke-width="1"/>
- @endforeach
- @foreach($outer as $i => $p)
- @php
- $name = $radar[$i]['name'] ?? '';
- $children = $radar[$i]['children'] ?? [];
- $labelX = $p[0] + (($p[0] >= $cx) ? 9 : -9);
- $labelY = $p[1] + (($p[1] >= $cy) ? 12 : -8);
- $anchor = $p[0] >= $cx ? 'start' : 'end';
- $dotColor = $statusColor((string) ($radar[$i]['status'] ?? '暂无'));
- $value = number_format((float) ($radar[$i]['value'] ?? 0), 2);
- $axisAngle = atan2(($p[1] - $cy), ($p[0] - $cx));
- @endphp
- <text x="{{ round($labelX,2) }}" y="{{ round($labelY,2) }}" font-size="11" fill="#334155" text-anchor="{{ $anchor }}">{{ $name }} {{ $value }}</text>
- <circle cx="{{ round($inner[$i][0],2) }}" cy="{{ round($inner[$i][1],2) }}" r="4" fill="{{ $dotColor }}" />
- @if(!empty($children))
- @foreach($children as $cIdx => $child)
- @php
- $childN = max(1, count($children));
- $depth = max(1, intval($child['depth'] ?? 1));
- $offset = ($cIdx - (($childN - 1) / 2)) * 0.04;
- $childAngle = $axisAngle + $offset;
- // 子知识点必须从父轴外圈向外发散,避免父轴值低时挤在中心
- $axisOuterR = sqrt(pow(($outer[$i][0] - $cx), 2) + pow(($outer[$i][1] - $cy), 2));
- $startR = max($axisOuterR + 4, 112 + (($depth - 1) * 10));
- $endR = $startR + 12 + (($depth - 1) * 4);
- $sx = $cx + $startR * cos($childAngle);
- $sy = $cy + $startR * sin($childAngle);
- $ex = $cx + $endR * cos($childAngle);
- $ey = $cy + $endR * sin($childAngle);
- $changed = !empty($child['changed']);
- $cColor = $changed ? '#e11d48' : '#94a3b8';
- $cWidth = $changed ? 1.5 : 0.8;
- $masteryPct = isset($child['mastery_level']) ? max(0, min(100, (float) $child['mastery_level'] * 100)) : null;
- $label = $masteryPct !== null ? number_format($masteryPct, 1) . '%' : '—';
- $tx = $cx + ($endR + 5 + (($depth - 1) * 2)) * cos($childAngle);
- $ty = $cy + ($endR + 5 + (($depth - 1) * 2)) * sin($childAngle);
- $anchor = cos($childAngle) >= 0 ? 'start' : 'end';
- @endphp
- <line x1="{{ round($sx,2) }}" y1="{{ round($sy,2) }}" x2="{{ round($ex,2) }}" y2="{{ round($ey,2) }}"
- stroke="{{ $cColor }}" stroke-width="{{ $cWidth }}" opacity="{{ $changed ? 0.95 : 0.85 }}"/>
- <circle cx="{{ round($ex,2) }}" cy="{{ round($ey,2) }}" r="{{ $changed ? 1.6 : 1.0 }}" fill="{{ $cColor }}" />
- <text x="{{ round($tx,2) }}" y="{{ round($ty,2) }}" font-size="9" fill="{{ $cColor }}" text-anchor="{{ $anchor }}">{{ $label }}</text>
- @endforeach
- @endif
- @endforeach
- </svg>
- <div class="legend">
- <span><i class="dot" style="background:#16a34a"></i>良好(4.0-5.0)</span>
- <span><i class="dot" style="background:#f97316"></i>一般(2.0-3.9)</span>
- <span><i class="dot" style="background:#e11d48"></i>薄弱(0-1.9)</span>
- <span><i class="dot" style="background:#64748b"></i>未涉及</span>
- <span><i class="dot" style="background:#94a3b8"></i>子知识点</span>
- <span><i class="dot" style="background:#e11d48"></i>子知识点变化</span>
- <span>外圈越远表示层级越深</span>
- </div>
- </div>
- <div class="radar-right">
- <div class="radar-desc">
- <strong>雷达图解读</strong>
- @foreach($radar as $item)
- @php $color = $statusColor((string) ($item['status'] ?? '暂无')); @endphp
- <span class="radar-item">
- <i class="dot" style="background:{{ $color }}"></i>
- {{ $item['name'] }}:{{ $item['status'] }}
- ({{ !empty($item['has_mastery']) ? number_format((float) ($item['value'] ?? 0), 2) . '/5' : '—' }})
- @if(!empty($item['children']))
- ,子知识点 {{ count($item['children']) }} 个
- @endif
- </span>
- @endforeach
- </div>
- </div>
- </div>
- </div>
- <div class="section">
- <div class="section-title">三、模块能力分析表</div>
- <table>
- <thead>
- <tr>
- <th style="width: 16%;">模块</th>
- <th style="width: 13%;">掌握分值</th>
- <th style="width: 12%;">掌握状态</th>
- <th style="width: 10%;">样本数</th>
- <th style="width: 12%;">得分率</th>
- <th>学生当前能力</th>
- </tr>
- </thead>
- <tbody>
- @foreach($modules as $m)
- @php
- $status = (string) ($m['status'] ?? '暂无');
- $color = $statusColor($status);
- $rate = $m['exam_score_rate'] ?? null;
- @endphp
- <tr>
- <td>{{ $m['module_name'] ?? '-' }}</td>
- <td>{{ $m['mastery_score_5'] !== null ? number_format((float) $m['mastery_score_5'], 2) . '/5' : '-' }}</td>
- <td><span class="badge" style="background:{{ $color }}">{{ $status }}</span></td>
- <td>{{ $m['kp_count'] ?? 0 }}</td>
- <td>{{ $rate !== null ? number_format((float) $rate * 100, 1) . '%' : '-' }}</td>
- <td>{{ $m['ability_text'] ?? '-' }}</td>
- </tr>
- @endforeach
- </tbody>
- </table>
- </div>
- <div class="section">
- <div class="section-title">四、分模块提分路径</div>
- <div class="path-stack">
- <div class="path-box keep">
- <div class="path-title">保分模块(保持优势)</div>
- <ul>
- @foreach(($paths['keep'] ?? []) as $item)
- <li>{{ $item['name'] }}:掌握度 {{ number_format((float) ($item['mastery_level'] ?? 0) * 100, 1) }}%</li>
- @endforeach
- </ul>
- @if(empty($paths['keep']))
- <div class="muted">暂无数据</div>
- @endif
- </div>
- <div class="path-box boost">
- <div class="path-title">涨分模块(重点突破)</div>
- <ul>
- @foreach(($paths['boost'] ?? []) as $item)
- <li>{{ $item['name'] }}:掌握度 {{ number_format((float) ($item['mastery_level'] ?? 0) * 100, 1) }}%</li>
- @endforeach
- </ul>
- @if(empty($paths['boost']))
- <div class="muted">暂无数据</div>
- @endif
- </div>
- <div class="path-box key">
- <div class="path-title">提分关键(优先补短)</div>
- <ul>
- @foreach(($paths['key'] ?? []) as $item)
- <li>{{ $item['name'] }}:掌握度 {{ number_format((float) ($item['mastery_level'] ?? 0) * 100, 1) }}%</li>
- @endforeach
- </ul>
- @if(empty($paths['key']))
- <div class="muted">暂无数据</div>
- @endif
- </div>
- </div>
- </div>
- <div class="section">
- <div class="section-title">五、整体提升方案</div>
- <div class="plan">
- <ol>
- @foreach($overallPlan as $line)
- <li>{{ $line }}</li>
- @endforeach
- </ol>
- </div>
- </div>
- @if(!empty($wrongQuestions))
- <div class="section" style="page-break-inside:auto; break-inside:auto;">
- <div class="section-title">六、这次错题记录</div>
- @if(!empty($kpWrongStats))
- <div style="margin-bottom:8px; padding:8px; border:1px solid #e5e7eb; border-radius:6px; background:#f8fafc;">
- <div style="font-size:12px; font-weight:600; margin-bottom:6px;">知识点错误率</div>
- <div style="font-size:12px; color:#475569; line-height:1.7;">
- @foreach($kpWrongStats as $item)
- <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>
- @endforeach
- </div>
- </div>
- @endif
- @foreach($wrongQuestions as $q)
- @php
- $studentAnswer = $q['student_answer'] ?? null;
- $correctAnswer = $q['answer'] ?? $q['correct_answer'] ?? null;
- $isCorrect = $q['is_correct'] ?? null;
- if ($isCorrect === null && !empty($studentAnswer) && !empty($correctAnswer)) {
- $isCorrect = (trim($studentAnswer) === trim($correctAnswer)) ? 1 : 0;
- }
- $statusText = '';
- $statusColorValue = '';
- if ($isCorrect === 1) {
- $statusText = '正确';
- $statusColorValue = '#10b981';
- } elseif ($isCorrect === 0) {
- $statusText = '错误';
- $statusColorValue = '#ef4444';
- }
- $showStatus = $statusText !== '';
- $insight = $insightMap[$q['question_number']] ?? ($insightMap[$q['display_number'] ?? null] ?? []);
- $fullScore = $insight['full_score'] ?? ($q['score'] ?? null);
- if ($isCorrect === 1) {
- $score = $fullScore;
- } elseif ($isCorrect === 0) {
- $score = $q['score_obtained'] ?? 0;
- } else {
- $score = null;
- }
- $analysisRaw = $insight['analysis']
- ?? $insight['thinking_process']
- ?? $insight['feedback']
- ?? $insight['suggestions']
- ?? $insight['reason']
- ?? ($insight['correct_solution'] ?? null);
- if (empty($analysisRaw) && !empty($insight['next_steps'])) {
- $analysisRaw = '后续建议:' . (is_array($insight['next_steps']) ? implode(';', $insight['next_steps']) : $insight['next_steps']);
- }
- $analysis = is_array($analysisRaw) ? json_encode($analysisRaw, JSON_UNESCAPED_UNICODE) : $analysisRaw;
- if ($analysis === null || $analysis === '') {
- $analysis = '暂无解题思路,待补充';
- }
- if (is_string($analysis)) {
- $analysis = preg_replace('/^【?\s*解题思路\s*】?\s*[::]?\s*/u', '', $analysis);
- }
- $formatSolutionLikeGrading = function ($text) {
- if (!is_string($text) || trim($text) === '') {
- return $text;
- }
- $normalized = preg_replace('/\s*;\s*步骤\s*(\d+)/u', ";\n步骤$1", $text);
- $normalized = preg_replace('/\s*。\s*步骤\s*(\d+)/u', "。\n步骤$1", $normalized);
- $normalized = preg_replace('/(?<!^)(步骤\s*\d+\s*[::])/u', "\n$1", $normalized);
- $normalized = preg_replace('/(?<!^)(第\s*\d+\s*步\s*[::]?)/u', "\n$1", $normalized);
- $normalized = preg_replace('/\n{3,}/u', "\n\n", $normalized);
- $normalized = preg_replace('/^[\h\x{3000}]+/mu', '', $normalized);
- return trim($normalized);
- };
- $stepsRaw = $insight['steps'] ?? $insight['solution_steps'] ?? $insight['analysis_steps'] ?? null;
- $steps = [];
- if (is_array($stepsRaw)) {
- $steps = $stepsRaw;
- } elseif (is_string($stepsRaw) && trim($stepsRaw) !== '') {
- $steps = preg_split('/[\r\n]+/', trim($stepsRaw));
- }
- $typeMap = ['choice' => '选择题', 'fill' => '填空题', 'answer' => '解答题'];
- $typeLabel = $typeMap[$q['question_type'] ?? ''] ?? ($q['question_type'] ?? '题型未标注');
- $questionText = is_string($q['question_text']) ? $q['question_text'] : json_encode($q['question_text'], JSON_UNESCAPED_UNICODE);
- $solution = $q['solution'] ?? null;
- if (is_string($solution)) {
- $solution = preg_replace('/^【?\s*解题思路\s*】?\s*[::]?\s*/u', '', $solution);
- }
- $solution = $formatSolutionLikeGrading($solution);
- $analysis = $formatSolutionLikeGrading($analysis);
- $renderLikeGrading = function ($text) {
- if (is_array($text)) {
- $text = json_encode($text, JSON_UNESCAPED_UNICODE);
- }
- $text = is_string($text) ? trim($text) : '';
- if ($text === '') {
- return '';
- }
- // 兼容题库里常见的转义写法:\$x\$、\$\frac{...}\$
- $text = preg_replace('/\\\\\\$/u', '$', $text);
- return \App\Services\MathFormulaProcessor::processFormulas($text);
- };
- $questionTextRendered = $renderLikeGrading($questionText);
- $displayCorrectAnswer = is_array($correctAnswer) ? json_encode($correctAnswer, JSON_UNESCAPED_UNICODE) : (string) $correctAnswer;
- $questionTypeRaw = strtolower(trim((string) ($q['question_type'] ?? '')));
- $isChoiceQuestion = in_array($questionTypeRaw, ['choice', 'multiple_choice', 'single_choice', '选择题', 'select'], true);
- $normalizedOptions = [];
- $correctAnswerLetters = [];
- if ($isChoiceQuestion) {
- $rawOptions = $q['options'] ?? [];
- if (is_string($rawOptions)) {
- $decodedOptions = json_decode($rawOptions, true);
- $rawOptions = is_array($decodedOptions) ? $decodedOptions : [];
- }
- if (is_array($rawOptions)) {
- foreach ($rawOptions as $optKey => $optValue) {
- $letter = null;
- if (is_string($optKey) && preg_match('/([A-H])/i', $optKey, $m)) {
- $letter = strtoupper($m[1]);
- } elseif (is_array($optValue)) {
- $candidate = $optValue['label'] ?? $optValue['key'] ?? $optValue['option'] ?? null;
- if (is_string($candidate) && preg_match('/([A-H])/i', $candidate, $m)) {
- $letter = strtoupper($m[1]);
- }
- }
- if ($letter === null) {
- continue;
- }
- $content = is_array($optValue) ? ($optValue['content'] ?? $optValue['text'] ?? $optValue['value'] ?? '') : $optValue;
- if (!is_string($content)) {
- $content = json_encode($content, JSON_UNESCAPED_UNICODE);
- }
- $content = trim((string) $content);
- if ($content !== '') {
- $normalizedOptions[$letter] = $content;
- }
- }
- }
- if (trim((string) $correctAnswer) !== '') {
- preg_match_all('/[A-H]/i', strtoupper((string) $correctAnswer), $answerMatches);
- $correctAnswerLetters = array_values(array_unique($answerMatches[0] ?? []));
- }
- if (!empty($normalizedOptions) && !empty($correctAnswerLetters)) {
- $mappedAnswers = [];
- foreach ($correctAnswerLetters as $letter) {
- if (isset($normalizedOptions[$letter])) {
- $mappedAnswers[] = $letter . '. ' . $normalizedOptions[$letter];
- }
- }
- if (!empty($mappedAnswers)) {
- $displayCorrectAnswer = implode(';', $mappedAnswers);
- }
- }
- }
- $choiceOptionLetters = !empty($normalizedOptions) ? array_keys($normalizedOptions) : [];
- sort($choiceOptionLetters);
- $choiceLayoutClass = 'options-grid-1';
- $layoutDecider = app(\App\Support\OptionLayoutDecider::class);
- if (! empty($normalizedOptions) && ! empty($choiceOptionLetters)) {
- $optValuesForLayout = [];
- foreach ($choiceOptionLetters as $L) {
- $optValuesForLayout[] = $normalizedOptions[$L];
- }
- $layoutMeta = $layoutDecider->decide($optValuesForLayout, 'grading');
- $choiceLayoutClass = $layoutMeta['class'] ?? 'options-grid-1';
- }
- @endphp
- <div class="question-card">
- <div style="display:flex; justify-content:space-between; align-items:center; gap:8px; margin-bottom:4px;">
- <div style="display:flex; align-items:center; gap:8px; font-weight:600;">
- <span class="tag">题号 {{ $q['display_number'] ?? $q['question_number'] }} · {{ $typeLabel }}</span>
- @php
- $kpName = $q['knowledge_point_name'] ?? $q['knowledge_point'] ?? null;
- if (!empty($kpName) && $kpName !== '-' && $kpName !== '未标注') {
- echo '<span class="tag" style="background: #eef2ff; color:#4338ca;">' . e($kpName) . '</span>';
- }
- @endphp
- @if($showStatus)
- <span class="tag" style="background: {{ $statusColorValue }}; color:#fff;">{{ $statusText }}</span>
- @endif
- </div>
- @if($score !== null && $fullScore !== null)
- <div class="muted">得分 {{ $score }} / {{ $fullScore }}</div>
- @endif
- </div>
- <div class="question-stem math-content" style="margin-bottom:6px;">{!! $questionTextRendered !!}</div>
- @if(!empty($isChoiceQuestion) && !empty($normalizedOptions))
- <div class="report-options {{ $choiceLayoutClass }}">
- @foreach($choiceOptionLetters as $optLetter)
- @php
- $isCorrectOpt = in_array($optLetter, $correctAnswerLetters ?? [], true);
- $rawOpt = (string) ($normalizedOptions[$optLetter] ?? '');
- $normalizedOpt = str_replace('\\dfrac', '\\frac', $rawOpt);
- $normalizedOpt = str_replace('\\displaystyle', '', $normalizedOpt);
- $normalizedOpt = $layoutDecider->normalizeCompactMathForDisplay($normalizedOpt);
- $rawOptPlain = html_entity_decode(strip_tags($rawOpt), ENT_QUOTES | ENT_HTML5, 'UTF-8');
- $rawOptPlain = preg_replace('/\s+/u', '', $rawOptPlain ?? '');
- $isShortOption = mb_strlen((string) $rawOptPlain, 'UTF-8') <= 8;
- $valClass = $isShortOption ? 'option-short' : 'option-long';
- $renderedOpt = $renderLikeGrading($normalizedOpt);
- @endphp
- <div class="option option-compact">
- <strong>{{ $optLetter }}.</strong>
- <span class="option-value {{ $valClass }}">{!! $renderedOpt !!}</span>
- @if($isCorrectOpt)
- <span style="margin-left:4px; font-size:13px; color:#15803d; font-weight:700;">✅</span>
- @endif
- </div>
- @endforeach
- </div>
- @endif
- @if(!empty($correctAnswer) && (!$isChoiceQuestion || empty($normalizedOptions)))
- <div class="question-block" style="background:#f0fdf4; border-left:3px solid #10b981;">
- <div style="font-weight:600; font-size:12px; color:#111827; margin-bottom:3px;">正确答案</div>
- <div class="math-content" style="line-height:1.7; color:#374151;">
- {!! $renderLikeGrading($displayCorrectAnswer) !!}
- </div>
- </div>
- @endif
- @if(!empty($solution))
- <div class="report-answer-meta">
- <div class="answer-line">
- <strong>解题思路:</strong>
- <span class="solution-content">{!! $renderLikeGrading($solution) !!}</span>
- </div>
- </div>
- @elseif(!empty($analysis) && $analysis !== '暂无解题思路记录')
- <div class="report-answer-meta">
- <div class="answer-line">
- <strong>解题思路:</strong>
- <span class="solution-content">{!! $renderLikeGrading($analysis) !!}</span>
- </div>
- </div>
- @endif
- @if(!empty($steps))
- <div style="margin-top:6px; font-size:12px;">
- <div style="font-weight:600; margin-bottom:3px;">解题步骤</div>
- <ol style="margin:0; padding-left:18px;">
- @foreach($steps as $s)
- @php
- $stepText = is_array($s) ? json_encode($s, JSON_UNESCAPED_UNICODE) : (string) $s;
- @endphp
- <li style="margin-bottom:2px;">{!! nl2br($renderLikeGrading($stepText)) !!}</li>
- @endforeach
- </ol>
- </div>
- @endif
- </div>
- @endforeach
- </div>
- @endif
- </div>
- <script src="/js/katex.min.js"></script>
- <script src="/js/auto-render.min.js"></script>
- <script>
- document.addEventListener('DOMContentLoaded', function() {
- try {
- renderMathInElement(document.body, {
- delimiters: [
- {left: "$$", right: "$$", display: true},
- {left: "$", right: "$", display: false},
- {left: "\\(", right: "\\)", display: false},
- {left: "\\[", right: "\\]", display: true}
- ],
- throwOnError: false,
- strict: false,
- trust: true
- });
- } catch (e) {}
- });
- </script>
- </body>
- </html>
|