rails_profile 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 +20 -0
- data/Rakefile +32 -0
- data/app/controllers/profiled/admin/address_organs_controller.rb +27 -0
- data/app/controllers/profiled/admin/addresses_controller.rb +48 -0
- data/app/controllers/profiled/admin/base_controller.rb +4 -0
- data/app/controllers/profiled/admin/profiles_controller.rb +42 -0
- data/app/controllers/profiled/areas_controller.rb +42 -0
- data/app/controllers/profiled/base_controller.rb +4 -0
- data/app/controllers/profiled/me/base_controller.rb +9 -0
- data/app/controllers/profiled/me/profiles_controller.rb +43 -0
- data/app/controllers/profiled/my/address_users_controller.rb +27 -0
- data/app/controllers/profiled/my/addresses_controller.rb +102 -0
- data/app/controllers/profiled/my/base_controller.rb +4 -0
- data/app/controllers/profiled/my/profiles_controller.rb +67 -0
- data/app/controllers/profiled/panel/areas_controller.rb +27 -0
- data/app/controllers/profiled/panel/base_controller.rb +4 -0
- data/app/models/concerns/qq_map_helper.rb +80 -0
- data/app/models/profiled/address.rb +8 -0
- data/app/models/profiled/address_organ.rb +5 -0
- data/app/models/profiled/address_user.rb +5 -0
- data/app/models/profiled/application_record.rb +5 -0
- data/app/models/profiled/area.rb +6 -0
- data/app/models/profiled/ext/organ.rb +11 -0
- data/app/models/profiled/ext/user.rb +17 -0
- data/app/models/profiled/model/account.rb +17 -0
- data/app/models/profiled/model/address.rb +33 -0
- data/app/models/profiled/model/address_organ.rb +23 -0
- data/app/models/profiled/model/address_user.rb +29 -0
- data/app/models/profiled/model/area.rb +120 -0
- data/app/models/profiled/model/profile.rb +43 -0
- data/app/models/profiled/profile.rb +5 -0
- data/app/models/profiled.rb +11 -0
- data/app/views/admin/_profile_nav.html.erb +10 -0
- data/app/views/me/_profile_nav.html.erb +4 -0
- data/app/views/my/_profile_nav.html.erb +5 -0
- data/app/views/panel/_profile_nav.html.erb +10 -0
- data/app/views/profiled/admin/base/_nav.html.erb +4 -0
- data/app/views/profiled/admin/profiles/_edit_form.html.erb +5 -0
- data/app/views/profiled/admin/profiles/_filter_form.html.erb +9 -0
- data/app/views/profiled/admin/profiles/_form.html.erb +6 -0
- data/app/views/profiled/admin/profiles/_index_tbody.html.erb +6 -0
- data/app/views/profiled/admin/profiles/_index_thead.html.erb +7 -0
- data/app/views/profiled/admin/profiles/_new_form.html.erb +5 -0
- data/app/views/profiled/admin/profiles/_profile.json.jbuilder +2 -0
- data/app/views/profiled/admin/profiles/_show_table.html.erb +24 -0
- data/app/views/profiled/admin/profiles/index.html.erb +5 -0
- data/app/views/profiled/admin/profiles/qrcode.json.jbuilder +1 -0
- data/app/views/profiled/areas/_index.html.erb +26 -0
- data/app/views/profiled/areas/follow.turbo_stream.erb +11 -0
- data/app/views/profiled/areas/index.json.jbuilder +2 -0
- data/app/views/profiled/areas/index.turbo_stream+phone.erb +1 -0
- data/app/views/profiled/me/profiles/_edit_form.html.erb +4 -0
- data/app/views/profiled/me/profiles/_form.html.erb +5 -0
- data/app/views/profiled/me/profiles/_profile.json.jbuilder +14 -0
- data/app/views/profiled/me/profiles/_show_table.html.erb +20 -0
- data/app/views/profiled/me/profiles/show.json.jbuilder +1 -0
- data/app/views/profiled/my/address_users/create.turbo_stream.erb +3 -0
- data/app/views/profiled/my/addresses/_filter_form.html.erb +9 -0
- data/app/views/profiled/my/addresses/_form.html+phone.erb +15 -0
- data/app/views/profiled/my/addresses/_form.html.erb +4 -0
- data/app/views/profiled/my/addresses/_index/_address.html.erb +20 -0
- data/app/views/profiled/my/addresses/_index_tbody.html.erb +4 -0
- data/app/views/profiled/my/addresses/_index_thead.html.erb +5 -0
- data/app/views/profiled/my/addresses/_list/_address.html.erb +18 -0
- data/app/views/profiled/my/addresses/_new_form.html+phone.erb +12 -0
- data/app/views/profiled/my/addresses/_new_form.html.erb +4 -0
- data/app/views/profiled/my/addresses/_outer_select.html+phone.erb +14 -0
- data/app/views/profiled/my/addresses/_outer_select.html.erb +17 -0
- data/app/views/profiled/my/addresses/_select.html.erb +10 -0
- data/app/views/profiled/my/addresses/_show_table.html+phone.erb +25 -0
- data/app/views/profiled/my/addresses/_show_table.html.erb +12 -0
- data/app/views/profiled/my/addresses/_wechat_form.html.erb +36 -0
- data/app/views/profiled/my/addresses/create.turbo_stream.erb +5 -0
- data/app/views/profiled/my/addresses/fork.turbo_stream.erb +3 -0
- data/app/views/profiled/my/addresses/index.html+phone.erb +26 -0
- data/app/views/profiled/my/addresses/index.html.erb +7 -0
- data/app/views/profiled/my/addresses/list.html+phone.erb +41 -0
- data/app/views/profiled/my/addresses/select.turbo_stream.erb +1 -0
- data/app/views/profiled/my/addresses/show.html+phone.erb +26 -0
- data/app/views/profiled/my/addresses/update.turbo_stream.erb +7 -0
- data/app/views/profiled/my/addresses/wechat.turbo_stream.erb +3 -0
- data/app/views/profiled/my/profiles/_edit_form.html+phone.erb +15 -0
- data/app/views/profiled/my/profiles/_edit_form.html.erb +4 -0
- data/app/views/profiled/my/profiles/_form.html.erb +6 -0
- data/app/views/profiled/my/profiles/_profile.json.jbuilder +1 -0
- data/app/views/profiled/my/profiles/_show_table.html+phone.erb +24 -0
- data/app/views/profiled/my/profiles/_show_table.html.erb +20 -0
- data/app/views/profiled/my/profiles/index.html+phone.erb +3 -0
- data/app/views/profiled/my/profiles/index.html.erb +31 -0
- data/app/views/profiled/my/profiles/index.json.jbuilder +1 -0
- data/app/views/profiled/my/profiles/show.html+phone.erb +8 -0
- data/app/views/profiled/my/profiles/show.html.erb +1 -0
- data/app/views/profiled/my/profiles/show.json.jbuilder +1 -0
- data/app/views/profiled/panel/addresses/_address.html.erb +24 -0
- data/app/views/profiled/panel/addresses/_edit_form.html.erb +4 -0
- data/app/views/profiled/panel/addresses/_form.html.erb +22 -0
- data/app/views/profiled/panel/addresses/_index_tbody.html.erb +16 -0
- data/app/views/profiled/panel/addresses/_index_thead.html.erb +5 -0
- data/app/views/profiled/panel/addresses/_new_form.html.erb +4 -0
- data/app/views/profiled/panel/addresses/index.html.erb +5 -0
- data/app/views/profiled/panel/areas/_filter_form.html.erb +9 -0
- data/app/views/profiled/panel/areas/_form.html.erb +5 -0
- data/app/views/profiled/panel/areas/_index_tbody.html.erb +17 -0
- data/app/views/profiled/panel/areas/_index_thead.html.erb +8 -0
- data/app/views/profiled/panel/areas/_show_table.html.erb +8 -0
- data/app/views/profiled/panel/areas/index.html.erb +5 -0
- data/app/views/profiled/panel/base/_nav.html.erb +3 -0
- data/config/locales/en.controller.yml +30 -0
- data/config/locales/en.enum.yml +15 -0
- data/config/locales/zh.attributes.yml +28 -0
- data/config/locales/zh.controller.yml +38 -0
- data/config/locales/zh.enum.yml +10 -0
- data/config/routes.rb +45 -0
- data/lib/rails_profile/config.rb +11 -0
- data/lib/rails_profile/engine.rb +21 -0
- data/lib/rails_profile.rb +2 -0
- metadata +174 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c8b72c8cc86db3097cf87e17b457a6b36a8cc69346689799f88dce4e25683573
|
4
|
+
data.tar.gz: efa3547fa72ca9b7c12f33a3bf22e71f293e3037f9333ed8110a3b3e572872b0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 914289a8e2fec1ca7c348fb868b2179f6447d2bdf29b6b619d8badf9d01f42d5f01914a78c32e83bea37fed59f5b6138c86b5e26a02b1cf4ffdf1e508ab7f9d9
|
7
|
+
data.tar.gz: '0923dad0e7af7576f7bb5add09f61f4011ce61ada4aa7bfc4f2ea3c60e9045a59181999be5e38f06381033af6b05fe0b943cd9aa7dc02789c5d418becb3eefbb'
|
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,20 @@
|
|
1
|
+
# RailsProfile
|
2
|
+
|
3
|
+
[![测试](https://github.com/work-design/rails_profile/actions/workflows/test.yml/badge.svg)](https://github.com/work-design/rails_profile/actions/workflows/test.yml)
|
4
|
+
[![Docker构建](https://github.com/work-design/rails_profile/actions/workflows/cd.yml/badge.svg)](https://github.com/work-design/rails_profile/actions/workflows/cd.yml)
|
5
|
+
[![Gem](https://github.com/work-design/rails_profile/actions/workflows/gempush.yml/badge.svg)](https://github.com/work-design/rails_profile/actions/workflows/gempush.yml)
|
6
|
+
|
7
|
+
用户画像,
|
8
|
+
|
9
|
+
`RailsProfile`用于拓展用户的资料,比如简历、所在地区管理等;
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
|
16
|
+
## Contributing
|
17
|
+
Contribution directions go here.
|
18
|
+
|
19
|
+
## License
|
20
|
+
遵循[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 = 'RailsShip'
|
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,27 @@
|
|
1
|
+
module Profiled
|
2
|
+
class Admin::AddressOrgansController < Admin::BaseController
|
3
|
+
before_action :set_address
|
4
|
+
before_action :set_new_address_user, only: [:new, :create]
|
5
|
+
|
6
|
+
def index
|
7
|
+
@address_users = @address.address_users.page(params[:page])
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
def set_new_address_user
|
12
|
+
@address_user = @address.address_users.build(**params.permit(:user_id))
|
13
|
+
end
|
14
|
+
|
15
|
+
def set_address
|
16
|
+
@address = Address.find(params[:address_id])
|
17
|
+
end
|
18
|
+
|
19
|
+
def address_user_params
|
20
|
+
params.fetch(:address_user, {}).permit(
|
21
|
+
:user_id,
|
22
|
+
:state
|
23
|
+
)
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module Profiled
|
2
|
+
class Admin::AddressesController < Admin::BaseController
|
3
|
+
before_action :set_address, only: [:show, :edit, :update, :destroy]
|
4
|
+
|
5
|
+
def index
|
6
|
+
q_params = {}
|
7
|
+
q_params.merge! params.permit('address_users.user_id')
|
8
|
+
|
9
|
+
@addresses = current_organ.addresses.includes(:area).default_where(q_params).page(params[:page])
|
10
|
+
end
|
11
|
+
|
12
|
+
def new
|
13
|
+
@address = Address.new params.permit(*address_permit_params)
|
14
|
+
@address.area ||= Area.new
|
15
|
+
end
|
16
|
+
|
17
|
+
def create
|
18
|
+
@address = current_organ.addresses.build(address_params)
|
19
|
+
|
20
|
+
if @address.save
|
21
|
+
render 'create'
|
22
|
+
else
|
23
|
+
render :new, locals: { model: @address }, status: :unprocessable_entity
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
def set_address
|
29
|
+
@address = Address.find(params[:id])
|
30
|
+
end
|
31
|
+
|
32
|
+
def address_params
|
33
|
+
params.fetch(:address, {}).permit(*address_permit_params)
|
34
|
+
end
|
35
|
+
|
36
|
+
def address_permit_params
|
37
|
+
[
|
38
|
+
:kind,
|
39
|
+
:name,
|
40
|
+
:contact,
|
41
|
+
:tel,
|
42
|
+
:detail,
|
43
|
+
:area_ancestors
|
44
|
+
]
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Profiled
|
2
|
+
class Admin::ProfilesController < Admin::BaseController
|
3
|
+
before_action :set_profile, only: [:show, :edit, :update, :user, :qrcode, :destroy]
|
4
|
+
|
5
|
+
def index
|
6
|
+
q_params = {}
|
7
|
+
q_params.merge! default_params
|
8
|
+
|
9
|
+
@profiles = Profile.default_where(q_params).page(params[:page])
|
10
|
+
end
|
11
|
+
|
12
|
+
def user
|
13
|
+
@profile.init_user
|
14
|
+
end
|
15
|
+
|
16
|
+
def qrcode
|
17
|
+
@profile.init_user
|
18
|
+
@profile.account.qrcode
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
def set_profile
|
23
|
+
@profile = Profile.find(params[:id])
|
24
|
+
end
|
25
|
+
|
26
|
+
def profile_params
|
27
|
+
[
|
28
|
+
:real_name,
|
29
|
+
:nick_name,
|
30
|
+
:gender,
|
31
|
+
:birthday_type,
|
32
|
+
:birthday,
|
33
|
+
:area_id,
|
34
|
+
:address,
|
35
|
+
:note,
|
36
|
+
:resume,
|
37
|
+
:avatar
|
38
|
+
]
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Profiled
|
2
|
+
class AreasController < BaseController
|
3
|
+
|
4
|
+
def index
|
5
|
+
@areas = Area.roots
|
6
|
+
end
|
7
|
+
|
8
|
+
def follow
|
9
|
+
@area = Area.find params[:id]
|
10
|
+
@areas = @area.children
|
11
|
+
end
|
12
|
+
|
13
|
+
# for weui.js
|
14
|
+
def list
|
15
|
+
values = Area.list(value_name: 'value', label_name: 'label')
|
16
|
+
|
17
|
+
if params[:area_id]
|
18
|
+
area = Area.find params[:area_id]
|
19
|
+
default = area.parent_ancestors.values + [area.id]
|
20
|
+
else
|
21
|
+
default = []
|
22
|
+
end
|
23
|
+
|
24
|
+
render json: { values: values, default: default }
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
def set_area
|
29
|
+
@area = Area.unscoped.find params[:id]
|
30
|
+
end
|
31
|
+
|
32
|
+
def area_params
|
33
|
+
params.fetch(:area, {}).permit(
|
34
|
+
:name,
|
35
|
+
:popular,
|
36
|
+
:published,
|
37
|
+
:parent_ancestors
|
38
|
+
)
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Profiled
|
2
|
+
class Me::ProfilesController < Me::BaseController
|
3
|
+
before_action :set_profile, only: [:show, :edit, :update, :destroy]
|
4
|
+
|
5
|
+
def show
|
6
|
+
end
|
7
|
+
|
8
|
+
def edit
|
9
|
+
end
|
10
|
+
|
11
|
+
def update
|
12
|
+
@profile.assign_attributes profile_params
|
13
|
+
|
14
|
+
unless @profile.save
|
15
|
+
render :edit, locals: { model: @profile }, status: :unprocessable_entity
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def destroy
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
def set_profile
|
24
|
+
@profile = current_member.profile || current_member.create_profile
|
25
|
+
end
|
26
|
+
|
27
|
+
def profile_params
|
28
|
+
params.fetch(:profile, {}).permit(
|
29
|
+
:real_name,
|
30
|
+
:nick_name,
|
31
|
+
:gender,
|
32
|
+
:birthday_type,
|
33
|
+
:birthday,
|
34
|
+
:note,
|
35
|
+
:degree,
|
36
|
+
:major,
|
37
|
+
:identity,
|
38
|
+
extra: {}
|
39
|
+
)
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Profiled
|
2
|
+
class My::AddressUsersController < My::BaseController
|
3
|
+
before_action :set_address
|
4
|
+
before_action :set_new_address_user, only: [:new, :create]
|
5
|
+
|
6
|
+
def index
|
7
|
+
@address_users = @address.address_users.page(params[:page])
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
def set_new_address_user
|
12
|
+
@address_user = @address.address_users.build(**params.permit(:user_id))
|
13
|
+
end
|
14
|
+
|
15
|
+
def set_address
|
16
|
+
@address = Address.find(params[:address_id])
|
17
|
+
end
|
18
|
+
|
19
|
+
def address_user_params
|
20
|
+
params.fetch(:address_user, {}).permit(
|
21
|
+
:user_id,
|
22
|
+
:state
|
23
|
+
)
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
module Profiled
|
2
|
+
class My::AddressesController < My::BaseController
|
3
|
+
before_action :set_address, only: [:show, :edit, :update, :destroy]
|
4
|
+
|
5
|
+
def index
|
6
|
+
q_params = {}
|
7
|
+
|
8
|
+
@addresses = current_user.addresses.includes(:area).default_where(q_params).page(params[:page])
|
9
|
+
@address = current_user.addresses.build
|
10
|
+
end
|
11
|
+
|
12
|
+
def list
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
def new
|
17
|
+
@address = current_user.addresses.build
|
18
|
+
r = QqMapHelper.ip '110.53.215.204' || request.remote_ip
|
19
|
+
area_params = r['ad_info']
|
20
|
+
if area_params
|
21
|
+
area = Area.sure_find_full [area_params['province'], area_params['city'], area_params['district'].presence].compact
|
22
|
+
else
|
23
|
+
area = Area.new
|
24
|
+
end
|
25
|
+
@address.area = area
|
26
|
+
end
|
27
|
+
|
28
|
+
def create
|
29
|
+
@address = current_user.addresses.build(address_params)
|
30
|
+
|
31
|
+
if @address.save
|
32
|
+
render 'create'
|
33
|
+
else
|
34
|
+
render :new, locals: { model: @address }, status: :unprocessable_entity
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def fork
|
39
|
+
@address = current_user.addresses.build
|
40
|
+
@address.contact = params[:userName]
|
41
|
+
@address.tel = params[:telNumber]
|
42
|
+
@address.detail = params[:detailInfo]
|
43
|
+
@address.post_code = params[:postalCode]
|
44
|
+
end
|
45
|
+
|
46
|
+
def wechat
|
47
|
+
# uniq 解决['上海市', '上海市'] 的问题
|
48
|
+
area = Area.sure_find [params['provinceName'], params['cityName'], params['countyName']].reject(&:blank?).uniq
|
49
|
+
cached_key = [area.id, address_params[:detail], address_params[:contact], address_params[:tel]].join(',')
|
50
|
+
|
51
|
+
@address = current_user.addresses.find_or_initialize_by(cached_key: cached_key)
|
52
|
+
@address.assign_attributes address_params
|
53
|
+
@address.area = area
|
54
|
+
@address.source = 'wechat'
|
55
|
+
@address.save
|
56
|
+
|
57
|
+
return_to = URI(params[:return_to])
|
58
|
+
return_to.query = "address_id=#{@address.id}"
|
59
|
+
render 'wechat', locals: { return_to: return_to.to_s }
|
60
|
+
end
|
61
|
+
|
62
|
+
def program
|
63
|
+
area = Area.sure_find [params['provinceName'], params['cityName'], params['countyName']].reject(&:blank?).uniq
|
64
|
+
cached_key = [area.id, params['detailInfo'], params['userName'], params['telNumber']].join(',')
|
65
|
+
|
66
|
+
@address = current_user.addresses.find_or_initialize_by(cached_key: cached_key)
|
67
|
+
@address.contact = params['userName']
|
68
|
+
@address.tel = params['telNumber']
|
69
|
+
@address.detail = params['detailInfo']
|
70
|
+
@address.post_code = params[:postalCode]
|
71
|
+
@address.area = area
|
72
|
+
@address.source = 'program'
|
73
|
+
@address.save
|
74
|
+
|
75
|
+
render json: { id: @address.id }
|
76
|
+
end
|
77
|
+
|
78
|
+
def join
|
79
|
+
au = current_user.address_users.find_or_initialize_by(address_id: @address.id)
|
80
|
+
au.save
|
81
|
+
render 'show'
|
82
|
+
end
|
83
|
+
|
84
|
+
private
|
85
|
+
def set_address
|
86
|
+
@address = Address.find(params[:id])
|
87
|
+
end
|
88
|
+
|
89
|
+
def address_params
|
90
|
+
params.fetch(:address, {}).permit(
|
91
|
+
:name,
|
92
|
+
:contact,
|
93
|
+
:tel,
|
94
|
+
:detail,
|
95
|
+
:post_code,
|
96
|
+
:area_id,
|
97
|
+
:area_ancestors
|
98
|
+
)
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module Profiled
|
2
|
+
class My::ProfilesController < My::BaseController
|
3
|
+
before_action :set_profile, only: [:show, :edit, :update, :destroy]
|
4
|
+
|
5
|
+
def new
|
6
|
+
@profile = current_user.profiles.build
|
7
|
+
prepare_form
|
8
|
+
end
|
9
|
+
|
10
|
+
def create
|
11
|
+
@profile = current_user.profiles.build(profile_params)
|
12
|
+
|
13
|
+
if @profile.save
|
14
|
+
render 'create'
|
15
|
+
else
|
16
|
+
prepare_form
|
17
|
+
render :new
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def show
|
22
|
+
end
|
23
|
+
|
24
|
+
def edit
|
25
|
+
prepare_form
|
26
|
+
end
|
27
|
+
|
28
|
+
def update
|
29
|
+
@profile.assign_attributes profile_params
|
30
|
+
|
31
|
+
if @profile.save
|
32
|
+
render 'update'
|
33
|
+
else
|
34
|
+
render :edit, locals: { model: @profile }, status: :unprocessable_entity
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def destroy
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
def set_profile
|
43
|
+
@profile = current_user.profiles.find_or_create_by(default_params)
|
44
|
+
end
|
45
|
+
|
46
|
+
def prepare_form
|
47
|
+
@accounts = current_user.accounts.confirmed
|
48
|
+
end
|
49
|
+
|
50
|
+
def profile_params
|
51
|
+
p = params.fetch(:profile, {}).permit(
|
52
|
+
:real_name,
|
53
|
+
:nick_name,
|
54
|
+
:gender,
|
55
|
+
:birthday_type,
|
56
|
+
:birthday,
|
57
|
+
:note,
|
58
|
+
:degree,
|
59
|
+
:major,
|
60
|
+
:identity,
|
61
|
+
extra: {}
|
62
|
+
)
|
63
|
+
p.merge! default_form_params
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Profiled
|
2
|
+
class Panel::AreasController < Panel::BaseController
|
3
|
+
before_action :set_area, only: [:show, :edit, :update, :destroy]
|
4
|
+
|
5
|
+
def index
|
6
|
+
q_params = {}
|
7
|
+
q_params.merge! params.permit(:name)
|
8
|
+
|
9
|
+
@areas = Area.unscoped.default_where(q_params).order(id: :asc).page(params[:page])
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
def set_area
|
14
|
+
@area = Area.unscoped.find params[:id]
|
15
|
+
end
|
16
|
+
|
17
|
+
def area_permit_params
|
18
|
+
[
|
19
|
+
:name,
|
20
|
+
:popular,
|
21
|
+
:published,
|
22
|
+
:parent_ancestors
|
23
|
+
]
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
module QqMapHelper
|
2
|
+
KEY = Rails.application.credentials.dig(:qq_map, :ws)
|
3
|
+
extend self
|
4
|
+
|
5
|
+
def geocoder(lat:, lng:)
|
6
|
+
url = 'https://apis.map.qq.com/ws/geocoder/v1'
|
7
|
+
body = {
|
8
|
+
key: KEY,
|
9
|
+
location: [lat, lng].join(',')
|
10
|
+
}
|
11
|
+
|
12
|
+
r = HTTPX.get(url, params: body)
|
13
|
+
result = JSON.parse(r.to_s)
|
14
|
+
if result['status'] == 0
|
15
|
+
result['result']
|
16
|
+
else
|
17
|
+
result
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def ip(ip)
|
22
|
+
url = 'https://apis.map.qq.com/ws/location/v1/ip'
|
23
|
+
body = {
|
24
|
+
key: KEY,
|
25
|
+
ip: ip
|
26
|
+
}
|
27
|
+
|
28
|
+
r = HTTPX.get(url, params: body)
|
29
|
+
result = JSON.parse(r.to_s)
|
30
|
+
if result['status'] == 0
|
31
|
+
result['result']
|
32
|
+
else
|
33
|
+
result
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def districts
|
38
|
+
url = 'https://apis.map.qq.com/ws/district/v1/list'
|
39
|
+
body = {
|
40
|
+
key: KEY
|
41
|
+
}
|
42
|
+
|
43
|
+
r = HTTPX.get(url, params: body)
|
44
|
+
result = JSON.parse(r.to_s)
|
45
|
+
if result['status'] == 0
|
46
|
+
result['result']
|
47
|
+
else
|
48
|
+
result
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def sync_to_areas
|
53
|
+
results = districts
|
54
|
+
results[0].each do |result|
|
55
|
+
area = Profiled::Area.find_or_initialize_by(name: result['name'])
|
56
|
+
area.full = result['fullname']
|
57
|
+
area.code = result['id']
|
58
|
+
area.save
|
59
|
+
end
|
60
|
+
|
61
|
+
results[1].each do |result|
|
62
|
+
area = Profiled::Area.find_or_initialize_by(name: result['name'])
|
63
|
+
parent = Profiled::Area.find_by(code: "#{result['id'][0..1]}0000")
|
64
|
+
area.parent = parent
|
65
|
+
area.full = result['fullname']
|
66
|
+
area.code = result['id']
|
67
|
+
area.save
|
68
|
+
end
|
69
|
+
|
70
|
+
results[2].each do |result|
|
71
|
+
area = Profiled::Area.find_or_initialize_by(name: result['fullname'])
|
72
|
+
parent = Profiled::Area.find_by(code: "#{result['id'][0..3]}00")
|
73
|
+
area.parent = parent
|
74
|
+
area.full = result['fullname']
|
75
|
+
area.code = result['id']
|
76
|
+
area.save
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Profiled
|
2
|
+
module Ext::Organ
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
has_many :address_organs, class_name: 'Profiled::AddressOrgan', inverse_of: :organ, dependent: :delete_all
|
7
|
+
has_many :addresses, class_name: 'Profiled::Address', through: :address_organs
|
8
|
+
end
|
9
|
+
|
10
|
+
end
|
11
|
+
end
|