diff --git a/app/models/user.rb b/app/models/user.rb index 0bebe8584..2f5400051 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -642,6 +642,14 @@ class User < ApplicationRecord login end + def bind_open_user?(type) + case type + when 'wechat' then wechat_open_user.present? + when 'qq' then qq_open_user.present? + else false + end + end + protected def validate_password_length # 管理员的初始密码是5位 diff --git a/app/services/create_bind_user_service.rb b/app/services/create_bind_user_service.rb index 5455b7561..93d9d87ca 100644 --- a/app/services/create_bind_user_service.rb +++ b/app/services/create_bind_user_service.rb @@ -17,6 +17,7 @@ class CreateBindUserService < ApplicationService bind_user = User.try_to_login(params[:username], params[:password]) raise Error, '用户名或者密码错误' if bind_user.blank? + raise Error, '该账号已被绑定' if bind_user.bind_open_user?(params[:type].to_s) ActiveRecord::Base.transaction do open_user.user_id = bind_user.id