|  |  | @ -38,6 +38,7 @@ class Shixun < ApplicationRecord | 
			
		
	
		
		
			
				
					
					|  |  |  |   belongs_to :user |  |  |  |   belongs_to :user | 
			
		
	
		
		
			
				
					
					|  |  |  |   # 实训服务配置 |  |  |  |   # 实训服务配置 | 
			
		
	
		
		
			
				
					
					|  |  |  |   has_many :shixun_service_configs, :dependent => :destroy |  |  |  |   has_many :shixun_service_configs, :dependent => :destroy | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |   has_many :tidings, as: :container, dependent: :destroy | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 	scope :search_by_name, ->(keyword) { where("name like ? or description like ? ", |  |  |  | 	scope :search_by_name, ->(keyword) { where("name like ? or description like ? ", | 
			
		
	
		
		
			
				
					
					|  |  |  | 				"%#{keyword}%", "%#{keyword}%") } |  |  |  | 				"%#{keyword}%", "%#{keyword}%") } | 
			
		
	
	
		
		
			
				
					|  |  | @ -62,6 +63,8 @@ class Shixun < ApplicationRecord | 
			
		
	
		
		
			
				
					
					|  |  |  |   scope :field_for_recommend, lambda{ select([:id, :name, :identifier, :myshixuns_count]) } |  |  |  |   scope :field_for_recommend, lambda{ select([:id, :name, :identifier, :myshixuns_count]) } | 
			
		
	
		
		
			
				
					
					|  |  |  |   scope :find_by_ids,lambda{|k| where(id:k)} |  |  |  |   scope :find_by_ids,lambda{|k| where(id:k)} | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |   after_create :send_tiding | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |   # REDO:  |  |  |  |   # REDO:  | 
			
		
	
		
		
			
				
					
					|  |  |  |   def propaedeutics |  |  |  |   def propaedeutics | 
			
		
	
		
		
			
				
					
					|  |  |  |     shixun_info.try(:propaedeutics) |  |  |  |     shixun_info.try(:propaedeutics) | 
			
		
	
	
		
		
			
				
					|  |  | @ -242,4 +245,11 @@ class Shixun < ApplicationRecord | 
			
		
	
		
		
			
				
					
					|  |  |  |   def finished_challenges_count(user) |  |  |  |   def finished_challenges_count(user) | 
			
		
	
		
		
			
				
					
					|  |  |  |     Game.joins(:myshixun).where(user_id: user.id, status: 2, myshixuns: { shixun_id: id }).count |  |  |  |     Game.joins(:myshixun).where(user_id: user.id, status: 2, myshixuns: { shixun_id: id }).count | 
			
		
	
		
		
			
				
					
					|  |  |  |   end |  |  |  |   end | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |   private | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |   def send_tiding | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     self.tidings << Tiding.new(:user_id => user_id, :trigger_user_id => 1, :belong_container_id => id, :belong_container_type =>'Shixun', :tiding_type => "System", :viewed => 0) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |   end | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | end |  |  |  | end | 
			
		
	
	
		
		
			
				
					|  |  | 
 |