From a9bd3af9813d2a43598f5b0ad340c7b49d758d46 Mon Sep 17 00:00:00 2001 From: qinmingyuan Date: Thu, 7 Mar 2024 22:30:06 +0800 Subject: [PATCH] the growth logic --- app/controllers/growth/controller/application.rb | 2 +- app/models/growth/inner/text.rb | 6 +++++- app/models/growth/model/aim.rb | 2 +- app/models/growth/model/aim_entity.rb | 2 +- app/models/growth/model/aim_user.rb | 2 +- 5 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app/controllers/growth/controller/application.rb b/app/controllers/growth/controller/application.rb index a3f64ba..5642e9f 100755 --- a/app/controllers/growth/controller/application.rb +++ b/app/controllers/growth/controller/application.rb @@ -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 diff --git a/app/models/growth/inner/text.rb b/app/models/growth/inner/text.rb index b4d196c..77f39c6 100644 --- a/app/models/growth/inner/text.rb +++ b/app/models/growth/inner/text.rb @@ -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 @@ -22,5 +22,9 @@ def filter_hash } end + def origin_date + text_date.to_date + end + end end diff --git a/app/models/growth/model/aim.rb b/app/models/growth/model/aim.rb index f718b25..209c223 100644 --- a/app/models/growth/model/aim.rb +++ b/app/models/growth/model/aim.rb @@ -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' diff --git a/app/models/growth/model/aim_entity.rb b/app/models/growth/model/aim_entity.rb index b217a06..5ed8e44 100644 --- a/app/models/growth/model/aim_entity.rb +++ b/app/models/growth/model/aim_entity.rb @@ -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 diff --git a/app/models/growth/model/aim_user.rb b/app/models/growth/model/aim_user.rb index 20327a1..eb64564 100644 --- a/app/models/growth/model/aim_user.rb +++ b/app/models/growth/model/aim_user.rb @@ -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