问卷 新闻

master
lion 20 hours ago
parent 03a06faa0a
commit ba174c5603

@ -151,6 +151,23 @@ class CourseContentEvaluationFormController extends BaseController
}
$detail = $this->model->with('user')->find($all['id']);
if (!$detail) return $this->fail([ResponseCode::ERROR_BUSINESS, '答卷不存在']);
if (request()->filled('download_file_id')) {
$fileId = (string) request('download_file_id');
$attached = false;
foreach ($detail->data ?? [] as $answer) {
if (($answer['edit_input'] ?? '') !== 'file' || !is_array($answer['value'] ?? null)) continue;
foreach ($answer['value'] as $file) {
if ((string) ($file['id'] ?? '') === $fileId) $attached = true;
}
}
if (!$attached) return response()->json(['errmsg' => '附件不属于当前答卷'], 403);
$file = \App\Models\Upload::find($fileId);
if (!$file || $file->folder !== 'storage/files' || basename($file->name) !== $file->name) return response()->json(['errmsg' => '附件记录不存在或路径无效'], 404);
$disk = \Illuminate\Support\Facades\Storage::disk('public');
$path = 'files/'.$file->name;
if (!$disk->exists($path)) return response()->json(['errmsg' => '服务器上的附件文件不存在,请检查文件是否已同步'], 404);
return $disk->download($path, $file->original_name);
}
$questions = CourseContentEvaluationAsk::where('course_content_evaluation_id', $detail->course_content_evaluation_id)->orderBy('sort')->orderBy('id')->get()->toArray();
$detail->questions = SurveySchema::replyQuestions($questions, $detail->data, $detail->snapshot);
return $this->success($detail);

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -90,6 +90,12 @@ class SurveyWorkflowTest extends TestCase
$payload['data'][0]['value'] = [['id' => 81, 'original_name' => 'fake', 'url' => 'https://evil.invalid']];
$replyId = $this->postJson($url, $payload)->assertJsonPath('data.0.value.0.original_name', '调研附件.pdf')->json('id');
$this->getJson('/api/admin/course-content-evaluation-form/show?id='.$replyId)->assertJsonPath('questions.0.display_value', '调研附件.pdf')->assertJsonPath('questions.0.value.0.id', 81);
$download = '/api/admin/course-content-evaluation-form/show?id='.$replyId.'&download_file_id=';
$this->get($download.'81')->assertStatus(404)->assertJsonPath('errmsg', '服务器上的附件文件不存在,请检查文件是否已同步');
\Illuminate\Support\Facades\Storage::disk('public')->put('files/81.pdf', 'example attachment');
$this->get($download.'81')->assertOk()->assertStreamedContent('example attachment');
$this->get($download.'82')->assertStatus(403);
$this->getJson('/api/admin/course-content-evaluation-form/text-answers?course_content_evaluation_id=10&question_id='.$id)->assertJsonPath('data.0.files.0.original_name', '调研附件.pdf');
$this->getJson('/api/mobile/course/evaluation-detail?course_content_evaluation_id=10')->assertJsonPath('my_response.questions.0.value.0.id', 81);
$this->postJson($url, $payload)->assertJsonPath('id', $replyId);

Loading…
Cancel
Save