diff --git a/app/models/challenge.rb b/app/models/challenge.rb index 036f387b1..d532d6d55 100644 --- a/app/models/challenge.rb +++ b/app/models/challenge.rb @@ -79,16 +79,6 @@ class Challenge < ApplicationRecord end end - # 开启挑战 - def open_game user_id, shixun - game = self.games.where(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 - # # 开启挑战 # def open_game(user_id, shixun) # @@ -120,24 +110,6 @@ class Challenge < ApplicationRecord end end - ## 用户关卡状态 0: 不能开启实训; 1:直接开启; 2表示已完成 - def user_tpi_status 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 - def tags_show if self.challenge_tags.nil? "--" diff --git a/app/views/challenges/index.json.jbuilder b/app/views/challenges/index.json.jbuilder index 0ffaff0ad..693f3717f 100644 --- a/app/views/challenges/index.json.jbuilder +++ b/app/views/challenges/index.json.jbuilder @@ -19,8 +19,7 @@ if @challenges.present? json.passed_count challenge.user_passed_count json.playing_count challenge.playing_count json.name_url shixun_challenge_path(challenge, shixun_identifier: @shixun.identifier) - #json.open_game challenge.open_game - challenge.open_game(@user.id, @shixun) + json.open_game challenge.open_game 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) @@ -28,7 +27,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 @user.id + json.status challenge.user_tpi_status end end