40 lines
883 B
Ruby
40 lines
883 B
Ruby
class JamRuby::AffiliateTrafficTotal < ActiveRecord::Base
|
|
|
|
belongs_to :affiliate_partner, class_name: 'JamRuby::AffiliatePartner', inverse_of: :traffic_totals
|
|
|
|
|
|
def self.index(user, options)
|
|
unless user.affiliate_partner
|
|
return [[], nil]
|
|
end
|
|
|
|
page = options[:page].to_i
|
|
per_page = options[:per_page].to_i
|
|
|
|
if page == 0
|
|
page = 1
|
|
end
|
|
|
|
if per_page == 0
|
|
per_page = 50
|
|
end
|
|
|
|
start = (page -1 ) * per_page
|
|
limit = per_page
|
|
|
|
query = AffiliateTrafficTotal
|
|
.paginate(page: page, per_page: per_page)
|
|
.where(affiliate_partner_id: user.affiliate_partner.id)
|
|
.where('visits != 0 OR signups != 0')
|
|
.order('day DESC')
|
|
|
|
if query.length == 0
|
|
[query, nil]
|
|
elsif query.length < limit
|
|
[query, nil]
|
|
else
|
|
[query, start + limit]
|
|
end
|
|
end
|
|
end
|