diff --git a/app/services/create_watch_video_service.rb b/app/services/create_watch_video_service.rb index f2d360638..b110bcc97 100644 --- a/app/services/create_watch_video_service.rb +++ b/app/services/create_watch_video_service.rb @@ -28,17 +28,18 @@ class CreateWatchVideoService < ApplicationService watch_course_video = watch_video_history.watch_course_video - watch_course_video.total_duration = watch_course_video.watch_video_histories.sum(:total_duration) - watch_course_video.end_at = current_time - watch_course_video.save! - - if watch_course_video.present? && !watch_course_video.is_finished && watch_course_video.watch_duration < params[:watch_duration].to_f - # 更新课程视频的时长及是否看完状态 - watch_course_video.watch_duration = params[:watch_duration] - if params[:ed].present? - watch_course_video.is_finished = watch_course_video.watch_video_histories.sum(:total_duration) >= watch_course_video.duration - end + if watch_course_video.present? + watch_course_video.total_duration = watch_course_video.watch_video_histories.sum(:total_duration) + watch_course_video.end_at = current_time watch_course_video.save! + if !watch_course_video.is_finished && watch_course_video.watch_duration < params[:watch_duration].to_f + # 更新课程视频的时长及是否看完状态 + watch_course_video.watch_duration = params[:watch_duration] + if params[:ed].present? + watch_course_video.is_finished = watch_course_video.total_duration >= watch_course_video.duration + end + watch_course_video.save! + end end end else