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.
61 lines
1.5 KiB
61 lines
1.5 KiB
class Users::UpdateAccountService < ApplicationService
|
|
|
|
attr_reader :user, :params
|
|
|
|
def initialize(user, params)
|
|
@user = user
|
|
@params = params
|
|
end
|
|
|
|
def call
|
|
form = Users::UpdateAccountForm.new(params.merge(user: user))
|
|
form.validate!
|
|
|
|
first_full_reward = false
|
|
ActiveRecord::Base.transaction do
|
|
first_full_reward = user.nickname.blank?
|
|
|
|
extension = user.user_extension || user.build_user_extension
|
|
|
|
user.assign_attributes(user_attributes)
|
|
extension.assign_attributes(user_extension_attributes)
|
|
|
|
# 未认证下才能修改姓名
|
|
if !user.authentication? && user.process_real_name_apply.blank?
|
|
user.lastname = params[:name]
|
|
user.firstname = ''
|
|
extension.gender = params[:gender]
|
|
end
|
|
|
|
if extension.student?
|
|
extension.student_id = params[:student_id]
|
|
extension.technical_title = nil
|
|
else
|
|
extension.student_id = nil
|
|
extension.technical_title = params[:technical_title]
|
|
end
|
|
|
|
# 表示资料完整
|
|
user.profile_completed = true
|
|
|
|
extension.save!
|
|
user.save!
|
|
end
|
|
|
|
if first_full_reward
|
|
RewardGradeService.call(user, container_id: user.id, container_type: 'Account', score: 500)
|
|
end
|
|
|
|
user
|
|
end
|
|
|
|
private
|
|
|
|
def user_attributes
|
|
params.slice(*%i[nickname show_realname])
|
|
end
|
|
|
|
def user_extension_attributes
|
|
params.slice(*%i[location location_city identity student_id technical_title school_id department_id])
|
|
end
|
|
end |