From 53e792918bda655622604c5299309420bb69b19c Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 4 Apr 2019 14:48:35 +0800 Subject: [PATCH] 1 --- app/controllers/managements_controller.rb | 49 +++++++++ .../managements/_customer_addUnit.html.erb | 100 ++++++++++++++++++ app/views/managements/customers_list.js.erb | 6 ++ app/views/managements/partners.html.erb | 3 +- config/routes.rb | 2 + 5 files changed, 159 insertions(+), 1 deletion(-) create mode 100644 app/views/managements/_customer_addUnit.html.erb create mode 100644 app/views/managements/customers_list.js.erb diff --git a/app/controllers/managements_controller.rb b/app/controllers/managements_controller.rb index c92ae34d..20e40fc6 100644 --- a/app/controllers/managements_controller.rb +++ b/app/controllers/managements_controller.rb @@ -1193,6 +1193,53 @@ end end + # 添加客户 + def customers_list + @search = params[:search] + @province = params[:province] + partner_id = params[:partner] + @partner = Partner.find partner_id + @customers = @partner.customers + customer_id = @customers.present? ? @customers.map(&:id).join(",") : -1 + @schools = School.where("partner_id != ? and customer_id not in(#{customer_id})", @partner.id) + + if params[:search] + @schools = @schools.where("name like ?", "%#{@search}%") + end + + if params[:province] + @schools = @schools.where("province like ?", "%#{@province}%") + end + + @limit = 10 + @page = params[:page] || 1 + @schools_count = @schools.count + + @total_pages = (@schools_count / 10.0).ceil + @schools = paginateHelper @schools, @limit + respond_to do |format| + format.js + format.json { + render json: @schools + } + end + end + + def add_customers + school_ids = params[:school_ids] + if school_ids.length > 0 + school_ids.each do |s| + school = School.where("id = ?",s).first + if school.present? + customer = Customer.new(partner_id: params[:partner_id]) + customer.save! + school.update_attributes(:customer_id => customer.id) + end + end + render :json => {status: 1, message: "创建成功!"} + end + end + def all_partners @search = params[:search] @province = params[:province] @@ -1238,6 +1285,8 @@ end + + # 删除部门管理员 def delete_depart_member DepartmentMember.where(:department_id => params[:depart], :user_id => params[:user_id]).destroy_all diff --git a/app/views/managements/_customer_addUnit.html.erb b/app/views/managements/_customer_addUnit.html.erb new file mode 100644 index 00000000..17f31b47 --- /dev/null +++ b/app/views/managements/_customer_addUnit.html.erb @@ -0,0 +1,100 @@ +