From da368ae9087a005b469330dcf53f3a626c1e92a9 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Mon, 10 Feb 2020 19:04:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E8=AF=BE=E5=A0=82=E6=97=B6?= =?UTF-8?q?=E5=B0=86=E8=AF=BE=E5=A0=82=E7=9B=B8=E5=85=B3=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E7=BD=AE=E4=B8=BA=E5=88=A0=E9=99=A4=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 1 + app/controllers/tidings_controller.rb | 4 ++-- app/models/tiding.rb | 2 ++ db/migrate/20200210105238_add_delete_to_tiding.rb | 5 +++++ db/migrate/20200210105323_update_tiding_delete_status.rb | 5 +++++ 5 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20200210105238_add_delete_to_tiding.rb create mode 100644 db/migrate/20200210105323_update_tiding_delete_status.rb diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index d819b1039..bd96fd30c 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -386,6 +386,7 @@ class CoursesController < ApplicationController def destroy if @course.is_delete == 0 @course.delete! + Tiding.where(belong_container: @course).update_all(delete: 1) Tiding.create!(user_id: current_user.id, trigger_user_id: current_user.id, container_id: @course.id, container_type: 'DeleteCourse', tiding_type: 'System', belong_container: @course, extra: @course.name) normal_status(0, "成功") diff --git a/app/controllers/tidings_controller.rb b/app/controllers/tidings_controller.rb index 9305046b0..91d6c095d 100644 --- a/app/controllers/tidings_controller.rb +++ b/app/controllers/tidings_controller.rb @@ -5,7 +5,7 @@ class TidingsController < ApplicationController after_action :update_onclick_time!, only: [:index] def index - tidings = current_user.tidings + tidings = current_user.tidings.visible @onclick_time = current_user.click_time tiding_types = @@ -21,7 +21,7 @@ class TidingsController < ApplicationController tidings = tidings.where(container_type: 'JoinCourse', status: 0) if params[:type] == 'course_apply' # @course_apply_count = tidings.where("created_at > '#{@onclick_time}'").where(container_type: 'JoinCourse', status: 0).count - @course_apply_count = tidings.where("created_at > '#{@onclick_time}'").where(container_type: 'JoinCourse', status: 0).count + @course_apply_count = tidings.where(container_type: 'JoinCourse', status: 0).count tidings = tidings.where(container_type: 'ProjectPackage') if params[:type] == 'project_package' diff --git a/app/models/tiding.rb b/app/models/tiding.rb index 02692085a..1b84f41bd 100644 --- a/app/models/tiding.rb +++ b/app/models/tiding.rb @@ -7,6 +7,8 @@ class Tiding < ApplicationRecord has_many :attachments, as: :container + scope :visible, -> { where.not(delete: 0) } + def identifier value = nil diff --git a/db/migrate/20200210105238_add_delete_to_tiding.rb b/db/migrate/20200210105238_add_delete_to_tiding.rb new file mode 100644 index 000000000..6f0a09958 --- /dev/null +++ b/db/migrate/20200210105238_add_delete_to_tiding.rb @@ -0,0 +1,5 @@ +class AddDeleteToTiding < ActiveRecord::Migration[5.2] + def change + add_column :tidings, :delete, :boolean, default: 0 + end +end diff --git a/db/migrate/20200210105323_update_tiding_delete_status.rb b/db/migrate/20200210105323_update_tiding_delete_status.rb new file mode 100644 index 000000000..7267a8d4f --- /dev/null +++ b/db/migrate/20200210105323_update_tiding_delete_status.rb @@ -0,0 +1,5 @@ +class UpdateTidingDeleteStatus < ActiveRecord::Migration[5.2] + def change + Tiding.where.not(container_type: 'DeleteCourse').where(belong_container_type: "Course", belong_container_id: Course.where(is_delete: 1).pluck(:id)).update_all(delete: 1) + end +end