From 38cf5d82be9a40d99a718602be1d53c7b3f2983d Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Mon, 9 Mar 2020 18:17:28 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/challenges_controller.rb | 4 ++-- app/models/challenge.rb | 4 ++-- app/views/challenges/index.json.jbuilder | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/controllers/challenges_controller.rb b/app/controllers/challenges_controller.rb index c6c62e922..c69f5bbfb 100644 --- a/app/controllers/challenges_controller.rb +++ b/app/controllers/challenges_controller.rb @@ -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 diff --git a/app/models/challenge.rb b/app/models/challenge.rb index d532d6d55..5646da363 100644 --- a/app/models/challenge.rb +++ b/app/models/challenge.rb @@ -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 diff --git a/app/views/challenges/index.json.jbuilder b/app/views/challenges/index.json.jbuilder index 8accbf69b..d4f2a7f59 100644 --- a/app/views/challenges/index.json.jbuilder +++ b/app/views/challenges/index.json.jbuilder @@ -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