forked from Trustie/forgeplus
64 lines
2.8 KiB
Ruby
64 lines
2.8 KiB
Ruby
class Admins::ResidentExpertsController < Admins::BaseController
|
|
before_action :require_admin
|
|
before_action :get_expert, only: [:approve, :reject, :destroy, :residency_info]
|
|
|
|
def index
|
|
sort_by = ResidentExpert.column_names.include?(params[:sort_by]) ? params[:sort_by] : 'created_at'
|
|
sort_direction = %w(desc asc).include?(params[:sort_direction]) ? params[:sort_direction] : 'desc'
|
|
q = ResidentExpert.ransack(name_or_department_cont: params[:search])
|
|
experts = q.result(distinct: true).order("#{sort_by} #{sort_direction}")
|
|
@experts = paginate(experts)
|
|
end
|
|
|
|
def destroy
|
|
if @expert.destroy
|
|
redirect_to admins_resident_experts_path
|
|
flash[:success] = "删除成功"
|
|
else
|
|
redirect_to admins_resident_experts_path
|
|
flash[:danger] = "删除失败"
|
|
end
|
|
end
|
|
|
|
def approve
|
|
if @expert.update_attributes(status: :approved)
|
|
@expert.resident_expert_actions.where.not(action_type: ResidentExpertAction::action_types[:approved]).destroy_all
|
|
@expert.resident_expert_actions.create(action_type: ResidentExpertAction::action_types[:approved], action_name: '管理员审核通过' )
|
|
@expert.resident_expert_actions.create(action_type: ResidentExpertAction::action_types[:approved], action_name: '专家主页上线' )
|
|
SendTemplateMessageJob.perform_later('ResidentExpertApproved', [@expert.user_id], @expert.id)
|
|
redirect_to admins_resident_experts_path
|
|
flash[:success] = "入驻通过成功"
|
|
else
|
|
redirect_to admins_resident_experts_path
|
|
flash[:danger] = "入驻通过失败"
|
|
end
|
|
end
|
|
|
|
def reject
|
|
if @expert.update_attributes(status: :rejected, reject_remark: params[:reject_remark])
|
|
@expert.resident_expert_actions.where.not(action_type: ResidentExpertAction::action_types[:approved]).destroy_all
|
|
@expert.resident_expert_actions.create(action_type: ResidentExpertAction::action_types[:rejected], action_name: '管理员驳回', action_description: params[:rejection_reason] )
|
|
@expert.resident_expert_actions.create(action_type: ResidentExpertAction::action_types[:todo], action_name: '展示上线', action_description: "待重新申请并通过审核" )
|
|
SendTemplateMessageJob.perform_later('ResidentExpertRejected', [@expert.user_id], @expert.id)
|
|
redirect_to admins_resident_experts_path
|
|
flash[:success] = "入驻驳回成功"
|
|
else
|
|
redirect_to admins_resident_experts_path
|
|
flash[:danger] = "入驻驳回失败"
|
|
end
|
|
end
|
|
|
|
def residency_info
|
|
render partial: 'admins/resident_experts/residency_info', locals: { resident_expert: @expert }
|
|
end
|
|
|
|
private
|
|
|
|
def get_expert
|
|
@expert = ResidentExpert.find_by(id: params[:id])
|
|
unless @expert.present?
|
|
redirect_to admins_resident_experts_path
|
|
flash[:danger] = "专家入驻信息不存在"
|
|
end
|
|
end
|
|
end |