Class: EducodeSales::ShixunDectectsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/educode_sales/shixun_dectects_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#authenticate_admin, #authenticate_request, #current_user, #filter, #is_commissioner_above?, #paginate, #render_failure, #render_success, #subject_members, #subject_staffs, #subject_url

Methods included from ApplicationHelper

#add_businesses_score, #base_url, #collection_amount_score, #completion_rate, #current?, #disk_filename, #get_businesses_chart, #handled_data, #handled_time_data, #handled_time_data_accurate, #relative_path, #signed_amount_score, #storage_path, #url_to_avatar, #visits_score

Instance Method Details

#createObject



164
165
# File 'app/controllers/educode_sales/shixun_dectects_controller.rb', line 164

def create
end

#editObject

审核拒绝通过



150
151
152
153
# File 'app/controllers/educode_sales/shixun_dectects_controller.rb', line 150

def edit
  authorize! :checkout, BusinessDeliverSubject
  render layout: false
end

#examineObject

通过审核



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'app/controllers/educode_sales/shixun_dectects_controller.rb', line 102

def examine
  authorize! :checkout, BusinessDeliverSubject
  ActiveRecord::Base.transaction do
    if params[:id].present? && params[:type].present?
      business_subject_shixun = BusinessSubjectShixun.find(params[:id])
      if business_subject_shixun.present? && business_subject_shixun.last_dectect.present?

        shixun_dectect = business_subject_shixun.last_dectect
                                                .update(reviewed_id: current_user.id,
                                                 date: Time.now,
                                                 content: params[:content].gsub(/\r\n?/, "\n").strip,
                                                 business_subject_shixun_id: params[:id],
                                                 dectect_type: params[:type].to_i)
        if params[:type].to_i == 2
          business_subject_shixun.update( shixun_status: 5)
        elsif params[:type].to_i == 1
          # 审核通过
          business_subject_shixun.update( shixun_status: 9)
        end
        arrs = []
        user_list = business_subject_shixun.all_staff.map{ |item| item.id}

        user_list.each do |item|
          attr = {
            user_id: item,
            trigger_user_id: 0,
            container_id: business_subject_shixun.shixun_dectect_id.to_i,
            container_type: 'EducodeSales::ShixunDectect',
            tiding_type: "Project",
            belong_container_type: "User",
            belong_container_id: item,
            created_at: Time.now,
            updated_at: Time.now
          }
          arrs << attr
        end
        Tiding.create!(arrs)

      end
      render_success
    else
      render_failure("操作失败")
    end
  end
end

#indexObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'app/controllers/educode_sales/shixun_dectects_controller.rb', line 7

def index
  authorize! :checkout, BusinessDeliverSubject
  respond_to do |format|
    format.html do
    end
    format.json do
      # 默认显示为待审核的
      index = 1
      if params[:q].present? && params[:q][:index].present?
        index = params[:q][:index].to_i
      end
      @shixun_dectects = BusinessSubjectShixun.left_joins(:shixun)
                                              .left_joins(:school)
                                              .joins(last_dectect: [reviewed_staff: :user])

      if params[:q].present? && params[:q][:category].present? && params[:q][:category].to_i != 0
        @shixun_dectects = @shixun_dectects.where(category: params[:q][:category])
      end
      if params[:q].present? && params[:q][:shixun_name].present?
        @shixun_dectects = @shixun_dectects.where("shixuns.name like '%#{params[:q][:shixun_name]}%'")
      end

      case index
      when 1 # 显示待审核的
        @shixun_dectects = @shixun_dectects.where("dectect_type = 0")

      when 2 # 显示已审核的
        str = 'dectect_type = 1 or dectect_type = 2'
        if params[:q].present? && params[:q][:dectect_type].present?
          if params[:q][:dectect_type].to_i == 1
            str = "dectect_type = 1"
          elsif params[:q][:dectect_type].to_i == 2
            str = "dectect_type = 2"
          end
        end
        @shixun_dectects = @shixun_dectects.where(str)
      else
        render_failure("操作失败,index只能为1,2")
      end
      times = {}
      BusinessSubjectShixun.includes(business_subject:[ business_deliver_subject: [:manages, business: [:school, last_follow_up: :assign_follow_ups]] ]).find_each do |d|
        b_d_s = d.business_subject
        if b_d_s.blank? || b_d_s.business.blank?
          times.merge!({"#{d.id}": d.deliver_date })
        elsif b_d_s.business.present?
          times.merge!({ "#{d.id}": b_d_s.business.last_follow_up.reception_at })
        end
      end
      @times = times.stringify_keys
      @url
      @shixun_dectects = @shixun_dectects.select("educode_sales_business_subject_shixuns.*,
                                          schools.name as school_name,
                                          shixuns.identifier,
                                          educode_sales_business_subject_shixuns.name as shixun_name,
                                          educode_sales_business_subject_shixuns.id as shixuns_id,
                                          CONCAT(users.lastname, users.firstname) as real_name,
                                          educode_sales_shixun_dectects.dectect_type,
                                          educode_sales_shixun_dectects.content")
                                         .page(params[:page])
                                         .per(params[:limit])
    end
  end

end

#markdownObject



167
168
169
170
# File 'app/controllers/educode_sales/shixun_dectects_controller.rb', line 167

def markdown
  authorize! :checkout, BusinessDeliverSubject
  render layout: false
end

#newObject



159
160
161
162
# File 'app/controllers/educode_sales/shixun_dectects_controller.rb', line 159

def new
  authorize! :checkout, BusinessDeliverSubject
  render layout: false
end

#submitObject

审核提交



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'app/controllers/educode_sales/shixun_dectects_controller.rb', line 73

def submit
  authorize! :checkout, BusinessDeliverSubject
  respond_to do |format|
    format.json do
      ActiveRecord::Base.transaction do
        @shixuns = ShixunDectect.order(created_at: :desc).find_by(business_subject_shixun_id: params[:id])
        if @shixuns.blank?
          @shixuns = ShixunDectect.create!(business_subject_shixun_id: params[:id],
                                           reviewed_id: current_user.id,
                                           dectect_type: 0)
          BusinessSubjectShixun.find(params[:id]).update(shixun_dectect_id: @shixuns.id,
                                                         shixun_status:4)
          render_success
        elsif @shixuns.present? && @shixuns.dectect_type == 'agreed'
          @shixuns = ShixunDectect.create!(business_subject_shixun_id: params[:id],
                                           reviewed_id: current_user.id,
                                           dectect_type: 0)
          BusinessSubjectShixun.find(params[:id]).update(shixun_dectect_id: @shixuns.id,
                                                         shixun_status:4)
          render_success
        else
          render_failure("已经提交过了")
        end
      end
    end
  end
end

#updateObject



155
156
157
# File 'app/controllers/educode_sales/shixun_dectects_controller.rb', line 155

def update
  authorize! :checkout, BusinessDeliverSubject
end