From 583eef8086b9a9b341e8f9abc87ee9a88052d617 Mon Sep 17 00:00:00 2001 From: cxt Date: Wed, 9 Aug 2017 09:01:22 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A6=96=E9=A1=B5=E7=9A=84=E6=8A=80=E8=83=BD?= =?UTF-8?q?=E6=A0=87=E7=AD=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 6 +++++- app/controllers/users_controller.rb | 1 - app/models/user.rb | 8 ++++++++ app/views/users/show.html.erb | 3 ++- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index adae03fa9..c56ae152a 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -295,7 +295,11 @@ class GamesController < ApplicationController had_done = @game.had_done shixun = @myshixun.shixun if shixun.status > 1 && !@game.answer_open - User.current.update_attributes(:grade => (User.current.grade + @game.challenge.score), :experience => (User.current.experience + @game.challenge.score)) if correct + if correct + #User.current.update_attributes(:grade => (User.current.grade + @game.challenge.score), :experience => (User.current.experience + @game.challenge.score)) + reward_grade(@game.user, @game.id, @game.class, game_challenge.score) + reward_experience(@game.user, @game.id, @game.class, game_challenge.score) + end end if @game.outputs.blank? Output.create(:game_id => @game.id, :actual_output => user_answer, :result => correct) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 012f3be73..0e06132da 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -2277,7 +2277,6 @@ class UsersController < ApplicationController end end - def user_show_course_list @courses = @user.courses.not_deleted_not_end.order("updated_at desc") @courses_count = @courses.count diff --git a/app/models/user.rb b/app/models/user.rb index 050c72842..f9607c038 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -130,6 +130,7 @@ class User < Principal has_many :shixuns, :through => :shixun_members has_many :shixun_members, :dependent => :destroy has_many :challenges, :dependent => :destroy + has_many :games, :dependent => :destroy has_many :subjects @@ -310,6 +311,13 @@ class User < Principal end end } + def challenge_tags + shixuns = Shixun.where(:id => Myshixun.where(:user_id => self.id).map(&:shixun_id), :status => [2,3]) + myshixuns = Myshixun.where(:user_id => self.id, :shixun_id => shixuns.map(&:id)) + games = self.games.where(:myshixun_id => myshixuns.map(&:id), :status => 2) + challenge_tags = ChallengeTag.where(:challenge_id => games.map(&:challenge_id)) + end + def self.search(query) __elasticsearch__.search( { diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index a4c37e78e..f7560382c 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -114,7 +114,8 @@ <% if new_message_count > 0 %> 新留言<%= new_message_count %> <% end %> - + <%= %> + 技能标签<%= @user.challenge_tags.count %> 经验值<%= @user.experience %> 金币<%= @user.grade %>