'array']; public function availabilityError(): ?array { $now = \Illuminate\Support\Carbon::now(); if ($this->start_time) { $start = \Illuminate\Support\Carbon::parse($this->start_time); if ($start->greaterThan($now)) { $formatted = $start->format($start->format('H:i:s') === '00:00:00' ? 'Y年m月d日' : 'Y年m月d日 H:i:s'); return ['access_state' => 'not_started', 'access_error' => '该问卷尚未开始,请于'.$formatted.'后扫码打开该问卷。']; } } if ((int) $this->status !== 1) return ['access_state' => 'draft', 'access_error' => '该问卷还未开始。']; if ($this->end_time && \Illuminate\Support\Carbon::parse($this->end_time)->lessThanOrEqualTo($now)) { return ['access_state' => 'ended', 'access_error' => '该问卷已结束。']; } return null; } public function participationError($userId): ?string { if ($this->audience_course_ids && !CourseSign::where('user_id', $userId)->whereIn('course_id', $this->audience_course_ids)->where('status', 1)->exists()) return '您还未报名相关课程'; return null; } protected $appends = ['course_content']; public function getCourseContentAttribute() { if (empty($this->course_content_id)) { return []; } $course_content_id = explode(',', $this->course_content_id); return CourseContent::whereIn('id', $course_content_id)->get(); } public function course() { return $this->belongsTo(Course::class, 'course_id', 'id'); } public function courseContentEvaluationAsks() { return $this->hasMany(CourseContentEvaluationAsk::class, 'course_content_evaluation_id', 'id'); } public function courseContentEvaluationForms() { return $this->hasMany(CourseContentEvaluationForm::class, 'course_content_evaluation_id', 'id'); } }