kaijiang_controller.rb 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. # encoding:utf-8
  2. class KaijiangController < BaseController
  3. before_filter :authenticate_admin_user!
  4. def index
  5. # 项目ID
  6. pid = params[:pid].to_i
  7. @project = Project.where("id=?",pid).first
  8. #开奖人数
  9. @num = params[:num].to_i
  10. #开奖人数
  11. @all_num = params[:all].to_i
  12. #重庆时彩号码
  13. @code = params[:code].to_i
  14. # 项目的投资人总数-排重
  15. # sql = "select count(DISTINCT user_id) as count from d5c_project_joins where project_id = " + pid + " and state = 1 and is_deleted=0 and is_refunded = 0"
  16. sql = "select FROM_UNIXTIME(paied_at,'%Y%m%d%H%i') c from d5c_project_joins where project_id = " + pid.to_s + " and state = 1 and is_deleted=0 and is_refunded = 0 group by user_id order by paied_at asc, created_at asc limit #{@all_num};"
  17. @items = ProjectJoin.find_by_sql(sql)
  18. @count = @items.size
  19. @sum = 0
  20. @items.each do |item|
  21. @sum = @sum + item.c.to_i
  22. end
  23. if @count > 0
  24. code_date = @items[1].c
  25. @code_date = "#{code_date[0...4]}-#{code_date[4...6]}-#{code_date[6...8]}"
  26. end
  27. render :layout => false
  28. end
  29. #项目投资排名
  30. def rank
  31. pid = params[:id].to_i
  32. @project = Project.where("id=?",pid).first
  33. sql = "select sum(j.total_price) as investment, j.user_id, j.paied_at as invest_time,u.real_name,u.tel from d5c_project_joins j,d5c_users u where j.user_id=u.id and j.project_id = #{pid} and j.state = 1 and j.is_refunded = 0 and j.is_deleted = 0 group by j.user_id order by invest_time asc, j.created_at asc";
  34. @items = ProjectJoin.find_by_sql(sql)
  35. end
  36. end