rails_ship 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (185) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +20 -0
  3. data/README.md +32 -0
  4. data/Rakefile +32 -0
  5. data/app/controllers/ship/admin/addresses_controller.rb +48 -0
  6. data/app/controllers/ship/admin/base_controller.rb +5 -0
  7. data/app/controllers/ship/admin/home_controller.rb +8 -0
  8. data/app/controllers/ship/admin/packages_controller.rb +43 -0
  9. data/app/controllers/ship/admin/trade_items_controller.rb +72 -0
  10. data/app/controllers/ship/driver/base_controller.rb +9 -0
  11. data/app/controllers/ship/driver/favorites_controller.rb +39 -0
  12. data/app/controllers/ship/my/addresses_controller.rb +58 -0
  13. data/app/controllers/ship/my/base_controller.rb +5 -0
  14. data/app/controllers/ship/my/cars_controller.rb +54 -0
  15. data/app/controllers/ship/my/drivers_controller.rb +38 -0
  16. data/app/controllers/ship/my/favorites_controller.rb +40 -0
  17. data/app/controllers/ship/my/lines_controller.rb +71 -0
  18. data/app/controllers/ship/my/locations_controller.rb +60 -0
  19. data/app/controllers/ship/my/packages_controller.rb +53 -0
  20. data/app/controllers/ship/my/principal_addresses_controller.rb +26 -0
  21. data/app/controllers/ship/panel/base_controller.rb +5 -0
  22. data/app/controllers/ship/panel/lines_controller.rb +53 -0
  23. data/app/controllers/ship/panel/similars_controller.rb +61 -0
  24. data/app/jobs/ship/car_ocr_job.rb +11 -0
  25. data/app/jobs/ship/driver_ocr_job.rb +11 -0
  26. data/app/jobs/ship/location_geo_job.rb +10 -0
  27. data/app/models/ship/address.rb +7 -0
  28. data/app/models/ship/car.rb +5 -0
  29. data/app/models/ship/driver.rb +5 -0
  30. data/app/models/ship/ext/order.rb +7 -0
  31. data/app/models/ship/ext/trade_item.rb +11 -0
  32. data/app/models/ship/ext/user.rb +15 -0
  33. data/app/models/ship/favorite.rb +5 -0
  34. data/app/models/ship/line.rb +5 -0
  35. data/app/models/ship/line_similar.rb +5 -0
  36. data/app/models/ship/location.rb +5 -0
  37. data/app/models/ship/model/address.rb +10 -0
  38. data/app/models/ship/model/car.rb +34 -0
  39. data/app/models/ship/model/driver.rb +45 -0
  40. data/app/models/ship/model/favorite.rb +14 -0
  41. data/app/models/ship/model/line.rb +28 -0
  42. data/app/models/ship/model/line_similar.rb +16 -0
  43. data/app/models/ship/model/location.rb +53 -0
  44. data/app/models/ship/model/package.rb +28 -0
  45. data/app/models/ship/model/packaged.rb +29 -0
  46. data/app/models/ship/model/shipment.rb +22 -0
  47. data/app/models/ship/model/shipping.rb +9 -0
  48. data/app/models/ship/package.rb +6 -0
  49. data/app/models/ship/packaged.rb +5 -0
  50. data/app/models/ship/shipment.rb +5 -0
  51. data/app/models/ship.rb +11 -0
  52. data/app/views/admin/_ship_nav.html.erb +11 -0
  53. data/app/views/panel/_ship_nav.html.erb +10 -0
  54. data/app/views/ship/admin/addresses/_address.html.erb +24 -0
  55. data/app/views/ship/admin/addresses/_edit_form.html.erb +3 -0
  56. data/app/views/ship/admin/addresses/_form.html.erb +9 -0
  57. data/app/views/ship/admin/addresses/index.html.erb +36 -0
  58. data/app/views/ship/admin/base/_nav.html.erb +3 -0
  59. data/app/views/ship/admin/home/index.html.erb +0 -0
  60. data/app/views/ship/admin/packages/_button.html.erb +0 -0
  61. data/app/views/ship/admin/packages/_edit_form.html.erb +4 -0
  62. data/app/views/ship/admin/packages/_filter_form.html.erb +9 -0
  63. data/app/views/ship/admin/packages/_form.html.erb +5 -0
  64. data/app/views/ship/admin/packages/_index_tbody.html.erb +8 -0
  65. data/app/views/ship/admin/packages/_index_thead.html.erb +5 -0
  66. data/app/views/ship/admin/packages/_new_form.html.erb +4 -0
  67. data/app/views/ship/admin/packages/_show_table.html.erb +16 -0
  68. data/app/views/ship/admin/packages/index.html.erb +5 -0
  69. data/app/views/ship/admin/rallies/_filter.html.erb +7 -0
  70. data/app/views/ship/admin/rallies/_form.html+phone.erb +17 -0
  71. data/app/views/ship/admin/rallies/_show_table.html+phone.erb +24 -0
  72. data/app/views/ship/admin/rallies/_show_table.html.erb +12 -0
  73. data/app/views/ship/admin/rallies/index.html+phone.erb +26 -0
  74. data/app/views/ship/admin/rallies/show.html.erb +26 -0
  75. data/app/views/ship/admin/trade_items/_filter.html.erb +9 -0
  76. data/app/views/ship/admin/trade_items/_form.html.erb +7 -0
  77. data/app/views/ship/admin/trade_items/_show_table.html.erb +24 -0
  78. data/app/views/ship/admin/trade_items/index.html.erb +51 -0
  79. data/app/views/ship/driver/favorites/_button.html+phone.erb +4 -0
  80. data/app/views/ship/driver/favorites/_edit_form.html.erb +4 -0
  81. data/app/views/ship/driver/favorites/_filter_form.html+phone.erb +14 -0
  82. data/app/views/ship/driver/favorites/_filter_form.html.erb +9 -0
  83. data/app/views/ship/driver/favorites/_form.html.erb +3 -0
  84. data/app/views/ship/driver/favorites/_index_tbody.html.erb +6 -0
  85. data/app/views/ship/driver/favorites/_index_thead.html.erb +3 -0
  86. data/app/views/ship/driver/favorites/_index_tr.html.erb +4 -0
  87. data/app/views/ship/driver/favorites/_new_form.html.erb +4 -0
  88. data/app/views/ship/driver/favorites/_show_table.html.erb +8 -0
  89. data/app/views/ship/driver/favorites/index.html.erb +5 -0
  90. data/app/views/ship/my/addresses/_edit_form.html.erb +21 -0
  91. data/app/views/ship/my/addresses/_form.html.erb +23 -0
  92. data/app/views/ship/my/addresses/index.html.erb +44 -0
  93. data/app/views/ship/my/cars/_edit_form.html.erb +6 -0
  94. data/app/views/ship/my/cars/_filter_form.html.erb +9 -0
  95. data/app/views/ship/my/cars/_index_tbody.html.erb +3 -0
  96. data/app/views/ship/my/cars/_index_thead.html.erb +4 -0
  97. data/app/views/ship/my/cars/_new_form.html.erb +4 -0
  98. data/app/views/ship/my/cars/_show_table.html.erb +16 -0
  99. data/app/views/ship/my/cars/create.turbo_stream.erb +1 -0
  100. data/app/views/ship/my/cars/index.html+phone.erb +19 -0
  101. data/app/views/ship/my/cars/index.html.erb +5 -0
  102. data/app/views/ship/my/cars/new.html.erb +25 -0
  103. data/app/views/ship/my/drivers/_edit_form.html.erb +6 -0
  104. data/app/views/ship/my/drivers/_form.html.erb +4 -0
  105. data/app/views/ship/my/drivers/_index_tbody.html.erb +3 -0
  106. data/app/views/ship/my/drivers/_index_thead.html.erb +4 -0
  107. data/app/views/ship/my/drivers/_new_form.html.erb +4 -0
  108. data/app/views/ship/my/drivers/_show_table.html.erb +12 -0
  109. data/app/views/ship/my/drivers/_uploader.html.erb +22 -0
  110. data/app/views/ship/my/drivers/edit.html.erb +20 -0
  111. data/app/views/ship/my/drivers/show.html.erb +33 -0
  112. data/app/views/ship/my/favorites/_button.html+phone.erb +4 -0
  113. data/app/views/ship/my/favorites/_edit_form.html.erb +4 -0
  114. data/app/views/ship/my/favorites/_filter_form.html+phone.erb +14 -0
  115. data/app/views/ship/my/favorites/_filter_form.html.erb +9 -0
  116. data/app/views/ship/my/favorites/_form.html.erb +3 -0
  117. data/app/views/ship/my/favorites/_index_tbody.html.erb +6 -0
  118. data/app/views/ship/my/favorites/_index_thead.html.erb +3 -0
  119. data/app/views/ship/my/favorites/_new_form.html.erb +4 -0
  120. data/app/views/ship/my/favorites/_show_table.html.erb +8 -0
  121. data/app/views/ship/my/favorites/index.html.erb +5 -0
  122. data/app/views/ship/my/lines/_edit_form.html.erb +4 -0
  123. data/app/views/ship/my/lines/_filter_form.html.erb +1 -0
  124. data/app/views/ship/my/lines/_form.html.erb +3 -0
  125. data/app/views/ship/my/lines/_index_tbody.html.erb +6 -0
  126. data/app/views/ship/my/lines/_index_tr.html.erb +4 -0
  127. data/app/views/ship/my/lines/_item_field.html.erb +8 -0
  128. data/app/views/ship/my/lines/_item_location.html.erb +13 -0
  129. data/app/views/ship/my/lines/_new_form.html.erb +15 -0
  130. data/app/views/ship/my/lines/_select/_tab_bar.html.erb +10 -0
  131. data/app/views/ship/my/lines/_select.html.erb +10 -0
  132. data/app/views/ship/my/lines/_show/_index_tbody.html.erb +6 -0
  133. data/app/views/ship/my/lines/_show/_index_tr.html+phone.erb +6 -0
  134. data/app/views/ship/my/lines/_show_table.html.erb +9 -0
  135. data/app/views/ship/my/lines/add.turbo_stream.erb +1 -0
  136. data/app/views/ship/my/lines/index.html.erb +5 -0
  137. data/app/views/ship/my/lines/new.html.erb +1 -0
  138. data/app/views/ship/my/lines/requirement.html.erb +5 -0
  139. data/app/views/ship/my/lines/select.turbo_stream.erb +1 -0
  140. data/app/views/ship/my/lines/show.html+phone.erb +30 -0
  141. data/app/views/ship/my/locations/_edit_form.html.erb +4 -0
  142. data/app/views/ship/my/locations/_filter_form.html.erb +9 -0
  143. data/app/views/ship/my/locations/_form.html.erb +6 -0
  144. data/app/views/ship/my/locations/_index_tbody.html.erb +5 -0
  145. data/app/views/ship/my/locations/_index_thead.html.erb +6 -0
  146. data/app/views/ship/my/locations/_new_form.html.erb +4 -0
  147. data/app/views/ship/my/locations/_show_table.html.erb +20 -0
  148. data/app/views/ship/my/locations/index.html.erb +5 -0
  149. data/app/views/ship/my/packages/index.html.erb +31 -0
  150. data/app/views/ship/my/principal_addresses/index.html+phone.erb +32 -0
  151. data/app/views/ship/my/principal_addresses/plans.html+phone.erb +23 -0
  152. data/app/views/ship/my/principal_addresses/show.html+phone.erb +27 -0
  153. data/app/views/ship/panel/base/_nav.html.erb +3 -0
  154. data/app/views/ship/panel/lines/_edit_form.html.erb +4 -0
  155. data/app/views/ship/panel/lines/_filter_form.html.erb +9 -0
  156. data/app/views/ship/panel/lines/_form.html.erb +4 -0
  157. data/app/views/ship/panel/lines/_index_tbody.html.erb +4 -0
  158. data/app/views/ship/panel/lines/_index_thead.html.erb +5 -0
  159. data/app/views/ship/panel/lines/_index_tr.html.erb +19 -0
  160. data/app/views/ship/panel/lines/_new_form.html.erb +4 -0
  161. data/app/views/ship/panel/lines/_show_table.html.erb +12 -0
  162. data/app/views/ship/panel/lines/index.html.erb +5 -0
  163. data/app/views/ship/panel/similars/_breadcrumb.html.erb +7 -0
  164. data/app/views/ship/panel/similars/_button.html.erb +3 -0
  165. data/app/views/ship/panel/similars/_edit_form.html.erb +4 -0
  166. data/app/views/ship/panel/similars/_filter_form.html.erb +9 -0
  167. data/app/views/ship/panel/similars/_form.html.erb +4 -0
  168. data/app/views/ship/panel/similars/_index_tbody.html.erb +3 -0
  169. data/app/views/ship/panel/similars/_index_thead.html.erb +4 -0
  170. data/app/views/ship/panel/similars/_new/_button.html.erb +0 -0
  171. data/app/views/ship/panel/similars/_new/_index_tr.html.erb +10 -0
  172. data/app/views/ship/panel/similars/_new/_index_tr_remove.html.erb +10 -0
  173. data/app/views/ship/panel/similars/_new_form.html.erb +4 -0
  174. data/app/views/ship/panel/similars/_show_table.html.erb +12 -0
  175. data/app/views/ship/panel/similars/create.turbo_stream.erb +3 -0
  176. data/app/views/ship/panel/similars/destroy.turbo_stream.erb +3 -0
  177. data/app/views/ship/panel/similars/index.html.erb +5 -0
  178. data/app/views/ship/panel/similars/new.html.erb +16 -0
  179. data/config/locales/zh.attributes.yml +15 -0
  180. data/config/locales/zh.yml +51 -0
  181. data/config/routes.rb +66 -0
  182. data/lib/rails_ship/config.rb +11 -0
  183. data/lib/rails_ship/engine.rb +21 -0
  184. data/lib/rails_ship.rb +2 -0
  185. 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,5 @@
1
+ module Ship
2
+ class Panel::BaseController < PanelController
3
+
4
+ end
5
+ 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,11 @@
1
+ module Ship
2
+ class CarOcrJob < ApplicationJob
3
+
4
+ def perform(car)
5
+ car.ocr
6
+ car.for_update
7
+ end
8
+
9
+ end
10
+ end
11
+
@@ -0,0 +1,11 @@
1
+ module Ship
2
+ class DriverOcrJob < ApplicationJob
3
+
4
+ def perform(driver)
5
+ driver.ocr
6
+ driver.for_update
7
+ end
8
+
9
+ end
10
+ end
11
+
@@ -0,0 +1,10 @@
1
+ module Ship
2
+ class LocationGeoJob < ApplicationJob
3
+
4
+ def perform(location)
5
+ location.geo
6
+ end
7
+
8
+ end
9
+ end
10
+
@@ -0,0 +1,7 @@
1
+ module Ship
2
+ class Address < ApplicationRecord
3
+ self.table_name = 'profiled_addresses'
4
+ include Model::Address
5
+ include Profiled::Model::Address
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ module Ship
2
+ class Car < ApplicationRecord
3
+ include Model::Car
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module Ship
2
+ class Driver < ApplicationRecord
3
+ include Model::Driver
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ module Ship
2
+ module Ext::Order
3
+ extend ActiveSupport::Concern
4
+
5
+
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ module Ship
2
+ module Ext::TradeItem
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ has_many :packageds, class_name: 'Ship::Packaged', dependent: :delete_all
7
+ has_many :packages, class_name: 'Ship::Package', through: :packageds
8
+ end
9
+
10
+ end
11
+ 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,5 @@
1
+ module Ship
2
+ class Favorite < ApplicationRecord
3
+ include Model::Favorite
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module Ship
2
+ class Line < ApplicationRecord
3
+ include Model::Line
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module Ship
2
+ class LineSimilar < ApplicationRecord
3
+ include Model::LineSimilar
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module Ship
2
+ class Location < ApplicationRecord
3
+ include Model::Location
4
+ end
5
+ end
@@ -0,0 +1,10 @@
1
+ module Ship
2
+ module Model::Address
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ has_many :packages
7
+ end
8
+
9
+ end
10
+ 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,14 @@
1
+ module Ship
2
+ module Model::Favorite
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ attribute :remark, :string
7
+
8
+ belongs_to :user, class_name: 'Auth::User'
9
+
10
+ belongs_to :driver
11
+ end
12
+
13
+ end
14
+ 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
@@ -0,0 +1,9 @@
1
+ module Ship
2
+ module Model::Shipping
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ end
7
+
8
+ end
9
+ end
@@ -0,0 +1,6 @@
1
+ module Ship
2
+ class Package < ApplicationRecord
3
+ include Model::Package
4
+ include Wait::Ext::Waiting if defined? RailsWait
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ module Ship
2
+ class Packaged < ApplicationRecord
3
+ include Model::Packaged
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module Ship
2
+ class Shipment < ApplicationRecord
3
+ include Model::Shipment
4
+ end
5
+ end
@@ -0,0 +1,11 @@
1
+ module Ship
2
+
3
+ def self.use_relative_model_naming?
4
+ true
5
+ end
6
+
7
+ def self.table_name_prefix
8
+ 'ship_'
9
+ end
10
+
11
+ end
@@ -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>