|
|
|
@ -1191,7 +1191,7 @@ end
|
|
|
|
|
if params[:search].blank?
|
|
|
|
|
@partners = Partner.includes(:school).order("partners.created_at desc")
|
|
|
|
|
else
|
|
|
|
|
@partners = Partner.where("name like ? ", "%#{params[:search]}%").includes(:school).order("partners.created_at desc")
|
|
|
|
|
@partners = Partner.includes(:school).where("schools.name like ? ", "%#{params[:search]}%").order("partners.created_at desc")
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
@current_partner = nil
|
|
|
|
@ -1212,6 +1212,14 @@ end
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def delete_partner
|
|
|
|
|
partner = Partner.find params[:partner_id]
|
|
|
|
|
partner.destroy
|
|
|
|
|
@partners = Partner.includes(:school).order("partners.created_at desc")
|
|
|
|
|
@current_partner = nil
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 添加客户
|
|
|
|
|
def customers_list
|
|
|
|
|
@search = params[:search]
|
|
|
|
@ -1219,11 +1227,10 @@ end
|
|
|
|
|
partner_id = params[:partner_id]
|
|
|
|
|
@partner = Partner.find partner_id
|
|
|
|
|
@customers = @partner.customers
|
|
|
|
|
if @customers.present?
|
|
|
|
|
@schools = School.where("(partner_id != ? or partner_id is NULL) and customer_id is NULL", @partner.id)
|
|
|
|
|
else
|
|
|
|
|
@schools = School.where("customer_id is null and (partner_id != ? or partner_id is NULL)", @partner.id)
|
|
|
|
|
end
|
|
|
|
|
existed_school_ids = @customers.pluck(:school_id)
|
|
|
|
|
existed_school_ids = existed_school_ids.present? ? existed_school_ids.join(",") : -1
|
|
|
|
|
@schools = School.where("id not in (#{existed_school_ids})")
|
|
|
|
|
|
|
|
|
|
if params[:search]
|
|
|
|
|
@schools = @schools.where("name like ?", "%#{@search}%")
|
|
|
|
|
end
|
|
|
|
@ -1247,13 +1254,14 @@ end
|
|
|
|
|
|
|
|
|
|
def add_customers
|
|
|
|
|
school_ids = params[:school_ids]
|
|
|
|
|
if school_ids.length > 0
|
|
|
|
|
partner_id = params[:partner_id]
|
|
|
|
|
if school_ids.length > 0 && partner_id.present?
|
|
|
|
|
school_ids.each do |s|
|
|
|
|
|
school = School.where("id = ?",s).first
|
|
|
|
|
if school.present?
|
|
|
|
|
customer = Customer.new(partner_id: params[:partner_id])
|
|
|
|
|
customer = Customer.new(school_id: s)
|
|
|
|
|
customer.save!
|
|
|
|
|
school.update_attributes(:customer_id => customer.id)
|
|
|
|
|
PartnerCustomer.create(partner_id: partner_id,customer_id: customer.id )
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
render :json => {status: 1, message: "创建成功!"}
|
|
|
|
@ -1262,17 +1270,20 @@ end
|
|
|
|
|
|
|
|
|
|
def delete_customers
|
|
|
|
|
if params[:customer]
|
|
|
|
|
customer = Customer.where(id: params[:customer]).first
|
|
|
|
|
@current_partner = customer.partner
|
|
|
|
|
customer.school.update_attributes(:customer_id => nil)
|
|
|
|
|
customer = Customer.find(params[:customer])
|
|
|
|
|
@current_partner = Partner.find(params[:partner_id])
|
|
|
|
|
customer.destroy
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# 添加合作伙伴弹框数据
|
|
|
|
|
def all_partners
|
|
|
|
|
@search = params[:search]
|
|
|
|
|
@province = params[:province]
|
|
|
|
|
@schools = School.where("partner_id IS NULL")
|
|
|
|
|
# 已经选过的合作伙伴不能再再列表中显示
|
|
|
|
|
used_school_ids = Partner.pluck(:school_id)
|
|
|
|
|
used_school_ids = used_school_ids.blank? ? -1 : used_school_ids.join(",")
|
|
|
|
|
@schools = School.where("id not in (#{used_school_ids})")
|
|
|
|
|
|
|
|
|
|
if params[:search]
|
|
|
|
|
@schools = @schools.where("name like ?", "%#{@search}%")
|
|
|
|
@ -1296,26 +1307,20 @@ end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def add_partner
|
|
|
|
|
school_ids = params[:school_ids]
|
|
|
|
|
if school_ids.length > 0
|
|
|
|
|
school_ids.each do |s|
|
|
|
|
|
school = School.where("id = ?",s).first
|
|
|
|
|
if school.present? && school.partner_id.nil?
|
|
|
|
|
partner = Partner.new(name: school.name)
|
|
|
|
|
old_partner = Partner.where(:school_id => s)
|
|
|
|
|
if old_partner.blank?
|
|
|
|
|
partner = Partner.new(school_id: s)
|
|
|
|
|
partner.save
|
|
|
|
|
school.update_attributes(:partner_id => partner.id)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
render :json => {status: 1, message: "创建成功!"}
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 删除部门管理员
|
|
|
|
|
def delete_depart_member
|
|
|
|
|
DepartmentMember.where(:department_id => params[:depart], :user_id => params[:user_id]).destroy_all
|
|
|
|
|