|  |  |  | @ -31,12 +31,6 @@ 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) | 
			
		
	
		
			
				
					|  |  |  |  |   end | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |   def challenge_ids | 
			
		
	
		
			
				
					|  |  |  |  |     sub_shixuns = shixuns.published.pluck(:id) | 
			
		
	
		
			
				
					|  |  |  |  |     challenge_ids = Challenge.where(shixun_id: sub_shixuns).pluck(:id) | 
			
		
	
		
			
				
					|  |  |  |  |   end | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |   # 挑战过路径的成员数 | 
			
		
	
		
			
				
					|  |  |  |  |   def member_count | 
			
		
	
		
			
				
					|  |  |  |  |     shixuns.pluck(:myshixuns_count).sum | 
			
		
	
	
		
			
				
					|  |  |  | @ -60,8 +54,8 @@ class Subject < ApplicationRecord | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |   def my_subject_score | 
			
		
	
		
			
				
					|  |  |  |  |     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).sum(:score) | 
			
		
	
		
			
				
					|  |  |  |  |     my_choose_score = ChallengeChoose.joins(challenge: :games).where(games: {status: 2, user_id: User.current.id}, challenges: {shixun_id: shixuns_id}).sum(:score) | 
			
		
	
		
			
				
					|  |  |  |  |     my_shixun_score = Challenge.joins(:games).where(games: {status: 2, user_id: User.current.id}, 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}).pluck(:score).sum | 
			
		
	
		
			
				
					|  |  |  |  |     return my_shixun_score.to_i + my_choose_score.to_i | 
			
		
	
		
			
				
					|  |  |  |  |   end | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
	
		
			
				
					|  |  |  | @ -74,7 +68,8 @@ class Subject < ApplicationRecord | 
			
		
	
		
			
				
					|  |  |  |  |   end | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |   def my_subject_progress | 
			
		
	
		
			
				
					|  |  |  |  |     my_challenge_count = Game.where(user_id: User.current.id, status: 2, challenge_id: challenge_ids).pluck(:challenge_id).uniq.size | 
			
		
	
		
			
				
					|  |  |  |  |     my_challenge_count = Game.joins(:challenge).where(user_id: User.current.id, status: 2, challenges: {shixun_id: shixuns.published_closed}). | 
			
		
	
		
			
				
					|  |  |  |  |       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 | 
			
		
	
		
			
				
					|  |  |  |  |   end | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
	
		
			
				
					|  |  |  | 
 |