From 1e6b39ed1b7ab95a96d678bea9604f6f001d00c5 Mon Sep 17 00:00:00 2001 From: qinmingyuan Date: Thu, 7 Mar 2024 20:25:40 +0800 Subject: [PATCH] growth aim entity --- app/models/growth/model/aim.rb | 22 +++++++--------------- app/models/growth/model/aim_entity.rb | 7 ++++++- app/models/growth/model/aim_user.rb | 2 +- lib/rails_growth.rb | 2 -- 4 files changed, 14 insertions(+), 19 deletions(-) diff --git a/app/models/growth/model/aim.rb b/app/models/growth/model/aim.rb index 8d524d5..d261024 100644 --- a/app/models/growth/model/aim.rb +++ b/app/models/growth/model/aim.rb @@ -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 diff --git a/app/models/growth/model/aim_entity.rb b/app/models/growth/model/aim_entity.rb index 8d12542..68e1f8b 100644 --- a/app/models/growth/model/aim_entity.rb +++ b/app/models/growth/model/aim_entity.rb @@ -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 @@ -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 diff --git a/app/models/growth/model/aim_user.rb b/app/models/growth/model/aim_user.rb index be42903..6091edf 100644 --- a/app/models/growth/model/aim_user.rb +++ b/app/models/growth/model/aim_user.rb @@ -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 diff --git a/lib/rails_growth.rb b/lib/rails_growth.rb index 3037d53..5e19880 100644 --- a/lib/rails_growth.rb +++ b/lib/rails_growth.rb @@ -1,4 +1,2 @@ require 'rails_growth/engine' require 'rails_growth/config' - -require 'rails_growth/serial_number_helper'