Merge remote-tracking branch 'origin/dev_aliyun' into dev_aliyun

video_log
杨树明 5 years ago
commit fa329c5daa

@ -0,0 +1,80 @@
class Admins::WeappBannersController < Admins::BaseController
before_action :convert_file!, only: [:create]
def index
end
def create
position = WeappSettings::Carousel.count + 1
ActiveRecord::Base.transaction do
carousel = WeappSettings::Carousel.create!(create_params.merge(position: position))
file_path = Util::FileManage.source_disk_filename(carousel)
File.delete(file_path) if File.exist?(file_path) # 删除之前的文件
Util.write_file(@file, file_path)
end
flash[:success] = '保存成功'
redirect_to admins_weapp_carousels_path
end
def update
current_carousel.update!(update_params)
render_ok
end
def destroy
ActiveRecord::Base.transaction do
current_carousel.destroy!
# 前移
WeappSettings::Carousel.where('position > ?', current_carousel.position)
.update_all('position = position - 1')
file_path = Util::FileManage.source_disk_filename(current_carousel)
File.delete(file_path) if File.exist?(file_path)
end
render_delete_success
end
def drag
move = WeappSettings::Carousel.find_by(id: params[:move_id])
after = WeappSettings::Carousel.find_by(id: params[:after_id])
Admins::DragWeappCarouselService.call(move, after)
render_ok
rescue ApplicationService::Error => e
render_error(e.message)
end
private
def current_carousel
@_current_carousel ||= WeappSettings::Carousel.find(params[:id])
end
def create_params
params.require(:weapp_settings_carousel).permit(:link)
end
def update_params
params.permit(:link, :online)
end
def convert_file!
max_size = 10 * 1024 * 1024 # 10M
file = params.dig('weapp_settings_carousel', 'image')
if file.class == ActionDispatch::Http::UploadedFile
@file = file
render_error('请上传文件') if @file.size.zero?
render_error('文件大小超过限制') if @file.size > max_size
else
file = file.to_s.strip
return render_error('请上传正确的图片') if file.blank?
@file = Util.convert_base64_image(file, max_size: max_size)
end
rescue Base64ImageConverter::Error => ex
render_error(ex.message)
end
end

@ -14,7 +14,9 @@ class CreateStudentWorkJob < ApplicationJob
student_ids = course.students.pluck(:user_id)
student_ids.each do |user_id|
worker.add same_attrs.merge(user_id: user_id)
unless StudentWork.where(user_id: user_id, homework_common_id: homework.id).exists?
worker.add same_attrs.merge(user_id: user_id)
end
end
end
end

@ -125,6 +125,7 @@
<%= sidebar_item_group('#weapp-setting-submenu', '小程序设置', icon: 'id-badge') do %>
<li><%= sidebar_item(admins_weapp_carousels_path, '轮播图', icon: 'image', controller: 'admins-weapp_carousels') %></li>
<li><%= sidebar_item(admins_weapp_adverts_path, '广告栏', icon: 'paper-plane', controller: 'admins-weapp_adverts') %></li>
<li><%= sidebar_item(admins_weapp_banners_path, 'banner', icon: 'image', controller: 'admins-weapp_banners') %></li>
<% end %>
</li>

@ -0,0 +1,7 @@
<% define_admin_breadcrumbs do %>
<% add_admin_breadcrumb('banner设置') %>
<% end %>
<div class="box weapp-banner-setting-container">
</div>

@ -1331,6 +1331,8 @@ Rails.application.routes.draw do
resources :weapp_adverts, only: [:index, :create, :update, :destroy] do
post :drag, on: :collection
end
resources :weapp_banners, only: [:index, :create, :update, :destroy]
resources :subject_settings, only: [:index, :update] do
post :update_mobile_show, on: :collection

Loading…
Cancel
Save