follow_up_ids = EducodeSales::AssignFollowUp.where(staff_id: @current_admin.id).pluck(:follow_up_id) follow_count = 0 json.data do json.array! @businesses do |d| json.id d.id json.number d.number 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_counts'] || 0 json.follow_ups_count follow_ups_count follow_count += follow_ups_count json.follow_up_id d.last_follow_up_id json.clazz d.clazz&.name || "" json.extras_clazz d.clazz&.extras json.clazz_changed d.last_follow_up&.clazz_changed || false 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.advise d.last_follow_up&.advise.to_s json.o_business_deployment EducodeSales::FollowUp::BUSINESS_DEPLOYMENT[1..-1].to_h.invert[d.last_follow_up&.o_business_deployment] json.service_end_time d.last_follow_up&.service_start_time.to_s + "-" + d.last_follow_up&.service_end_time.to_s json.created_at d.created_at.to_s json.no_followup_days (d['latest_time'] ? DateTime.parse(Time.now.strftime("%Y-%m-%d")) - DateTime.parse(d['latest_time'].strftime("%Y-%m-%d")) : DateTime.parse(Time.now.strftime("%Y-%m-%d")) - DateTime.parse(d.created_at.strftime("%Y-%m-%d"))).to_i json.staff_manages d.last_follow_up&.assign_follow_ups.present? ? (d.last_follow_up.assign_follow_ups.map{ |d| d.staff.user.real_name}.join("、")) : d.staff&.user&.real_name json.divide_rate d.divide_rate json.divide_money d.divide_amount.to_f.round(2) json.budget_amount d.budget_amount.to_f.round(2) #d.follow_ups.where(stage_id: @budget_stage_ids).order("created_at desc").first&.total_amount&.round(2) || 0 json.area d.department&.school&.province json.majors d.department&.department_majors&.pluck(:name).present? ? d.department&.department_majors&.pluck(:name).join(",") : "" json.keys_person_count d.last_follow_up.present? ? EducodeSales::KeyPerson.where("follow_up_id = #{d.last_follow_up.id}").count : 0 json.rival d.last_follow_up&.rival || '' # school_property = d.department.school.school_property # property = [] # if school_property.present? # property << '本科地方院校' if school_property.regular_college || school_property.project_985 || school_property.project_211 # property << '高职' if school_property.junior_college || school_property.secondary_school # property << '本科军校' if school_property.military_school # property << '企业' if school_property.enterprise # end if d.department&.school json.property d.department.school.school_tags.where(for_missions: true).pluck(:name).join("、") else json.property '' end json.delete_reason d.delete_reason json.state_id d.state_id # json.property d.school.school_property.school_tags.where(for_missions: true).pluck(:name).join("、")#property.join("、") json.sale_way d.last_follow_up&.place&.name.present? ? '渠道' : '直销' json.year d.last_follow_up&.year.to_s json.total_amount d.last_follow_up&.total_amount.to_f.round(2) 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_f.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 : d.staff&.user&.real_name if ["会议活动", "渠道代理", "客户"].include?(d.source_way) json.source "#{d.source_way} #{d.sourcable&.name}" else json.source "#{d.source_way} #{d.sourcable_type}" end 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.self_flag (d.staff_id == @current_admin.id) || (d.last_follow_up_id.in? follow_up_ids) json.followed d.users.pluck(:user_id).include?(@current_admin.user.id) ? 1 : 0 # d.users.where(user_id:@current_admin.user.id).first ? 1 : 0 json.p_deploy_time d.p_deploy_time end end json.totalRow do json.follow_ups_count follow_count.to_i.to_s end json.code 0 json.count @businesses.total_count json.msg 'succcess'