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