From 80b58717563494b108a539ce3def6fcc10676d99 Mon Sep 17 00:00:00 2001 From: z9hang Date: Wed, 23 Jul 2014 17:56:15 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AB=9E=E8=B5=9B=E9=A6=96=E9=A1=B5=E5=AE=9A?= =?UTF-8?q?=E5=88=B6=E4=B8=AD=E6=B7=BB=E5=8A=A0=E7=BC=96=E8=BE=91=E9=80=9A?= =?UTF-8?q?=E7=9F=A5=E9=80=9A=E5=91=8A=E7=9A=84=E7=BC=96=E8=BE=91=E6=A1=86?= =?UTF-8?q?=E5=B9=B6=E5=AD=98=E5=85=A5=E6=95=B0=E6=8D=AE=E5=BA=93=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=96=B0=E7=9A=84=E8=A1=A8=E8=AE=B0=E5=BD=95?= =?UTF-8?q?=E4=B8=AA=E4=BA=BA=E5=BE=97=E5=88=86=E7=9B=B8=E5=85=B3=E7=BB=86?= =?UTF-8?q?=E8=8A=82=EF=BC=8C=E5=8F=8A=E5=90=84=E7=A7=8D=E5=BE=97=E5=88=86?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/admin_controller.rb | 5 +- app/helpers/user_score_helper.rb | 77 +++++++++++++++++++++- app/views/admin/contest_page_made.html.erb | 12 +++- config/locales/zh.yml | 2 + db/schema.rb | 28 +++++++- 5 files changed, 119 insertions(+), 5 deletions(-) diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index edc526217..781d07d58 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -220,7 +220,10 @@ class AdminController < ApplicationController @contest_page.web_title = params[:web_title] @contest_page.title = params[:contest_title] @contest_page.description = params[:contest_description] - if @first_page.save && @contest_page.save + @notification.title = params[:contest_notification_title] + @notification.content = params[:contest_notification][:content] + + if @first_page.save && @contest_page.save && @notification.save respond_to do |format| format.html { flash[:notice] = l(:notice_successful_update) diff --git a/app/helpers/user_score_helper.rb b/app/helpers/user_score_helper.rb index 768e87a8f..ede00b694 100644 --- a/app/helpers/user_score_helper.rb +++ b/app/helpers/user_score_helper.rb @@ -336,8 +336,81 @@ module UserScoreHelper user.user_score.update_attributes(:collaboration => collaboration, :influence => influence, :skill => skill, :activity => activity, :file => file, :issue => issue, :level => level) end - - + #==================================================================================================== + def get_option_number(user,type) + option_number = OptionNumber.where("user_id = '#{user.id}' and score_type = '#{type}'"); + if option_number.nil? + option_number = OptionNumber.new + option_number.user_id = user.id + option_number.score_type =type + end + option_number + end + + #更新分数 + def update_score(option_number) + option_number.total_score = collaboration(option_number) + influence(option_number) + skill(option_number) + active(option_number) + option_number.save + end + + #协同得分 + def collaboration(option_number) + option_number.memo * 2 + option_number.messages_for_issues + option_number.issues_status + option_number.replay_for_message + option_number.replay_for_memo + end + #影响力得分 + def influence(option_number) + option_number.follow * 2 + end + #技术得分 + def skill(option_number) + option_number.praise_by_one * 4 + option_number.praise_by_two * 6 + option_number.praise_by_three * 8 - option_number.tread * 2 - option_number.tread_by_one * 2 - option_number.tread_by_two * 4 - option_number.tread_by_three * 6 + end + #项目贡献得分 + def active(option_number) + option_number.changeset * 4 + option_number.document * 4 + option_number.attachment * 4 + option_number.issue_done_ratio * 2 + option_number.post_issue * 4 + end + + #更新发帖数 + def update_memo_number(user,type) + option_number = get_option_number(user,type) + option_number.memo = Message.includes(:author).where("parent_id IS NULL and author_id = '#{user.id}'").all.count + update_score(option_number) + end + + #更新对缺陷留言数 + def update_messges_for_issue(user,type) + option_number = get_option_number(user,type) + option_number.messages_for_issues = Journal.includes(:user).where("user_id = '#{user.id}'").all.count + update_score(option_number) + end + + #更新更改缺陷状态状态次数 + def update_issues_status(user,type) + option_number = get_option_number(user,type) + option_number.issues_status = Journal.joins(:details, :user).where("#{JournalDetail.table_name}.prop_key = 'status_id' and #{User.table_name}.id = '#{user.id}'").count + update_score(option_number) + end + #更新对留言的回复数量 + def update_replay_for_message(user,type) + option_number = get_option_number(user,type) + option_number.replay_for_message = JournalsForMessage.includes(:user).where("m_parent_id IS NOT NULL and user_id = #{user.id}").count + update_score(option_number) + end + + #更新对帖子的回复数量 + def update_replay_for_memo(user,type) + option_number = get_option_number(user,type) + option_number.replay_for_memo = Message.includes(:author).where("parent_id IS NOT NULL and author_id = #{user.id}").count + update_score(option_number) + end + + #更新被关注的人数 + def update_follow(user,type) + option_number = get_option_number(user,type) + option_number.follow = Watcher.includes(:watchable).where("watchable_type = 'Principal' and watchable_id = '#{user.id}'").count + update_score(option_number) + end + #更新踩别人帖子的数量 end diff --git a/app/views/admin/contest_page_made.html.erb b/app/views/admin/contest_page_made.html.erb index d9a9b2f65..7f054324d 100644 --- a/app/views/admin/contest_page_made.html.erb +++ b/app/views/admin/contest_page_made.html.erb @@ -35,9 +35,19 @@

- + + +

+ <%= text_field_tag 'contest_notification_title', params[:label_contest_notification_title], :value => @notification.title,:size => 30,:style => "font-size:small;width:490px;margin-left:10px;" %> +

+ <%= text_area 'contest_notification', 'content', :value => @notification.content,:cols => 80, :rows => 15, :class => 'wiki-edit' %> <%= wikitoolbar_for 'contest_notification_content' %> + +
<%= submit_tag l(:button_save), :class => "small", :name => nil %> <% end %> diff --git a/config/locales/zh.yml b/config/locales/zh.yml index cd5dd630a..52cc04000 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -573,6 +573,8 @@ zh: label_site_description: 网站简介 label_site_image: 简介图片 label_sort_type: 热门项目排序方式 + label_contest_notification_title: 竞赛通知标题 + label_contest_notification_content: 竞赛通知内容 #by young label_requirement: 需求 label_new_course: 课程列表 diff --git a/db/schema.rb b/db/schema.rb index 870703254..0cc830fd8 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20140722080924) do +ActiveRecord::Schema.define(:version => 20140723082637) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -716,6 +716,32 @@ ActiveRecord::Schema.define(:version => 20140722080924) do t.datetime "updated_at", :null => false end + create_table "option_numbers", :force => true do |t| + t.string "user_id" + t.integer "memo" + t.integer "messages_for_issues" + t.integer "issues_status" + t.integer "replay_for_message" + t.integer "replay_for_memo" + t.integer "follow" + t.integer "tread" + t.integer "praise_by_one" + t.integer "praise_by_two" + t.integer "praise_by_three" + t.integer "tread_by_one" + t.integer "tread_by_two" + t.integer "tread_by_three" + t.integer "changeset" + t.integer "document" + t.integer "attachment" + t.integer "issue_done_ratio" + t.integer "post_issue" + t.integer "score_type" + t.integer "total_score" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + create_table "praise_tread_caches", :force => true do |t| t.integer "object_id", :null => false t.string "object_type"