diff --git a/app/controllers/managements_controller.rb b/app/controllers/managements_controller.rb index 9992d000..599e8da4 100644 --- a/app/controllers/managements_controller.rb +++ b/app/controllers/managements_controller.rb @@ -2104,25 +2104,36 @@ end condition = (params[:research_condition].nil? || params[:research_condition] == "name") ? "concat(lastname, firstname)" : params[:research_condition] if 0 == status if params[:research_condition] == "phone" && params[:research_contents].blank? - @users = User.order("#{@order_key} #{@us_order}") + @users = User.where(nil) else - @users = User.where("#{condition} like '%#{params[:research_contents]}%'").order("#{@order_key} #{@us_order}") + @users = User.where("#{condition} like '%#{params[:research_contents]}%'") end else if params[:research_condition] == "phone" && params[:research_contents].blank? - @users = User.where(:status => status).order("#{@order_key} #{@us_order}") + @users = User.where(:status => status) else - @users = User.where("status = #{status} and #{condition} like '%#{params[:research_contents]}%'").order("#{@order_key} #{@us_order}") + @users = User.where("status = #{status} and #{condition} like '%#{params[:research_contents]}%'") end end + if params[:identity] && params[:identity].to_i != -1 + @users = @users.includes(:user_extensions).where("user_extensions.identity = ?", params[:identity].to_i) + end + + if params[:auto_school] && params[:auto_school].to_i != 0 + @users = @users.includes(:user_extensions => [:school]).where("schools.auto_users_trial = ?", params[:auto_school].to_i == 1 ? 1 : 0) + end + if params[:school] && params[:school] != '' school_name = params[:school] school = School.where("name like '%#{school_name}%'") school_id = school.map(&:id) user_id = UserExtensions.where(:school_id => school_id).map(&:user_id) - @users = @users.where(:id => user_id).order("#{@order_key} #{@us_order}") + @users = @users.where(:id => user_id) end + + @users = @users.order("#{@order_key} #{@us_order}") + @page = (params['page'] || 1).to_i @users_count = @users.count @limit = 20 @@ -3186,25 +3197,44 @@ end search = params[:search] @status = trial_authorization_status(params[:status]) # @status = (params[:status].blank? || params[:status] == "0") ? 0 : [1,2] - if search.blank? - @authorizations = ApplyAction.where(:container_type => "TrialAuthorization", :status => @status).includes(:user) - else - user_id = User.find_by_sql("select id from users where concat(lastname,firstname) like '%#{search}%'") - @authorizations = ApplyAction.where(:container_type => "TrialAuthorization", :status => @status, :user_id => user_id).includes(:user) + user_id = [] + search = false + @authorizations = ApplyAction.where(:container_type => "TrialAuthorization", :status => @status) + + unless search.blank? + user_id = User.find_by_sql("select id from users where concat(lastname,firstname) like '%#{search}%'").map(&:id) end - if params[:sname] && params[:sname] != '' + if params[:sname] && params[:sname].strip != '' school_id = School.where("name like '%#{params[:sname]}%'") - user_id = UserExtensions.where(:school_id => school_id).map(&:user_id) - @authorizations = @authorizations.where(:user_id => user_id).order("updated_at desc") + new_user_id = UserExtensions.where(:school_id => school_id).map(&:user_id) + user_id = user_id.size == 0 ? new_user_id : user_id & new_user_id + search = true + end + + if params[:identity] && params[:identity].to_i != -1 + new_user_id = UserExtensions.where(:identity => params[:identity].to_i).map(&:user_id) + user_id = user_id.size == 0 ? new_user_id : user_id & new_user_id + search = true end + if params[:auto_school] && params[:auto_school].to_i != 0 + school_id = School.where(auto_users_trial: params[:auto_school].to_i == 1 ? 1 : 0) + new_user_id = UserExtensions.where(:school_id => school_id).map(&:user_id) + user_id = user_id.size == 0 ? new_user_id : user_id & new_user_id + search = true + end + + @authorizations = user_id.size == 0 && !search ? @authorizations.order("updated_at desc") : @authorizations.where(:user_id => user_id.uniq).order("updated_at desc") + @autu_count = @authorizations.count @limit = 15 @is_remote = true @autu_pages = Paginator.new @autu_count, @limit, params['page'] || 1 @offset ||= @autu_pages.offset @authorizations = paginateHelper @authorizations, @limit + + @authorizations = @authorizations.includes(:user) respond_to do |format| format.js format.html diff --git a/app/views/managements/trial_authorization.html.erb b/app/views/managements/trial_authorization.html.erb index 5f2c17a1..acdc4d69 100644 --- a/app/views/managements/trial_authorization.html.erb +++ b/app/views/managements/trial_authorization.html.erb @@ -28,11 +28,22 @@
+
+ +全部状态
- -真实姓名搜索
- -全部状态
+ +真实姓名搜索
+ +