diff --git a/app/controllers/managements/video_applies_controller.rb b/app/controllers/managements/video_applies_controller.rb new file mode 100644 index 00000000..55c4c337 --- /dev/null +++ b/app/controllers/managements/video_applies_controller.rb @@ -0,0 +1,47 @@ +class Managements::VideoAppliesController < Managements::BaseController + before_filter :set_menu_type + + def index + applies = VideoApply.order('video_applies.updated_at desc') + + search = params[:search].to_s.strip + if search.present? + applies = applies.joins(:video) + .where('videos.title like :search', search: "%#{search}%") + end + + applies = applies.where(status: params[:status].presence || :pending) + + @video_applies = paginateHelper applies.includes(video: { user: :user_extensions }) + + respond_to do |format| + format.js + format.html + end + end + + def agree + Videos::AgreeApplyService.new(current_video_apply, current_user).call + render json: { status: 0 } + rescue Videos::AgreeApplyService::Error => e + render json: { status: -1, message: e.message } + end + + def refuse + Videos::RefuseApplyService.new(current_video_apply, current_user, reason: params[:reason]).call + render json: { status: 0 } + rescue Videos::RefuseApplyService::Error => e + render json: { status: -1, message: e.message } + end + + private + + def current_video_apply + @_current_video_apply ||= VideoApply.find(params[:id]) + end + + def set_menu_type + @menu_type = 10 + @sub_type = 10 + end +end \ No newline at end of file diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 6a62503e..c497cb4e 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -756,6 +756,7 @@ module ApplicationHelper when 7 then '职业认证' when 8 then '教学案例发布' when 9 then '众包需求发布' + when 10 then '视频发布' else '职业认证' end when 11 diff --git a/app/models/video.rb b/app/models/video.rb new file mode 100644 index 00000000..c849f1fa --- /dev/null +++ b/app/models/video.rb @@ -0,0 +1,36 @@ +class Video < ActiveRecord::Base + include AASM + + belongs_to :user + + has_many :video_applies, dependent: :destroy + has_one :processing_video_apply, conditions: { status: :pending }, class_name: 'VideoApply' + + aasm(:status) do + state :pending, initial: true + state :processing + state :refused + state :published + + event :apply_publish do + transitions from: :pending, to: :processing + end + + event :refuse do + transitions from: :processing, to: :refused + end + + event :publish do + transitions from: :processing, to: :published, guard: :vod_uploaded? + end + end + + aasm(:vod_status, namespace: :vod) do + state :uploading, initial: true + state :uploaded + + event :upload_success do + transitions from: :uploading, to: :uploaded + end + end +end \ No newline at end of file diff --git a/app/models/video_apply.rb b/app/models/video_apply.rb new file mode 100644 index 00000000..8d91bb7a --- /dev/null +++ b/app/models/video_apply.rb @@ -0,0 +1,19 @@ +class VideoApply < ActiveRecord::Base + include AASM + + belongs_to :video + + aasm(:status) do + state :pending, initial: true + state :refused + state :agreed + + event :refuse do + transitions from: :pending, to: :refused + end + + event :agree do + transitions from: :pending, to: :agreed + end + end +end \ No newline at end of file diff --git a/app/services/videos/agree_apply_service.rb b/app/services/videos/agree_apply_service.rb new file mode 100644 index 00000000..a317f8fa --- /dev/null +++ b/app/services/videos/agree_apply_service.rb @@ -0,0 +1,35 @@ +class Videos::AgreeApplyService + Error = Class.new(StandardError) + + attr_reader :video_apply, :video, :user + + def initialize(video_apply, user) + @video_apply = video_apply + @video = video_apply.video + @user = user + end + + def call + raise Error, '该状态下不能进行此操作' unless video_apply.may_agree? && video.may_publish? + + ActiveRecord::Base.transaction do + video_apply.agree! + + video.published_at = Time.now + video.publish + video.save! + + # 将消息改为已处理 + Tiding.where(container_id: video.id, container_type: 'Video', tiding_type: 'Apply', status: 0).update_all(status: 1) + notify_video_author! + end + end + + private + + def notify_video_author! + Tiding.create!(user_id: video.user_id, trigger_user_id: 1, + container_id: video.id, container_type: 'Video', + tiding_type: 'System', status: 1) + end +end \ No newline at end of file diff --git a/app/services/videos/refuse_apply_service.rb b/app/services/videos/refuse_apply_service.rb new file mode 100644 index 00000000..e6ef65dc --- /dev/null +++ b/app/services/videos/refuse_apply_service.rb @@ -0,0 +1,38 @@ +class Videos::RefuseApplyService + Error = Class.new(StandardError) + + attr_reader :video_apply, :video, :user, :params + + def initialize(video_apply, user, params) + @video_apply = video_apply + @video = video_apply.video + @user = user + @params = params + end + + def call + reason = params[:reason].to_s.strip + raise Error, '原因不能为空' if reason.blank? + raise Error, '该状态下不能进行此操作' unless video_apply.may_refuse? + + ActiveRecord::Base.transaction do + video_apply.reason = reason + video_apply.refuse + video_apply.save! + + video.refuse! + + # 将消息改为已处理 + Tiding.where(container_id: video.id, container_type: 'Video', tiding_type: 'Apply', status: 0).update_all(status: 1) + notify_video_author! + end + end + + private + + def notify_video_author! + Tiding.create!(user_id: video.user_id, trigger_user_id: 1, + container_id: video.id, container_type: 'Video', + tiding_type: 'System', status: 2, extra: video_apply.reason) + end +end \ No newline at end of file diff --git a/app/views/layouts/base_management.html.erb b/app/views/layouts/base_management.html.erb index 3392f099..fc5e0afe 100644 --- a/app/views/layouts/base_management.html.erb +++ b/app/views/layouts/base_management.html.erb @@ -123,6 +123,7 @@
视频发布
++ <%= link_to "全部", video_applies_path(status: [:refused, :agreed]), :class => "edu-filter-cir-grey mr5 fl font-12 active", :id => "video_all_authentication", :remote => true %> + <%= link_to "同意", video_applies_path(status: :agreed), :class => "edu-filter-cir-grey mr5 fl font-12", :id => "video_agree_authentication", :remote => true %> + <%= link_to "拒绝", video_applies_path(status: :refused), :class => "edu-filter-cir-grey mr5 fl font-12", :id => "video_reject_authentication", :remote => true %> +
+ + +