Skip to content

Commit

Permalink
growth aim entity
Browse files Browse the repository at this point in the history
  • Loading branch information
qinmingyuan committed Mar 7, 2024
1 parent ce90319 commit 1e6b39e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 19 deletions.
22 changes: 7 additions & 15 deletions app/models/growth/model/aim.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,31 +36,23 @@ def aim_user(user_id)
self.aim_users.find { |i| i.user_id == user_id }
end

def serial_number(timestamp)
time = timestamp.to_datetime
year = time.year
month = time.month
day = time.day
cweek = time.cweek
seconds = time.seconds_since_midnight

def serial_number(now = Time.current)
case repeat_type
when 'forever'
[year, month, cweek, day, seconds, UidHelper.rand_string].join('-')
now.strftime('%Y%j%H%M%S%L')
when 'daily'
[year, month, cweek, day].join('-')
now.strftime('%Y%j')
when 'weekly'
[year, month, cweek].join('-')
now.strftime('%Y%U')
when 'monthly'
[year, month].join('-')
now.strftime('%Y%m')
when 'yearly'
year.to_s
now.strftime('%Y')
else
''
now.strftime('%Y%j%H%M%S%L')
end
end


class_methods do

def reward_codes
Expand Down
7 changes: 6 additions & 1 deletion app/models/growth/model/aim_entity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ module Model::AimEntity
included do
attribute :present_point, :integer
attribute :state, :string
attribute :serial_number, :string
attribute :text_year, :string
attribute :text_month, :string
attribute :text_week, :string
Expand Down Expand Up @@ -38,6 +37,12 @@ module Model::AimEntity
}
end

def filter_hash
{
text_year: text_year
}
end

def init_aim_user
self.aim_user || create_aim_user if self.user_id
if aim.reward_point == 0
Expand Down
2 changes: 1 addition & 1 deletion app/models/growth/model/aim_user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Model::AimUser
extend ActiveSupport::Concern

included do
attribute :serial_number, :string
attribute :text_year, :string
attribute :state, :string, default: 'task_doing'
attribute :reward_amount, :integer, default: 0
attribute :aim_entities_count, :integer, default: 0
Expand Down
2 changes: 0 additions & 2 deletions lib/rails_growth.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
require 'rails_growth/engine'
require 'rails_growth/config'

require 'rails_growth/serial_number_helper'

0 comments on commit 1e6b39e

Please sign in to comment.