rails_crm 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +20 -0
- data/README.md +33 -0
- data/Rakefile +32 -0
- data/app/controllers/crm/admin/base_controller.rb +20 -0
- data/app/controllers/crm/admin/maintain_logs_controller.rb +65 -0
- data/app/controllers/crm/admin/maintain_source_templates_controller.rb +52 -0
- data/app/controllers/crm/admin/maintain_sources_controller.rb +62 -0
- data/app/controllers/crm/admin/maintain_tag_templates_controller.rb +56 -0
- data/app/controllers/crm/admin/maintain_tags_controller.rb +66 -0
- data/app/controllers/crm/admin/maintains_controller.rb +289 -0
- data/app/controllers/crm/my/base_controller.rb +4 -0
- data/app/models/crm/application_record.rb +5 -0
- data/app/models/crm/maintain.rb +6 -0
- data/app/models/crm/maintain_log.rb +5 -0
- data/app/models/crm/maintain_source.rb +5 -0
- data/app/models/crm/maintain_source_template.rb +5 -0
- data/app/models/crm/maintain_tag.rb +5 -0
- data/app/models/crm/maintain_tag_template.rb +5 -0
- data/app/models/crm/model/agency.rb +18 -0
- data/app/models/crm/model/maintain.rb +91 -0
- data/app/models/crm/model/maintain_log.rb +18 -0
- data/app/models/crm/model/maintain_source.rb +19 -0
- data/app/models/crm/model/maintain_source_template.rb +12 -0
- data/app/models/crm/model/maintain_tag.rb +44 -0
- data/app/models/crm/model/maintain_tag_template.rb +17 -0
- data/app/models/crm/model/member.rb +11 -0
- data/app/models/crm/model/order.rb +10 -0
- data/app/models/crm/model/organ.rb +15 -0
- data/app/models/crm.rb +11 -0
- data/app/views/admin/_crm_nav.html.erb +13 -0
- data/app/views/crm/admin/maintain_logs/_breadcrumb.html.erb +6 -0
- data/app/views/crm/admin/maintain_logs/_filter_form.html.erb +8 -0
- data/app/views/crm/admin/maintain_logs/_form.html.erb +6 -0
- data/app/views/crm/admin/maintain_logs/_index_tbody.html.erb +8 -0
- data/app/views/crm/admin/maintain_logs/_index_thead.html.erb +14 -0
- data/app/views/crm/admin/maintain_logs/_maintain_log.json.jbuilder +11 -0
- data/app/views/crm/admin/maintain_logs/_show.json.jbuilder +1 -0
- data/app/views/crm/admin/maintain_logs/_show_table.html.erb +16 -0
- data/app/views/crm/admin/maintain_logs/index.json.jbuilder +2 -0
- data/app/views/crm/admin/maintain_source_templates/_edit_form.html.erb +4 -0
- data/app/views/crm/admin/maintain_source_templates/_filter_form.html.erb +8 -0
- data/app/views/crm/admin/maintain_source_templates/_form.html.erb +2 -0
- data/app/views/crm/admin/maintain_source_templates/_index_tbody.html.erb +14 -0
- data/app/views/crm/admin/maintain_source_templates/_index_thead.html.erb +2 -0
- data/app/views/crm/admin/maintain_source_templates/_maintain_source.json.jbuilder +7 -0
- data/app/views/crm/admin/maintain_source_templates/_new_form.html.erb +4 -0
- data/app/views/crm/admin/maintain_source_templates/_show.json.jbuilder +1 -0
- data/app/views/crm/admin/maintain_source_templates/_show_table.html.erb +8 -0
- data/app/views/crm/admin/maintain_source_templates/index.json.jbuilder +1 -0
- data/app/views/crm/admin/maintain_sources/_breadcrumb.html.erb +6 -0
- data/app/views/crm/admin/maintain_sources/_edit_form.html.erb +4 -0
- data/app/views/crm/admin/maintain_sources/_filter_form.html.erb +9 -0
- data/app/views/crm/admin/maintain_sources/_form.html.erb +2 -0
- data/app/views/crm/admin/maintain_sources/_index_tbody.html.erb +12 -0
- data/app/views/crm/admin/maintain_sources/_index_thead.html.erb +3 -0
- data/app/views/crm/admin/maintain_sources/_maintain_source.json.jbuilder +6 -0
- data/app/views/crm/admin/maintain_sources/_new_form.html.erb +4 -0
- data/app/views/crm/admin/maintain_sources/_show.json.jbuilder +1 -0
- data/app/views/crm/admin/maintain_sources/_show_table.html.erb +8 -0
- data/app/views/crm/admin/maintain_sources/index.json.jbuilder +1 -0
- data/app/views/crm/admin/maintain_sources/templates.html.erb +18 -0
- data/app/views/crm/admin/maintain_tag_templates/_edit_form.html.erb +4 -0
- data/app/views/crm/admin/maintain_tag_templates/_filter_form.html.erb +8 -0
- data/app/views/crm/admin/maintain_tag_templates/_form.html.erb +7 -0
- data/app/views/crm/admin/maintain_tag_templates/_index_tbody.html.erb +8 -0
- data/app/views/crm/admin/maintain_tag_templates/_index_thead.html.erb +7 -0
- data/app/views/crm/admin/maintain_tag_templates/_maintain_tag_template.json.jbuilder +11 -0
- data/app/views/crm/admin/maintain_tag_templates/_new_form.html.erb +4 -0
- data/app/views/crm/admin/maintain_tag_templates/_show.json.jbuilder +1 -0
- data/app/views/crm/admin/maintain_tag_templates/_show_table.html.erb +20 -0
- data/app/views/crm/admin/maintain_tag_templates/index.json.jbuilder +1 -0
- data/app/views/crm/admin/maintain_tags/_breadcrumb.html.erb +6 -0
- data/app/views/crm/admin/maintain_tags/_edit_form.html.erb +4 -0
- data/app/views/crm/admin/maintain_tags/_filter_form.html.erb +9 -0
- data/app/views/crm/admin/maintain_tags/_form.html.erb +5 -0
- data/app/views/crm/admin/maintain_tags/_index_tbody.html.erb +7 -0
- data/app/views/crm/admin/maintain_tags/_index_thead.html.erb +6 -0
- data/app/views/crm/admin/maintain_tags/_maintain_tag.json.jbuilder +9 -0
- data/app/views/crm/admin/maintain_tags/_new_form.html.erb +4 -0
- data/app/views/crm/admin/maintain_tags/_show.json.jbuilder +1 -0
- data/app/views/crm/admin/maintain_tags/_show_table.html.erb +24 -0
- data/app/views/crm/admin/maintain_tags/index.json.jbuilder +1 -0
- data/app/views/crm/admin/maintain_tags/templates.html.erb +22 -0
- data/app/views/crm/admin/maintains/_button.html.erb +3 -0
- data/app/views/crm/admin/maintains/_create_detect.html.erb +23 -0
- data/app/views/crm/admin/maintains/_edit_assign.html.erb +21 -0
- data/app/views/crm/admin/maintains/_edit_form.html.erb +4 -0
- data/app/views/crm/admin/maintains/_edit_order.html.erb +5 -0
- data/app/views/crm/admin/maintains/_edit_transfer.html.erb +19 -0
- data/app/views/crm/admin/maintains/_filter_form.html.erb +12 -0
- data/app/views/crm/admin/maintains/_filter_table.html.erb +54 -0
- data/app/views/crm/admin/maintains/_form.html.erb +37 -0
- data/app/views/crm/admin/maintains/_index_thead.html.erb +40 -0
- data/app/views/crm/admin/maintains/_index_tr.html.erb +36 -0
- data/app/views/crm/admin/maintains/_maintain.json.jbuilder +24 -0
- data/app/views/crm/admin/maintains/_new_batch_assign.html.erb +13 -0
- data/app/views/crm/admin/maintains/_new_detect.html.erb +15 -0
- data/app/views/crm/admin/maintains/_new_form.html.erb +4 -0
- data/app/views/crm/admin/maintains/_show.json.jbuilder +1 -0
- data/app/views/crm/admin/maintains/_show_table.html.erb +54 -0
- data/app/views/crm/admin/maintains/create_detect.js.erb +3 -0
- data/app/views/crm/admin/maintains/edit_assign.js +8 -0
- data/app/views/crm/admin/maintains/edit_assign.js.erb +3 -0
- data/app/views/crm/admin/maintains/edit_order.js.erb +12 -0
- data/app/views/crm/admin/maintains/edit_transfer.js +8 -0
- data/app/views/crm/admin/maintains/edit_transfer.js.erb +3 -0
- data/app/views/crm/admin/maintains/index.html.erb +26 -0
- data/app/views/crm/admin/maintains/index.json.jbuilder +2 -0
- data/app/views/crm/admin/maintains/new.json.jbuilder +5 -0
- data/app/views/crm/admin/maintains/new_batch_assign.js.erb +3 -0
- data/app/views/crm/admin/maintains/new_detect.js.erb +1 -0
- data/app/views/crm/admin/maintains/orders.html.erb +54 -0
- data/app/views/crm/admin/maintains/public.html.erb +83 -0
- data/app/views/crm/admin/maintains/public.json.jbuilder +2 -0
- data/config/locales/zh.attributes.yml +33 -0
- data/config/locales/zh.controller.yml +35 -0
- data/config/locales/zh.enum.yml +10 -0
- data/config/routes.rb +41 -0
- data/lib/rails_crm/config.rb +9 -0
- data/lib/rails_crm/engine.rb +16 -0
- data/lib/rails_crm.rb +2 -0
- metadata +178 -0
@@ -0,0 +1,18 @@
|
|
1
|
+
module Crm
|
2
|
+
module Model::Agency
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
has_one :maintain, inverse_of: :agency
|
7
|
+
has_many :maintains
|
8
|
+
|
9
|
+
before_validation :sync_from_maintain, if: -> { self.maintain.present? }
|
10
|
+
end
|
11
|
+
|
12
|
+
def sync_from_maintain
|
13
|
+
self.agent = maintain.agent
|
14
|
+
self.client = maintain.client
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
module Crm
|
2
|
+
module Model::Maintain
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
attribute :note, :string
|
7
|
+
attribute :position, :integer
|
8
|
+
|
9
|
+
belongs_to :organ, optional: true
|
10
|
+
belongs_to :member, inverse_of: :maintains, optional: true
|
11
|
+
belongs_to :maintain_source, optional: true
|
12
|
+
belongs_to :task_template, optional: true
|
13
|
+
belongs_to :agency, optional: true, inverse_of: :maintain
|
14
|
+
belongs_to :client, class_name: 'Profile', inverse_of: :client_maintains
|
15
|
+
belongs_to :agent, class_name: 'User', inverse_of: :agent_maintains, optional: true
|
16
|
+
belongs_to :upstream, class_name: self.name
|
17
|
+
belongs_to :source, class_name: self.name
|
18
|
+
|
19
|
+
has_many :maintain_logs, dependent: :delete_all
|
20
|
+
has_many :maintain_tags, -> { distinct }, through: :maintain_logs
|
21
|
+
has_many :orders, dependent: :nullify
|
22
|
+
|
23
|
+
accepts_nested_attributes_for :agency, reject_if: :all_blank
|
24
|
+
accepts_nested_attributes_for :agent, reject_if: :all_blank
|
25
|
+
accepts_nested_attributes_for :client, reject_if: :all_blank
|
26
|
+
|
27
|
+
enum state: {
|
28
|
+
init: 'init',
|
29
|
+
transferred: 'transferred'
|
30
|
+
}, _default: 'init'
|
31
|
+
|
32
|
+
before_validation do
|
33
|
+
self.upstream ||= self
|
34
|
+
self.source ||= self
|
35
|
+
self.position = self.pipeline_member&.position
|
36
|
+
end
|
37
|
+
before_save :sync_pipeline_member, if: -> { pipeline_id_changed? }
|
38
|
+
end
|
39
|
+
|
40
|
+
def sync_pipeline_member
|
41
|
+
self.pipeline_member ||= self.pipeline.pipeline_members.first if self.pipeline
|
42
|
+
end
|
43
|
+
|
44
|
+
def tags
|
45
|
+
ids = maintain_logs.pluck(:maintain_tag_id).uniq
|
46
|
+
MaintainTag.cached.slice(*ids).values
|
47
|
+
end
|
48
|
+
|
49
|
+
def transfer!
|
50
|
+
self.state = 'transferred'
|
51
|
+
|
52
|
+
next_member = pipeline_member&.next_member
|
53
|
+
if next_member
|
54
|
+
m = Maintain.new
|
55
|
+
m.upstream = self
|
56
|
+
m.source = self.source
|
57
|
+
m.pipeline_member = next_member
|
58
|
+
m.assign_attributes self.attributes.slice('organ_id', 'client_type', 'client_id', 'agent_type', 'agent_id', 'agency_id', 'maintain_source_id', 'pipeline_id')
|
59
|
+
|
60
|
+
self.class.transaction do
|
61
|
+
self.save!
|
62
|
+
m.save!
|
63
|
+
end
|
64
|
+
m
|
65
|
+
else
|
66
|
+
self.save
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def confirm_booker_time!(booked)
|
71
|
+
ml = self.maintain_logs.build
|
72
|
+
ml.member = self.member
|
73
|
+
ml.note = "已预约成功"
|
74
|
+
ml.logged = booked
|
75
|
+
mt = option_maintain_tags.find_by(logged_type: booked.class.name)
|
76
|
+
if mt
|
77
|
+
ml.maintain_tag = mt
|
78
|
+
end
|
79
|
+
ml.extra = {
|
80
|
+
booked_type: booked.booked_type,
|
81
|
+
booked_id: booked.booked_id
|
82
|
+
}
|
83
|
+
ml.save
|
84
|
+
end
|
85
|
+
|
86
|
+
def option_maintain_tags
|
87
|
+
MaintainTag.where(organ_id: self.organ_id)
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Crm
|
2
|
+
module Model::MaintainLog
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
attribute :note, :string
|
7
|
+
attribute :tag_str, :string
|
8
|
+
attribute :tag_sequence, :integer
|
9
|
+
attribute :extra, :json
|
10
|
+
|
11
|
+
belongs_to :maintain
|
12
|
+
belongs_to :member
|
13
|
+
belongs_to :logged, polymorphic: true, optional: true
|
14
|
+
belongs_to :maintain_tag, counter_cache: true, optional: true
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Crm
|
2
|
+
module Model::MaintainSource
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
attribute :name, :string
|
7
|
+
attribute :maintains_count, :integer, default: 0
|
8
|
+
belongs_to :organ, optional: true
|
9
|
+
belongs_to :maintain_source_template, optional: true
|
10
|
+
|
11
|
+
validates :name, presence: true
|
12
|
+
|
13
|
+
before_validation do
|
14
|
+
self.name = maintain_source_template.name if maintain_source_template
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Crm
|
2
|
+
module Model::MaintainTag
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
attribute :name, :string
|
7
|
+
attribute :logged_type, :string # TimeBooking/Order
|
8
|
+
attribute :entity_column, :string # entity_type
|
9
|
+
attribute :entity_value, :string # lesson
|
10
|
+
attribute :sequence, :integer, default: 1
|
11
|
+
attribute :manual, :boolean, default: true
|
12
|
+
attribute :color, :string, default: '#2A92CA'
|
13
|
+
attribute :maintain_logs_count, :integer, default: 0
|
14
|
+
|
15
|
+
belongs_to :organ, optional: true
|
16
|
+
belongs_to :maintain_tag_template, optional: true
|
17
|
+
|
18
|
+
validates :logged_type, uniqueness: { scope: [:organ_id, :sequence] }, allow_blank: true
|
19
|
+
validates :name, presence: true
|
20
|
+
|
21
|
+
before_validation do
|
22
|
+
if maintain_tag_template
|
23
|
+
self.name = maintain_tag_template.name
|
24
|
+
self.color = maintain_tag_template.color
|
25
|
+
self.manual = false
|
26
|
+
end
|
27
|
+
end
|
28
|
+
after_update_commit :delete_default_cache
|
29
|
+
end
|
30
|
+
|
31
|
+
def delete_default_cache
|
32
|
+
Rails.cache.delete('maintain_tag')
|
33
|
+
end
|
34
|
+
|
35
|
+
class_methods do
|
36
|
+
def cached
|
37
|
+
Rails.cache.fetch('maintain_tag') do
|
38
|
+
MaintainTag.pluck(:id, :name).to_h
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Crm
|
2
|
+
module Model::MaintainTagTemplate
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
attribute :name, :string
|
7
|
+
attribute :logged_type, :string
|
8
|
+
attribute :entity_column, :string
|
9
|
+
attribute :entity_value, :string
|
10
|
+
attribute :color, :string
|
11
|
+
attribute :sequence, :integer, default: 1
|
12
|
+
|
13
|
+
has_many :maintain_tags
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Crm
|
2
|
+
module Model::Organ
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
has_many :maintains, dependent: :nullify
|
7
|
+
has_many :pupils, through: :maintains
|
8
|
+
end
|
9
|
+
|
10
|
+
def maintains_count
|
11
|
+
maintains.select(:source_id).distinct.count
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
data/app/models/crm.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
<div class="<%= active_helper(modules: 'crm/admin', active: 'menu ex-accordion is-active', item: 'menu ex-accordion') %>" data-controller="menu">
|
2
|
+
<%= content_tag :div, class: 'menu-list' do %>
|
3
|
+
<%= link_to t('crm.admin.maintains.index.title'), { controller: 'crm/admin/maintains' }, class: active_helper(controllers: ['maintain_logs'], 'maintains': ['index', 'show'], active: 'is-active') %>
|
4
|
+
<%= link_to t('crm.admin.maintains.public.title'), { controller: 'crm/admin/maintains', action: 'public' }, class: active_helper('maintains': 'public', active: 'is-active') %>
|
5
|
+
<%= link_to t('crm.admin.maintain_source_templates.index.title'), { controller: 'crm/admin/maintain_source_templates' }, class: active_helper(controllers: 'maintain_source_templates', active: 'is-active') %>
|
6
|
+
<%= link_to t('crm.admin.maintain_tag_templates.index.title'), { controller: 'crm/admin/maintain_tag_templates' }, class: active_helper(controllers: 'maintain_tag_templates', active: 'is-active') -%>
|
7
|
+
<% end %>
|
8
|
+
<a class="menu-label" data-action="menu#toggle">
|
9
|
+
<i class="fas fa-chart-line fa-fw"></i>
|
10
|
+
<span><%= t('crm.admin.title') %></span>
|
11
|
+
<i class="fas dropdown"></i>
|
12
|
+
</a>
|
13
|
+
</div>
|
@@ -0,0 +1,8 @@
|
|
1
|
+
<td><%= model.maintain_tag&.name %></td>
|
2
|
+
<td><%= model.note %></td>
|
3
|
+
<td>
|
4
|
+
<p><%= model.logged_type %></p>
|
5
|
+
<p><%= model.logged_id %></p>
|
6
|
+
</td>
|
7
|
+
<td><%= simple_format model.extra %></td>
|
8
|
+
<td><time data-controller="time"><%= model.created_at.to_s(:rfc822) %></time></td>
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<th>
|
2
|
+
<%= MaintainLog.human_attribute_name(:maintain_tag_id) %>
|
3
|
+
<%= link_to({ controller: 'maintain_tags' }, aria: { label: '标签设置' }, target: '_blank') do %>
|
4
|
+
<i class="fas fa-cog"></i>
|
5
|
+
<% end %>
|
6
|
+
</th>
|
7
|
+
<th><%= MaintainLog.human_attribute_name(:note) %></th>
|
8
|
+
<th>
|
9
|
+
<p><%= MaintainLog.human_attribute_name(:logged_type) %></p>
|
10
|
+
<p><%= MaintainLog.human_attribute_name(:logged_id) %></p>
|
11
|
+
</th>
|
12
|
+
<th><%= MaintainLog.human_attribute_name(:extra) %></th>
|
13
|
+
<th><%= MaintainLog.human_attribute_name(:created_at) %></th>
|
14
|
+
<th></th>
|
@@ -0,0 +1 @@
|
|
1
|
+
json.maintain_log @maintain_log, partial: 'maintain_log', as: :maintain_log
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<tr>
|
2
|
+
<td class="has-text-right"><%= MaintainLog.human_attribute_name(:note) %></td>
|
3
|
+
<td><%= @maintain_log.note %></td>
|
4
|
+
</tr>
|
5
|
+
<tr>
|
6
|
+
<td class="has-text-right"><%= MaintainLog.human_attribute_name(:logged_type) %></td>
|
7
|
+
<td><%= @maintain_log.logged_type %></td>
|
8
|
+
</tr>
|
9
|
+
<tr>
|
10
|
+
<td class="has-text-right"><%= MaintainLog.human_attribute_name(:logged_id) %></td>
|
11
|
+
<td><%= @maintain_log.logged_id %></td>
|
12
|
+
</tr>
|
13
|
+
<tr>
|
14
|
+
<td class="has-text-right"><%= MaintainLog.human_attribute_name(:created_at) %></td>
|
15
|
+
<td><%= @maintain_log.created_at %></td>
|
16
|
+
</tr>
|