diff --git a/app/controllers/challenges_controller.rb b/app/controllers/challenges_controller.rb index 5773d7297..b4f4d6683 100644 --- a/app/controllers/challenges_controller.rb +++ b/app/controllers/challenges_controller.rb @@ -129,10 +129,12 @@ class ChallengesController < ApplicationController end def destroy + next_challenges = @shixun.challenges.where("position > #{@challenge.position}") + next_challenges.update_all("position = position - 1") @challenge.destroy - respond_to do |format| - format.html{redirect_to shixun_challenges_path(@shixun)} - end + @challenges = @shixun.challenges + + add_shixun_modify_status(@shixun, 1) end def update diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 1bb5dfaeb..c711acbf2 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -35,12 +35,12 @@ class GamesController < ApplicationController end # logger.info("#################%%%%%%#{@game.outputs.first.out_put}") # @games = @myshixun.games.includes(:challenge) + @game_challenge = @game.challenge @challenges = Challenge.where(:shixun_id => @myshixun.shixun_id) @shixun = @myshixun.shixun - @praise_count = PraiseTread.where(:praise_tread_object_id => @challenges, :praise_tread_object_type => "Challenge").count - @tread_count = PraiseTread.where(:praise_tread_object_id => @challenges, :praise_tread_object_type => "ChallengeTread").count + @praise_count = PraiseTread.where(:praise_tread_object_id => @game_challenge.id, :praise_tread_object_type => "Challenge").count + @tread_count = PraiseTread.where(:praise_tread_object_id => @game_challenge.id, :praise_tread_object_type => "ChallengeTread").count # @games_count = @games.count - @game_challenge = @game.challenge @st = @game_challenge.st @had_done = @game.had_done @praise = PraiseTread.where("praise_tread_object_id=? and praise_tread_object_type=? and user_id=?", @game_challenge.id, @game_challenge.class.to_s, User.current.id).first @@ -218,8 +218,8 @@ class GamesController < ApplicationController @game.update_attribute(:end_time, Time.now) game_passed_code(@game.id, game_challenge.try(:path), @myshixun.try(:gpid), 1) if !@game.answer_open && shixun.status > 1 - reward_grade(@game.user, @game.id, @game.class, game_challenge.score) - reward_experience(@game.user, @game.id, @game.class, game_challenge.score) + reward_grade(@game.user, @game.id, 'Game', game_challenge.score) + reward_experience(@game.user, @game.id, 'Game', game_challenge.score) end end game_status = @game.status @@ -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', game_challenge.score) + reward_experience(@game.user, @game.id, 'Game', 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/praise_tread_controller.rb b/app/controllers/praise_tread_controller.rb index d202a8fb4..ad8655bdb 100644 --- a/app/controllers/praise_tread_controller.rb +++ b/app/controllers/praise_tread_controller.rb @@ -22,9 +22,9 @@ class PraiseTreadController < ApplicationController if(params[:game_praise] == "true") pts.delete if params[:obj_type] == "Challenge" - praise_tread_count = PraiseTread.where(:praise_tread_object_id => params[:obj_id], :praise_tread_object_type => "Challenge").count + praise_tread_count = PraiseTread.where(:praise_tread_object_id => @obj_id, :praise_tread_object_type => "Challenge").count else - praise_tread_count = PraiseTread.where(:praise_tread_object_id => params[:obj_id], :praise_tread_object_type => "ChallengeTread").count + praise_tread_count = PraiseTread.where(:praise_tread_object_id =>@obj_id, :praise_tread_object_type => "ChallengeTread").count end render :json => {praise: false, praise_tread_count: praise_tread_count} return @@ -46,9 +46,9 @@ class PraiseTreadController < ApplicationController # end if params[:game_praise] == "true" if params[:obj_type] == "Challenge" - praise_tread_count = PraiseTread.where(:praise_tread_object_id => params[:obj_id], :praise_tread_object_type => "Challenge").count + praise_tread_count = PraiseTread.where(:praise_tread_object_id => @obj_id, :praise_tread_object_type => "Challenge").count else - praise_tread_count = PraiseTread.where(:praise_tread_object_id => params[:obj_id], :praise_tread_object_type => "ChallengeTread").count + praise_tread_count = PraiseTread.where(:praise_tread_object_id => @obj_id, :praise_tread_object_type => "ChallengeTread").count end render :json => {praise: true, praise_tread_count: praise_tread_count} return diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index eab591a15..6fd7bcf21 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -78,14 +78,18 @@ class ShixunsController < ApplicationController end def index - @order = "created_at" - @sort = "desc" + @order = "myshixun_count" + @sort = "asc" search = params[:search] @shixun_all_count = Shixun.all.count #@shixuns = Shixun.find_by_sql("select * from shixuns where id in (SELECT distinct(shixun_id) FROM `challenges`) and name like '%#{search}%' order by created_at desc") @shixuns = Shixun.where("name like ?", "%#{search}%").reorder("created_at desc") # @shixun_my_score = Game.find_by_sql("select sum(final_score) as score from games where myshixun_id in (select id from myshixuns where status =1 # and user_id=#{User.current.id} and shixun_id in (SELECT id FROM `shixuns` where status > 1))").first.try(:score).to_i + @shixuns.each do |shixun| + shixun[:myshixunCount] = shixun.myshixuns.count + end + @shixuns = @shixuns.sort{|x, y| y[:myshixunCount] <=> x[:myshixunCount]} @shixun_my_score = Experience.find_by_sql("SELECT sum(score) as score FROM `experiences` where user_id=#{User.current.id}").first.try(:score).to_i @current_user_had_passed = Myshixun.find_by_sql("select count(*) as had_passed from myshixuns where status =1 and user_id=#{User.current.id} and shixun_id in (SELECT id FROM `shixuns` where status > 1)").first.try(:had_passed).to_i @@ -154,7 +158,7 @@ class ShixunsController < ApplicationController def search # 确定 sort 1升序 2 降序 - @order = params[:order] || "created_at" + @order = params[:order] || "myshixun_count" bsort = params[:sort] || "desc" @sort = bsort == "desc" ? "asc" : "desc" if @order == "created_at" @@ -218,7 +222,11 @@ class ShixunsController < ApplicationController @shixuns.each do |shixun| shixun[:myshixunCount] = shixun.myshixuns.count end - @shixuns = @shixuns.sort{|x, y| y[:myshixunCount] <=> x[:myshixunCount]} + if bsort == "desc" + @shixuns = @shixuns.sort{|x, y| y[:myshixunCount] <=> x[:myshixunCount]} + else + @shixuns = @shixuns.sort{|x, y| x[:myshixunCount] <=> y[:myshixunCount]} + end end # @shixuns = Shixun.where(:authentication => 1).reorder(order) @shixuns_count = @shixuns.count diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 012f3be73..d1fb01bac 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -45,7 +45,7 @@ class UsersController < ApplicationController :user_courses4show,:user_projects4show,:user_contests4show,:user_course_activities,:user_project_activities,:user_feedback4show,:user_visitorlist,:user_messages,:edit_brief_introduction, :user_import_homeworks,:user_search_homeworks,:user_import_resource, :user_system_messages,:choose_user_course,:user_courselist,:user_projectlist,:sort_syllabus_list, :sort_project_list,:my_homeworks,:manage_or_receive_homeworks,:search_m_r_homeworks, :cancel_or_collect,:expand_courses,:homepage, :user_issues, :course_community, :project_community, :contest_community, - :shixuns, :user_show_course_list, :shixuns_or_courses_filter, :user_wathlist_and_fanslist] + :shixuns, :user_show_course_list, :shixuns_or_courses_filter, :user_wathlist_and_fanslist, :growth_record, :user_grade, :user_experience] before_filter :auth_user_extension, only: :show before_filter :show_system_message, :only => [:show] #before_filter :rest_user_score, only: :show @@ -2277,6 +2277,40 @@ class UsersController < ApplicationController end end + def growth_record + @user_tags = @user.experiences.reorder("created_at desc") + @limit = 20 + @is_remote = true + @tags_count = @user_tags.count + @tags_pages = Paginator.new @tags_count, @limit, params['page'] || 1 + @offset ||= @tags_pages.offset + @user_tags = paginateHelper @user_tags, @limit + respond_to do |format| + format.js + format.html {render :layout => 'base_edu_user'} + end + end + + def user_experience + @user_experiences = @user.experiences.reorder("created_at desc") + @limit = 20 + @is_remote = true + @experiences_count = @user_experiences.count + @experiences_pages = Paginator.new @experiences_count, @limit, params['page'] || 1 + @offset ||= @experiences_pages.offset + @user_experiences = paginateHelper @user_experiences, @limit + end + + def user_grade + @type = params[:type] ? params[:type].to_i : 1 + @user_grades = @type == 1 ? @user.grades.where("score > 0").reorder("created_at desc") : @user.grades.where("score < 0").reorder("created_at desc") + @limit = 20 + @is_remote = true + @grades_count = @user_grades.count + @grades_pages = Paginator.new @grades_count, @limit, params['page'] || 1 + @offset ||= @grades_pages.offset + @user_grades = paginateHelper @user_grades, @limit + end def user_show_course_list @courses = @user.courses.not_deleted_not_end.order("updated_at desc") diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index c9cef2a8e..1c098ae1b 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -3012,9 +3012,8 @@ module ApplicationHelper end end - def identity_authentication_status user_id - apply = ApplyAction.where(:user_id => user_id).first - case apply.try(:status) + def identity_authentication_status status + case status when nil "未授权" when 0 @@ -3026,6 +3025,38 @@ module ApplicationHelper end end + def user_certification_status user + status = "" + if user.authentication + status = "已实名认证" + else + apply_auth = ApplyUserAuthentication.where(:user_id => user.id, :auth_type => 1).last + if apply_auth && apply_auth.status == 0 + status = "实名认证中" + elsif apply_auth && apply_auth.status == 2 + status = "实名认证未通过" + else + status = "未实名认证" + end + end + end + + def pro_certification_status user + status = "" + if user.professional_certification + status = "已职业认证" + else + apply_auth = ApplyUserAuthentication.where(:user_id => user.id, :auth_type => 2).last + if apply_auth && apply_auth.status == 0 + status = "职业认证中" + elsif apply_auth && apply_auth.status == 2 + status = "职业认证未通过" + else + status = "未职业认证" + end + end + end + def shixun_authentication_status shixun case shixun.try(:status) when 0,nil diff --git a/app/models/experience.rb b/app/models/experience.rb index c229f5f35..1892f2f13 100644 --- a/app/models/experience.rb +++ b/app/models/experience.rb @@ -1,3 +1,5 @@ class Experience < ActiveRecord::Base attr_accessible :container_id, :container_type, :score, :user_id + + belongs_to :user end diff --git a/app/models/grade.rb b/app/models/grade.rb index d0b686dfd..b4fae2b09 100644 --- a/app/models/grade.rb +++ b/app/models/grade.rb @@ -1,5 +1,7 @@ # container_type: -# Phone-手机注册;Mail-邮箱绑定;Account-完善资料 +# Phone-手机注册;Mail-邮箱绑定;Account-完善资料;Answer-查看参考答案;Game-闯关 class Grade < ActiveRecord::Base attr_accessible :container_id, :container_type, :score, :user_id + + belongs_to :user end diff --git a/app/models/user.rb b/app/models/user.rb index 14ce956e7..1580df643 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 @@ -202,6 +203,9 @@ class User < Principal ##### has_many :shares ,:dependent => :destroy + has_many :grades + has_many :experiences + ### has_many :apply_actions, :dependent => :destroy @@ -310,6 +314,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( { @@ -1420,21 +1431,21 @@ class User < Principal # 为新注册用户发送留言 # 只发三条没可以不用delay job,而且这个最好是注册的时候就能看到 def add_new_jour - Rails.logger.info "add_new_jour_delay!!!!!!!!!" - if Setting.find_by_name("hidden_non_project") && Setting.find_by_name("hidden_non_project").value != "0" - if Message.where("id=19504").any? and Message.where("id=19291").any? and Message.where("id=19292").any? - lead_message1 = Message.find(19292) - notes1 = lead_message1.content - lead_message2 = Message.find(19291) - notes2 = lead_message2.content - lead_message3 = Message.find(19504) - notes3 = lead_message3.content - #user_id 默认为课程使者创建 - self.journals_for_messages << JournalsForMessage.new(:user_id => 1, :notes => notes1, :reply_id => 0, :status => true, :is_readed => false, :private => 0) - self.journals_for_messages << JournalsForMessage.new(:user_id => 1, :notes => notes2, :reply_id => 0, :status => true, :is_readed => false, :private => 0) - self.journals_for_messages << JournalsForMessage.new(:user_id => 1, :notes => notes3, :reply_id => 0, :status => true, :is_readed => false, :private => 0) - end - end + # Rails.logger.info "add_new_jour_delay!!!!!!!!!" + # if Setting.find_by_name("hidden_non_project") && Setting.find_by_name("hidden_non_project").value != "0" + # if Message.where("id=19504").any? and Message.where("id=19291").any? and Message.where("id=19292").any? + # lead_message1 = Message.find(19292) + # notes1 = lead_message1.content + # lead_message2 = Message.find(19291) + # notes2 = lead_message2.content + # lead_message3 = Message.find(19504) + # notes3 = lead_message3.content + # #user_id 默认为课程使者创建 + # self.journals_for_messages << JournalsForMessage.new(:user_id => 1, :notes => notes1, :reply_id => 0, :status => true, :is_readed => false, :private => 0) + # self.journals_for_messages << JournalsForMessage.new(:user_id => 1, :notes => notes2, :reply_id => 0, :status => true, :is_readed => false, :private => 0) + # self.journals_for_messages << JournalsForMessage.new(:user_id => 1, :notes => notes3, :reply_id => 0, :status => true, :is_readed => false, :private => 0) + # end + # end # self.delay.add_new_jour_delay end diff --git a/app/views/challenges/_content_list.html.erb b/app/views/challenges/_content_list.html.erb index 7cc37a224..91a7e2e31 100644 --- a/app/views/challenges/_content_list.html.erb +++ b/app/views/challenges/_content_list.html.erb @@ -38,13 +38,14 @@ <% if User.current.manager_of_shixun?(@shixun) && @shixun.status == 0 %>
+ <% unless challenge.position < 2 %> - + <% end %> <% if @shixun.challenges.count != challenge.position %> - + <% end %> - +
diff --git a/app/views/challenges/_edit_skill.html.erb b/app/views/challenges/_edit_skill.html.erb index f57446c82..599337fa2 100644 --- a/app/views/challenges/_edit_skill.html.erb +++ b/app/views/challenges/_edit_skill.html.erb @@ -10,7 +10,7 @@当前经验值:<%= @user.experience %>,您可以通过<%= link_to '实训挑战', shixuns_path(), :class => "color-orange03" %>的方式获得经验值
+
+ 您还没有获得过经验值哦~
+| 操作 | +变更 | +详情 | +操作时间 | +
|---|---|---|---|
| 闯关 | ++ <%= exp.score %> | + <% game = Game.where(:id => exp.container_id).first %> +<%= game ? "通过实训“#{game.challenge.shixun.name}”的第#{game.challenge.position}关获得的奖励" : "" %> | +<%= format_time exp.created_at %> | +
当前金币:<%= @user.grade %>,您可以通过<%= link_to '完善基本资料', my_account_path(), :class => "color-orange03" %> + 、<%= link_to '首次绑定邮箱和手机', security_settings_path(), :class => "color-orange03" %> + 以及<%= link_to '实训挑战', shixuns_path(), :class => "color-orange03" %>的方式获得金币
+
+ 您还没有获得过金币哦~
+| 操作 | +变更 | +详情 | +操作时间 | +||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 绑定手机 | ++ <%= grade.score %> | +用户首次绑定手机号码获得的奖励 | + <% when 'Mail' %> +绑定邮箱 | ++ <%= grade.score %> | +用户首次绑定邮箱获得的奖励 | + <% when 'Account' %> +完善基本资料 | ++ <%= grade.score %> | +新用户首次填写基本资料获得的奖励 | + <% when 'Answer' %> +查看参考答案 | +- <%= grade.score.abs %> | + <% game = Game.where(:id => grade.container_id).first %> +<%= game ? "查看实训“#{game.challenge.shixun.name}”第#{game.challenge.position}关的参考答案消耗的金币" : "" %> | + <% when 'Game' %> +闯关 | ++ <%= grade.score %> | + <% game = Game.where(:id => grade.container_id).first %> +<%= game ? "通过实训“#{game.challenge.shixun.name}”的第#{game.challenge.position}关获得的奖励" : "" %> | + <% end %> +<%= format_time grade.created_at %> | +
当前技能标签:<%= @user.challenge_tags.count %>,您可以通过<%= link_to '实训挑战', shixuns_path(), :class => "color-orange03" %>的方式获得技能标签
+
+ 您还没有获得过技能标签哦~
+| 操作 | +变更 | +详情 | +操作时间 | +
|---|---|---|---|
| 闯关 | + <% game = Game.where(:id => tag.container_id).first %> ++ 标签:<%= game ? game.challenge.challenge_tags.map(&:name).join("、") : "" %> | +<%= game ? "通过实训“#{game.challenge.shixun.name}”的第#{game.challenge.position}关获得的标签" : "" %> | +<%= format_time tag.created_at %> | +
你好~<%= @user.show_name %>,欢迎来到个人成长记录中心
+
+ 技能标签<%= @user.challenge_tags.count %>
+ 经验值<%= @user.experience %>
+
金币<%= @user.grade %>
+