客户列表

dev_local
cxt 6 years ago
parent b930943368
commit 00dadf7531

@ -1,6 +1,20 @@
class CooperatesController < ApplicationController class CooperatesController < ApplicationController
def show def partner_list
search = params[:search]
@schools = School.where(id: [179, 3181, 3216]).where("name like ?", "'%#{search}%'")
@all_count = @schools.size
unless search.blank?
@schools = @schools.where("name like ?", "'%#{search}%'")
end
@search_count = @schools.size
@schools = paginateHelper @schools, 15
@schools = @schools.includes(:courses, users: :user_extensions)
respond_to do |format|
format.js
format.html{render :layout => "base_edu"}
end
end end
end end

@ -26,4 +26,36 @@ class School < ActiveRecord::Base
def to_s def to_s
self.name.to_s self.name.to_s
end end
def teacher_count
User.find_by_sql("SELECT COUNT(users.`id`) AS teacher_count FROM users LEFT JOIN user_extensions ON
users.id=user_extensions.user_id WHERE user_extensions.`school_id` = #{self.id} AND
user_extensions.`identity` = 0").first.try(:teacher_count)
end
def student_count
User.find_by_sql("SELECT COUNT(users.`id`) AS student_count FROM users LEFT JOIN user_extensions ON
users.id=user_extensions.user_id WHERE user_extensions.`school_id` = #{self.id} AND
user_extensions.`identity` = 1").first.try(:student_count)
end
def course_count
Course.find_by_sql("SELECT COUNT(courses.`id`) AS course_count FROM courses LEFT JOIN user_extensions ON
courses.tea_id=user_extensions.user_id WHERE user_extensions.`school_id` = #{self.id} AND
courses.id != 1309").first.try(:course_count)
end
def shixun_count
Shixun.find_by_sql("select count(s.id) as shixun_count from users u right join shixuns s on u.id=s.user_id and
s.status in (2, 3) inner join user_extensions ue on u.id=ue.user_id and
ue.school_id=#{self.id}").first.try(:shixun_count)
end
def shixun_report_count
StudentWork.find_by_sql("SELECT count(*) as sw_count FROM `student_works` where user_id in
(SELECT users.id FROM users RIGHT JOIN user_extensions ON users.id=user_extensions.user_id
WHERE user_extensions.`school_id`=#{self.id}) and work_status between 1 and 2 and
myshixun_id !=0").first.try(:sw_count)
end
end end

Loading…
Cancel
Save