Skip to content

Commit

Permalink
the growth logic
Browse files Browse the repository at this point in the history
  • Loading branch information
qinmingyuan committed Mar 7, 2024
1 parent b98a9ad commit a9bd3af
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/controllers/growth/controller/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def growth_api(code, entity = nil)
Aim.where(id: aim_ids).map do |aim|
if current_user
aim_user = current_user.aim_users.find_or_create_by(aim_id: aim.id, **aim.serial_hash)
unless aim_user.task_done? && entity
if !aim_user.task_done? && entity
aim_entity = aim_user.aim_entities.find_or_initialize_by(entity_type: entity.class, entity_id: entity.try(:id))
aim_entity.aim_logs.build(aim_id: aim.id)
aim_entity.save
Expand Down
6 changes: 5 additions & 1 deletion app/models/growth/inner/text.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Inner::Text
attribute :text_year, :string
attribute :text_month, :string
attribute :text_week, :string
attribute :text_date, :date
attribute :text_date, :string

belongs_to :user, class_name: 'Auth::User', optional: true
belongs_to :aim, optional: true
Expand All @@ -22,5 +22,9 @@ def filter_hash
}
end

def origin_date
text_date.to_date
end

end
end
2 changes: 1 addition & 1 deletion app/models/growth/model/aim.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def serial_hash(now = Time.current)
when 'forever'
now.strftime('%Y%j%H%M%S%L')
when 'daily'
{ text_day: now.strftime('%Y%j') }
{ text_date: now.strftime('%Y%j') }
when 'weekly'
{ text_week: now.strftime('%Y%U') }
when 'monthly'
Expand Down
2 changes: 1 addition & 1 deletion app/models/growth/model/aim_entity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module Model::AimEntity

has_many :aim_logs, ->(o){ where(user_id: o.user_id, entity_type: o.entity_type, entity_id: o.entity_id) }, foreign_key: :aim_id, primary_key: :aim_id

validates :user_id, presence: true, uniqueness: { scope: [:aim_id, :serial_number, :entity_type, :entity_id] }, if: -> { ip.blank? }
# validates :user_id, presence: true, uniqueness: { scope: [:aim_id, :serial_number, :entity_type, :entity_id] }, if: -> { ip.blank? }
# validates :ip, presence: true, uniqueness: { scope: [:aim_id, :entity_type, :entity_id] }, if: -> { user_id.blank? }

before_create :init_aim_user
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 @@ -15,7 +15,7 @@ module Model::AimUser
task_done: 'task_done'
}

after_commit :sync_log, if: -> { saved_change_to_reward_amount? }, on: [:create, :update]
#after_commit :sync_log, if: -> { saved_change_to_reward_amount? }, on: [:create, :update]
end

def progress
Expand Down

0 comments on commit a9bd3af

Please sign in to comment.