|
@@ -2,6 +2,7 @@
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
|
|
+use App\Models\Paper;
|
|
|
use App\Services\QuestionBankService;
|
|
use App\Services\QuestionBankService;
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Request;
|
|
|
use Illuminate\Support\Facades\Cache;
|
|
use Illuminate\Support\Facades\Cache;
|
|
@@ -1042,7 +1043,6 @@ class ExamPdfController extends Controller
|
|
|
|
|
|
|
|
// 批量获取知识点讲解
|
|
// 批量获取知识点讲解
|
|
|
$knowledgePoints = $pdfService->buildExplanations($kpCodes);
|
|
$knowledgePoints = $pdfService->buildExplanations($kpCodes);
|
|
|
-info('knowledgePoints'.json_encode($knowledgePoints));
|
|
|
|
|
return view('pdf.exam-knowledge-explanation', [
|
|
return view('pdf.exam-knowledge-explanation', [
|
|
|
'paperId' => $paper_id,
|
|
'paperId' => $paper_id,
|
|
|
'examCode' => $examCode ?: $paper_id,
|
|
'examCode' => $examCode ?: $paper_id,
|
|
@@ -1071,19 +1071,34 @@ info('knowledgePoints'.json_encode($knowledgePoints));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
- // 调用 PDF 生成服务
|
|
|
|
|
- $pdfService = app(\App\Services\ExamPdfExportService::class);
|
|
|
|
|
|
|
+ // 【修复】首先检查试卷是否存在
|
|
|
|
|
+ $paperModel = Paper::with('questions')->find($paper_id);
|
|
|
|
|
+ if (! $paperModel || $paperModel->questions->isEmpty()) {
|
|
|
|
|
+ return response()->json([
|
|
|
|
|
+ 'success' => false,
|
|
|
|
|
+ 'message' => '无效的试卷',
|
|
|
|
|
+ 'paper_id' => $paper_id,
|
|
|
|
|
+ ], 400);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- // 是否包含知识点讲解(可选):未传参则使用 config/pdf.php 默认值
|
|
|
|
|
|
|
+ // 根据 config 或 env 配置决定是否包含知识点讲解
|
|
|
|
|
+ // 还需要判断如果摸底(paper_type =0)的时候也是不需要插入知识点讲解内容
|
|
|
$includeKpExplain = null;
|
|
$includeKpExplain = null;
|
|
|
|
|
+
|
|
|
if ($request->has('include_kp_explain')) {
|
|
if ($request->has('include_kp_explain')) {
|
|
|
$includeKpExplain = filter_var(
|
|
$includeKpExplain = filter_var(
|
|
|
$request->input('include_kp_explain'),
|
|
$request->input('include_kp_explain'),
|
|
|
FILTER_VALIDATE_BOOLEAN,
|
|
FILTER_VALIDATE_BOOLEAN,
|
|
|
FILTER_NULL_ON_FAILURE
|
|
FILTER_NULL_ON_FAILURE
|
|
|
);
|
|
);
|
|
|
|
|
+ } elseif ($paperModel->paper_type === 0) {
|
|
|
|
|
+ $includeKpExplain = false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ info("includekpexplain", [$includeKpExplain]);
|
|
|
|
|
+ // 调用 PDF 生成服务
|
|
|
|
|
+ $pdfService = app(\App\Services\ExamPdfExportService::class);
|
|
|
|
|
+
|
|
|
// 生成统一 PDF(卷子 + 判卷)
|
|
// 生成统一 PDF(卷子 + 判卷)
|
|
|
$pdfUrl = $pdfService->generateUnifiedPdf($paper_id, $includeKpExplain);
|
|
$pdfUrl = $pdfService->generateUnifiedPdf($paper_id, $includeKpExplain);
|
|
|
|
|
|