unidom-price 2.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/unidom/price/application_controller.rb +8 -2
- data/app/helpers/unidom/price/application_helper.rb +7 -1
- data/app/jobs/unidom/price/application_job.rb +7 -1
- data/app/mailers/unidom/price/application_mailer.rb +9 -3
- data/app/models/unidom/price/application_record.rb +8 -2
- data/app/models/unidom/price/concerns/as_priced.rb +28 -20
- data/app/models/unidom/price/concerns/as_pricer.rb +28 -20
- data/app/models/unidom/price/price.rb +55 -49
- data/app/types/unidom/price/calculation.rb +9 -3
- data/app/types/unidom/price/charging.rb +9 -3
- data/app/types/unidom/price/pricing.rb +9 -3
- data/app/views/layouts/unidom/price/application.html.erb +1 -1
- data/db/migrate/20020301000000_create_unidom_prices.rb +1 -1
- data/lib/unidom/price/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: 0eceb203e83e315331b5a2dbf77638805322c64aa743505f753dfc6fb276c637
|
4
|
+
data.tar.gz: fe3e9e23fe9bc7d0bce917cefd64e18795e1f178563e32d0447747d86545580b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6907d5214cb8233c422a896c1b9835c12eb6e03768de40bb34c7f04210b05fc10cffff4b484b12cbe83438cdac23cdb6ee7818ad96bf7f592d099bf5aecdc3f1
|
7
|
+
data.tar.gz: c86b2fe7ba4c9b8da9f47606872b909a6c020dcb4747a87b95ac886d9b3ca279cbb9764cd9f2981cb9be02e7813201a0dc7a254a04318fb980003086719d3697
|
@@ -1,6 +1,12 @@
|
|
1
1
|
##
|
2
2
|
# Application controller 是模块内所有控制器的基类。
|
3
3
|
|
4
|
-
|
5
|
-
|
4
|
+
module Unidom
|
5
|
+
module Price
|
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 Price
|
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 Price
|
6
|
+
|
7
|
+
class ApplicationRecord < ActiveRecord::Base
|
8
|
+
self.abstract_class = true
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
6
12
|
end
|
@@ -1,38 +1,46 @@
|
|
1
1
|
##
|
2
2
|
# As Priced 是被定价物品的领域逻辑关注点。
|
3
3
|
|
4
|
-
module Unidom
|
4
|
+
module Unidom
|
5
|
+
module Price
|
6
|
+
module Concerns
|
5
7
|
|
6
|
-
|
7
|
-
include Unidom::Common::Concerns::ArgumentValidation
|
8
|
+
module AsPriced
|
8
9
|
|
9
|
-
|
10
|
+
extend ActiveSupport::Concern
|
11
|
+
include Unidom::Common::Concerns::ArgumentValidation
|
10
12
|
|
11
|
-
|
13
|
+
included do |includer|
|
12
14
|
|
13
|
-
|
15
|
+
has_many :prices, class_name: 'Unidom::Price::Price', as: :priced
|
14
16
|
|
15
|
-
|
16
|
-
assert_present! :by, by
|
17
|
-
assert_present! :at, at
|
17
|
+
def is_priced!(amount, by: nil, at: Time.now)
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
assert_present! :amount, amount
|
20
|
+
assert_present! :by, by
|
21
|
+
assert_present! :at, at
|
22
22
|
|
23
|
-
|
23
|
+
pricing = prices.valid_at(now: at).alive.first
|
24
|
+
pricing.soft_destroy if pricing.present?
|
25
|
+
prices.create! pricer: by, amount: amount, opened_at: at
|
24
26
|
|
25
|
-
|
27
|
+
end
|
26
28
|
|
27
|
-
|
29
|
+
def is_priced?(at: Time.now)
|
28
30
|
|
29
|
-
|
31
|
+
assert_present! :at, at
|
30
32
|
|
31
|
-
|
33
|
+
prices.valid_at(now: at).alive.exists?
|
32
34
|
|
33
|
-
|
35
|
+
end
|
34
36
|
|
35
|
-
|
36
|
-
end
|
37
|
+
end
|
37
38
|
|
39
|
+
module ClassMethods
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
38
46
|
end
|
@@ -1,38 +1,46 @@
|
|
1
1
|
##
|
2
2
|
# As Pricer 是定价者的领域逻辑关注点。
|
3
3
|
|
4
|
-
module Unidom
|
4
|
+
module Unidom
|
5
|
+
module Price
|
6
|
+
module Concerns
|
5
7
|
|
6
|
-
|
8
|
+
module AsPricer
|
7
9
|
|
8
|
-
|
10
|
+
extend ActiveSupport::Concern
|
9
11
|
|
10
|
-
|
12
|
+
included do |includer|
|
11
13
|
|
12
|
-
|
14
|
+
has_many :pricings, class_name: 'Unidom::Price::Price', as: :pricer
|
13
15
|
|
14
|
-
|
15
|
-
assert_present! :amount, amount
|
16
|
-
assert_present! :at, at
|
16
|
+
def price!(it, amount, at: Time.now)
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
assert_present! :it, it
|
19
|
+
assert_present! :amount, amount
|
20
|
+
assert_present! :at, at
|
21
21
|
|
22
|
-
|
22
|
+
pricing = pricings.priced_is(it).valid_at(now: at).alive.first
|
23
|
+
pricing.soft_destroy if pricing.present?
|
24
|
+
pricings.create! priced: it, amount: amount, opened_at: at
|
23
25
|
|
24
|
-
|
26
|
+
end
|
25
27
|
|
26
|
-
|
27
|
-
assert_present! :at, at
|
28
|
+
def price?(it, at: Time.now)
|
28
29
|
|
29
|
-
|
30
|
+
assert_present! :it, it
|
31
|
+
assert_present! :at, at
|
30
32
|
|
31
|
-
|
33
|
+
pricings.priced_is(it).valid_at(now: at).alive.exists?
|
32
34
|
|
33
|
-
|
35
|
+
end
|
34
36
|
|
35
|
-
|
36
|
-
end
|
37
|
+
end
|
37
38
|
|
39
|
+
module ClassMethods
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
38
46
|
end
|
@@ -2,55 +2,61 @@
|
|
2
2
|
# pricing: 基价(Base)、折扣成分、额外收费成分、厂商建议价。
|
3
3
|
# charging: 一次性收费、重复性收费、使用率收费。
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
5
|
+
module Unidom
|
6
|
+
module Price
|
7
|
+
|
8
|
+
class Price < ApplicationRecord
|
9
|
+
|
10
|
+
self.table_name = 'unidom_prices'
|
11
|
+
|
12
|
+
include Unidom::Common::Concerns::ModelExtension
|
13
|
+
include ProgneTapera::EnumCode
|
14
|
+
|
15
|
+
validates :amount, presence: true, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 1_000_000_000 }
|
16
|
+
|
17
|
+
belongs_to :priced, polymorphic: true
|
18
|
+
belongs_to :pricer, polymorphic: true
|
19
|
+
|
20
|
+
scope :priced_by, ->(pricer) { where pricer: pricer }
|
21
|
+
scope :priced_is, ->(priced) { where priced: priced }
|
22
|
+
|
23
|
+
code :calculation, Unidom::Price::Calculation
|
24
|
+
code :charging, Unidom::Price::Charging
|
25
|
+
code :pricing, Unidom::Price::Pricing
|
26
|
+
|
27
|
+
##
|
28
|
+
# 将物品 priced 定价为 amount , 定价者是 pricer。
|
29
|
+
def self.price!(priced, amount: 0, pricer: nil, calculation_code: 'AMNT', pricing_code: 'BASE', charging_code: 'ONCE', opened_at: Time.now)
|
30
|
+
|
31
|
+
assert_present! :priced, priced
|
32
|
+
assert_present! :amount, amount
|
33
|
+
assert_present! :calculation_code, calculation_code
|
34
|
+
assert_present! :pricing_code, pricing_code
|
35
|
+
assert_present! :charging_code, charging_code
|
36
|
+
assert_present! :opened_at, opened_at
|
37
|
+
|
38
|
+
price = priced_is(priced).calculation_coded_as(calculation_code).pricing_coded_as(pricing_code).charging_coded_as(charging_code).valid_at.alive.first
|
39
|
+
if price.present?
|
40
|
+
price.amount = amount
|
41
|
+
if pricer.present?
|
42
|
+
price.pricer = pricer
|
43
|
+
else
|
44
|
+
price.pricer_id = Unidom::Common::NULL_UUID
|
45
|
+
price.pricer_type = ''
|
46
|
+
end
|
47
|
+
else
|
48
|
+
attributes = { priced: priced, amount: amount, calculation_code: calculation_code, pricing_code: pricing_code, charging_code: charging_code, opened_at: opened_at }
|
49
|
+
if pricer.present?
|
50
|
+
attributes[:pricer] = pricer
|
51
|
+
else
|
52
|
+
attributes[:pricer_id] = Unidom::Common::NULL_UUID
|
53
|
+
attributes[:pricer_type] = ''
|
54
|
+
end
|
55
|
+
create! attributes
|
56
|
+
end
|
57
|
+
end
|
27
58
|
|
28
|
-
|
29
|
-
assert_present! :amount, amount
|
30
|
-
assert_present! :calculation_code, calculation_code
|
31
|
-
assert_present! :pricing_code, pricing_code
|
32
|
-
assert_present! :charging_code, charging_code
|
33
|
-
assert_present! :opened_at, opened_at
|
59
|
+
end unless Unidom::Common::Neglection.namespace_neglected? 'Unidom::Price::Price'
|
34
60
|
|
35
|
-
price = priced_is(priced).calculation_coded_as(calculation_code).pricing_coded_as(pricing_code).charging_coded_as(charging_code).valid_at.alive.first
|
36
|
-
if price.present?
|
37
|
-
price.amount = amount
|
38
|
-
if pricer.present?
|
39
|
-
price.pricer = pricer
|
40
|
-
else
|
41
|
-
price.pricer_id = Unidom::Common::NULL_UUID
|
42
|
-
price.pricer_type = ''
|
43
|
-
end
|
44
|
-
else
|
45
|
-
attributes = { priced: priced, amount: amount, calculation_code: calculation_code, pricing_code: pricing_code, charging_code: charging_code, opened_at: opened_at }
|
46
|
-
if pricer.present?
|
47
|
-
attributes[:pricer] = pricer
|
48
|
-
else
|
49
|
-
attributes[:pricer_id] = Unidom::Common::NULL_UUID
|
50
|
-
attributes[:pricer_type] = ''
|
51
|
-
end
|
52
|
-
create! attributes
|
53
|
-
end
|
54
61
|
end
|
55
|
-
|
56
|
-
end unless Unidom::Common::Neglection.namespace_neglected? 'Unidom::Price::Price'
|
62
|
+
end
|
@@ -1,7 +1,13 @@
|
|
1
|
-
|
1
|
+
module Unidom
|
2
|
+
module Price
|
2
3
|
|
3
|
-
|
4
|
+
class Calculation < ActiveRecord::Type::Value
|
4
5
|
|
5
|
-
|
6
|
+
include ProgneTapera::EnumConfig
|
6
7
|
|
8
|
+
enum :unidom_calculation
|
9
|
+
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
7
13
|
end
|
@@ -1,7 +1,13 @@
|
|
1
|
-
|
1
|
+
module Unidom
|
2
|
+
module Price
|
2
3
|
|
3
|
-
|
4
|
+
class Charging < ActiveRecord::Type::Value
|
4
5
|
|
5
|
-
|
6
|
+
include ProgneTapera::EnumConfig
|
6
7
|
|
8
|
+
enum :unidom_charging
|
9
|
+
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
7
13
|
end
|
@@ -1,7 +1,13 @@
|
|
1
|
-
|
1
|
+
module Unidom
|
2
|
+
module Price
|
2
3
|
|
3
|
-
|
4
|
+
class Pricing < ActiveRecord::Type::Value
|
4
5
|
|
5
|
-
|
6
|
+
include ProgneTapera::EnumConfig
|
6
7
|
|
8
|
+
enum :unidom_pricing
|
9
|
+
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
7
13
|
end
|
data/lib/unidom/price/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: unidom-price
|
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-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: unidom-common
|
@@ -68,11 +68,11 @@ files:
|
|
68
68
|
- lib/unidom/price/types_rspec.rb
|
69
69
|
- lib/unidom/price/validators_rspec.rb
|
70
70
|
- lib/unidom/price/version.rb
|
71
|
-
homepage: https://
|
71
|
+
homepage: https://gitee.com/Unidom/unidom-price
|
72
72
|
licenses:
|
73
73
|
- MIT
|
74
74
|
metadata: {}
|
75
|
-
post_install_message:
|
75
|
+
post_install_message:
|
76
76
|
rdoc_options: []
|
77
77
|
require_paths:
|
78
78
|
- lib
|
@@ -87,8 +87,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
87
87
|
- !ruby/object:Gem::Version
|
88
88
|
version: '0'
|
89
89
|
requirements: []
|
90
|
-
rubygems_version: 3.
|
91
|
-
signing_key:
|
90
|
+
rubygems_version: 3.2.3
|
91
|
+
signing_key:
|
92
92
|
specification_version: 4
|
93
93
|
summary: Unidom Price Domain Model Engine 价格领域模型引擎
|
94
94
|
test_files: []
|