diff --git a/app/Http/Admin/Services/Course.php b/app/Http/Admin/Services/Course.php index 414a011f..24fb1d61 100644 --- a/app/Http/Admin/Services/Course.php +++ b/app/Http/Admin/Services/Course.php @@ -163,6 +163,9 @@ class Course extends Service if (isset($post['published'])) { $data['published'] = $validator->checkPublishStatus($post['published']); + if ($post['published'] == 1) { + $validator->checkPublishAbility($course); + } } if (isset($post['category_id']) && !empty($post['category_id'])) { diff --git a/app/Validators/Course.php b/app/Validators/Course.php index 16bbae68..5b8d521a 100644 --- a/app/Validators/Course.php +++ b/app/Validators/Course.php @@ -258,4 +258,25 @@ class Course extends Validator return $status; } + public function checkPublishAbility(CourseModel $course) + { + $courseRepo = new CourseRepo(); + + $lessons = $courseRepo->findLessons($course->id); + + $ability = false; + + if ($lessons->count() > 0) { + foreach ($lessons as $lesson) { + if ($lesson->published == 1) { + $ability = true; + } + } + } + + if (!$ability) { + throw new BadRequestException('course.content_not_ready'); + } + } + } diff --git a/config/errors.php b/config/errors.php index 28a52c52..cc7c3359 100644 --- a/config/errors.php +++ b/config/errors.php @@ -187,7 +187,7 @@ $error['course.invalid_study_expiry'] = '无效的学习期限'; $error['course.invalid_refund_expiry'] = '无效的退款期限'; $error['course.invalid_feature_status'] = '无效的推荐状态'; $error['course.invalid_publish_status'] = '无效的发布状态'; -$error['course.teacher_not_assigned'] = '尚未指定授课教师'; +$error['course.content_not_ready'] = '课程内容未就绪'; /** * 面授课程相关