fix error

This commit is contained in:
chiu 2020-08-28 16:36:24 +08:00
parent a6282477ae
commit 0cfb699647
2 changed files with 34 additions and 1 deletions

View File

@ -0,0 +1,33 @@
module Admin::EpaperHelper
extend self
def get_all_categories
app = ModuleApp.where(key: 'e_paper').first
asc_flag = app.asc rescue true
app.categories.enabled.sort_by do |category|
tmp = category.sort_number.to_i rescue 0
asc_flag ? tmp : -tmp
end
end
def get_paper_data(paper_criteria)
papers = paper_criteria.epaper_topics.group_by(&:category)
papers_data = []
papers_sorted = get_all_categories.map do |v|
tmp = papers.select{|cat,topics| (cat.id==v.id rescue false)}
if tmp.count==0
tmp = nil
end
tmp
end.compact
papers_sorted.each do |paper|
paper.each do |category, topics|
topics_data = Array(topics).compact
papers_data << {
"category_title" => (category.title rescue nil),
"category" => category,
"topics" => topics_data
}
end
end
papers_data
end
end

View File

@ -10,7 +10,7 @@ namespace :epaper do
emails = [] emails = []
mail_limit = 25 mail_limit = 25
subscribers.each do |subscriber| subscribers.each do |subscriber|
emails << subscriber.email if paper.language_to_send.include? subscriber.language emails << subscriber.email if paper.language_to_send.include?(subscriber.language) && !subscriber.email.blank?
subscriber.last_paper_sent = paper.id.to_s subscriber.last_paper_sent = paper.id.to_s
subscriber.save subscriber.save
if emails.count == mail_limit if emails.count == mail_limit