|
|
|
@ -79,20 +79,34 @@ class Challenge < ApplicationRecord
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# # 开启挑战
|
|
|
|
|
# def open_game(user_id, shixun)
|
|
|
|
|
#
|
|
|
|
|
#
|
|
|
|
|
# game = self.games.select([:status, :identifier]).where(user_id: user_id).first
|
|
|
|
|
# game = self.games.select{|game| game.user_id == user_id}
|
|
|
|
|
# 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
|
|
|
|
|
# "/api/shixuns/#{shixun.identifier}/shixun_exec"
|
|
|
|
|
# self.position == 1 ? "/api/shixuns/#{shixun.identifier}/shixun_exec" : ""
|
|
|
|
|
# end
|
|
|
|
|
# end
|
|
|
|
|
|
|
|
|
|
## 用户关卡状态 0: 不能开启实训; 1:直接开启; 2表示已完成
|
|
|
|
|
# def user_tpi_status shixun, user_id
|
|
|
|
|
# # todo: 以前没加索引导致相同关卡,同一用户有多个games
|
|
|
|
|
# # 允许跳关则直接开启
|
|
|
|
|
# game = games.where(user_id: user_id).take
|
|
|
|
|
# if game.blank?
|
|
|
|
|
# position == 1 ? 1 : 0
|
|
|
|
|
# else
|
|
|
|
|
# if game.status == 3
|
|
|
|
|
# shixun.task_pass ? 1 : 0
|
|
|
|
|
# elsif game.status == 2
|
|
|
|
|
# 2
|
|
|
|
|
# else
|
|
|
|
|
# 1
|
|
|
|
|
# end
|
|
|
|
|
# end
|
|
|
|
|
# end
|
|
|
|
|
|
|
|
|
|
# ## 用户关卡状态 0: 不能开启实训; 1:直接开启; 2表示已完成
|
|
|
|
|
def user_tpi_status shixun
|
|
|
|
|
# todo: 以前没加索引导致相同关卡,同一用户有多个games
|
|
|
|
|
# 允许跳关则直接开启
|
|
|
|
@ -128,12 +142,14 @@ class Challenge < ApplicationRecord
|
|
|
|
|
|
|
|
|
|
# 关卡用户通关数
|
|
|
|
|
def user_passed_count
|
|
|
|
|
games.where(status: 2).count
|
|
|
|
|
#games.map{|g| g.status == 2}.count
|
|
|
|
|
self.games.where(status: 1).count
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# 关卡用户正在挑战的人数
|
|
|
|
|
def playing_count
|
|
|
|
|
games.where(status: [0, 1]).count
|
|
|
|
|
#games.map{|g| g.status == 0 || g.status == 1}.count
|
|
|
|
|
self.games.where(status: [0,1]).count
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def last_challenge
|
|
|
|
|