|
|
@ -31,6 +31,12 @@ class Subject < ApplicationRecord
|
|
|
|
self.tidings << Tiding.new(user_id: self.user_id, trigger_user_id: self.user_id, belong_container_id: self.id, belong_container_type: 'Subject', tiding_type: "System", viewed: 0)
|
|
|
|
self.tidings << Tiding.new(user_id: self.user_id, trigger_user_id: self.user_id, belong_container_id: self.id, belong_container_type: 'Subject', tiding_type: "System", viewed: 0)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def challenge_ids
|
|
|
|
|
|
|
|
sub_shixuns = shixuns.published.pluck(:id)
|
|
|
|
|
|
|
|
challenge_ids = Challenge.where(shixun_id: sub_shixuns).pluck(:id)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# 挑战过路径的成员数
|
|
|
|
# 挑战过路径的成员数
|
|
|
|
def member_count
|
|
|
|
def member_count
|
|
|
|
shixuns.pluck(:myshixuns_count).sum
|
|
|
|
shixuns.pluck(:myshixuns_count).sum
|
|
|
@ -54,8 +60,8 @@ class Subject < ApplicationRecord
|
|
|
|
|
|
|
|
|
|
|
|
def my_subject_score
|
|
|
|
def my_subject_score
|
|
|
|
shixuns_id = shixuns.published_closed.pluck(:id)
|
|
|
|
shixuns_id = shixuns.published_closed.pluck(:id)
|
|
|
|
my_shixun_score = Challenge.joins(:games).where(games: {status: 2, user_id: User.current.id}, shixun_id: shixuns_id).pluck(:score).sum
|
|
|
|
my_shixun_score = Challenge.joins(:games).where(games: {status: 2, user_id: User.current.id}, shixun_id: shixuns_id).sum(:score)
|
|
|
|
my_choose_score = ChallengeChoose.joins(challenge: :games).where(games: {status: 2, user_id: User.current.id}, challenges: {shixun_id: shixuns_id}).pluck(:score).sum
|
|
|
|
my_choose_score = ChallengeChoose.joins(challenge: :games).where(games: {status: 2, user_id: User.current.id}, challenges: {shixun_id: shixuns_id}).sum(:score)
|
|
|
|
return my_shixun_score.to_i + my_choose_score.to_i
|
|
|
|
return my_shixun_score.to_i + my_choose_score.to_i
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
@ -68,8 +74,7 @@ class Subject < ApplicationRecord
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def my_subject_progress
|
|
|
|
def my_subject_progress
|
|
|
|
my_challenge_count = Game.joins(:challenge).where(user_id: User.current.id, status: 2, challenges: {shixun_id: shixuns.published_closed}).
|
|
|
|
my_challenge_count = Game.where(user_id: User.current.id, status: 2, challenge_id: challenge_ids).pluck(:challenge_id).uniq.size
|
|
|
|
pluck(:challenge_id).uniq.size
|
|
|
|
|
|
|
|
count = self.subject_challenge_count == 0 ? 0 : ((my_challenge_count.to_f / self.subject_challenge_count).round(2) * 100).to_i
|
|
|
|
count = self.subject_challenge_count == 0 ? 0 : ((my_challenge_count.to_f / self.subject_challenge_count).round(2) * 100).to_i
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|