diff --git a/app/models/challenge.rb b/app/models/challenge.rb index 7c3c31ff9..50528b327 100644 --- a/app/models/challenge.rb +++ b/app/models/challenge.rb @@ -69,25 +69,25 @@ class Challenge < ApplicationRecord end # 开启挑战 - # def open_game shixun - # # 这里的identifier,status是关联了games取了games的identifier,status - # identifier = self.identifier - # if identifier.present? - # shixun.task_pass || self.status != 3 ? "/tasks/#{identifier}" : "" - # else - # self.position == 1 ? "/api/shixuns/#{shixun.identifier}/shixun_exec" : "" - # end - # end - - def open_game shixun, user_id - game = self.games.map{|g| g.user_id == user_id}.first - if game.present? - shixun.task_pass || game.status != 3 ? "/tasks/#{game.identifier}" : "" + def open_game shixun + # 这里的identifier,status是关联了games取了games的identifier,status + identifier = self.identifier + if identifier.present? + shixun.task_pass || self.status != 3 ? "/tasks/#{identifier}" : "" else self.position == 1 ? "/api/shixuns/#{shixun.identifier}/shixun_exec" : "" end end + # def open_game shixun, user_id + # game = self.games.map{|g| g.user_id == user_id}.first + # if game.present? + # shixun.task_pass || game.status != 3 ? "/tasks/#{game.identifier}" : "" + # else + # self.position == 1 ? "/api/shixuns/#{shixun.identifier}/shixun_exec" : "" + # end + # end + ## 用户关卡状态 0: 不能开启实训; 1:直接开启; 2表示已完成 def user_tpi_status shixun, user_id # todo: 以前没加索引导致相同关卡,同一用户有多个games @@ -142,12 +142,14 @@ class Challenge < ApplicationRecord # 关卡用户通关数 def user_passed_count - games.map{|g| g.status == 2}.count + #games.map{|g| g.status == 2}.count + self.games.where(status: 1).count end # 关卡用户正在挑战的人数 def playing_count - games.map{|g| g.status == 0 || g.status == 1}.count + #games.map{|g| g.status == 0 || g.status == 1}.count + self.games.where(status: [0,1]).count end def last_challenge