newyslclassrooms
daiao 5 years ago
parent cb6acf22fe
commit c9157cdf42

@ -69,25 +69,25 @@ class Challenge < ApplicationRecord
end end
# 开启挑战 # 开启挑战
# def open_game shixun def open_game shixun
# # 这里的identifier,status是关联了games取了games的identifier,status # 这里的identifier,status是关联了games取了games的identifier,status
# identifier = self.identifier identifier = self.identifier
# if identifier.present? if identifier.present?
# shixun.task_pass || self.status != 3 ? "/tasks/#{identifier}" : "" 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 else
self.position == 1 ? "/api/shixuns/#{shixun.identifier}/shixun_exec" : "" self.position == 1 ? "/api/shixuns/#{shixun.identifier}/shixun_exec" : ""
end end
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表示已完成 ## 用户关卡状态 0: 不能开启实训; 1:直接开启; 2表示已完成
def user_tpi_status shixun, user_id def user_tpi_status shixun, user_id
# todo: 以前没加索引导致相同关卡,同一用户有多个games # todo: 以前没加索引导致相同关卡,同一用户有多个games
@ -142,12 +142,14 @@ class Challenge < ApplicationRecord
# 关卡用户通关数 # 关卡用户通关数
def user_passed_count 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 end
# 关卡用户正在挑战的人数 # 关卡用户正在挑战的人数
def playing_count 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 end
def last_challenge def last_challenge

Loading…
Cancel
Save