You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
2.3 KiB
72 lines
2.3 KiB
class Admins::DepartmentAppliesController < Admins::BaseController
|
|
|
|
before_action :get_apply,only:[:agree,:edit,:update,:destroy]
|
|
def index
|
|
params[:status] ||= 0
|
|
params[:sort_by] = params[:sort_by].presence || 'created_at'
|
|
params[:sort_direction] = params[:sort_direction].presence || 'desc'
|
|
applies = Admins::DepartmentApplyQuery.call(params)
|
|
@depart_applies = paginate applies.preload(:school,user: :user_extension)
|
|
end
|
|
|
|
def agree
|
|
ActiveRecord::Base.transaction do
|
|
@depart_apply.update_attribute("status",1)
|
|
@depart_apply&.applied_messages&.update_all(status:1)
|
|
@depart_apply&.department&.update_attribute("is_auth",1)
|
|
@depart_apply&.user&.user_extension&.update_attribute("department_id",@depart_apply.department_id)
|
|
render_success_js
|
|
end
|
|
end
|
|
|
|
def update
|
|
depart_name = params[:name]
|
|
ActiveRecord::Base.transaction do
|
|
@depart_apply.update_attribute("name",depart_name)
|
|
@depart_apply&.department&.update_attribute("name",depart_name)
|
|
extra = depart_name + "(#{@depart_apply&.department&.school&.try(:name)})"
|
|
tiding_params = {
|
|
user_id: @depart_apply.user_id,
|
|
trigger_user_id: 0,
|
|
container_id: @depart_apply.id,
|
|
container_type: 'ApplyAddDepartment',
|
|
belong_container_id: @depart_apply.department.school_id,
|
|
belong_container_type: "School",
|
|
tiding_type: "System",
|
|
status: 3,
|
|
extra: extra
|
|
}
|
|
Tiding.create(tiding_params)
|
|
render_success_js
|
|
end
|
|
end
|
|
|
|
def destroy
|
|
ActiveRecord::Base.transaction do
|
|
@depart_apply.update_attribute("status",3)
|
|
@depart_apply&.applied_messages&.update_all(status:3)
|
|
@depart_apply&.department&.destroy
|
|
@depart_apply&.user&.user_extension&.update_attribute("department_id", nil)
|
|
tiding_params = {
|
|
user_id: @depart_apply.user_id,
|
|
trigger_user_id: 0,
|
|
container_id: @depart_apply.id,
|
|
container_type: 'ApplyAddDepartment',
|
|
belong_container_id: @depart_apply.department.school_id,
|
|
belong_container_type: "School",
|
|
tiding_type: "System",
|
|
status: 2,
|
|
extra: params[:reason]
|
|
}
|
|
Tiding.create(tiding_params)
|
|
render_success_js
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def get_apply
|
|
@depart_apply = ApplyAddDepartment.find_by(id:params[:id])
|
|
end
|
|
end
|