From 9eb33593222501db22a6d4aeddca172700f1013a Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Tue, 10 Mar 2020 01:43:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/challenge.rb | 48 ++++++++++++------------ app/views/challenges/index.json.jbuilder | 3 +- 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/app/models/challenge.rb b/app/models/challenge.rb index 50528b327..31a683760 100644 --- a/app/models/challenge.rb +++ b/app/models/challenge.rb @@ -89,34 +89,16 @@ class Challenge < ApplicationRecord # 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 + # def user_tpi_status shixun, user_id # # todo: 以前没加索引导致相同关卡,同一用户有多个games # # 允许跳关则直接开启 - # identifier = self.identifier - # if identifier.blank? - # self.position == 1 ? 1 : 0 + # game = games.where(user_id: user_id).take + # if game.blank? + # position == 1 ? 1 : 0 # else - # if status == 3 + # if game.status == 3 # shixun.task_pass ? 1 : 0 - # elsif status == 2 + # elsif game.status == 2 # 2 # else # 1 @@ -124,6 +106,24 @@ class Challenge < ApplicationRecord # end # end + # ## 用户关卡状态 0: 不能开启实训; 1:直接开启; 2表示已完成 + def user_tpi_status shixun + # todo: 以前没加索引导致相同关卡,同一用户有多个games + # 允许跳关则直接开启 + identifier = self.identifier + if identifier.blank? + self.position == 1 ? 1 : 0 + else + if status == 3 + shixun.task_pass ? 1 : 0 + elsif 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 c86acc95b..6613dd888 100644 --- a/app/views/challenges/index.json.jbuilder +++ b/app/views/challenges/index.json.jbuilder @@ -30,6 +30,7 @@ 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(@shixun, @user.id) + #json.status challenge.user_tpi_status(@shixun, @user.id) + json.status challenge.user_tpi_status(@shixun) end end