forgeplus/app/controllers/applied_projects_controller.rb

59 lines
2.1 KiB
Ruby

class AppliedProjectsController < ApplicationController
before_action :require_login
def create
@applied_project = Projects::ApplyJoinService.call(current_user, applied_params)
if @applied_project.class.to_s != "AppliedProject"
render_ok({data: @applied_project})
end
rescue Projects::ApplyJoinService::Error => ex
render_error(ex.message)
end
#审核列表
def index
project = Project.find_by(identifier: params[:project_identifier])
tip_exception(-1, "该项目不存在~") if project.blank?
status = params[:status] || 1
if status.to_i == 1
status = ["common"]
elsif status.to_i == 2
status = ["accepted", "refused"]
end
applied_projects = project.applied_projects
if status.present?
applied_projects = applied_projects.where(status: status)
end
keyword = params[:keyword].to_s.strip
if keyword.present?
applied_projects = applied_projects.joins(user: :user_extension).where("CONCAT(users.lastname, users.firstname) LIKE :keyword OR users.phone LIKE :keyword", keyword: "%#{params[:keyword].to_s.strip}%")
end
@count = applied_projects.size
@applied_projects = paginate applied_projects.order(updated_at: :DESC)
end
#审核
def verify
tip_exception(-1, "参数值有误") if !["agree","reject"].include?(params[:verify_status])
applied_project = AppliedProject.find_by(id: params[:id])
tip_exception(-1, '该数据不存在') if applied_project.blank?
tip_exception(-1, '该数据已审核,请勿重复操作') if applied_project.status != "common"
begin
ActiveRecord::Base.transaction do
if params[:verify_status] == "agree"
Projects::VerifyService.new(applied_project, current_user, params).agree
elsif params[:verify_status] == "reject"
Projects::VerifyService.new(applied_project, current_user, params).reject
end
render_ok
end
rescue => e
uid_logger_error(e.message)
tip_exception("审核失败:#{e.message}")
end
end
private
def applied_params
params.require(:applied_project).permit(:code, :role, :alert_remarks, :remarks, :attachment_id)
end
end