|
|
@ -47,14 +47,6 @@ class User < ApplicationRecord
|
|
|
|
|
|
|
|
|
|
|
|
has_many :graduation_works, dependent: :destroy
|
|
|
|
has_many :graduation_works, dependent: :destroy
|
|
|
|
|
|
|
|
|
|
|
|
# 关注
|
|
|
|
|
|
|
|
has_many :relationships, foreign_key: "follower_id", dependent: :destroy
|
|
|
|
|
|
|
|
has_many :followed_users, through: :relationships, source: :followed
|
|
|
|
|
|
|
|
# 粉丝
|
|
|
|
|
|
|
|
has_many :reverse_relationships, foreign_key: "followed_id",
|
|
|
|
|
|
|
|
class_name: "Relationship",
|
|
|
|
|
|
|
|
dependent: :destroy
|
|
|
|
|
|
|
|
has_many :followers, through: :reverse_relationships, source: :follower
|
|
|
|
|
|
|
|
has_many :students_for_courses, foreign_key: :student_id, dependent: :destroy
|
|
|
|
has_many :students_for_courses, foreign_key: :student_id, dependent: :destroy
|
|
|
|
has_one :onclick_time, :dependent => :destroy
|
|
|
|
has_one :onclick_time, :dependent => :destroy
|
|
|
|
|
|
|
|
|
|
|
@ -161,19 +153,16 @@ class User < ApplicationRecord
|
|
|
|
self.user_extension.try(:student_id)
|
|
|
|
self.user_extension.try(:student_id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# 关注总数
|
|
|
|
# 关注数
|
|
|
|
def following?(other_user)
|
|
|
|
def follow_count
|
|
|
|
relationships.find_by(followed_id: other_user)
|
|
|
|
Watcher.where(user_id: id, watchable_type: %w(Principal User)).count
|
|
|
|
end
|
|
|
|
# User.watched_by(id).count
|
|
|
|
|
|
|
|
|
|
|
|
# 关注
|
|
|
|
|
|
|
|
def follow!(other_user)
|
|
|
|
|
|
|
|
relationships.create!(followed_id: other_user)
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# 取消关注
|
|
|
|
# 粉丝数
|
|
|
|
def unfollow!(other_user)
|
|
|
|
def fan_count
|
|
|
|
relationships.find_by(followed_id: other_user.id).destroy
|
|
|
|
Watcher.where(watchable_type: %w(Principal User), watchable_id: id).count
|
|
|
|
|
|
|
|
# watchers.count
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# 判断当前用户是否为老师
|
|
|
|
# 判断当前用户是否为老师
|
|
|
@ -545,6 +534,51 @@ class User < ApplicationRecord
|
|
|
|
Educoder::Utils.random_hex(16)
|
|
|
|
Educoder::Utils.random_hex(16)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 基本资料是否完善
|
|
|
|
|
|
|
|
def base_info_completed?
|
|
|
|
|
|
|
|
user_columns = %i[nickname lastname]
|
|
|
|
|
|
|
|
user_extension_columns = %i[gender location location_city identity school_id department]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
user_columns.all? { |column| public_send(column).present? } &&
|
|
|
|
|
|
|
|
user_extension_columns.all? { |column| user_extension.send(column).present? }
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 全部已认证
|
|
|
|
|
|
|
|
def all_certified?
|
|
|
|
|
|
|
|
authentication? && professional_certification?
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 是否绑定邮箱
|
|
|
|
|
|
|
|
def email_binded?
|
|
|
|
|
|
|
|
mail.present?
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 学院的url标识
|
|
|
|
|
|
|
|
def college_identifier
|
|
|
|
|
|
|
|
Department.find_by_id(department_members.pluck(:department_id).first)&.identifier
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 是否能申请试用
|
|
|
|
|
|
|
|
def can_apply_trial?
|
|
|
|
|
|
|
|
return false if certification == 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
apply = ApplyAction.order(created_at: :desc).find_by(user_id: id, container_type: 'TrialAuthorization')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
apply.present? && !apply.status.zero?
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 是否已经签到
|
|
|
|
|
|
|
|
def attendance_signed?
|
|
|
|
|
|
|
|
attendance = Attendance.find_by(user_id: id)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
attendance.present? && Util.days_between(Time.zone.now, attendance.created_at).zero?
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 明日签到金币
|
|
|
|
|
|
|
|
def tomorrow_attendance_gold
|
|
|
|
|
|
|
|
Attendance.find_by(user_id: id)&.next_gold || 60 # 基础50,连续签到+10
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
protected
|
|
|
|
protected
|
|
|
|
def validate_password_length
|
|
|
|
def validate_password_length
|
|
|
|
# 管理员的初始密码是5位
|
|
|
|
# 管理员的初始密码是5位
|
|
|
|