diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 23f6870c8..a1f6a5495 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -73,8 +73,7 @@ class UsersController < ApplicationController @user_url = "/users/#{@user.login}" @career = Career.where(status: true).order("created_at asc").pluck(:id, :name) - ec_user = EcSchoolUser.where(:user_id => current_user.id).first - @auth = ec_user ? "#{@old_domain}/ecs/department?school_id=#{ec_user.school_id}" : nil + @auth = User.current.ec_school.present? ? "#{@old_domain}/ecs/department?school_id=#{User.current.ec_school}" : nil end # 用户回复功能 diff --git a/app/models/user.rb b/app/models/user.rb index f2d9c7fb1..a95776be9 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -497,6 +497,13 @@ class User < ApplicationRecord ) end + # 工程认证的学校 + def ec_school + school_id = self.ec_school_users.pluck(:school_id).first || + self.ec_major_schools.pluck(:school_id).first || + (self.ec_course_users.first && self.ec_course_users.first.try(:ec_course).try(:ec_year).try(:ec_major_school).try(:school_id)) + end + # 登录,返回用户名与密码匹配的用户 def self.try_to_login(login, password) login = login.to_s.strip