修改首页定制中热门项目排序方式的实现

This commit is contained in:
z9hang 2014-07-25 09:19:29 +08:00
parent 4542b9e21a
commit f83336aed0
3 changed files with 21 additions and 19 deletions

View File

@ -24,24 +24,19 @@ class WelcomeController < ApplicationController
def index
@first_page = FirstPage.where("page_type = 'project'").first
@hot_projects = find_miracle_project(10, 3)
@hot_projects_ids = []
@hot_projects.each do |p|
@hot_projects_ids << p
end
@projects_all = Project.active.visible.
joins("LEFT JOIN #{ProjectStatus.table_name} ON #{Project.table_name}.id = #{ProjectStatus.table_name}.project_id").
where("#{Project.table_name}.project_type = ? and #{Project.table_name}.id in (?)", Project::ProjectType_project,@hot_projects_ids)
if @first_page.nil? || @first_page.sort_type.nil?
@projects = @projects_all.order("grade desc")
@projects = find_miracle_project(10, 3,"grade desc")
else
case @first_page.sort_type
when 0
@projects = @projects_all.order("created_on desc")
@projects = find_miracle_project(10, 3,"created_on desc")
#@projects = @projects_all.order("created_on desc")
when 1
@projects = @projects_all.order("grade desc")
@projects = find_miracle_project(10, 3,"grade desc")
#@projects = @projects_all.order("grade desc")
when 2
@projects = @projects_all.order("watchers_count desc")
@projects = find_miracle_project(10, 3,"watchers_count desc")
#@projects = @projects_all.order("watchers_count desc")
#gcm
#when '3'

View File

@ -203,12 +203,12 @@ module WelcomeHelper
#end
end
def find_miracle_project(sum, max_rate)
def find_miracle_project(sum, max_rate,order)
#max = sum*(max_rate.to_f/10)
#c1 = find_new_project(sum).to_a.dup
#c2 = find_all_hot_project(sum).to_a.dup
#(c2.take(sum-max)+c1.take(max)).take(sum)
find_all_hot_project(sum).dup#.to_a.dup
find_all_hot_project(sum,order).to_a.dup
end
def find_new_course limit=15
@ -220,8 +220,8 @@ module WelcomeHelper
end
def find_all_hot_project limit=15
sort_project_by_hot limit
def find_all_hot_project limit=15,order
sort_project_by_hot limit,order
end
def find_all_hot_course limit=15
@ -366,8 +366,9 @@ module WelcomeHelper
private
def sort_project_by_hot limit=15
sort_project_by_hot_rails 0, 'grade DESC', limit
def sort_project_by_hot limit=15,order
#'grade DESC'
sort_project_by_hot_rails 0,order , limit
end
def sort_course_by_hot limit=15
@ -433,7 +434,7 @@ module WelcomeHelper
# FROM projects AS p LEFT OUTER JOIN (
# SELECT project_id,grade FROM project_statuses
# WHERE project_type = #{project_type} ORDER BY #{order_by} LIMIT #{limit} ) AS t ON p.id = t.project_id ")
Project.visible.joins(:project_status).where("#{Project.table_name}.project_type = ?", project_type).order(order_by).limit(limit)#.all
Project.visible.joins(:project_status).where("#{Project.table_name}.project_type = ?", project_type).order(order_by).limit(limit).all
end
def sort_bid_by_hot_rails reward_type, limit = 10

View File

@ -0,0 +1,6 @@
class ChangeOptionNumber < ActiveRecord::Migration
def change
change_column("option_numbers","user_id",:integer)
add_column("option_numbers","project_id",:integer)
end
end