You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
1.7 KiB
62 lines
1.7 KiB
class Users::ApplyProfessionalAuthService < ApplicationService
|
|
Error = Class.new(StandardError)
|
|
|
|
attr_reader :user, :params
|
|
|
|
def initialize(user, params)
|
|
@user = user
|
|
@params = params
|
|
end
|
|
|
|
def call
|
|
Users::ApplyProfessionalAuthForm.new(params).validate!
|
|
raise Error, '您已经申请过职业认证了' if ApplyUserAuthentication.professional_auth.processing.exists?(user_id: user.id)
|
|
|
|
user.professional_certification = false
|
|
|
|
extension = user.user_extension
|
|
extension.school_id = params[:school_id]
|
|
extension.department_id = params[:department_id]
|
|
extension.identity = params[:identity]
|
|
|
|
extra = params[:extra].to_s.strip.presence
|
|
if extension.identity.to_s == 'student'
|
|
extension.technical_title = nil
|
|
extension.student_id = extra
|
|
else
|
|
extension.technical_title = extra
|
|
extension.student_id = nil
|
|
end
|
|
|
|
ActiveRecord::Base.transaction do
|
|
user.save!
|
|
extension.save!
|
|
|
|
user.apply_user_authentication.create!(auth_type: 2, status: 0)
|
|
|
|
move_image_file! unless params[:upload_image].to_s == 'false'
|
|
|
|
sms_notify_admin
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def move_image_file!
|
|
image_url = ApplicationController.helpers.disk_professional_auth_filename(user.id)
|
|
temp_image_url = image_url + 'temp'
|
|
|
|
FileUtils.mv(temp_image_url, image_url, force: true) if File.exist?(temp_image_url)
|
|
rescue RuntimeError => ex
|
|
Util.logger_error(ex)
|
|
raise Error, '申请失败'
|
|
ensure
|
|
File.delete(temp_image_url) if File.exist?(temp_image_url)
|
|
end
|
|
|
|
def sms_notify_admin
|
|
Educoder::Sms.notify_admin(send_type: 'apply_pro_certification')
|
|
rescue => ex
|
|
Util.logger_error(ex)
|
|
end
|
|
end |