master
cody 4 months ago
parent 271ce97959
commit 005b9b7ee8

@ -13,6 +13,7 @@ use App\Models\Course;
use App\Models\CourseAppointmentTotal;
use App\Models\CourseContent;
use App\Models\CourseContentCheck;
use App\Models\CourseContentEvaluation;
use App\Models\CourseContentEvaluationForm;
use App\Models\CourseSign;
use App\Models\Notice;
@ -291,7 +292,7 @@ class CourseController extends CommonController
* path="/api/mobile/course/course-content-form",
* tags={"小程序-课程"},
* summary="提交评价",
* @OA\Parameter(name="course_content_id", in="query", @OA\Schema(type="string"), required=false, description="课表的课堂id"),
* @OA\Parameter(name="course_content_evaluation_id", in="query", @OA\Schema(type="string"), required=false, description="问卷id"),
* @OA\Parameter(name="data", in="query", @OA\Schema(type="string"), required=false, description="表单数据数组"),
* @OA\Parameter(name="time_total", in="query", @OA\Schema(type="string"), required=false, description="用时,单位秒"),
* @OA\Response(
@ -304,35 +305,36 @@ class CourseController extends CommonController
{
$all = \request()->all();
$messages = [
'course_content_id.required' => '课表课堂id必填',
'course_content_evaluation_id.required' => '问卷id必填',
'data.required' => '表单数据必填',
'time_total.required' => '用时必填'
];
$validator = Validator::make($all, [
'course_content_id' => 'required',
'course_content_evaluation_id' => 'required',
'data' => 'required',
'time_total' => 'required'
], $messages);
if ($validator->fails()) {
return $this->fail([ResponseCode::ERROR_PARAMETER, implode(',', $validator->errors()->all())]);
}
$courseContentEvaluationForm = CourseContentEvaluationForm::where('user_id', $this->getUserId())
->where('course_content_id', $all['course_content_id'])
->first();
if ($courseContentEvaluationForm) {
return $this->fail([ResponseCode::ERROR_BUSINESS, '您已提交过评价']);
}
$courseContent = CourseContent::find($all['course_content_id']);
if ($courseContent->course_content_evaluation_status == 0) {
$courseContentEvaluation = CourseContentEvaluation::find($all['course_content_evaluation_id']);
if ($courseContentEvaluation->status == 0) {
return $this->fail([ResponseCode::ERROR_BUSINESS, '问卷未发布']);
}
if (strtotime($courseContent->course_content_evaluation_start_time) > time()) {
if (strtotime($courseContentEvaluation->start_time) > time()) {
return $this->fail([ResponseCode::ERROR_BUSINESS, '评价时间未开始']);
}
if (strtotime($courseContent->course_content_evaluation_end_time) < time()) {
if (strtotime($courseContentEvaluation->end_time) < time()) {
return $this->fail([ResponseCode::ERROR_BUSINESS, '评价时间已结束']);
}
$courseContentEvaluationForm = CourseContentEvaluationForm::where('user_id', $this->getUserId())
->where('course_content_evaluation_id', $all['course_content_evaluation_id'])
->first();
if ($courseContentEvaluationForm) {
return $this->fail([ResponseCode::ERROR_BUSINESS, '您已提交过评价']);
}
$model = CourseContentEvaluationForm::create([
'course_content_evaluation_id' => $all['course_content_evaluation_id'],
'user_id' => $this->getUserId(),
'time_total' => $all['time_total'],
'data' => $all['data']

@ -14,7 +14,7 @@ return new class extends Migration {
{
Schema::create('course_content_evaluation_forms', function (Blueprint $table) {
$table->id();
$table->integer('course_content_id')->nullable()->comment('课程内容id');
$table->integer('course_content_evaluation_id')->nullable()->comment('课程内容id');
$table->integer('user_id')->nullable()->comment('用户id');
$table->integer('time_total')->nullable()->comment('用时,单位秒');
$table->json('data')->nullable()->comment('数据');

Loading…
Cancel
Save