From 5914d83323bd29d8489ea632c4d133176106e6c8 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Wed, 24 Jul 2019 16:05:43 +0800 Subject: [PATCH] fix bind phone api --- app/controllers/users/interests_controller.rb | 6 ++++-- app/services/users/bind_phone_service.rb | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/controllers/users/interests_controller.rb b/app/controllers/users/interests_controller.rb index 3f931612d..93f2345f1 100644 --- a/app/controllers/users/interests_controller.rb +++ b/app/controllers/users/interests_controller.rb @@ -9,13 +9,15 @@ class Users::InterestsController < Users::BaseController extension = current_user.user_extension || current_user.build_user_extension return render_error('请选择职业') unless %w(teacher student professional).include?(identity) + interest_ids = Array.wrap(params[:interest_ids]).map(&:to_i) + return render_error('请选择兴趣') if interest_ids.blank? + ActiveRecord::Base.transaction do extension.update_column(:identity, identity) # 兴趣 - current_user.user_interests.delete_all UserInterest.bulk_insert(:user_id, :repertoire_id) do |worker| - (Repertoire.pluck(:id) & Array.wrap(params[:interest_ids]).map(&:to_i)).each do |repertoire_id| + (Repertoire.pluck(:id) & interest_ids).each do |repertoire_id| worker.add(user_id: current_user.id, repertoire_id: repertoire_id) end end diff --git a/app/services/users/bind_phone_service.rb b/app/services/users/bind_phone_service.rb index 0ea39ae9b..af4292230 100644 --- a/app/services/users/bind_phone_service.rb +++ b/app/services/users/bind_phone_service.rb @@ -13,7 +13,7 @@ class Users::BindPhoneService < ApplicationService raise Error, '该手机号已被绑定' if User.where.not(id: user.id).exists?(phone: params[:phone]) - code = VerificationCode.where(phone: params[:phone], code: params[:code], code_type: 5).last + code = VerificationCode.where(phone: params[:phone], code: params[:code], code_type: 4).last raise Error, '验证码无效' unless code&.effective? ActiveRecord::Base.transaction do