diff --git a/app/models/weapp_settings/advert.rb b/app/models/weapp_settings/advert.rb index 564e85565..993b1fd85 100644 --- a/app/models/weapp_settings/advert.rb +++ b/app/models/weapp_settings/advert.rb @@ -1,2 +1,3 @@ class WeappSettings::Advert < WeappSetting + default_scope { order(position: :asc) } end \ No newline at end of file diff --git a/app/services/admins/drag_weapp_advert_service.rb b/app/services/admins/drag_weapp_advert_service.rb index b041c9d18..8bfb7c317 100644 --- a/app/services/admins/drag_weapp_advert_service.rb +++ b/app/services/admins/drag_weapp_advert_service.rb @@ -9,22 +9,22 @@ class Admins::DragWeappAdvertService < ApplicationService def call return if move.position + 1 == after&.position # 未移动 - carousels = WeappSettings::Advert.all + adverts = WeappSettings::Advert.all ActiveRecord::Base.transaction do if after.blank? || move.id == after.id # 移动至末尾 - total = carousels.count + total = adverts.count - carousels.where('position > ?', move.position).update_all('position = position - 1') + adverts.where('position > ?', move.position).update_all('position = position - 1') move.update!(position: total) return end if move.position > after.position # 前移 - carousels.where('position >= ? AND position < ?', after.position, move.position).update_all('position = position + 1') + adverts.where('position >= ? AND position < ?', after.position, move.position).update_all('position = position + 1') move.update!(position: after.position) else # 后移 - carousels.where('position > ? AND position < ?', move.position, after.position).update_all('position = position - 1') + adverts.where('position > ? AND position < ?', move.position, after.position).update_all('position = position - 1') move.update!(position: after.position - 1) end end