|
|
@ -51,9 +51,8 @@ class Challenge < ApplicationRecord
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# 开启挑战
|
|
|
|
# 开启挑战
|
|
|
|
def open_game(user_id)
|
|
|
|
def open_game user_id, challenge_id, shixun
|
|
|
|
game = self.games.select([:status, :identifier]).where(user_id: user_id).first
|
|
|
|
game = games.select{|game| game.challenge_id = challenge_id && game.user_id == user_id}.first
|
|
|
|
shixun = self.shixun
|
|
|
|
|
|
|
|
if game.present?
|
|
|
|
if game.present?
|
|
|
|
shixun.task_pass || game.status != 3 ? "/tasks/#{game.identifier}" : ""
|
|
|
|
shixun.task_pass || game.status != 3 ? "/tasks/#{game.identifier}" : ""
|
|
|
|
else
|
|
|
|
else
|
|
|
@ -61,11 +60,24 @@ class Challenge < ApplicationRecord
|
|
|
|
end
|
|
|
|
end
|
|
|
|
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}
|
|
|
|
|
|
|
|
# if game.present?
|
|
|
|
|
|
|
|
# shixun.task_pass || game.status != 3 ? "/tasks/#{game.identifier}" : ""
|
|
|
|
|
|
|
|
# else
|
|
|
|
|
|
|
|
# "/api/shixuns/#{shixun.identifier}/shixun_exec"
|
|
|
|
|
|
|
|
# end
|
|
|
|
|
|
|
|
# end
|
|
|
|
|
|
|
|
|
|
|
|
## 用户关卡状态 0: 不能开启实训; 1:直接开启; 2表示已完成
|
|
|
|
## 用户关卡状态 0: 不能开启实训; 1:直接开启; 2表示已完成
|
|
|
|
def user_tpi_status user_id
|
|
|
|
def user_tpi_status user_id
|
|
|
|
# todo: 以前没加索引导致相同关卡,同一用户有多个games
|
|
|
|
# todo: 以前没加索引导致相同关卡,同一用户有多个games
|
|
|
|
game = self.games.where(user_id: user_id).last
|
|
|
|
game = games.select{|game| game.user_id == user_id }.last
|
|
|
|
status =
|
|
|
|
|
|
|
|
if game.blank?
|
|
|
|
if game.blank?
|
|
|
|
self.position == 1 ? 1 : 0
|
|
|
|
self.position == 1 ? 1 : 0
|
|
|
|
elsif game.status == 2
|
|
|
|
elsif game.status == 2
|
|
|
@ -85,12 +97,12 @@ class Challenge < ApplicationRecord
|
|
|
|
|
|
|
|
|
|
|
|
# 关卡用户通关数
|
|
|
|
# 关卡用户通关数
|
|
|
|
def user_passed_count
|
|
|
|
def user_passed_count
|
|
|
|
games.where(status: 2).count
|
|
|
|
games.select{|game| game.status == 2}.size
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# 关卡用户正在挑战的人数
|
|
|
|
# 关卡用户正在挑战的人数
|
|
|
|
def playing_count
|
|
|
|
def playing_count
|
|
|
|
games.where(status: [0, 1]).count
|
|
|
|
games.select{|game| game.status == 0 || game.status == 1}.size
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def last_challenge
|
|
|
|
def last_challenge
|
|
|
|