rails_ship 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 +32 -0
- data/Rakefile +32 -0
- data/app/controllers/ship/admin/addresses_controller.rb +48 -0
- data/app/controllers/ship/admin/base_controller.rb +5 -0
- data/app/controllers/ship/admin/home_controller.rb +8 -0
- data/app/controllers/ship/admin/packages_controller.rb +43 -0
- data/app/controllers/ship/admin/trade_items_controller.rb +72 -0
- data/app/controllers/ship/driver/base_controller.rb +9 -0
- data/app/controllers/ship/driver/favorites_controller.rb +39 -0
- data/app/controllers/ship/my/addresses_controller.rb +58 -0
- data/app/controllers/ship/my/base_controller.rb +5 -0
- data/app/controllers/ship/my/cars_controller.rb +54 -0
- data/app/controllers/ship/my/drivers_controller.rb +38 -0
- data/app/controllers/ship/my/favorites_controller.rb +40 -0
- data/app/controllers/ship/my/lines_controller.rb +71 -0
- data/app/controllers/ship/my/locations_controller.rb +60 -0
- data/app/controllers/ship/my/packages_controller.rb +53 -0
- data/app/controllers/ship/my/principal_addresses_controller.rb +26 -0
- data/app/controllers/ship/panel/base_controller.rb +5 -0
- data/app/controllers/ship/panel/lines_controller.rb +53 -0
- data/app/controllers/ship/panel/similars_controller.rb +61 -0
- data/app/jobs/ship/car_ocr_job.rb +11 -0
- data/app/jobs/ship/driver_ocr_job.rb +11 -0
- data/app/jobs/ship/location_geo_job.rb +10 -0
- data/app/models/ship/address.rb +7 -0
- data/app/models/ship/car.rb +5 -0
- data/app/models/ship/driver.rb +5 -0
- data/app/models/ship/ext/order.rb +7 -0
- data/app/models/ship/ext/trade_item.rb +11 -0
- data/app/models/ship/ext/user.rb +15 -0
- data/app/models/ship/favorite.rb +5 -0
- data/app/models/ship/line.rb +5 -0
- data/app/models/ship/line_similar.rb +5 -0
- data/app/models/ship/location.rb +5 -0
- data/app/models/ship/model/address.rb +10 -0
- data/app/models/ship/model/car.rb +34 -0
- data/app/models/ship/model/driver.rb +45 -0
- data/app/models/ship/model/favorite.rb +14 -0
- data/app/models/ship/model/line.rb +28 -0
- data/app/models/ship/model/line_similar.rb +16 -0
- data/app/models/ship/model/location.rb +53 -0
- data/app/models/ship/model/package.rb +28 -0
- data/app/models/ship/model/packaged.rb +29 -0
- data/app/models/ship/model/shipment.rb +22 -0
- data/app/models/ship/model/shipping.rb +9 -0
- data/app/models/ship/package.rb +6 -0
- data/app/models/ship/packaged.rb +5 -0
- data/app/models/ship/shipment.rb +5 -0
- data/app/models/ship.rb +11 -0
- data/app/views/admin/_ship_nav.html.erb +11 -0
- data/app/views/panel/_ship_nav.html.erb +10 -0
- data/app/views/ship/admin/addresses/_address.html.erb +24 -0
- data/app/views/ship/admin/addresses/_edit_form.html.erb +3 -0
- data/app/views/ship/admin/addresses/_form.html.erb +9 -0
- data/app/views/ship/admin/addresses/index.html.erb +36 -0
- data/app/views/ship/admin/base/_nav.html.erb +3 -0
- data/app/views/ship/admin/home/index.html.erb +0 -0
- data/app/views/ship/admin/packages/_button.html.erb +0 -0
- data/app/views/ship/admin/packages/_edit_form.html.erb +4 -0
- data/app/views/ship/admin/packages/_filter_form.html.erb +9 -0
- data/app/views/ship/admin/packages/_form.html.erb +5 -0
- data/app/views/ship/admin/packages/_index_tbody.html.erb +8 -0
- data/app/views/ship/admin/packages/_index_thead.html.erb +5 -0
- data/app/views/ship/admin/packages/_new_form.html.erb +4 -0
- data/app/views/ship/admin/packages/_show_table.html.erb +16 -0
- data/app/views/ship/admin/packages/index.html.erb +5 -0
- data/app/views/ship/admin/rallies/_filter.html.erb +7 -0
- data/app/views/ship/admin/rallies/_form.html+phone.erb +17 -0
- data/app/views/ship/admin/rallies/_show_table.html+phone.erb +24 -0
- data/app/views/ship/admin/rallies/_show_table.html.erb +12 -0
- data/app/views/ship/admin/rallies/index.html+phone.erb +26 -0
- data/app/views/ship/admin/rallies/show.html.erb +26 -0
- data/app/views/ship/admin/trade_items/_filter.html.erb +9 -0
- data/app/views/ship/admin/trade_items/_form.html.erb +7 -0
- data/app/views/ship/admin/trade_items/_show_table.html.erb +24 -0
- data/app/views/ship/admin/trade_items/index.html.erb +51 -0
- data/app/views/ship/driver/favorites/_button.html+phone.erb +4 -0
- data/app/views/ship/driver/favorites/_edit_form.html.erb +4 -0
- data/app/views/ship/driver/favorites/_filter_form.html+phone.erb +14 -0
- data/app/views/ship/driver/favorites/_filter_form.html.erb +9 -0
- data/app/views/ship/driver/favorites/_form.html.erb +3 -0
- data/app/views/ship/driver/favorites/_index_tbody.html.erb +6 -0
- data/app/views/ship/driver/favorites/_index_thead.html.erb +3 -0
- data/app/views/ship/driver/favorites/_index_tr.html.erb +4 -0
- data/app/views/ship/driver/favorites/_new_form.html.erb +4 -0
- data/app/views/ship/driver/favorites/_show_table.html.erb +8 -0
- data/app/views/ship/driver/favorites/index.html.erb +5 -0
- data/app/views/ship/my/addresses/_edit_form.html.erb +21 -0
- data/app/views/ship/my/addresses/_form.html.erb +23 -0
- data/app/views/ship/my/addresses/index.html.erb +44 -0
- data/app/views/ship/my/cars/_edit_form.html.erb +6 -0
- data/app/views/ship/my/cars/_filter_form.html.erb +9 -0
- data/app/views/ship/my/cars/_index_tbody.html.erb +3 -0
- data/app/views/ship/my/cars/_index_thead.html.erb +4 -0
- data/app/views/ship/my/cars/_new_form.html.erb +4 -0
- data/app/views/ship/my/cars/_show_table.html.erb +16 -0
- data/app/views/ship/my/cars/create.turbo_stream.erb +1 -0
- data/app/views/ship/my/cars/index.html+phone.erb +19 -0
- data/app/views/ship/my/cars/index.html.erb +5 -0
- data/app/views/ship/my/cars/new.html.erb +25 -0
- data/app/views/ship/my/drivers/_edit_form.html.erb +6 -0
- data/app/views/ship/my/drivers/_form.html.erb +4 -0
- data/app/views/ship/my/drivers/_index_tbody.html.erb +3 -0
- data/app/views/ship/my/drivers/_index_thead.html.erb +4 -0
- data/app/views/ship/my/drivers/_new_form.html.erb +4 -0
- data/app/views/ship/my/drivers/_show_table.html.erb +12 -0
- data/app/views/ship/my/drivers/_uploader.html.erb +22 -0
- data/app/views/ship/my/drivers/edit.html.erb +20 -0
- data/app/views/ship/my/drivers/show.html.erb +33 -0
- data/app/views/ship/my/favorites/_button.html+phone.erb +4 -0
- data/app/views/ship/my/favorites/_edit_form.html.erb +4 -0
- data/app/views/ship/my/favorites/_filter_form.html+phone.erb +14 -0
- data/app/views/ship/my/favorites/_filter_form.html.erb +9 -0
- data/app/views/ship/my/favorites/_form.html.erb +3 -0
- data/app/views/ship/my/favorites/_index_tbody.html.erb +6 -0
- data/app/views/ship/my/favorites/_index_thead.html.erb +3 -0
- data/app/views/ship/my/favorites/_new_form.html.erb +4 -0
- data/app/views/ship/my/favorites/_show_table.html.erb +8 -0
- data/app/views/ship/my/favorites/index.html.erb +5 -0
- data/app/views/ship/my/lines/_edit_form.html.erb +4 -0
- data/app/views/ship/my/lines/_filter_form.html.erb +1 -0
- data/app/views/ship/my/lines/_form.html.erb +3 -0
- data/app/views/ship/my/lines/_index_tbody.html.erb +6 -0
- data/app/views/ship/my/lines/_index_tr.html.erb +4 -0
- data/app/views/ship/my/lines/_item_field.html.erb +8 -0
- data/app/views/ship/my/lines/_item_location.html.erb +13 -0
- data/app/views/ship/my/lines/_new_form.html.erb +15 -0
- data/app/views/ship/my/lines/_select/_tab_bar.html.erb +10 -0
- data/app/views/ship/my/lines/_select.html.erb +10 -0
- data/app/views/ship/my/lines/_show/_index_tbody.html.erb +6 -0
- data/app/views/ship/my/lines/_show/_index_tr.html+phone.erb +6 -0
- data/app/views/ship/my/lines/_show_table.html.erb +9 -0
- data/app/views/ship/my/lines/add.turbo_stream.erb +1 -0
- data/app/views/ship/my/lines/index.html.erb +5 -0
- data/app/views/ship/my/lines/new.html.erb +1 -0
- data/app/views/ship/my/lines/requirement.html.erb +5 -0
- data/app/views/ship/my/lines/select.turbo_stream.erb +1 -0
- data/app/views/ship/my/lines/show.html+phone.erb +30 -0
- data/app/views/ship/my/locations/_edit_form.html.erb +4 -0
- data/app/views/ship/my/locations/_filter_form.html.erb +9 -0
- data/app/views/ship/my/locations/_form.html.erb +6 -0
- data/app/views/ship/my/locations/_index_tbody.html.erb +5 -0
- data/app/views/ship/my/locations/_index_thead.html.erb +6 -0
- data/app/views/ship/my/locations/_new_form.html.erb +4 -0
- data/app/views/ship/my/locations/_show_table.html.erb +20 -0
- data/app/views/ship/my/locations/index.html.erb +5 -0
- data/app/views/ship/my/packages/index.html.erb +31 -0
- data/app/views/ship/my/principal_addresses/index.html+phone.erb +32 -0
- data/app/views/ship/my/principal_addresses/plans.html+phone.erb +23 -0
- data/app/views/ship/my/principal_addresses/show.html+phone.erb +27 -0
- data/app/views/ship/panel/base/_nav.html.erb +3 -0
- data/app/views/ship/panel/lines/_edit_form.html.erb +4 -0
- data/app/views/ship/panel/lines/_filter_form.html.erb +9 -0
- data/app/views/ship/panel/lines/_form.html.erb +4 -0
- data/app/views/ship/panel/lines/_index_tbody.html.erb +4 -0
- data/app/views/ship/panel/lines/_index_thead.html.erb +5 -0
- data/app/views/ship/panel/lines/_index_tr.html.erb +19 -0
- data/app/views/ship/panel/lines/_new_form.html.erb +4 -0
- data/app/views/ship/panel/lines/_show_table.html.erb +12 -0
- data/app/views/ship/panel/lines/index.html.erb +5 -0
- data/app/views/ship/panel/similars/_breadcrumb.html.erb +7 -0
- data/app/views/ship/panel/similars/_button.html.erb +3 -0
- data/app/views/ship/panel/similars/_edit_form.html.erb +4 -0
- data/app/views/ship/panel/similars/_filter_form.html.erb +9 -0
- data/app/views/ship/panel/similars/_form.html.erb +4 -0
- data/app/views/ship/panel/similars/_index_tbody.html.erb +3 -0
- data/app/views/ship/panel/similars/_index_thead.html.erb +4 -0
- data/app/views/ship/panel/similars/_new/_button.html.erb +0 -0
- data/app/views/ship/panel/similars/_new/_index_tr.html.erb +10 -0
- data/app/views/ship/panel/similars/_new/_index_tr_remove.html.erb +10 -0
- data/app/views/ship/panel/similars/_new_form.html.erb +4 -0
- data/app/views/ship/panel/similars/_show_table.html.erb +12 -0
- data/app/views/ship/panel/similars/create.turbo_stream.erb +3 -0
- data/app/views/ship/panel/similars/destroy.turbo_stream.erb +3 -0
- data/app/views/ship/panel/similars/index.html.erb +5 -0
- data/app/views/ship/panel/similars/new.html.erb +16 -0
- data/config/locales/zh.attributes.yml +15 -0
- data/config/locales/zh.yml +51 -0
- data/config/routes.rb +66 -0
- data/lib/rails_ship/config.rb +11 -0
- data/lib/rails_ship/engine.rb +21 -0
- data/lib/rails_ship.rb +2 -0
- metadata +240 -0
@@ -0,0 +1,53 @@
|
|
1
|
+
module Ship
|
2
|
+
class My::PackagesController < My::BaseController
|
3
|
+
before_action :set_address
|
4
|
+
before_action :set_package, only: [:show, :wait, :edit, :update, :destroy]
|
5
|
+
|
6
|
+
def index
|
7
|
+
q_params = {}
|
8
|
+
q_params.merge! params.permit(:produce_plan_id)
|
9
|
+
@produce_plan = ProducePlan.find params[:produce_plan_id]
|
10
|
+
@produce_plan.wait_lists.find_or_create_by(address_id: @address.id)
|
11
|
+
|
12
|
+
@packages = @address.packages.default_where(q_params).page(params[:page])
|
13
|
+
end
|
14
|
+
|
15
|
+
def show
|
16
|
+
end
|
17
|
+
|
18
|
+
def wait
|
19
|
+
wait_list = @address.wait_lists.find_by(wait_for_type: 'ProducePlan', wait_for_id: @package.produce_plan_id)
|
20
|
+
wait_item = wait_list.wait_items.find_or_initialize_by(user_id: @package.user_id)
|
21
|
+
@package.wait_item = wait_item
|
22
|
+
|
23
|
+
if @package.save
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def edit
|
29
|
+
end
|
30
|
+
|
31
|
+
def update
|
32
|
+
@package.assign_attributes(package_params)
|
33
|
+
|
34
|
+
unless @package.save
|
35
|
+
render :edit, locals: { model: @package }, status: :unprocessable_entity
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def destroy
|
40
|
+
@package.destroy
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
def set_address
|
45
|
+
@address = current_user.principal_addresses.find params[:principal_address_id]
|
46
|
+
end
|
47
|
+
|
48
|
+
def set_package
|
49
|
+
@package = @address.packages.find(params[:id])
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Ship
|
2
|
+
class My::PrincipalAddressesController < My::BaseController
|
3
|
+
before_action :set_principal_address, only: [:show, :plans]
|
4
|
+
|
5
|
+
def index
|
6
|
+
@addresses = current_user.principal_addresses.page(params[:page])
|
7
|
+
end
|
8
|
+
|
9
|
+
def show
|
10
|
+
@customs = @address.customs
|
11
|
+
end
|
12
|
+
|
13
|
+
def plans
|
14
|
+
q_params = {}
|
15
|
+
q_params.merge! default_params
|
16
|
+
|
17
|
+
@produce_plans = ProducePlan.default_where(q_params)
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
def set_principal_address
|
22
|
+
@address = current_user.principal_addresses.find(params[:id])
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Ship
|
2
|
+
class Panel::LinesController < Panel::BaseController
|
3
|
+
before_action :set_line, only: [:show, :edit, :update, :destroy]
|
4
|
+
|
5
|
+
def index
|
6
|
+
@lines = Line.page(params[:page])
|
7
|
+
end
|
8
|
+
|
9
|
+
def new
|
10
|
+
@line = Line.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def create
|
14
|
+
@line = Line.new(line_params)
|
15
|
+
|
16
|
+
unless @line.save
|
17
|
+
render :new, locals: { model: @line }, status: :unprocessable_entity
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def show
|
22
|
+
end
|
23
|
+
|
24
|
+
def edit
|
25
|
+
end
|
26
|
+
|
27
|
+
def update
|
28
|
+
@line.assign_attributes(line_params)
|
29
|
+
|
30
|
+
unless @line.save
|
31
|
+
render :edit, locals: { model: @line }, status: :unprocessable_entity
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def destroy
|
36
|
+
@line.destroy
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
def set_line
|
41
|
+
@line = Line.find(params[:id])
|
42
|
+
end
|
43
|
+
|
44
|
+
def line_params
|
45
|
+
params.fetch(:line, {}).permit(
|
46
|
+
:name,
|
47
|
+
:start_name,
|
48
|
+
:finish_name
|
49
|
+
)
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module Ship
|
2
|
+
class Panel::SimilarsController < Panel::BaseController
|
3
|
+
before_action :set_line
|
4
|
+
before_action :set_similar, only: [:show, :edit, :update, :destroy]
|
5
|
+
|
6
|
+
def index
|
7
|
+
@similars = @line.similars.page(params[:page])
|
8
|
+
end
|
9
|
+
|
10
|
+
def new
|
11
|
+
@similars = @line.similars.page(params[:page])
|
12
|
+
@lines = Line.where.not(id: @line.similar_ids).page(params[:page])
|
13
|
+
end
|
14
|
+
|
15
|
+
def create
|
16
|
+
@line_similar = @line.line_similars.build
|
17
|
+
@line_similar.similar_id = params[:similar_id]
|
18
|
+
|
19
|
+
unless @line_similar.save
|
20
|
+
render :new, locals: { model: @line_similar }, status: :unprocessable_entity
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def show
|
25
|
+
end
|
26
|
+
|
27
|
+
def edit
|
28
|
+
end
|
29
|
+
|
30
|
+
def update
|
31
|
+
@similar.assign_attributes(similar_params)
|
32
|
+
|
33
|
+
unless @similar.save
|
34
|
+
render :edit, locals: { model: @similar }, status: :unprocessable_entity
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def destroy
|
39
|
+
@line_similar = @line.line_similars.find_by(similar_id: params[:id])
|
40
|
+
@line_similar.destroy
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
def set_line
|
45
|
+
@line = Line.find params[:line_id]
|
46
|
+
end
|
47
|
+
|
48
|
+
def set_similar
|
49
|
+
@similar = Line.find(params[:id])
|
50
|
+
end
|
51
|
+
|
52
|
+
def similar_params
|
53
|
+
params.fetch(:line_similar, {}).permit(
|
54
|
+
:name,
|
55
|
+
:similar_id,
|
56
|
+
:position
|
57
|
+
)
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Ship
|
2
|
+
module Ext::User
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
has_one :driver, class_name: 'Ship::Driver'
|
7
|
+
has_many :cars, class_name: 'Ship::Car'
|
8
|
+
has_many :lines, class_name: 'Ship::Line'
|
9
|
+
|
10
|
+
has_many :favorites, class_name: 'Ship::Favorite'
|
11
|
+
has_many :drivers, class_name: 'Ship::Driver', through: :favorites
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Ship
|
2
|
+
module Model::Car
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
attribute :location, :string
|
7
|
+
attribute :number, :string
|
8
|
+
attribute :detail, :json
|
9
|
+
|
10
|
+
belongs_to :user, class_name: 'Auth::User'
|
11
|
+
|
12
|
+
has_one_attached :registration
|
13
|
+
|
14
|
+
after_create_commit :ocr_later
|
15
|
+
end
|
16
|
+
|
17
|
+
def ocr_later
|
18
|
+
CarOcrJob.perform_later(self)
|
19
|
+
end
|
20
|
+
|
21
|
+
def ocr
|
22
|
+
r = TencentHelper.registration_ocr(registration.url)
|
23
|
+
self.detail = r['FrontInfo']
|
24
|
+
self.number = detail['PlateNo'] if detail.is_a?(Hash)
|
25
|
+
self.save
|
26
|
+
r
|
27
|
+
end
|
28
|
+
|
29
|
+
def for_update
|
30
|
+
broadcast_action_to 'car_new', action: :update, target: 'car_update', partial: 'ship/my/cars/edit_form', locals: { car: self }
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Ship
|
2
|
+
module Model::Driver
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
attribute :name, :string
|
7
|
+
attribute :number, :string
|
8
|
+
attribute :detail, :jsonb, default: {}
|
9
|
+
|
10
|
+
belongs_to :user, class_name: 'Auth::User'
|
11
|
+
has_many :favorites, dependent: :delete_all
|
12
|
+
has_many :users, through: :favorites
|
13
|
+
|
14
|
+
has_one_attached :license
|
15
|
+
|
16
|
+
after_create_commit :ocr_later
|
17
|
+
after_create_commit :sync_to_favorite
|
18
|
+
end
|
19
|
+
|
20
|
+
def ocr_later
|
21
|
+
DriverOcrJob.perform_later(self)
|
22
|
+
end
|
23
|
+
|
24
|
+
def ocr
|
25
|
+
r = TencentHelper.license_ocr(license.url)
|
26
|
+
self.name = r['Name']
|
27
|
+
self.number = r['CardCode']
|
28
|
+
self.detail = r
|
29
|
+
self.save
|
30
|
+
r
|
31
|
+
end
|
32
|
+
|
33
|
+
def for_update
|
34
|
+
broadcast_action_to 'driver_edit', action: :update, target: 'driver_update', partial: 'ship/my/drivers/edit_form', locals: { driver: self }
|
35
|
+
end
|
36
|
+
|
37
|
+
def sync_to_favorite
|
38
|
+
if user.inviter_id
|
39
|
+
favorite = favorites.build(user_id: user.inviter_id)
|
40
|
+
favorite.save
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Ship
|
2
|
+
module Model::Line
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
attribute :name, :string
|
7
|
+
attribute :start_name, :string
|
8
|
+
attribute :finish_name, :string
|
9
|
+
attribute :locations_count, :integer, default: 0
|
10
|
+
|
11
|
+
belongs_to :user, class_name: 'Auth::User'
|
12
|
+
|
13
|
+
has_many :locations, -> { order(position: :asc) }, dependent: :delete_all, inverse_of: :line
|
14
|
+
accepts_nested_attributes_for :locations
|
15
|
+
has_many :line_similars, dependent: :delete_all
|
16
|
+
has_many :similars, through: :line_similars
|
17
|
+
|
18
|
+
after_create_commit :sync_names
|
19
|
+
end
|
20
|
+
|
21
|
+
def sync_names
|
22
|
+
self.start_name = locations[0].poiname
|
23
|
+
self.finish_name = locations[1].poiname
|
24
|
+
self.save
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Ship
|
2
|
+
module Model::LineSimilar
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
attribute :score, :decimal
|
7
|
+
attribute :position, :integer
|
8
|
+
|
9
|
+
belongs_to :line
|
10
|
+
belongs_to :similar, class_name: 'Line'
|
11
|
+
|
12
|
+
acts_as_list
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Ship
|
2
|
+
module Model::Location
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
attribute :poiname, :string
|
7
|
+
attribute :poiaddress, :string
|
8
|
+
attribute :cityname, :string
|
9
|
+
attribute :lat, :decimal, precision: 10, scale: 8
|
10
|
+
attribute :lng, :decimal, precision: 11, scale: 8
|
11
|
+
attribute :position, :integer
|
12
|
+
attribute :coordinate, :point
|
13
|
+
|
14
|
+
belongs_to :area, class_name: 'Profiled::Area', optional: true
|
15
|
+
belongs_to :line, counter_cache: true
|
16
|
+
|
17
|
+
acts_as_list scope: [:line_id]
|
18
|
+
|
19
|
+
after_save_commit :geo_later, if: -> { saved_change_to_lat? || saved_change_to_lng? }
|
20
|
+
end
|
21
|
+
|
22
|
+
def position_text
|
23
|
+
if line.new_record?
|
24
|
+
count = line.locations.size
|
25
|
+
else
|
26
|
+
count = line.locations_count
|
27
|
+
end
|
28
|
+
|
29
|
+
if position == 1
|
30
|
+
'起点'
|
31
|
+
elsif position >= count
|
32
|
+
'终点'
|
33
|
+
else
|
34
|
+
"途经点#{position}"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def geo_later
|
39
|
+
LocationGeoJob.perform_later(self)
|
40
|
+
end
|
41
|
+
|
42
|
+
# todo 依赖 rails profiled
|
43
|
+
def geo
|
44
|
+
result = QqMapHelper.geocoder(lat: lat, lng: lng)
|
45
|
+
r = result['address_component']
|
46
|
+
area = Profiled::Area.sure_find [r['province'], r['city'], r['district']]
|
47
|
+
self.area = area
|
48
|
+
self.save
|
49
|
+
result
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Ship
|
2
|
+
module Model::Package
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
attribute :state, :string
|
7
|
+
attribute :expected_on, :date
|
8
|
+
attribute :pick_mode, :string
|
9
|
+
|
10
|
+
belongs_to :address
|
11
|
+
belongs_to :user
|
12
|
+
belongs_to :produce_plan, optional: true
|
13
|
+
has_many :shipments, dependent: :delete_all
|
14
|
+
has_many :packageds, dependent: :destroy
|
15
|
+
has_many :trade_items, through: :packageds
|
16
|
+
|
17
|
+
enum pick_mode: {
|
18
|
+
by_self: 'by_self',
|
19
|
+
by_man: 'by_man'
|
20
|
+
}
|
21
|
+
enum state: {
|
22
|
+
|
23
|
+
}
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Ship
|
2
|
+
module Model::Packaged
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
attribute :trade_item_status, :string
|
7
|
+
|
8
|
+
belongs_to :package, inverse_of: :packageds
|
9
|
+
belongs_to :trade_item
|
10
|
+
|
11
|
+
before_save :sync_trade_item_status
|
12
|
+
after_create :update_status
|
13
|
+
after_destroy :revert_status
|
14
|
+
end
|
15
|
+
|
16
|
+
def sync_trade_item_status
|
17
|
+
self.trade_item_status = trade_item.status
|
18
|
+
end
|
19
|
+
|
20
|
+
def update_status
|
21
|
+
self.trade_item.update status: 'packaged'
|
22
|
+
end
|
23
|
+
|
24
|
+
def revert_status
|
25
|
+
self.trade_item.update status: self.trade_item_status
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Ship
|
2
|
+
module Model::Shipment
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
attribute :state, :string
|
7
|
+
|
8
|
+
belongs_to :package
|
9
|
+
belongs_to :address
|
10
|
+
belongs_to :shipping, polymorphic: true
|
11
|
+
|
12
|
+
enum state: {
|
13
|
+
prepare: 'prepare',
|
14
|
+
packing: 'packing',
|
15
|
+
transporting: 'transporting',
|
16
|
+
dispatching: 'dispatching',
|
17
|
+
received: 'received'
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
data/app/models/ship.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
<div class="<%= active_helper(modules: 'ship/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('ship.admin.addresses.index.title'), { controller: 'ship/admin/addresses' }, class: active_helper(controllers: 'addresses', active: 'is-active') %>
|
4
|
+
<%= link_to t('ship.admin.packages.index.title'), { controller: 'ship/admin/packages' }, class: active_helper(controllers: 'packages', active: 'is-active') -%>
|
5
|
+
<% end %>
|
6
|
+
<a class="menu-label" data-action="menu#toggle">
|
7
|
+
<i class="fas fa-truck fa-fw"></i>
|
8
|
+
<span><%= t('ship.admin.title') %></span>
|
9
|
+
<i class="fas dropdown"></i>
|
10
|
+
</a>
|
11
|
+
</div>
|