|
|
@ -26,6 +26,7 @@ class CreateWatchVideoService < ApplicationService
|
|
|
|
watch_video_history.total_duration = params[:total_duration]
|
|
|
|
watch_video_history.total_duration = params[:total_duration]
|
|
|
|
watch_video_history.watch_duration = params[:watch_duration] > watch_video_history.duration ? watch_video_history.duration : params[:watch_duration]
|
|
|
|
watch_video_history.watch_duration = params[:watch_duration] > watch_video_history.duration ? watch_video_history.duration : params[:watch_duration]
|
|
|
|
watch_video_history.is_finished = params[:ed].present?
|
|
|
|
watch_video_history.is_finished = params[:ed].present?
|
|
|
|
|
|
|
|
watch_video_history.last_point = params[:point].to_i
|
|
|
|
watch_video_history.save!
|
|
|
|
watch_video_history.save!
|
|
|
|
|
|
|
|
|
|
|
|
watch_course_video = watch_video_history.watch_course_video
|
|
|
|
watch_course_video = watch_video_history.watch_course_video
|
|
|
@ -33,6 +34,18 @@ class CreateWatchVideoService < ApplicationService
|
|
|
|
if watch_course_video.present?
|
|
|
|
if watch_course_video.present?
|
|
|
|
watch_course_video.total_duration = watch_course_video.watch_video_histories.sum(:total_duration)
|
|
|
|
watch_course_video.total_duration = watch_course_video.watch_video_histories.sum(:total_duration)
|
|
|
|
watch_course_video.end_at = current_time
|
|
|
|
watch_course_video.end_at = current_time
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if params[:point].to_i > watch_course_video.last_point
|
|
|
|
|
|
|
|
detail = WatchCourseVideoDetail.find_or_initialize_by(watch_course_video_id: watch_course_video.id, user_id: user.id) do |d|
|
|
|
|
|
|
|
|
d.times = [[ watch_course_video.last_point, params[:point].to_i]]
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
if detail.persisted?
|
|
|
|
|
|
|
|
detail.times << [watch_course_video.last_point, params[:point].to_i]
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
detail.save
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
watch_course_video.last_point = params[:point].to_i
|
|
|
|
|
|
|
|
|
|
|
|
if !watch_course_video.is_finished
|
|
|
|
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.watch_duration = params[:watch_duration] if watch_course_video.watch_duration < params[:watch_duration]
|
|
|
@ -50,8 +63,8 @@ class CreateWatchVideoService < ApplicationService
|
|
|
|
d.start_at = current_time
|
|
|
|
d.start_at = current_time
|
|
|
|
d.duration = params[:duration]
|
|
|
|
d.duration = params[:duration]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
watch_course_video.last_point = params[:point].to_i
|
|
|
|
watch_course_video.save! unless watch_course_video.persisted?
|
|
|
|
watch_course_video.save!
|
|
|
|
watch_video_history = build_video_log(current_time, course_video.video_id, watch_course_video.id)
|
|
|
|
watch_video_history = build_video_log(current_time, course_video.video_id, watch_course_video.id)
|
|
|
|
watch_video_history.save!
|
|
|
|
watch_video_history.save!
|
|
|
|
else
|
|
|
|
else
|
|
|
|