rails_growth 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +20 -0
  3. data/README.md +28 -0
  4. data/Rakefile +32 -0
  5. data/app/controllers/growth/admin/aim_entities_controller.rb +30 -0
  6. data/app/controllers/growth/admin/aim_logs_controller.rb +21 -0
  7. data/app/controllers/growth/admin/aim_users_controller.rb +30 -0
  8. data/app/controllers/growth/admin/aims_controller.rb +73 -0
  9. data/app/controllers/growth/admin/base_controller.rb +4 -0
  10. data/app/controllers/growth/admin/praise_incomes_controller.rb +61 -0
  11. data/app/controllers/growth/admin/reward_expenses_controller.rb +63 -0
  12. data/app/controllers/growth/admin/reward_incomes_controller.rb +59 -0
  13. data/app/controllers/growth/admin/rewards_controller.rb +65 -0
  14. data/app/controllers/growth/controller/application.rb +77 -0
  15. data/app/controllers/growth/my/aim_logs_controller.rb +45 -0
  16. data/app/controllers/growth/my/aim_users_controller.rb +25 -0
  17. data/app/controllers/growth/my/aims_controller.rb +44 -0
  18. data/app/controllers/growth/my/base_controller.rb +4 -0
  19. data/app/controllers/growth/my/gifts_controller.rb +27 -0
  20. data/app/controllers/growth/my/rewards_controller.rb +28 -0
  21. data/app/models/growth/aim.rb +5 -0
  22. data/app/models/growth/aim_code.rb +5 -0
  23. data/app/models/growth/aim_entity.rb +5 -0
  24. data/app/models/growth/aim_log.rb +5 -0
  25. data/app/models/growth/aim_user.rb +5 -0
  26. data/app/models/growth/model/aim.rb +52 -0
  27. data/app/models/growth/model/aim_code.rb +40 -0
  28. data/app/models/growth/model/aim_entity.rb +74 -0
  29. data/app/models/growth/model/aim_log.rb +79 -0
  30. data/app/models/growth/model/aim_user.rb +60 -0
  31. data/app/models/growth/model/card.rb +25 -0
  32. data/app/models/growth/model/cash.rb +17 -0
  33. data/app/models/growth/model/entity.rb +74 -0
  34. data/app/models/growth/model/praise_compute.rb +70 -0
  35. data/app/models/growth/model/praise_income.rb +82 -0
  36. data/app/models/growth/model/praise_user.rb +47 -0
  37. data/app/models/growth/model/promote.rb +30 -0
  38. data/app/models/growth/model/reward.rb +67 -0
  39. data/app/models/growth/model/reward_expense.rb +98 -0
  40. data/app/models/growth/model/reward_income.rb +35 -0
  41. data/app/models/growth/model/royalty_compute.rb +72 -0
  42. data/app/models/growth/model/user.rb +21 -0
  43. data/app/models/growth/praise_income.rb +7 -0
  44. data/app/models/growth/praise_user.rb +5 -0
  45. data/app/models/growth/reward.rb +5 -0
  46. data/app/models/growth/reward_expense.rb +5 -0
  47. data/app/models/growth/reward_income.rb +5 -0
  48. data/app/models/growth.rb +11 -0
  49. data/app/views/application/_growth_nav.html.erb +12 -0
  50. data/app/views/growth/admin/aim_entities/_filter.html.erb +10 -0
  51. data/app/views/growth/admin/aim_entities/index.html.erb +68 -0
  52. data/app/views/growth/admin/aim_entities/show.html.erb +22 -0
  53. data/app/views/growth/admin/aim_logs/_filter.html.erb +9 -0
  54. data/app/views/growth/admin/aim_logs/index.html.erb +62 -0
  55. data/app/views/growth/admin/aim_logs/show.html.erb +14 -0
  56. data/app/views/growth/admin/aim_users/_filter.html.erb +7 -0
  57. data/app/views/growth/admin/aim_users/index.html.erb +63 -0
  58. data/app/views/growth/admin/aim_users/show.html.erb +30 -0
  59. data/app/views/growth/admin/aims/_filter.html.erb +8 -0
  60. data/app/views/growth/admin/aims/_form.html.erb +14 -0
  61. data/app/views/growth/admin/aims/_item_field.html.erb +3 -0
  62. data/app/views/growth/admin/aims/_item_form.html.erb +24 -0
  63. data/app/views/growth/admin/aims/add_item.js.erb +9 -0
  64. data/app/views/growth/admin/aims/index.html.erb +54 -0
  65. data/app/views/growth/admin/aims/remove_item.js.erb +1 -0
  66. data/app/views/growth/admin/aims/show.html.erb +38 -0
  67. data/app/views/growth/admin/managers/_edit.html.erb +13 -0
  68. data/app/views/growth/admin/managers/_form.html.erb +34 -0
  69. data/app/views/growth/admin/managers/_new.html.erb +13 -0
  70. data/app/views/growth/admin/managers/_search_form.html.erb +8 -0
  71. data/app/views/growth/admin/managers/edit.js.erb +8 -0
  72. data/app/views/growth/admin/managers/index.html.erb +68 -0
  73. data/app/views/growth/admin/managers/new.js.erb +8 -0
  74. data/app/views/growth/admin/managers/show.html.erb +0 -0
  75. data/app/views/growth/admin/managers/update.js.erb +1 -0
  76. data/app/views/growth/admin/praise_incomes/_filter.html.erb +5 -0
  77. data/app/views/growth/admin/praise_incomes/_form.html.erb +3 -0
  78. data/app/views/growth/admin/praise_incomes/edit.html.erb +11 -0
  79. data/app/views/growth/admin/praise_incomes/index.html.erb +59 -0
  80. data/app/views/growth/admin/praise_incomes/new.html.erb +11 -0
  81. data/app/views/growth/admin/praise_incomes/show.html.erb +18 -0
  82. data/app/views/growth/admin/reward_expenses/_filter.html.erb +5 -0
  83. data/app/views/growth/admin/reward_expenses/_form.html.erb +7 -0
  84. data/app/views/growth/admin/reward_expenses/index.html.erb +49 -0
  85. data/app/views/growth/admin/reward_expenses/show.html.erb +26 -0
  86. data/app/views/growth/admin/reward_incomes/_filter.html.erb +10 -0
  87. data/app/views/growth/admin/reward_incomes/_form.html.erb +3 -0
  88. data/app/views/growth/admin/reward_incomes/edit.html.erb +11 -0
  89. data/app/views/growth/admin/reward_incomes/index.html.erb +49 -0
  90. data/app/views/growth/admin/reward_incomes/new.html.erb +11 -0
  91. data/app/views/growth/admin/reward_incomes/show.html.erb +18 -0
  92. data/app/views/growth/admin/rewards/_filter.html.erb +14 -0
  93. data/app/views/growth/admin/rewards/_form.html.erb +27 -0
  94. data/app/views/growth/admin/rewards/index.html.erb +84 -0
  95. data/app/views/growth/admin/rewards/show.html.erb +26 -0
  96. data/app/views/growth/my/aims/_aim.json.jbuilder +6 -0
  97. data/app/views/growth/my/aims/index.json.jbuilder +3 -0
  98. data/app/views/growth/my/aims/show.json.jbuilder +1 -0
  99. data/app/views/growth/my/gifts/_gift.json.jbuilder +1 -0
  100. data/app/views/growth/my/gifts/_praise_income.json.jbuilder +8 -0
  101. data/app/views/growth/my/gifts/give.json.jbuilder +8 -0
  102. data/app/views/growth/my/gifts/index.json.jbuilder +9 -0
  103. data/app/views/growth/my/rewards/_praise_user.json.jbuilder +2 -0
  104. data/app/views/growth/my/rewards/top.json.jbuilder +6 -0
  105. data/config/locales/en.notify.yml +7 -0
  106. data/config/locales/en.yml +29 -0
  107. data/config/locales/zh.controller.yml +24 -0
  108. data/config/locales/zh.notify.yml +7 -0
  109. data/config/locales/zh.yml +11 -0
  110. data/config/routes.rb +57 -0
  111. data/lib/rails_growth/config.rb +13 -0
  112. data/lib/rails_growth/engine.rb +19 -0
  113. data/lib/rails_growth/serial_number_helper.rb +28 -0
  114. data/lib/rails_growth.rb +4 -0
  115. metadata +170 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: dd8f1a401d31911e0d3025f2dc0b9c0c9422deecfb92dff053920f55b427b2dc
4
+ data.tar.gz: 8945707b2262c0f935dcb3e25f81d14606eb9136fd3945ecd535a6d2cf9901be
5
+ SHA512:
6
+ metadata.gz: 83ce7b201e2560ddd1424c100d72498d2add0659256d841d9a67329c4f1773944e5a9d08d7eb6d344ad8de857dddf7ecc8696dbc74600d789a11b00d66d583fa
7
+ data.tar.gz: df60ba23971a4e0cfb8dea5e34278ef28f9373c5284647982abb86706a024a03a17a2de65100eac888e81855d16e3f8ec37a8ee8f5e2c01e18b8821622efc560
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2021 Mingyuan Qin <mingyuan0715@foxmail.com>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,28 @@
1
+ # RailsGrowth
2
+
3
+ [![测试](https://github.com/work-design/rails_growth/actions/workflows/test.yml/badge.svg)](https://github.com/work-design/rails_growth/actions/workflows/test.yml)
4
+ [![Docker构建](https://github.com/work-design/rails_growth/actions/workflows/cd.yml/badge.svg)](https://github.com/work-design/rails_growth/actions/workflows/cd.yml)
5
+ [![Gem](https://github.com/work-design/rails_growth/actions/workflows/gempush.yml/badge.svg)](https://github.com/work-design/rails_growth/actions/workflows/gempush.yml)
6
+
7
+ `rails_growth` 是一个用于运营增长的系统,具有如下特性:
8
+
9
+ * 不需要埋点:除了服务端无法获知的客户端行为(如分享、跳转),只需要监听相关请求即可;
10
+ * 支持客户端埋点;
11
+ * 可以基于某个目标定义任务、奖励;
12
+ * 可以对相应请求进行统计记录,用于数据分析;
13
+
14
+ ## 赏金类型
15
+ * 现金,可提现;
16
+ * 会员卡额度,可用于消费;
17
+ * 优惠券
18
+
19
+ ## 原理
20
+
21
+ ```
22
+ aim -> aim_user -> aim_entity -> aim_log
23
+ ```
24
+
25
+ ## 依赖
26
+
27
+ ## 注意
28
+
data/Rakefile ADDED
@@ -0,0 +1,32 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'RailsGrowth'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+ load 'rails/tasks/statistics.rake'
21
+
22
+ require 'bundler/gem_tasks'
23
+
24
+ require 'rake/testtask'
25
+
26
+ Rake::TestTask.new(:test) do |t|
27
+ t.libs << 'test'
28
+ t.pattern = 'test/**/*_test.rb'
29
+ t.verbose = false
30
+ end
31
+
32
+ task default: :test
@@ -0,0 +1,30 @@
1
+ module Growth
2
+ class Admin::AimEntitiesController < Admin::BaseController
3
+ before_action :set_aim_entity, only: [:show, :destroy]
4
+ before_action :set_aim, only: [:index]
5
+
6
+ def index
7
+ q_params = {}
8
+ q_params.merge! params.permit(:user_id, :ip, :entity_type, :entity_id)
9
+
10
+ @aim_entities = @aim.aim_entities.includes(:user).default_where(q_params).order(id: :desc).page(params[:page])
11
+ end
12
+
13
+ def show
14
+ end
15
+
16
+ def destroy
17
+ @aim_entity.destroy
18
+ end
19
+
20
+ private
21
+ def set_aim_entity
22
+ @aim_entity = AimEntity.find(params[:id])
23
+ end
24
+
25
+ def set_aim
26
+ @aim = Aim.find params[:aim_id]
27
+ end
28
+
29
+ end
30
+ end
@@ -0,0 +1,21 @@
1
+ module Growth
2
+ class Admin::AimLogsController < Admin::BaseController
3
+ before_action :set_aim_log, only: [:destroy]
4
+
5
+ def index
6
+ @aim_entity = AimEntity.find(params[:aim_entity_id])
7
+
8
+ @aim_logs = @aim_entity.aim_logs.order(id: :desc).page(params[:page])
9
+ end
10
+
11
+ def destroy
12
+ @aim_log.destroy
13
+ end
14
+
15
+ private
16
+ def set_aim_log
17
+ @aim_log = AimLog.find(params[:id])
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,30 @@
1
+ module Growth
2
+ class Admin::AimUsersController < Admin::BaseController
3
+ before_action :set_aim, only: [:index]
4
+ before_action :set_aim_user, only: [:show, :destroy]
5
+
6
+ def index
7
+ q_params = {}
8
+ q_params.merge! params.permit(:ip, :user_id)
9
+
10
+ @aim_users = @aim.aim_users.includes(:user).default_where(q_params).order(id: :desc).page(params[:page])
11
+ end
12
+
13
+ def show
14
+ end
15
+
16
+ def destroy
17
+ @aim_user.destroy
18
+ end
19
+
20
+ private
21
+ def set_aim
22
+ @aim = Aim.find(params[:aim_id])
23
+ end
24
+
25
+ def set_aim_user
26
+ @aim_user = AimUser.find(params[:id])
27
+ end
28
+
29
+ end
30
+ end
@@ -0,0 +1,73 @@
1
+ module Growth
2
+ class Admin::AimsController < Admin::BaseController
3
+ before_action :set_aim, only: [:show, :edit, :update, :destroy]
4
+
5
+ def index
6
+ @aims = Aim.includes(:aim_codes).order(id: :desc).page(params[:page])
7
+ end
8
+
9
+ def new
10
+ @aim = Aim.new
11
+ @aim.aim_codes.build
12
+ end
13
+
14
+ def create
15
+ @aim = Aim.new(aim_params)
16
+
17
+ if @aim.save
18
+ redirect_to admin_aims_url, notice: 'Aim was successfully created.'
19
+ else
20
+ render :new
21
+ end
22
+ end
23
+
24
+ def show
25
+ end
26
+
27
+ def edit
28
+ if @aim.aim_codes.count == 0
29
+ @aim.aim_codes.build
30
+ end
31
+ end
32
+
33
+ def update
34
+ if @aim.update(aim_params)
35
+ redirect_to admin_aims_url, notice: 'Aim was successfully updated.'
36
+ else
37
+ render :edit
38
+ end
39
+ end
40
+
41
+ def add_item
42
+ @aim = Aim.new
43
+ @aim.aim_codes.build
44
+ end
45
+
46
+ def remove_item
47
+
48
+ end
49
+
50
+ def destroy
51
+ @aim.destroy
52
+ end
53
+
54
+ private
55
+ def set_aim
56
+ @aim = Aim.find(params[:id])
57
+ end
58
+
59
+ def aim_params
60
+ params.fetch(:aim, {}).permit(
61
+ :name,
62
+ :task_point,
63
+ :reward_point,
64
+ :unit,
65
+ :rate,
66
+ :repeat_type,
67
+ :reward_amount,
68
+ aim_codes_attributes: {}
69
+ )
70
+ end
71
+
72
+ end
73
+ end
@@ -0,0 +1,4 @@
1
+ module Growth
2
+ class Admin::BaseController < AdminController
3
+ end
4
+ end
@@ -0,0 +1,61 @@
1
+ module Growth
2
+ class Admin::PraiseIncomesController < Admin::BaseController
3
+ before_action :set_reward, only: [:index, :new, :create]
4
+ before_action :set_reward_income, only: [:show, :edit, :update, :destroy]
5
+
6
+ def index
7
+ @reward_incomes = @reward.reward_incomes.page(params[:page])
8
+ end
9
+
10
+ def new
11
+ @reward_income = @reward.reward_incomes.build
12
+ end
13
+
14
+ def create
15
+ @reward_income = @reward.reward_incomes.build(reward_income_params)
16
+
17
+ if @reward_income.save
18
+ render 'create'
19
+ else
20
+ render :new, locals: { model: @reward_income }, status: :unprocessable_entity
21
+ end
22
+ end
23
+
24
+ def show
25
+ end
26
+
27
+ def edit
28
+ end
29
+
30
+ def update
31
+ @reward_income.assign_attributes(reward_income_params)
32
+
33
+ if @reward_income.update(reward_income_params)
34
+ render 'update'
35
+ else
36
+ render :edit, locals: { model: @reward_income }, status: :unprocessable_entity
37
+ end
38
+ end
39
+
40
+ def destroy
41
+ @reward_income.destroy
42
+ end
43
+
44
+ private
45
+ def set_reward
46
+ @reward = Reward.find(params[:reward_id])
47
+ end
48
+
49
+ def set_reward_income
50
+ @reward_income = RewardIncome.find(params[:id])
51
+ end
52
+
53
+ def reward_income_params
54
+ q = params.fetch(:reward_income, {}).permit(
55
+ :reward_amount
56
+ )
57
+ q.merge(user_id: current_user.id)
58
+ end
59
+
60
+ end
61
+ end
@@ -0,0 +1,63 @@
1
+ module Growth
2
+ class Admin::RewardExpensesController < Admin::BaseController
3
+ before_action :set_reward_expense, only: [:show, :edit, :update, :destroy]
4
+
5
+ def index
6
+ q_params = {}
7
+ q_params.merge! params.permit(:reward_id, :user_id)
8
+
9
+ @reward_expenses = RewardExpense.includes(:user).default_where(q_params).page(params[:page])
10
+ end
11
+
12
+ def new
13
+ @reward = Reward.find params[:reward_id]
14
+ @reward_expense = @reward.reward_expenses.build
15
+ end
16
+
17
+ def create
18
+ @reward_expense = RewardExpense.new(reward_expense_params)
19
+
20
+ if @reward_expense.save
21
+ render 'create'
22
+ else
23
+ render :new, locals: { model: @reward_expense }, status: :unprocessable_entity
24
+ end
25
+ end
26
+
27
+ def show
28
+ end
29
+
30
+ def edit
31
+ end
32
+
33
+ def update
34
+ @reward_expense.assign_attributes(reward_expense_params)
35
+
36
+ if @reward_expense.save
37
+ render 'update'
38
+ else
39
+ render :edit, locals: { model: @reward_expense }, status: :unprocessable_entity
40
+ end
41
+ end
42
+
43
+ def destroy
44
+ @reward_expense.destroy
45
+ end
46
+
47
+ private
48
+ def set_reward_expense
49
+ @reward_expense = RewardExpense.find(params[:id])
50
+ end
51
+
52
+ def reward_expense_params
53
+ q = params.fetch(:reward_expense, {}).permit(
54
+ :amount,
55
+ :reward_id,
56
+ :user_id
57
+ )
58
+ q.merge! user_id: current_user.id if q[:user_id].blank?
59
+ q
60
+ end
61
+
62
+ end
63
+ end
@@ -0,0 +1,59 @@
1
+ module Growth
2
+ class Admin::RewardIncomesController < Admin::BaseController
3
+ before_action :set_reward, only: [:index, :new, :create]
4
+ before_action :set_reward_income, only: [:show, :edit, :update, :destroy]
5
+
6
+ def index
7
+ @reward_incomes = @reward.reward_incomes.page(params[:page])
8
+ end
9
+
10
+ def new
11
+ @reward_income = @reward.reward_incomes.build
12
+ end
13
+
14
+ def create
15
+ @reward_income = @reward.reward_incomes.build(reward_income_params)
16
+
17
+ if @reward_income.save
18
+ render 'create'
19
+ else
20
+ render :new
21
+ end
22
+ end
23
+
24
+ def show
25
+ end
26
+
27
+ def edit
28
+ end
29
+
30
+ def update
31
+ if @reward_income.update(reward_income_params)
32
+ render 'update'
33
+ else
34
+ render :edit
35
+ end
36
+ end
37
+
38
+ def destroy
39
+ @reward_income.destroy
40
+ end
41
+
42
+ private
43
+ def set_reward
44
+ @reward = Reward.find(params[:reward_id])
45
+ end
46
+
47
+ def set_reward_income
48
+ @reward_income = RewardIncome.find(params[:id])
49
+ end
50
+
51
+ def reward_income_params
52
+ q = params.fetch(:reward_income, {}).permit(
53
+ :reward_amount
54
+ )
55
+ q.merge(user_id: current_user.id)
56
+ end
57
+
58
+ end
59
+ end