unidom-order 2.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/controllers/unidom/order/application_controller.rb +8 -2
- data/app/helpers/unidom/order/application_helper.rb +7 -1
- data/app/jobs/unidom/order/application_job.rb +7 -1
- data/app/mailers/unidom/order/application_mailer.rb +9 -3
- data/app/models/unidom/order/application_record.rb +8 -2
- data/app/models/unidom/order/concerns/as_adjusted.rb +34 -26
- data/app/models/unidom/order/concerns/as_order_placer.rb +15 -7
- data/app/models/unidom/order/concerns/as_order_taker.rb +15 -7
- data/app/models/unidom/order/order.rb +19 -13
- data/app/models/unidom/order/order_adjustment.rb +36 -30
- data/app/models/unidom/order/order_item.rb +44 -38
- data/app/types/unidom/order/adjustment_factor.rb +9 -3
- data/app/views/layouts/unidom/order/application.html.erb +1 -1
- data/db/migrate/20020601000000_create_unidom_orders.rb +2 -2
- data/db/migrate/20020602000000_create_unidom_order_items.rb +3 -3
- data/db/migrate/20020603000000_create_unidom_order_adjustments.rb +2 -2
- data/lib/unidom/order/version.rb +1 -1
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 65be3c651c2b77bfef5f74d06723a94f8b36c060a3418be80c8c92322ebe4c4c
|
4
|
+
data.tar.gz: 662944e10031a663cda34bec754b4ad465021f286b5ab9efd3a126dd81e2ab7a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f6b87ba705f596f32aa92e97e5e228fbecebc64da2bbae6b9de470abcb11e71ac3d0ff132e4c00d3411697b2907e8ea2bf0677ddd67e16d7fe818a5e3058ce9c
|
7
|
+
data.tar.gz: f2e5a93ece0a2de244afbe19783ec093c4cfe99e7b55a3c5cc781a3737243553e1600f4f12f8894d0b0dce4d123038b181a310de118159a175ac9c084e38d06d
|
@@ -1,6 +1,12 @@
|
|
1
1
|
##
|
2
2
|
# Application controller 是模块内所有控制器的基类。
|
3
3
|
|
4
|
-
|
5
|
-
|
4
|
+
module Unidom
|
5
|
+
module Order
|
6
|
+
|
7
|
+
class ApplicationController < ActionController::Base
|
8
|
+
protect_from_forgery with: :exception
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
6
12
|
end
|
@@ -1,7 +1,13 @@
|
|
1
1
|
##
|
2
2
|
# Application mailer 是模块内所有电子邮件发送类的基类。
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
module Unidom
|
5
|
+
module Order
|
6
|
+
|
7
|
+
class ApplicationMailer < ActionMailer::Base
|
8
|
+
default from: 'from@example.com'
|
9
|
+
layout 'mailer'
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
7
13
|
end
|
@@ -1,6 +1,12 @@
|
|
1
1
|
##
|
2
2
|
# Application record 是模块内所有模型的抽象基类。
|
3
3
|
|
4
|
-
|
5
|
-
|
4
|
+
module Unidom
|
5
|
+
module Order
|
6
|
+
|
7
|
+
class ApplicationRecord < ActiveRecord::Base
|
8
|
+
self.abstract_class = true
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
6
12
|
end
|
@@ -1,34 +1,42 @@
|
|
1
|
-
module Unidom
|
1
|
+
module Unidom
|
2
|
+
module Order
|
3
|
+
module Concerns
|
4
|
+
|
5
|
+
module AsAdjusted
|
6
|
+
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
|
9
|
+
included do |includer|
|
10
|
+
|
11
|
+
has_many :adjustments, class_name: 'Unidom::Order::OrderAdjustment', as: :adjusted
|
12
|
+
|
13
|
+
def is_adjusted!(amount, due_to: 'FRGT', at: Time.now)
|
14
|
+
query = adjustments.adjustment_factor_coded_as(due_to).valid_at(now: at).alive
|
15
|
+
adjustment = query.first
|
16
|
+
if adjustment.present?
|
17
|
+
if 0==amount
|
18
|
+
adjustment.soft_destroy
|
19
|
+
else
|
20
|
+
adjustment.amount = amount
|
21
|
+
adjustment.save!
|
22
|
+
end
|
23
|
+
else
|
24
|
+
adjustment = query.create! amount: amount, opened_at: at
|
25
|
+
end
|
26
|
+
adjustment
|
27
|
+
end
|
28
|
+
|
29
|
+
def is_adjusted?(due_to: 'FRGT', at: Time.now)
|
30
|
+
adjustments.adjustment_factor_coded_as(due_to).valid_at(now: at).alive.exists?
|
31
|
+
end
|
2
32
|
|
3
|
-
|
4
|
-
|
5
|
-
included do |includer|
|
6
|
-
|
7
|
-
has_many :adjustments, class_name: 'Unidom::Order::OrderAdjustment', as: :adjusted
|
33
|
+
end
|
8
34
|
|
9
|
-
|
10
|
-
query = adjustments.adjustment_factor_coded_as(due_to).valid_at(now: at).alive
|
11
|
-
adjustment = query.first
|
12
|
-
if adjustment.present?
|
13
|
-
if 0==amount
|
14
|
-
adjustment.soft_destroy
|
15
|
-
else
|
16
|
-
adjustment.amount = amount
|
17
|
-
adjustment.save!
|
35
|
+
module ClassMethods
|
18
36
|
end
|
19
|
-
|
20
|
-
adjustment = query.create! amount: amount, opened_at: at
|
37
|
+
|
21
38
|
end
|
22
|
-
adjustment
|
23
|
-
end
|
24
39
|
|
25
|
-
def is_adjusted?(due_to: 'FRGT', at: Time.now)
|
26
|
-
adjustments.adjustment_factor_coded_as(due_to).valid_at(now: at).alive.exists?
|
27
40
|
end
|
28
|
-
|
29
|
-
end
|
30
|
-
|
31
|
-
module ClassMethods
|
32
41
|
end
|
33
|
-
|
34
42
|
end
|
@@ -1,14 +1,22 @@
|
|
1
|
-
module Unidom
|
1
|
+
module Unidom
|
2
|
+
module Order
|
3
|
+
module Concerns
|
2
4
|
|
3
|
-
|
5
|
+
module AsOrderPlacer
|
4
6
|
|
5
|
-
|
7
|
+
extend ActiveSupport::Concern
|
6
8
|
|
7
|
-
|
9
|
+
included do |includer|
|
8
10
|
|
9
|
-
|
11
|
+
has_many :placed_orders, class_name: 'Unidom::Order::Order', as: :placer
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
+
end
|
14
|
+
|
15
|
+
module ClassMethods
|
16
|
+
end
|
13
17
|
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
14
22
|
end
|
@@ -1,14 +1,22 @@
|
|
1
|
-
module Unidom
|
1
|
+
module Unidom
|
2
|
+
module Order
|
3
|
+
module Concerns
|
2
4
|
|
3
|
-
|
5
|
+
module AsOrderTaker
|
4
6
|
|
5
|
-
|
7
|
+
extend ActiveSupport::Concern
|
6
8
|
|
7
|
-
|
9
|
+
included do |includer|
|
8
10
|
|
9
|
-
|
11
|
+
has_many :taken_orders, class_name: 'Unidom::Order::Order', as: :taker
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
+
end
|
14
|
+
|
15
|
+
module ClassMethods
|
16
|
+
end
|
13
17
|
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
14
22
|
end
|
@@ -1,23 +1,29 @@
|
|
1
1
|
##
|
2
2
|
# Order 是订单。
|
3
3
|
|
4
|
-
|
4
|
+
module Unidom
|
5
|
+
module Order
|
5
6
|
|
6
|
-
|
7
|
+
class Order < ApplicationRecord
|
7
8
|
|
8
|
-
|
9
|
-
include Unidom::Order::Concerns::AsAdjusted
|
9
|
+
self.table_name = 'unidom_orders'
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
validates :aggregate_amount, presence: true, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 1_000_000_000 }
|
11
|
+
include Unidom::Common::Concerns::ModelExtension
|
12
|
+
include Unidom::Order::Concerns::AsAdjusted
|
14
13
|
|
15
|
-
|
16
|
-
|
14
|
+
validates :number, presence: true, length: { is: self.columns_hash['number'].limit }
|
15
|
+
validates :purchase_amount, presence: true, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 1_000_000_000 }
|
16
|
+
validates :aggregate_amount, presence: true, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 1_000_000_000 }
|
17
17
|
|
18
|
-
|
18
|
+
belongs_to :placer, polymorphic: true
|
19
|
+
belongs_to :taker, polymorphic: true
|
19
20
|
|
20
|
-
|
21
|
-
scope :taken_by, ->(taker) { where taker: taker }
|
21
|
+
has_many :items, class_name: 'Unidom::Order::OrderItem'
|
22
22
|
|
23
|
-
|
23
|
+
scope :placed_by, ->(placer) { where placer: placer }
|
24
|
+
scope :taken_by, ->(taker) { where taker: taker }
|
25
|
+
|
26
|
+
end unless Unidom::Common::Neglection.namespace_neglected? 'Unidom::Order::Order'
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
@@ -1,44 +1,50 @@
|
|
1
1
|
##
|
2
2
|
# Order Adjustment 是订单调整项。
|
3
3
|
|
4
|
-
|
4
|
+
module Unidom
|
5
|
+
module Order
|
5
6
|
|
6
|
-
|
7
|
+
class OrderAdjustment < ApplicationRecord
|
7
8
|
|
8
|
-
|
9
|
-
include ProgneTapera::EnumCode
|
9
|
+
self.table_name = 'unidom_order_adjustments'
|
10
10
|
|
11
|
-
|
11
|
+
include Unidom::Common::Concerns::ModelExtension
|
12
|
+
include ProgneTapera::EnumCode
|
12
13
|
|
13
|
-
|
14
|
+
validates :amount, presence: true, numericality: { greater_than_or_equal_to: -1_000_000_000, less_than_or_equal_to: 1_000_000_000 }
|
14
15
|
|
15
|
-
|
16
|
+
belongs_to :adjusted, polymorphic: true
|
16
17
|
|
17
|
-
|
18
|
+
scope :adjusted_is, ->(adjusted) { where adjusted: adjusted }
|
18
19
|
|
19
|
-
|
20
|
-
# 对订单或者订单项 adjusted 进行调整。调整金额为 amount ,缺省为 0 。调整原因是 due_to ,缺省是 FRGT 。调整时间是 opened_at ,缺省为当前时间。如:
|
21
|
-
# Unidom::Order::OrderAdjustment.adjust! order, amount: 7.90, due_to: 'LTAX'
|
22
|
-
def self.adjust!(adjusted, amount: 0, due_to: 'FRGT', opened_at: Time.now)
|
20
|
+
code :adjustment_factor, Unidom::Order::AdjustmentFactor
|
23
21
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
22
|
+
##
|
23
|
+
# 对订单或者订单项 adjusted 进行调整。调整金额为 amount ,缺省为 0 。调整原因是 due_to ,缺省是 FRGT 。调整时间是 opened_at ,缺省为当前时间。如:
|
24
|
+
# Unidom::Order::OrderAdjustment.adjust! order, amount: 7.90, due_to: 'LTAX'
|
25
|
+
def self.adjust!(adjusted, amount: 0, due_to: 'FRGT', opened_at: Time.now)
|
28
26
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
adjustment
|
36
|
-
adjustment.
|
27
|
+
assert_present! :adjusted, adjusted
|
28
|
+
assert_present! :amount, amount
|
29
|
+
assert_present! :due_to, due_to
|
30
|
+
assert_present! :opened_at, opened_at
|
31
|
+
|
32
|
+
query = adjusted_is(adjusted).adjustment_factor_coded_as(due_to).valid_at(now: opened_at).alive
|
33
|
+
adjustment = query.first
|
34
|
+
if adjustment.present?
|
35
|
+
if 0==amount
|
36
|
+
adjustment.soft_destroy
|
37
|
+
else
|
38
|
+
adjustment.amount = amount
|
39
|
+
adjustment.save!
|
40
|
+
end
|
41
|
+
else
|
42
|
+
adjustment = query.create! amount: amount, opened_at: opened_at
|
43
|
+
end
|
44
|
+
adjustment
|
37
45
|
end
|
38
|
-
else
|
39
|
-
adjustment = query.create! amount: amount, opened_at: opened_at
|
40
|
-
end
|
41
|
-
adjustment
|
42
|
-
end
|
43
46
|
|
44
|
-
end unless Unidom::Common::Neglection.namespace_neglected? 'Unidom::Order::OrderAdjustment'
|
47
|
+
end unless Unidom::Common::Neglection.namespace_neglected? 'Unidom::Order::OrderAdjustment'
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
@@ -1,42 +1,48 @@
|
|
1
1
|
##
|
2
2
|
# Order Item 是订单项。
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
4
|
+
module Unidom
|
5
|
+
module Order
|
6
|
+
|
7
|
+
class OrderItem < ApplicationRecord
|
8
|
+
|
9
|
+
self.table_name = 'unidom_order_items'
|
10
|
+
|
11
|
+
include Unidom::Common::Concerns::ModelExtension
|
12
|
+
include Unidom::Order::Concerns::AsAdjusted
|
13
|
+
|
14
|
+
#validates :ordinal, presence: true, numericality: { only_integer: true, greater_than: 0, less_than: 1_000_000_000 }
|
15
|
+
validates :unit_price, presence: true, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 1_000_000_000 }
|
16
|
+
validates :quantity, presence: true, numericality: { greater_than: 0, less_than_or_equal_to: 1_000_000_000 }
|
17
|
+
validates :purchase_amount, presence: true, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 1_000_000_000 }
|
18
|
+
validates :subtotal_amount, presence: true, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 1_000_000_000 }
|
19
|
+
|
20
|
+
belongs_to :order, class_name: 'Unidom::Order::Order'
|
21
|
+
belongs_to :ordered, polymorphic: true
|
22
|
+
belongs_to :placer, polymorphic: true
|
23
|
+
|
24
|
+
scope :order_is, ->(order) { where order: order }
|
25
|
+
scope :ordered_is, ->(ordered) { where ordered: ordered }
|
26
|
+
scope :placed_by, ->(placer) { where placer: placer }
|
27
|
+
|
28
|
+
##
|
29
|
+
# 订购商品 ordered ,放入订单 of 。订购者为 by ,缺省为订单的下单者。单价为 unit_price ,缺省值为 0 。数量为 quantity ,缺省值为 1。如:
|
30
|
+
# Unidom::Order::OrderItem.order! coca_cola, of: order, by: current_person, unit_price: 3.50, quantity: 2
|
31
|
+
def self.order!(ordered, of: nil, by: of.placer, unit_price: 0, quantity: 1)
|
32
|
+
item = of.items.ordered_is(ordered).placed_by(by).valid_at.alive.first
|
33
|
+
if item.present?
|
34
|
+
item.quantity += quantity
|
35
|
+
item.unit_price = unit_price
|
36
|
+
item.purchase_amount = item.unit_price*item.quantity
|
37
|
+
item.subtotal_amount = item.purchase_amount+item.adjustments.valid_at.alive.sum(:amount).to_f
|
38
|
+
item.save!
|
39
|
+
else
|
40
|
+
ordinal = 1+of.items.valid_at.alive.maximum(:ordinal).to_i
|
41
|
+
of.items.create! ordered: ordered, placer: by, ordinal: ordinal, quantity: quantity, unit_price: unit_price, purchase_amount: unit_price*quantity, subtotal_amount: unit_price*quantity, opened_at: Time.now
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
end unless Unidom::Common::Neglection.namespace_neglected? 'Unidom::Order::OrderItem'
|
41
46
|
|
42
|
-
end
|
47
|
+
end
|
48
|
+
end
|
@@ -1,9 +1,15 @@
|
|
1
1
|
# Adjustment Factor 是调整因素。
|
2
2
|
|
3
|
-
|
3
|
+
module Unidom
|
4
|
+
module Order
|
4
5
|
|
5
|
-
|
6
|
+
class AdjustmentFactor < ActiveRecord::Type::Value
|
6
7
|
|
7
|
-
|
8
|
+
include ProgneTapera::EnumConfig
|
8
9
|
|
10
|
+
enum :unidom_adjustment_factor
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
9
15
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
class CreateUnidomOrders < ActiveRecord::Migration
|
1
|
+
class CreateUnidomOrders < ActiveRecord::Migration[6.0]
|
2
2
|
|
3
3
|
def change
|
4
4
|
|
@@ -18,7 +18,7 @@ class CreateUnidomOrders < ActiveRecord::Migration
|
|
18
18
|
t.text :description
|
19
19
|
|
20
20
|
t.string :slug, null: false, default: nil, limit: 200
|
21
|
-
t.column :state, 'char(1)', null: false, default:
|
21
|
+
t.column :state, 'char(1)', null: false, default: Unidom::Common::STATE
|
22
22
|
t.datetime :opened_at, null: false, default: Unidom::Common::OPENED_AT
|
23
23
|
t.datetime :closed_at, null: false, default: Unidom::Common::CLOSED_AT
|
24
24
|
t.boolean :defunct, null: false, default: false
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# Order Item 是订单项。
|
2
2
|
|
3
|
-
class CreateUnidomOrderItems < ActiveRecord::Migration
|
3
|
+
class CreateUnidomOrderItems < ActiveRecord::Migration[6.0]
|
4
4
|
|
5
5
|
def change
|
6
6
|
|
@@ -22,7 +22,7 @@ class CreateUnidomOrderItems < ActiveRecord::Migration
|
|
22
22
|
t.text :instruction
|
23
23
|
t.text :description
|
24
24
|
|
25
|
-
t.column :state, 'char(1)', null: false, default:
|
25
|
+
t.column :state, 'char(1)', null: false, default: Unidom::Common::STATE
|
26
26
|
t.datetime :opened_at, null: false, default: Unidom::Common::OPENED_AT
|
27
27
|
t.datetime :closed_at, null: false, default: Unidom::Common::CLOSED_AT
|
28
28
|
t.boolean :defunct, null: false, default: false
|
@@ -32,7 +32,7 @@ class CreateUnidomOrderItems < ActiveRecord::Migration
|
|
32
32
|
|
33
33
|
end
|
34
34
|
|
35
|
-
add_index :unidom_order_items, :order_id
|
35
|
+
#add_index :unidom_order_items, :order_id
|
36
36
|
add_index :unidom_order_items, :ordered_id
|
37
37
|
add_index :unidom_order_items, :placer_id
|
38
38
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
class CreateUnidomOrderAdjustments < ActiveRecord::Migration
|
1
|
+
class CreateUnidomOrderAdjustments < ActiveRecord::Migration[6.0]
|
2
2
|
|
3
3
|
def change
|
4
4
|
|
@@ -15,7 +15,7 @@ class CreateUnidomOrderAdjustments < ActiveRecord::Migration
|
|
15
15
|
t.text :instruction
|
16
16
|
t.text :description
|
17
17
|
|
18
|
-
t.column :state, 'char(1)', null: false, default:
|
18
|
+
t.column :state, 'char(1)', null: false, default: Unidom::Common::STATE
|
19
19
|
t.datetime :opened_at, null: false, default: Unidom::Common::OPENED_AT
|
20
20
|
t.datetime :closed_at, null: false, default: Unidom::Common::CLOSED_AT
|
21
21
|
t.boolean :defunct, null: false, default: false
|
data/lib/unidom/order/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: unidom-order
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Topbit Du
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-08-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: unidom-common
|
@@ -72,11 +72,11 @@ files:
|
|
72
72
|
- lib/unidom/order/types_rspec.rb
|
73
73
|
- lib/unidom/order/validators_rspec.rb
|
74
74
|
- lib/unidom/order/version.rb
|
75
|
-
homepage: https://
|
75
|
+
homepage: https://gitee.com/Unidom/unidom-order
|
76
76
|
licenses:
|
77
77
|
- MIT
|
78
78
|
metadata: {}
|
79
|
-
post_install_message:
|
79
|
+
post_install_message:
|
80
80
|
rdoc_options: []
|
81
81
|
require_paths:
|
82
82
|
- lib
|
@@ -91,8 +91,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
91
91
|
- !ruby/object:Gem::Version
|
92
92
|
version: '0'
|
93
93
|
requirements: []
|
94
|
-
rubygems_version: 3.
|
95
|
-
signing_key:
|
94
|
+
rubygems_version: 3.2.3
|
95
|
+
signing_key:
|
96
96
|
specification_version: 4
|
97
97
|
summary: Unidom Order Domain Model Engine 订单领域模型引擎
|
98
98
|
test_files: []
|