From 50ec127c5b3e2d0761b6f1d64f0bbf24fbc2dbd1 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 28 Jul 2016 20:01:22 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=95=E4=BD=8D=E5=90=8D=E7=A7=B0=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/admin_controller.rb | 61 ++- app/controllers/school_controller.rb | 1 + app/models/applied_message.rb | 2 +- app/models/apply_add_schools.rb | 2 +- app/views/admin/_all_schools.html.erb | 56 +++ app/views/admin/_update_school_form.html.erb | 27 ++ app/views/admin/all_schools.js.erb | 11 + app/views/admin/applied_schools.html.erb | 26 +- app/views/admin/has_applied_schools.html.erb | 29 +- .../users/_user_message_applied.html.erb | 26 +- config/routes.rb | 3 + ...60728041513_add_name_to_applied_message.rb | 5 + db/schema.rb | 419 +----------------- 13 files changed, 230 insertions(+), 438 deletions(-) create mode 100644 app/views/admin/_all_schools.html.erb create mode 100644 app/views/admin/_update_school_form.html.erb create mode 100644 app/views/admin/all_schools.js.erb create mode 100644 db/migrate/20160728041513_add_name_to_applied_message.rb diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index 4bfd9a514..397235f4b 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -617,7 +617,7 @@ class AdminController < ApplicationController def has_applied_schools @name = params[:name] - @has_apply_status = ApplyAddSchools.where(:status => 1).order('created_at desc') + @has_apply_status = ApplyAddSchools.where("status = 1 or status = 2").order('created_at desc') @has_apply_count = @has_apply_status.count @has_apply_pages = Paginator.new @has_apply_count, 30, params['page'] || 1 @@ -631,11 +631,14 @@ class AdminController < ApplicationController # 批准未审批的高校 # 消息发送,发送对象为申请人 - # status: 0表示未批准; status:1表示已批准; status: 2表示已拒绝 + # status: 0表示未批准; status:1表示已批准; status: 2表示已更改; status: 3表示已拒绝 def approve_applied_schools applied_school = ApplyAddSchools.find params[:id] applied_school.update_column('status', 1) unless applied_school.nil? - AppliedMessage.create(:user_id => applied_school.user_id, :status => true, :applied_id => applied_school.id, :applied_type => "ApplyAddSchools") + school = applied_school.school + school.update_attribute("province", applied_school.province) + AppliedMessage.create(:user_id => applied_school.user_id, :status => 1, :viewed => true, :applied_id => applied_school.id, :applied_type => "ApplyAddSchools", :name => applied_school.name ) + # School.create(:user_id => applied_school.user_id, :status => 1, :viewed => true, :applied_id => applied_school.id, :applied_type => "ApplyAddSchools", :name => applied_school.name ) respond_to do |format| format.html{ redirect_to unapplied_schools_url } end @@ -645,8 +648,43 @@ class AdminController < ApplicationController # REDO: 修改该字段 # REDO: 同步修改使用了改名称的用户单位 def edit_applied_schools - @applied_schools = ApplyAddSchools.find params[:id] - @applied_schools.update_column('name', params[:name]) + aas = ApplyAddSchools.find(params[:applied_id]) + # aas.update_attribute(:name, params[:name]) + #applied_add_school = ApplyAddSchools.where(:name => aas.name) + school = School.find params[:school_id] + begin + aas.update_attribute(:status, 2) + AppliedMessage.create(:user_id => aas.user_id, :status => 2, :viewed => true, :applied_id => aas.id, :applied_type => "ApplyAddSchools", :name => school[0].name ) + users = UserExtensions.where("school_id = #{aas.school_id}") + users.each do |user| + user.update_column("school_id", school[0].id) + end + aas.school.destroy + aas.update_attribute(:school_id, school[0].id) + rescue Exception => e + puts e + end + # applied_schools = ApplyAddSchools.find params[:applied_id] + # applied_schools.update_column('name', params[:name]) + redirect_to unapplied_schools_url + end + + def all_schools + apply_schools = ApplyAddSchools.where("status != 1") + apply_school_ids = apply_schools.empty? ? "(-1)" : "(" + apply_schools.map{|sc| sc.school_id}.join(',') + ")" + if !params[:search].nil? + search = "%#{params[:search].to_s.strip.downcase}%" + @schools = School.where("id not in #{apply_school_ids} and #{School.table_name}.name like :p",:p=>search) + #@schools = School.all + else + #@course = @user.courses.where("is_delete = 0 and #{Course.table_name}.id != #{homework.course_id}").select { |course| @user.allowed_to?(:as_teacher,course)} + @schools = School.where("id not in #{apply_school_ids}") + end + @edit_id = params[:school_id] + @search = params[:search] + respond_to do |format| + format.js + end end # 删除申请的高校 @@ -654,8 +692,17 @@ class AdminController < ApplicationController # REDO: 删除确认提示,是否删除 # REDO: 给申请人发送消息 def delete_applied_schools - @applied_schools = ApplyAddSchools.find params[:id] - @applied_schools.destroy + applied_school = ApplyAddSchools.find(params[:id]) + applied_school.update_attribute(:status, 3) + AppliedMessage.create(:user_id => applied_school.user_id, :status => 3, :viewed => true, :applied_id => applied_school.id, :applied_type => "ApplyAddSchools", :name => applied_school.name ) + users = UserExtensions.where("school_id = #{applied_school.school_id}") + users.each do |user| + user.update_column("school_id", nil) + end + applied_school.school.destroy + respond_to do |format| + format.html{ redirect_to unapplied_schools_url } + end end #移动端版本管理 diff --git a/app/controllers/school_controller.rb b/app/controllers/school_controller.rb index bdd99de61..568f1c401 100644 --- a/app/controllers/school_controller.rb +++ b/app/controllers/school_controller.rb @@ -169,6 +169,7 @@ class SchoolController < ApplicationController school = School.new school.name = params[:name].strip school.pinyin = Pinyin.t(params[:name].strip, splitter: '') + school.province = params[:province] #status 0未处理 1通过 2拒绝 applyschool = ApplyAddSchools.new diff --git a/app/models/applied_message.rb b/app/models/applied_message.rb index 1c6b3a8e7..de07dae22 100644 --- a/app/models/applied_message.rb +++ b/app/models/applied_message.rb @@ -1,6 +1,6 @@ class AppliedMessage < ActiveRecord::Base # status: 0表示未批准; status:1表示已批准; status: 2表示已拒绝 - attr_accessible :applied_id, :applied_type, :status, :user_id, :viewed + attr_accessible :applied_id, :applied_type, :status, :user_id, :viewed, :name belongs_to :applied ,:polymorphic => true belongs_to :apply_add_schools belongs_to :user diff --git a/app/models/apply_add_schools.rb b/app/models/apply_add_schools.rb index b7301af13..573a494ef 100644 --- a/app/models/apply_add_schools.rb +++ b/app/models/apply_add_schools.rb @@ -1,7 +1,7 @@ class ApplyAddSchools < ActiveRecord::Base # status:0 未审批 ; 1 已批阅 attr_accessible :address, :city, :name, :province, :remarks, :school_id, :status - has_many :applied_messages, :class_name =>'AppliedMessage', :as => :applied, :dependent => :destroy + has_many :applied_messages, :class_name =>'AppliedMessage', :as => :applied belongs_to :school after_create :send_massage diff --git a/app/views/admin/_all_schools.html.erb b/app/views/admin/_all_schools.html.erb new file mode 100644 index 000000000..0ecb38544 --- /dev/null +++ b/app/views/admin/_all_schools.html.erb @@ -0,0 +1,56 @@ +<%= stylesheet_link_tag 'css/common','css/popup' %> + +
详细地址 | -+ | 用户 | @@ -46,11 +46,11 @@ | |||
---|---|---|---|---|---|---|
<%= apply.id %> | -@@ -60,17 +60,29 @@ <%= apply.address %> | - <%= apply.user_id %> + <% count = UserExtensions.where("school_id = #{apply.school_id}").count %> + <%= count %> | <%= format_date(apply.created_at) %> | <%= link_to( l(:label_approve), { :controller => 'admin', :action => 'approve_applied_schools', :id => apply.id }, :class => 'icon-del') %> - <%= link_to( l(:button_delete), { :controller => 'admin', :action => 'delete_applied_schools', :id => apply.id }, :class => 'icon-del') %> - <%= link_to( l(:button_change), { :controller => 'admin', :action => 'edit_applied_schools', :id => apply.id, :name => apply.name }, :class => 'icon-del') %> + <%= link_to( l(:button_delete), { :controller => 'admin', :action => 'delete_applied_schools', :id => apply.id },:method => :delete, :confirm => l(:text_are_you_sure), :class => 'icon-del') %> + <%=link_to '更改', admin_all_schools_path(:school_id =>apply.id), :remote => true %> + | ||
+ + | ++ <%= apply.remarks %> + | +详细地址 | -- 用户 + | + 原名 | 创建时间 @@ -45,31 +45,40 @@ | <% @has_apply_status.each do |apply| %> - <% if apply.status == 1 %> -|
<%= apply.id %> | -- <%= apply.province + apply.city %> + <%= (School.find apply.school_id).province %> | - <%= apply.user_id %> + <%= apply.name %> | <%= format_date(apply.created_at) %> | - <%= link_to( l(:button_delete), { :controller => 'admin', :action => 'delete_applied_schools', :id => apply.id }, :class => 'icon-del') %> - <%= link_to( l(:button_change), { :controller => 'admin', :action => 'edit_applied_schools', :id => apply.id, :name => apply.name }, :class => 'icon-del') %> + <%= link_to( l(:button_delete), { :controller => 'admin', :action => 'delete_applied_schools', :id => apply.id },:method => :delete, :confirm => l(:text_are_you_sure), :class => 'icon-del') %> | ||
+ + | ++ <%= apply.remarks %> + | +