Sha256: ea846d459d562f56ea713b23ccf965c86ac73d0e41d7504a7c0182cc27f56550

Contents?: true

Size: 1.55 KB

Versions: 3

Compression:

Stored size: 1.55 KB

Contents

x = EducodeSales::Common.find_by(extras: EducodeSales::Common::XTYPE)&.id
o = EducodeSales::Common.find_by(extras: EducodeSales::Common::OTYPE)&.id
json.data do
  json.array! @customers do |d|
    business_ids = EducodeSales::Business.where(school_id: d.id).ids
    follow_ups = EducodeSales::FollowUp.where(business_id: business_ids)
    customer_follows = EducodeSales::CustomerFollow.where(school_id: d.id)
    a_last_follow_time = follow_ups.last&.created_at&.to_s
    b_last_follow_time = customer_follows.last&.created_at&.to_s
    if a_last_follow_time.present? && b_last_follow_time.present?
      json.last_follow_time a_last_follow_time < b_last_follow_time ? b_last_follow_time : a_last_follow_time
    else
      json.last_follow_time a_last_follow_time || b_last_follow_time
    end
    json.id d.id
    json.name d.name
    json.area d.province
    json.property d.school_tags.where(for_missions: true).pluck(:name).uniq.join("、")
    json.department d.departments.size
    json.business EducodeSales::Business.joins(:last_follow_up).where("educode_sales_follow_ups.clazz_id != ?", x).where("educode_sales_businesses.school_id = ?", d.id).size
    json.o_business EducodeSales::Business.joins(:last_follow_up).where("educode_sales_follow_ups.clazz_id = ?", o).where("educode_sales_businesses.school_id = ?", d.id).size
    json.follow follow_ups.size + customer_follows.size
    json.staff EducodeSales::CustomerExtension.find_by(school_id: d.id)&.customer_staff&.user&.real_name
  end
end

json.code 0
if params[:page].present?
  json.count @customers.total_count
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
educode_sales-1.10.74 app/views/educode_sales/customers/index.json.jbuilder
educode_sales-1.10.73 app/views/educode_sales/customers/index.json.jbuilder
educode_sales-1.10.72 app/views/educode_sales/customers/index.json.jbuilder