json.data do json.array! @businesses do |d| json.id d.id json.name d.name json.department d.department.name json.school d.department.school.name json.school_id d.department.school.id follow_ups_count = d.follow_ups.where(deleted_at: nil).size json.follow_ups_count follow_ups_count json.follow_up_id d.last_follow_up_id json.clazz d.last_follow_up&.clazz&.name || "" json.stage d.last_follow_up&.stage&.name json.invitation_at d.last_follow_up&.invitation_at.to_s json.reception_at d.last_follow_up&.reception_at.to_s json.bidded_date d.last_follow_up&.bidded_date.to_s json.signed_date d.last_follow_up&.signed_date.to_s json.total_amount d.last_follow_up&.total_amount.to_f.round(2) json.service_end_time d.last_follow_up&.service_start_time.to_s + "-" + d.last_follow_up&.service_end_time.to_s EducodeSales::FollowUp::BUSINESS_DEPLOYMENT[1..-1].each do |m| if d.last_follow_up&.o_business_deployment == m[1] json.o_business_deployment m[0] break end end json.actual_amount d.last_follow_up&.actual_amount.to_f.round(2) json.return_money d.return_money json.wait_return_money d.wait_return_money.to_i.round(2) json.return_money_days d.last_follow_up&.reception_at.present? && d.last_follow_up.money_plans.where(clazz: '实际回款').present? ? (d.last_follow_up.money_plans.where(clazz: '实际回款').order(created_at: :asc).first.date_at.to_s(:date).to_date - d.last_follow_up&.reception_at).to_i : '' json.place d.last_follow_up&.place&.name json.last_follow_person d.last_follow_up.present? ? d.last_follow_up.staff.user.real_name : EducodeSales::Staff.find(d.staff_id).user.real_name json.source d.source json.assign_follow_ups d.last_follow_up.present? ? d.last_follow_up.assign_follow_ups.pluck(:staff_id) : [] json.current_staff_id @current_admin.id json.staff_id d.staff_id json.latest_time d.last_follow_up.present? ? d.last_follow_up.created_at.to_s : '' json.year d.last_follow_up&.year.to_s end end