|
|
|
@ -16,11 +16,11 @@ class CreateWatchVideoService < ApplicationService
|
|
|
|
|
|
|
|
|
|
if params[:log_id].present?
|
|
|
|
|
watch_video_history = user.watch_video_histories.find(params[:log_id])
|
|
|
|
|
if params[:total_duration] < params[:watch_duration]
|
|
|
|
|
return watch_video_history
|
|
|
|
|
end
|
|
|
|
|
# if params[:total_duration] < params[:watch_duration]
|
|
|
|
|
# return watch_video_history
|
|
|
|
|
# end
|
|
|
|
|
# 更新观看时长
|
|
|
|
|
if watch_video_history.present? && !watch_video_history.is_finished && watch_video_history.watch_duration <= params[:watch_duration] && watch_video_history.total_duration <= params[:total_duration]
|
|
|
|
|
if watch_video_history.present? && !watch_video_history.is_finished && watch_video_history.total_duration <= params[:total_duration]
|
|
|
|
|
# 如果观看总时长没变,说明视频没有播放,无需再去记录
|
|
|
|
|
watch_video_history.end_at = current_time
|
|
|
|
|
watch_video_history.total_duration = params[:total_duration]
|
|
|
|
@ -49,7 +49,9 @@ class CreateWatchVideoService < ApplicationService
|
|
|
|
|
if !watch_course_video.is_finished
|
|
|
|
|
# 更新课程视频的时长及是否看完状态
|
|
|
|
|
watch_course_video.watch_duration = params[:watch_duration] if watch_course_video.watch_duration < params[:watch_duration]
|
|
|
|
|
watch_course_video.is_finished = watch_course_video.total_duration >= watch_course_video.duration if params[:ed].present?
|
|
|
|
|
if params[:ed].present? || (watch_course_video.duration >= 300 && (watch_course_video.duration - params[:point].to_i) <= 20)
|
|
|
|
|
watch_course_video.is_finished = watch_course_video.total_duration >= watch_course_video.duration
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
watch_course_video.save!
|
|
|
|
|
end
|
|
|
|
|