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.
educoder/app/services/users/bind_phone_service.rb

28 lines
760 B

6 years ago
class Users::BindPhoneService < ApplicationService
Error = Class.new(StandardError)
attr_reader :user, :params
def initialize(user, params)
@user = user
@params = params
end
def call
Users::BindPhoneForm.new(params).validate!
raise Error, '该手机号已被绑定' if User.where.not(id: user.id).exists?(phone: params[:phone])
code = VerificationCode.where(phone: params[:phone], code: params[:code], code_type: 4).last
6 years ago
raise Error, '验证码无效' unless code&.effective?
ActiveRecord::Base.transaction do
if user.phone.blank?
RewardGradeService.call(user, container_id: user.id, container_type: 'Phone', score: 500)
end
user.phone = params[:phone]
user.save!
end
end
end