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
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 72c2a95f835e19a0e39f7809c25bb57c34329fb6ddf643842ad46d1bce49319f
|
4
|
+
data.tar.gz: acb8d4f08c07645b95cff04448afc51251f7f4e2d921985124771edaf3550b1a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 349336ec26ed4919be8ac2c95eb723ad1976bf9b8595d41d45cbc199c521aea742871011f9d0322b0e2c877d24d43fd4e87bc9c5cc4f97da6e4e9f4e8330db68
|
7
|
+
data.tar.gz: c561031829901c37c790d63141642ab74dffc497561158fc764f678a0bcbf4a3179b2495af4a209f806477b10b6bc3ac573246f496cf2f8c0a195cea5297499f
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2019-Present 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,33 @@
|
|
1
|
+
# RailsCrm
|
2
|
+
|
3
|
+
[![测试](https://github.com/work-design/rails_crm/actions/workflows/test.yml/badge.svg)](https://github.com/work-design/rails_crm/actions/workflows/test.yml)
|
4
|
+
[![Docker构建](https://github.com/work-design/rails_crm/actions/workflows/cd.yml/badge.svg)](https://github.com/work-design/rails_crm/actions/workflows/cd.yml)
|
5
|
+
[![Gem](https://github.com/work-design/rails_crm/actions/workflows/gempush.yml/badge.svg)](https://github.com/work-design/rails_crm/actions/workflows/gempush.yml)
|
6
|
+
|
7
|
+
简单 CRM 架构
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
How to use my plugin.
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem 'rails_crm'
|
17
|
+
```
|
18
|
+
|
19
|
+
And then execute:
|
20
|
+
```bash
|
21
|
+
$ bundle
|
22
|
+
```
|
23
|
+
|
24
|
+
Or install it yourself as:
|
25
|
+
```bash
|
26
|
+
$ gem install rails_crm
|
27
|
+
```
|
28
|
+
|
29
|
+
## Contributing
|
30
|
+
Contribution directions go here.
|
31
|
+
|
32
|
+
## 开源协议
|
33
|
+
遵循 [MIT](https://opensource.org/licenses/MIT) 协议
|
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 = 'RailsCrm'
|
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,20 @@
|
|
1
|
+
module Crm
|
2
|
+
class Admin::BaseController < AdminController
|
3
|
+
|
4
|
+
def member_params
|
5
|
+
if current_member
|
6
|
+
{ member_id: current_member.all_follower_ids }
|
7
|
+
else
|
8
|
+
{}
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def transfer_params(original_params = {})
|
13
|
+
r = {}
|
14
|
+
if original_params['age-gte']
|
15
|
+
r['birthday-gte'] = ''
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module Crm
|
2
|
+
class Admin::MaintainLogsController < Admin::BaseController
|
3
|
+
before_action :set_maintain
|
4
|
+
before_action :set_maintain_log, only: [:show, :edit, :update, :destroy]
|
5
|
+
before_action :prepare_form, only: [:new, :edit]
|
6
|
+
|
7
|
+
def index
|
8
|
+
@maintain_logs = @maintain.maintain_logs.order(id: :desc).page(params[:page]).per(params[:per])
|
9
|
+
end
|
10
|
+
|
11
|
+
def new
|
12
|
+
@maintain_log = @maintain.maintain_logs.build
|
13
|
+
end
|
14
|
+
|
15
|
+
def create
|
16
|
+
@maintain_log = @maintain.maintain_logs.build(maintain_log_params)
|
17
|
+
@maintain_log.member_id = current_member.id
|
18
|
+
|
19
|
+
unless @maintain_log.save
|
20
|
+
render :new, locals: { model: @maintain_log }, status: :unprocessable_entity
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def show
|
25
|
+
end
|
26
|
+
|
27
|
+
def edit
|
28
|
+
end
|
29
|
+
|
30
|
+
def update
|
31
|
+
@maintain_log.assign_attributes(maintain_log_params)
|
32
|
+
|
33
|
+
unless @maintain_log.save
|
34
|
+
render :edit, locals: { model: @maintain_log }, status: :unprocessable_entity
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def destroy
|
39
|
+
@maintain_log.destroy
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
def prepare_form
|
44
|
+
@maintain_tags = MaintainTag.default_where(default_params)
|
45
|
+
end
|
46
|
+
|
47
|
+
def set_maintain
|
48
|
+
@maintain = Maintain.find params[:maintain_id]
|
49
|
+
end
|
50
|
+
|
51
|
+
def set_maintain_log
|
52
|
+
@maintain_log = @maintain.maintain_logs.find(params[:id])
|
53
|
+
end
|
54
|
+
|
55
|
+
def maintain_log_params
|
56
|
+
params.fetch(:maintain_log, {}).permit(
|
57
|
+
:maintain_tag_id,
|
58
|
+
:note,
|
59
|
+
:logged_type,
|
60
|
+
:logged_id
|
61
|
+
)
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module Crm
|
2
|
+
class Admin::MaintainSourceTemplatesController < Admin::BaseController
|
3
|
+
before_action :set_maintain_source_template, only: [:show, :edit, :update, :destroy]
|
4
|
+
|
5
|
+
def index
|
6
|
+
@maintain_source_templates = MaintainSourceTemplate.page(params[:page])
|
7
|
+
end
|
8
|
+
|
9
|
+
def new
|
10
|
+
@maintain_source_template = MaintainSourceTemplate.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def create
|
14
|
+
@maintain_source_template = MaintainSourceTemplate.new(maintain_source_template_params)
|
15
|
+
|
16
|
+
unless @maintain_source_template.save
|
17
|
+
render :new, locals: { model: @maintain_source_template }, status: :unprocessable_entity
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def show
|
22
|
+
end
|
23
|
+
|
24
|
+
def edit
|
25
|
+
end
|
26
|
+
|
27
|
+
def update
|
28
|
+
@maintain_source_template.assign_attributes(maintain_source_template_params)
|
29
|
+
|
30
|
+
unless @maintain_source_template.save
|
31
|
+
render :edit, locals: { model: @maintain_source_template }, status: :unprocessable_entity
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def destroy
|
36
|
+
@maintain_source_template.destroy
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
def set_maintain_source_template
|
41
|
+
@maintain_source_template = MaintainSourceTemplate.find(params[:id])
|
42
|
+
end
|
43
|
+
|
44
|
+
def maintain_source_template_params
|
45
|
+
params.fetch(:maintain_source_template, {}).permit(
|
46
|
+
:name,
|
47
|
+
:maintains_count
|
48
|
+
)
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module Crm
|
2
|
+
class Admin::MaintainSourcesController < Admin::BaseController
|
3
|
+
before_action :set_maintain_source, only: [:show, :edit, :update, :destroy]
|
4
|
+
|
5
|
+
def index
|
6
|
+
q_params = {}
|
7
|
+
q_params.merge! default_params
|
8
|
+
q_params.merge! params.permit(:name)
|
9
|
+
|
10
|
+
@maintain_sources = MaintainSource.includes(:maintain_source_template).default_where(q_params).page(params[:page])
|
11
|
+
end
|
12
|
+
|
13
|
+
def templates
|
14
|
+
@maintain_source_templates = MaintainSourceTemplate.order(id: :asc)
|
15
|
+
@selected_maintain_sources = MaintainSource.where.not(maintain_source_template_id: nil).default_where(q_params).order(maintain_source_template_id: :asc)
|
16
|
+
end
|
17
|
+
|
18
|
+
def new
|
19
|
+
@maintain_source = MaintainSource.new
|
20
|
+
end
|
21
|
+
|
22
|
+
def create
|
23
|
+
@maintain_source = MaintainSource.new(maintain_source_params)
|
24
|
+
|
25
|
+
unless @maintain_source.save
|
26
|
+
render :new, locals: { model: @maintain_source }, status: :unprocessable_entity
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def show
|
31
|
+
end
|
32
|
+
|
33
|
+
def edit
|
34
|
+
end
|
35
|
+
|
36
|
+
def update
|
37
|
+
@maintain_source.assign_attributes(maintain_source_params)
|
38
|
+
|
39
|
+
unless @maintain_source.save
|
40
|
+
render :edit, locals: { model: @maintain_source }, status: :unprocessable_entity
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def destroy
|
45
|
+
@maintain_source.destroy
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
def set_maintain_source
|
50
|
+
@maintain_source = MaintainSource.find(params[:id])
|
51
|
+
end
|
52
|
+
|
53
|
+
def maintain_source_params
|
54
|
+
p = params.fetch(:maintain_source, {}).permit(
|
55
|
+
:name,
|
56
|
+
:maintain_source_template_id
|
57
|
+
)
|
58
|
+
p.merge! default_form_params
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module Crm
|
2
|
+
class Admin::MaintainTagTemplatesController < Admin::BaseController
|
3
|
+
before_action :set_maintain_tag_template, only: [:show, :edit, :update, :destroy]
|
4
|
+
|
5
|
+
def index
|
6
|
+
@maintain_tag_templates = MaintainTagTemplate.order(sequence: :asc).page(params[:page])
|
7
|
+
end
|
8
|
+
|
9
|
+
def new
|
10
|
+
@maintain_tag_template = MaintainTagTemplate.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def create
|
14
|
+
@maintain_tag_template = MaintainTagTemplate.new(maintain_tag_template_params)
|
15
|
+
|
16
|
+
unless @maintain_tag_template.save
|
17
|
+
render :new, locals: { model: @maintain_tag_template }, status: :unprocessable_entity
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def show
|
22
|
+
end
|
23
|
+
|
24
|
+
def edit
|
25
|
+
end
|
26
|
+
|
27
|
+
def update
|
28
|
+
@maintain_tag_template.assign_attributes(maintain_tag_template_params)
|
29
|
+
|
30
|
+
unless @maintain_tag_template.save
|
31
|
+
render :edit, locals: { model: @maintain_tag_template }, status: :unprocessable_entity
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def destroy
|
36
|
+
@maintain_tag_template.destroy
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
def set_maintain_tag_template
|
41
|
+
@maintain_tag_template = MaintainTagTemplate.find(params[:id])
|
42
|
+
end
|
43
|
+
|
44
|
+
def maintain_tag_template_params
|
45
|
+
params.fetch(:maintain_tag_template, {}).permit(
|
46
|
+
:name,
|
47
|
+
:logged_type,
|
48
|
+
:entity_column,
|
49
|
+
:entity_value,
|
50
|
+
:sequence,
|
51
|
+
:color
|
52
|
+
)
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module Crm
|
2
|
+
class Admin::MaintainTagsController < Admin::BaseController
|
3
|
+
before_action :set_maintain_tag, only: [:show, :edit, :update, :destroy]
|
4
|
+
|
5
|
+
def index
|
6
|
+
q_params = {}
|
7
|
+
q_params.merge! default_params
|
8
|
+
q_params.merge! params.permit(:name)
|
9
|
+
|
10
|
+
@maintain_tags = MaintainTag.where(maintain_tag_template_id: nil).default_where(q_params).page(params[:page])
|
11
|
+
@selected_maintain_tags = MaintainTag.where.not(maintain_tag_template_id: nil).default_where(q_params).order(maintain_tag_template_id: :asc)
|
12
|
+
@maintain_tag_templates = MaintainTagTemplate.order(id: :asc)
|
13
|
+
end
|
14
|
+
|
15
|
+
def new
|
16
|
+
@maintain_tag = MaintainTag.new
|
17
|
+
end
|
18
|
+
|
19
|
+
def create
|
20
|
+
@maintain_tag = MaintainTag.new(maintain_tag_params)
|
21
|
+
|
22
|
+
unless @maintain_tag.save
|
23
|
+
render :new, locals: { model: @maintain_tag }, status: :unprocessable_entity
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def sync
|
28
|
+
q_params = default_params
|
29
|
+
MaintainTag.default_where(q_params).sync_from_template
|
30
|
+
end
|
31
|
+
|
32
|
+
def show
|
33
|
+
end
|
34
|
+
|
35
|
+
def edit
|
36
|
+
end
|
37
|
+
|
38
|
+
def update
|
39
|
+
@maintain_tag.assign_attributes(maintain_tag_params)
|
40
|
+
|
41
|
+
unless @maintain_tag.save
|
42
|
+
render :edit, locals: { model: @maintain_tag }, status: :unprocessable_entity
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def destroy
|
47
|
+
@maintain_tag.destroy
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
def set_maintain_tag
|
52
|
+
@maintain_tag = MaintainTag.find(params[:id])
|
53
|
+
end
|
54
|
+
|
55
|
+
def maintain_tag_params
|
56
|
+
p = params.fetch(:maintain_tag, {}).permit(
|
57
|
+
:name,
|
58
|
+
:sequence,
|
59
|
+
:color,
|
60
|
+
:logged_type
|
61
|
+
)
|
62
|
+
p.merge! default_form_params
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,289 @@
|
|
1
|
+
module Crm
|
2
|
+
class Admin::MaintainsController < Admin::BaseController
|
3
|
+
before_action :set_maintain, only: [
|
4
|
+
:show, :edit, :update, :orders,
|
5
|
+
:edit_order, :update_order,
|
6
|
+
:edit_transfer, :update_transfer,
|
7
|
+
:edit_assign, :update_assign,
|
8
|
+
:detach, :assume, :destroy
|
9
|
+
]
|
10
|
+
before_action :prepare_form, only: [:new, :create_detect, :edit]
|
11
|
+
|
12
|
+
def index
|
13
|
+
q_params = {}
|
14
|
+
q_params.merge! member_params
|
15
|
+
q_params.merge! search_params
|
16
|
+
if (q_params.keys - [:member_id]).blank?
|
17
|
+
q_params.merge! state: 'init'
|
18
|
+
end
|
19
|
+
|
20
|
+
@maintain_sources = MaintainSource.default_where(default_params)
|
21
|
+
@maintain_tags = MaintainTag.default_where(default_params)
|
22
|
+
@pipelines = Bench::TaskTemplate.default_where(default_params.merge(tasking_type: 'Crm::Maintain'))
|
23
|
+
@maintains = Maintain.default_where(q_params).includes(:agency, :maintain_source, :member, :maintain_logs).order(id: :desc).page(params[:page]).per(params[:per])
|
24
|
+
end
|
25
|
+
|
26
|
+
def public
|
27
|
+
q_params = {
|
28
|
+
member_id: nil,
|
29
|
+
allow: { member_id: nil }
|
30
|
+
}
|
31
|
+
q_params.merge! search_params
|
32
|
+
q_params.merge! 'pipeline_member.job_title_id': current_member.lower_job_title_ids + [nil] if current_member
|
33
|
+
q_params.merge! default_params
|
34
|
+
@maintains = Maintain.default_where(q_params).page(params[:page])
|
35
|
+
end
|
36
|
+
|
37
|
+
def new_detect
|
38
|
+
end
|
39
|
+
|
40
|
+
def create_detect
|
41
|
+
q_params = {}
|
42
|
+
q_params.merge! default_params
|
43
|
+
@agent = Profile.default_where(q_params).find_by(identity: params[:identity])
|
44
|
+
if @agent
|
45
|
+
@agencies = @agent.proteges
|
46
|
+
render 'create_detect'
|
47
|
+
else
|
48
|
+
@maintain = Maintain.new
|
49
|
+
@maintain.member_id = current_member.id if current_member
|
50
|
+
@maintain.agent = Profile.new(identity: params[:identity])
|
51
|
+
@maintain.client = Profile.new
|
52
|
+
@maintain.build_agency
|
53
|
+
@agencies = Agency.none
|
54
|
+
render 'new'
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def new
|
59
|
+
@maintain = Maintain.new
|
60
|
+
@maintain.member_id = current_member.id if current_member
|
61
|
+
if params[:agent_id]
|
62
|
+
@maintain.agent = Profile.find params[:agent_id]
|
63
|
+
else
|
64
|
+
@maintain.agent = Profile.new
|
65
|
+
end
|
66
|
+
if params[:agency_id]
|
67
|
+
agency = Agency.find params[:agency_id]
|
68
|
+
@maintain.agency = agency
|
69
|
+
@maintain.client = agency.client
|
70
|
+
else
|
71
|
+
@maintain.client = Profile.new
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def create
|
76
|
+
@maintain = Maintain.new(maintain_params)
|
77
|
+
@maintain.member_id ||= current_member.id
|
78
|
+
|
79
|
+
if client_params[:id]
|
80
|
+
@maintain.client = Profile.find client_params[:id]
|
81
|
+
else
|
82
|
+
@maintain.client = Profile.new client_params
|
83
|
+
end
|
84
|
+
if agent_params[:id]
|
85
|
+
@maintain.agent = Profile.find agent_params[:id]
|
86
|
+
else
|
87
|
+
@maintain.agent = Profile.new agent_params
|
88
|
+
end
|
89
|
+
if agency_params[:id]
|
90
|
+
@maintain.agency = Agency.find agency_params[:id]
|
91
|
+
else
|
92
|
+
@maintain.agency = Agency.new agency_params
|
93
|
+
end
|
94
|
+
|
95
|
+
unless @maintain.save
|
96
|
+
render :new, locals: { model: @maintain }, status: :unprocessable_entity
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def batch
|
101
|
+
maintains_params = params.fetch(:maintains, {})
|
102
|
+
maintains_params.each do |maintain_params|
|
103
|
+
p = maintain_params.permit!
|
104
|
+
p.merge! default_form_params
|
105
|
+
@maintain = Maintain.create(p)
|
106
|
+
end
|
107
|
+
|
108
|
+
head :ok
|
109
|
+
end
|
110
|
+
|
111
|
+
def new_batch_assign
|
112
|
+
pipeline_params = {
|
113
|
+
'pipeline.piping_type': 'Maintain',
|
114
|
+
'pipeline.piping_id': nil,
|
115
|
+
position: 1
|
116
|
+
}
|
117
|
+
pipeline_params.merge! job_title_id: current_member.lower_job_title_ids if current_member
|
118
|
+
pipeline_params.merge! default_params
|
119
|
+
job_title_ids = PipelineMember.default_where(pipeline_params).pluck(:job_title_id)
|
120
|
+
|
121
|
+
@members = Member.default_where('member_departments.job_title_id': job_title_ids)
|
122
|
+
end
|
123
|
+
|
124
|
+
def create_batch_assign
|
125
|
+
add_ids = params[:add_ids].to_s.split(',')
|
126
|
+
@maintains = Maintain.where(id: add_ids)
|
127
|
+
@maintains.update_all member_id: params[:member_id]
|
128
|
+
|
129
|
+
redirect_back fallback_location: admin_maintains_url, notice: '移交成功'
|
130
|
+
end
|
131
|
+
|
132
|
+
def show
|
133
|
+
end
|
134
|
+
|
135
|
+
def edit
|
136
|
+
end
|
137
|
+
|
138
|
+
def update
|
139
|
+
@maintain.assign_attributes(update_params)
|
140
|
+
|
141
|
+
unless @maintain.save
|
142
|
+
render :edit, locals: { model: @maintain }, status: :unprocessable_entity
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
def edit_transfer
|
147
|
+
pipeline_params = {
|
148
|
+
piping_type: 'Maintain',
|
149
|
+
piping_id: nil,
|
150
|
+
'pipeline_members.position': 1
|
151
|
+
}
|
152
|
+
pipeline_params.merge! 'pipeline_members.job_title_id': current_member.job_title_ids if current_member
|
153
|
+
pipeline_params.merge! default_params
|
154
|
+
@pipelines = Pipeline.default_where(pipeline_params)
|
155
|
+
if @maintain.pipeline_member
|
156
|
+
@members = Member.default_where('member_departments.job_title_id': @maintain.pipeline_member.job_title_id)
|
157
|
+
else
|
158
|
+
@members = Member.none
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
def update_transfer
|
163
|
+
@maintain.assign_attributes maintain_params.slice(:pipeline_id)
|
164
|
+
@maintain.transfer!
|
165
|
+
|
166
|
+
redirect_back fallback_location: admin_maintains_url, notice: '移交成功'
|
167
|
+
end
|
168
|
+
|
169
|
+
def edit_assign
|
170
|
+
pipeline_params = {
|
171
|
+
piping_type: 'Maintain',
|
172
|
+
piping_id: nil,
|
173
|
+
'pipeline_members.position': 1
|
174
|
+
}
|
175
|
+
pipeline_params.merge! 'pipeline_members.job_title_id': current_member.lower_job_title_ids if current_member
|
176
|
+
pipeline_params.merge! default_params
|
177
|
+
@pipelines = Pipeline.default_where(pipeline_params)
|
178
|
+
if @maintain.pipeline_member
|
179
|
+
@members = Member.default_where('member_departments.job_title_id': @maintain.pipeline_member.job_title_id)
|
180
|
+
else
|
181
|
+
@members = Member.none
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
def update_assign
|
186
|
+
@maintain.assign_attributes maintain_params.slice(:pipeline_id, :member_id)
|
187
|
+
@maintain.save
|
188
|
+
|
189
|
+
redirect_back fallback_location: admin_maintains_url(id: params[:id]), notice: '移交成功'
|
190
|
+
end
|
191
|
+
|
192
|
+
def detach
|
193
|
+
@maintain.update member_id: nil
|
194
|
+
redirect_to admin_maintains_url
|
195
|
+
end
|
196
|
+
|
197
|
+
def assume
|
198
|
+
@maintain.update member_id: current_member.id
|
199
|
+
redirect_to admin_maintains_url
|
200
|
+
end
|
201
|
+
|
202
|
+
def orders
|
203
|
+
@orders = @maintain.orders.order(id: :desc).page(params[:page])
|
204
|
+
end
|
205
|
+
|
206
|
+
def edit_order
|
207
|
+
@card_templates = CardTemplate.default_where(default_params)
|
208
|
+
end
|
209
|
+
|
210
|
+
def update_order
|
211
|
+
q_params = default_params
|
212
|
+
q_params.merge! params.permit(:advance_id)
|
213
|
+
advance = Advance.find(q_params['advance_id'])
|
214
|
+
|
215
|
+
order = advance.generate_order! buyer: @maintain.agent, maintain_id: @maintain.id
|
216
|
+
flash[:notice] = "已下单,请等待财务核销, 订单号为:#{order.uuid}"
|
217
|
+
redirect_to orders_admin_maintain_url(@maintain, order_id: order.id)
|
218
|
+
end
|
219
|
+
|
220
|
+
def destroy
|
221
|
+
@maintain.destroy
|
222
|
+
end
|
223
|
+
|
224
|
+
private
|
225
|
+
def set_maintain
|
226
|
+
@maintain = Maintain.find(params[:id])
|
227
|
+
end
|
228
|
+
|
229
|
+
def prepare_form
|
230
|
+
pipeline_params = {
|
231
|
+
piping_type: 'Maintain',
|
232
|
+
piping_id: nil,
|
233
|
+
'pipeline_members.position': 1
|
234
|
+
}
|
235
|
+
pipeline_params.merge! 'pipeline_members.job_title_id': current_member.lower_job_title_ids if current_member
|
236
|
+
pipeline_params.merge! default_params
|
237
|
+
@pipelines = Pipeline.default_where(pipeline_params)
|
238
|
+
@maintain_sources = MaintainSource.default_where(default_params)
|
239
|
+
end
|
240
|
+
|
241
|
+
def maintain_params
|
242
|
+
p = params.fetch(:maintain, {}).permit(
|
243
|
+
:note,
|
244
|
+
:pipeline_id,
|
245
|
+
:pipeline_member_id,
|
246
|
+
:member_id,
|
247
|
+
:maintain_source_id
|
248
|
+
)
|
249
|
+
p.merge! default_form_params
|
250
|
+
p
|
251
|
+
end
|
252
|
+
|
253
|
+
def update_params
|
254
|
+
maintain_params.merge! params.fetch(:maintain, {}).permit(client_attributes: {}, agent_attributes: {}, agency_attributes: {})
|
255
|
+
end
|
256
|
+
|
257
|
+
def client_params
|
258
|
+
p = params.fetch(:maintain, {}).fetch(:client_attributes, {}).permit!
|
259
|
+
p.merge! default_form_params
|
260
|
+
end
|
261
|
+
|
262
|
+
def agent_params
|
263
|
+
p = params.fetch(:maintain, {}).fetch(:agent_attributes, {}).permit!
|
264
|
+
p.merge! default_form_params
|
265
|
+
end
|
266
|
+
|
267
|
+
def agency_params
|
268
|
+
params.fetch(:maintain, {}).fetch(:agency_attributes, {}).permit!
|
269
|
+
end
|
270
|
+
|
271
|
+
def search_params
|
272
|
+
params.permit(
|
273
|
+
:state,
|
274
|
+
:maintain_source_id,
|
275
|
+
:pipeline_id,
|
276
|
+
:member_id,
|
277
|
+
'client.real_name',
|
278
|
+
'client.real_name-like',
|
279
|
+
'client.birthday-gte',
|
280
|
+
'client.birthday-lte',
|
281
|
+
'agent.identity',
|
282
|
+
'created_at-gte',
|
283
|
+
'created_at-lte',
|
284
|
+
'maintain_logs.maintain_tag_id'
|
285
|
+
)
|
286
|
+
end
|
287
|
+
|
288
|
+
end
|
289
|
+
end
|