newyslclassrooms
daiao 5 years ago
parent d5c0049b15
commit 38cf5d82be

@ -157,12 +157,12 @@ class ChallengesController < ApplicationController
uid_logger("identifier: #{params}")
base_columns = "challenges.id, challenges.subject, challenges.st, challenges.score, challenges.position,
challenges.shixun_id, games.identifier, games.status"
join_sql = "LEFT JOIN games ON games.challenge_id = challenges.id AND games.user_id = #{current_user.id}"
# 下面2个参数是为了解决列表获取通关人数与正在游玩人数的问题
@pass_games_map = @shixun.challenges.joins(:games).where(games: {status:2}).group(:challenge_id).reorder(nil).count
@play_games_map = @shixun.challenges.joins(:games).where(games: {status:[0,1]}).group(:challenge_id).reorder(nil).count
@challenges = @shixun.challenges.joins("left join games on games.challenge_id = challenges.id and games.user_id = #{current_user.id}")
.select(base_columns)
@challenges = @shixun.challenges.joins(join_sql).select(base_columns)
@editable = @shixun.status == 0 # before_action有判断权限如果没发布则肯定是管理人员
@user = current_user

@ -69,7 +69,7 @@ class Challenge < ApplicationRecord
end
# 开启挑战
def open_game
def open_game shixun
# 这里的identifier,status是关联了games取了games的identifier,status
identifier = self.identifier
if identifier.present?
@ -93,7 +93,7 @@ class Challenge < ApplicationRecord
# end
## 用户关卡状态 0: 不能开启实训; 1:直接开启; 2表示已完成
def user_tpi_status
def user_tpi_status shixun
# todo: 以前没加索引导致相同关卡,同一用户有多个games
# 允许跳关则直接开启
identifier = self.identifier

@ -21,7 +21,7 @@ if @challenges.present?
json.playing_count @play_games_map.fetch(challenge.id, 0)
#json.playing_count challenge.playing_count
json.name_url shixun_challenge_path(challenge, shixun_identifier: @shixun.identifier)
json.open_game challenge.open_game
json.open_game challenge.open_game(@shixun)
if @editable
json.edit_url edit_shixun_challenge_path(challenge, shixun_identifier: @shixun.identifier)
json.delete_url shixun_challenge_path(challenge, shixun_identifier: @shixun.identifier)
@ -29,6 +29,6 @@ if @challenges.present?
json.down_url index_down_shixun_challenge_path(challenge, :shixun_identifier => @shixun.identifier) if @shixun.challenges_count != challenge.position
end
#json.passed challenge.has_passed?(@user.id)
json.status challenge.user_tpi_status
json.status challenge.user_tpi_status(@shixun)
end
end

Loading…
Cancel
Save