|
|
@@ -165,13 +165,13 @@ class UploadExamPaper extends Page
|
|
|
})->toArray();
|
|
|
|
|
|
// 2. 获取所有Paper记录(包括草稿和已评分)
|
|
|
- $paperQuery = \App\Models\Paper::with(['createdByUser'])->latest();
|
|
|
+ $paperQuery = \App\Models\Paper::with(['student'])->latest();
|
|
|
|
|
|
// 如果选择了学生,则筛选该学生的记录
|
|
|
if (!empty($this->studentId)) {
|
|
|
- $paperQuery->where('created_by', $this->studentId);
|
|
|
+ $paperQuery->where('student_id', $this->studentId);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
$allPapers = $paperQuery->take(5)
|
|
|
->get()
|
|
|
->map(function($paper) {
|
|
|
@@ -181,17 +181,17 @@ class UploadExamPaper extends Page
|
|
|
|
|
|
return [
|
|
|
'type' => $type,
|
|
|
- 'id' => $paper->id,
|
|
|
+ 'id' => $paper->paper_id,
|
|
|
'record_id' => null,
|
|
|
- 'paper_id' => $paper->id,
|
|
|
- 'student_id' => $paper->created_by,
|
|
|
- 'student_name' => $paper->createdByUser?->full_name ?? $paper->created_by,
|
|
|
+ 'paper_id' => $paper->paper_id,
|
|
|
+ 'student_id' => $paper->student_id,
|
|
|
+ 'student_name' => $paper->student?->name ?? $paper->student_id,
|
|
|
'paper_type' => $paperType,
|
|
|
- 'paper_name' => $paper->title ?? '未命名试卷',
|
|
|
- 'status' => $paper->difficulty_level,
|
|
|
- 'total_questions' => 0, // papers表没有question_count字段
|
|
|
+ 'paper_name' => $paper->paper_name ?? '未命名试卷',
|
|
|
+ 'status' => $paper->difficulty_category,
|
|
|
+ 'total_questions' => $paper->question_count ?? 0,
|
|
|
'created_at' => $paper->created_at->format('Y-m-d H:i'),
|
|
|
- 'is_completed' => $paper->difficulty_level !== null,
|
|
|
+ 'is_completed' => $paper->status === 'completed',
|
|
|
'icon_color' => $iconColor,
|
|
|
];
|
|
|
})->toArray();
|
|
|
@@ -216,15 +216,22 @@ class UploadExamPaper extends Page
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
- return \App\Models\Paper::where('created_by', $this->studentId)
|
|
|
+ // 使用 Student 关联查询试卷
|
|
|
+ $student = \App\Models\Student::find($this->studentId);
|
|
|
+ if (!$student) {
|
|
|
+ \Log::warning('未找到指定学生', ['student_id' => $this->studentId]);
|
|
|
+ return [];
|
|
|
+ }
|
|
|
+
|
|
|
+ return $student->papers()
|
|
|
->withCount('questions') // 添加题目计数
|
|
|
->orderBy('created_at', 'desc')
|
|
|
->take(20)
|
|
|
->get()
|
|
|
->map(function($paper) {
|
|
|
return [
|
|
|
- 'paper_id' => $paper->id,
|
|
|
- 'paper_name' => $paper->title ?? '未命名试卷',
|
|
|
+ 'paper_id' => $paper->paper_id, // 使用 paper_id 而不是 id
|
|
|
+ 'paper_name' => $paper->paper_name ?? '未命名试卷',
|
|
|
'total_questions' => $paper->questions_count ?? 0,
|
|
|
'total_score' => $paper->total_score ?? 0,
|
|
|
'created_at' => $paper->created_at->format('Y-m-d H:i'),
|
|
|
@@ -266,7 +273,7 @@ class UploadExamPaper extends Page
|
|
|
|
|
|
try {
|
|
|
// 首先检查试卷是否存在
|
|
|
- $paper = \App\Models\Paper::find($this->selectedPaperId);
|
|
|
+ $paper = \App\Models\Paper::where('paper_id', $this->selectedPaperId)->first();
|
|
|
if (!$paper) {
|
|
|
\Log::warning('未找到指定试卷', ['paper_id' => $this->selectedPaperId]);
|
|
|
return [];
|
|
|
@@ -275,7 +282,7 @@ class UploadExamPaper extends Page
|
|
|
// 使用关联关系查询题目
|
|
|
$paperWithQuestions = \App\Models\Paper::with(['questions' => function($query) {
|
|
|
$query->orderBy('question_number');
|
|
|
- }])->find($this->selectedPaperId);
|
|
|
+ }])->where('paper_id', $this->selectedPaperId)->first();
|
|
|
|
|
|
$questions = $paperWithQuestions ? $paperWithQuestions->questions : collect([]);
|
|
|
|