module EducodeSales class BusinessSubjectShixun < ApplicationRecord belongs_to :business_subject, optional: true belongs_to :school, optional: true belongs_to :shixun, optional: true has_many :staffs, as: :container, dependent: :destroy, class_name: "EducodeSales::BusinessSubjectStaff" belongs_to :last_dectect, foreign_key: :shixun_dectect_id, class_name: "EducodeSales::ShixunDectect", optional: true module CATEGORY_TYPE TRAINING = 1 # 管培 WORKER = 2 # 全职 PLURALIST = 3 # 兼职 end # 项目状态: 待建设(constructed) 已签协议(signed) 建设中(construction) 审核中(review),返修中(repair) 已内部公开(public), 已公开发布(published) 已经付费(paid) # enum status: { constructed: 1, signed: 2, construction: 3, review: 4, repair: 5, public: 6, published: 7,paid: 8} def shixun_manages staffs.joins(staff: :user).where(category:BusinessSubjectStaff::CATEGORY_TYPES::SHIXUN_MANAGE).pluck("CONCAT(users.lastname, users.firstname) ").join(",") end def shixun_producer staffs.joins(staff: :user).where(category:BusinessSubjectStaff::CATEGORY_TYPES::SHIXUN_PRODUCER).pluck("CONCAT(users.lastname, users.firstname) ").join(",") end def shixun_staff return business_subject.manges unless business_subject.nil? staffs.joins(staff: :user).where(category:BusinessSubjectStaff::CATEGORY_TYPES::SHIXUN_STAFF).pluck("CONCAT(users.lastname, users.firstname) ").join(",") end # 查询审核历史和审核人 def audit_history ShixunDectect.joins("join educode_sales_staffs on educode_sales_staffs.id = educode_sales_shixun_dectects.reviewed_id join users on users.id = educode_sales_staffs.user_id") .where(business_subject_shixun_id:id) .where("dectect_type != 0") .select("educode_sales_shixun_dectects.*, CONCAT(users.lastname, users.firstname) as examine_name") .all end # def school_name # business_subject ? business_subject.school_name : school.name # end end end