Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
colorway
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
golang
colorway
Commits
6bc3863e
Commit
6bc3863e
authored
Jul 03, 2025
by
zhengyaoqiu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(colorway): 价格适配器迁移
parent
46fba849
Changes
16
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
723 additions
and
24 deletions
+723
-24
cache.go
internal/pkg/database/mongo/cache/cache.go
+21
-0
product_types.go
internal/pkg/database/mongo/model/product/product_types.go
+48
-8
site_platform_price_config_types.go
...platform_price_config/site_platform_price_config_types.go
+72
-2
memo.go
internal/pkg/database/mongo/types/memo.go
+14
-0
seller.go
internal/pkg/database/mongo/types/seller.go
+0
-11
platform_store_sku.go
internal/rpc/internal/svc/convert/platform_store_sku.go
+161
-0
IAdapter.go
internal/rpc/internal/svc/priceRouteAdapter/IAdapter.go
+11
-0
b2bAdapter.go
internal/rpc/internal/svc/priceRouteAdapter/b2bAdapter.go
+47
-0
b2cAdapter.go
internal/rpc/internal/svc/priceRouteAdapter/b2cAdapter.go
+71
-0
selector.go
internal/rpc/internal/svc/priceRouteAdapter/selector.go
+19
-0
types.go
internal/rpc/internal/svc/priceRouteAdapter/types.go
+19
-0
generate.go
pkg/model/generate.go
+0
-3
platform.go
pkg/types/platform.go
+66
-0
route.go
pkg/types/route.go
+8
-0
seller.go
pkg/types/seller.go
+6
-0
store.go
pkg/types/store.go
+160
-0
No files found.
internal/pkg/database/mongo/cache/cache.go
View file @
6bc3863e
...
@@ -19,6 +19,8 @@ type ChangeStream[T any] interface {
...
@@ -19,6 +19,8 @@ type ChangeStream[T any] interface {
type
Cache
[
T
any
]
interface
{
type
Cache
[
T
any
]
interface
{
GetCacheDocuments
()
[]
T
GetCacheDocuments
()
[]
T
StartCache
(
ctx
context
.
Context
)
error
StartCache
(
ctx
context
.
Context
)
error
GetCacheOne
(
hitFunc
func
(
document
T
)
bool
)
(
T
,
bool
)
GetCacheMany
(
hitFunc
func
(
document
T
)
bool
)
[]
T
}
}
type
Base
[
T
any
]
struct
{
type
Base
[
T
any
]
struct
{
...
@@ -99,6 +101,25 @@ func (receiver *Base[T]) Filter(data ChangeStreamData) bson.M {
...
@@ -99,6 +101,25 @@ func (receiver *Base[T]) Filter(data ChangeStreamData) bson.M {
return
bson
.
M
{
"_id"
:
id
}
return
bson
.
M
{
"_id"
:
id
}
}
}
func
(
receiver
*
Base
[
T
])
GetCacheOne
(
hitFunc
func
(
document
T
)
bool
)
(
T
,
bool
)
{
for
_
,
d
:=
range
receiver
.
GetCacheDocuments
()
{
if
hitFunc
(
d
)
{
return
d
,
true
}
}
return
*
new
(
T
),
false
}
func
(
receiver
*
Base
[
T
])
GetCacheMany
(
hitFunc
func
(
document
T
)
bool
)
[]
T
{
var
documents
[]
T
for
_
,
d
:=
range
receiver
.
GetCacheDocuments
()
{
if
hitFunc
(
d
)
{
documents
=
append
(
documents
,
d
)
}
}
return
documents
}
type
ChangeStreamData
struct
{
type
ChangeStreamData
struct
{
DocumentKey
struct
{
DocumentKey
struct
{
Id
struct
{
Id
struct
{
...
...
internal/pkg/database/mongo/model/product/product_types.go
View file @
6bc3863e
package
model
package
model
import
(
import
(
"git.chillcy.com/golang/colorway/internal/pkg/database/mongo/types"
"time"
"time"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/bson/primitive"
...
@@ -57,6 +58,14 @@ type ProductCategory struct {
...
@@ -57,6 +58,14 @@ type ProductCategory struct {
Children
[]
ProductCategory
`json:"children" bson:"children"`
Children
[]
ProductCategory
`json:"children" bson:"children"`
}
}
func
(
receiver
ProductCategory
)
GetIds
()
[]
string
{
ids
:=
[]
string
{
receiver
.
Id
}
for
_
,
child
:=
range
receiver
.
Children
{
ids
=
append
(
ids
,
child
.
GetIds
()
...
)
}
return
ids
}
type
ProductColor
struct
{
type
ProductColor
struct
{
ColorCode
string
`bson:"colorCode"`
ColorCode
string
`bson:"colorCode"`
Id
string
`bson:"id"`
Id
string
`bson:"id"`
...
@@ -71,14 +80,15 @@ type ProductColor struct {
...
@@ -71,14 +80,15 @@ type ProductColor struct {
type
ProductColors
[]
ProductColor
type
ProductColors
[]
ProductColor
type
ProductColorSku
struct
{
type
ProductColorSku
struct
{
Pc3SkuId
string
`bson:"pc3SkuId"`
Pc3SkuId
string
`bson:"pc3SkuId"`
Pc3ProductId
string
`bson:"pc3ProductId"`
Pc3ProductId
string
`bson:"pc3ProductId"`
SourceId
string
`bson:"sourceId"`
SourceId
string
`bson:"sourceId"`
SiteId
string
`bson:"siteId"`
SiteId
string
`bson:"siteId"`
Size
string
`bson:"size"`
Size
string
`bson:"size"`
Stock
int
`bson:"stock"`
Stock
int
`bson:"stock"`
Price
float64
`bson:"price"`
Price
float64
`bson:"price"`
Currency
string
`bson:"currency"`
Currency
string
`bson:"currency"`
ProductColorSkuPlatformStoreSkus
[]
ProductColorSkuPlatformStoreSkus
`bson:"productColorSkuPlatformStoreSkus"`
}
}
type
ProductColorSkus
[]
ProductColorSku
type
ProductColorSkus
[]
ProductColorSku
...
@@ -92,3 +102,33 @@ type ProductBrand struct {
...
@@ -92,3 +102,33 @@ type ProductBrand struct {
Id
string
`bson:"id"`
Id
string
`bson:"id"`
Name
string
`bson:"name"`
Name
string
`bson:"name"`
}
}
type
ProductColorSkuPlatformStoreSku
struct
{
Platform
string
`bson:"platform"`
// 销售平台
Store
string
`bson:"store"`
// 销售平台具体店铺
Qty
int
`bson:"qty"`
// 库存
FixedQty
*
int
`bson:"fixedQty,omitempty"`
// 虚拟库存
Route
string
`bson:"route"`
// 线路
Currency
string
`bson:"currency"`
// 销售平台的币种
OriginCurrency
string
`bson:"originCurrency"`
// 原始币种
Price
float64
`bson:"price"`
// 最终价格
FixPrice
*
float64
`bson:"fixPrice,omitempty"`
// 固定价格
FixMargin
*
float64
`bson:"fixMargin,omitempty"`
// 固定加价率(影响计价)
Rate
float64
`bson:"rate"`
// OriginCurrency -> Currency 的汇率
CnyRate
float64
`bson:"cnyRate"`
// Currency -> CNY 的汇率
Margin
float64
`bson:"margin"`
// 加价率
SubjectRate
float64
`bson:"subjectRate"`
// 专题系数
Subject
*
primitive
.
ObjectID
`bson:"subject"`
// 绑定的专题id
DiscountRate
float64
`bson:"discountRate"`
// 商家系数
TotalDiscount
float64
`bson:"totalDiscount"`
// 总折扣
TaxRate
float64
`bson:"taxRate"`
// 税率
Freight
float64
`bson:"freight"`
// 商家运费
Express
float64
`bson:"express"`
// 跨境费
ChangeRate
*
float64
`bson:"changeRate,omitempty"`
// 价格变动率, 0.1表示涨价10%, -0.1表示降价10%
ChangeAt
*
time
.
Time
`bson:"changeAt,omitempty"`
// 价格变动时间,方便筛选
Memos
types
.
Memos
`bson:"memos,omitempty"`
// 操作备注
// todo 有固定价格固定库存等操作就是有固定操作
IsFixed
*
bool
`bson:"isFixed,omitempty"`
// 是否有固定操作
}
type
ProductColorSkuPlatformStoreSkus
[]
ProductColorSkuPlatformStoreSku
internal/pkg/database/mongo/model/site_platform_price_config/site_platform_price_config_types.go
View file @
6bc3863e
...
@@ -2,7 +2,7 @@ package model
...
@@ -2,7 +2,7 @@ package model
import
(
import
(
"git.chillcy.com/golang/chillcy/pkg/currency"
"git.chillcy.com/golang/chillcy/pkg/currency"
"git.chillcy.com/golang/colorway/
internal/pkg/database/mongo
/types"
"git.chillcy.com/golang/colorway/
pkg
/types"
"time"
"time"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/bson/primitive"
...
@@ -21,7 +21,7 @@ type SitePlatformPriceConfig struct {
...
@@ -21,7 +21,7 @@ type SitePlatformPriceConfig struct {
}
}
type
RoutePriceConfig
struct
{
type
RoutePriceConfig
struct
{
Route
string
`json:"route" bson:"route"`
// 路线
Route
types
.
Route
`json:"route" bson:"route"`
// 路线
Currency
currency
.
Currency
`json:"currency" bson:"currency"`
// 结算币种
Currency
currency
.
Currency
`json:"currency" bson:"currency"`
// 结算币种
TaxRate
float64
`json:"taxRate" bson:"taxRate"`
// 税率
TaxRate
float64
`json:"taxRate" bson:"taxRate"`
// 税率
MarginConfig
MarginConfig
`json:"marginConfig" bson:"marginConfig"`
// 加价率配置
MarginConfig
MarginConfig
`json:"marginConfig" bson:"marginConfig"`
// 加价率配置
...
@@ -29,6 +29,38 @@ type RoutePriceConfig struct {
...
@@ -29,6 +29,38 @@ type RoutePriceConfig struct {
ExpressConfig
ExpressConfig
`json:"expressConfig" bson:"expressConfig"`
// 跨境快递配置,默认是0
ExpressConfig
ExpressConfig
`json:"expressConfig" bson:"expressConfig"`
// 跨境快递配置,默认是0
}
}
func
(
rc
*
RoutePriceConfig
)
IsValid
()
bool
{
// 路线价格配置校验-加价率
if
rc
.
MarginConfig
.
MarginStyle
==
MarginStyleFixed
&&
(
rc
.
MarginConfig
.
Margin
<=
0
||
rc
.
MarginConfig
.
Margin
>
1
)
{
return
false
}
if
rc
.
MarginConfig
.
MarginStyle
==
MarginStyleLadder
&&
len
(
rc
.
MarginConfig
.
Ladders
)
<=
0
{
return
false
}
if
rc
.
MarginConfig
.
MarginStyle
==
MarginStyleLadder
{
if
!
rc
.
MarginConfig
.
IsValidLadders
()
{
return
false
}
}
// 路线价格配置校验-运费
if
rc
.
Route
==
types
.
RouteCC
||
rc
.
Route
==
types
.
RouteBC
{
// toC线路必须有税率
if
rc
.
TaxRate
<=
0
{
return
false
}
}
if
rc
.
Route
==
types
.
RouteBB
&&
(
rc
.
FreightConfig
.
FreightStyle
==
FreightStyleCategory
||
rc
.
FreightConfig
.
FreightStyle
==
FreightStylePrice
)
{
// B2B线路不能按照分类计算运费, 也不能按照页面价格计算运费
return
false
}
if
rc
.
Route
==
types
.
RouteBB
&&
rc
.
ExpressConfig
.
ExpressStyle
==
ExpressStyleCategory
{
// B2B线路不能按照分类计算快递费
return
false
}
return
true
}
type
ExpressConfig
struct
{
type
ExpressConfig
struct
{
Express
float64
`json:"express" bson:"express"`
// 跨境快递费
Express
float64
`json:"express" bson:"express"`
// 跨境快递费
ExpressStyle
ExpressStyle
`json:"expressStyle" bson:"expressStyle"`
// 跨境快递费计算方式
ExpressStyle
ExpressStyle
`json:"expressStyle" bson:"expressStyle"`
// 跨境快递费计算方式
...
@@ -36,6 +68,9 @@ type ExpressConfig struct {
...
@@ -36,6 +68,9 @@ type ExpressConfig struct {
type
ExpressStyle
string
type
ExpressStyle
string
const
ExpressStyleDefault
=
"default"
// 默认计算方式
const
ExpressStyleCategory
=
"category"
// 按照分类计算方式
type
FreightConfig
struct
{
type
FreightConfig
struct
{
Freight
float64
`json:"freight" bson:"freight"`
// 商家运费
Freight
float64
`json:"freight" bson:"freight"`
// 商家运费
FreightStyle
FreightStyle
`json:"freightStyle" bson:"freightStyle" `
// 商家运费计算方式
FreightStyle
FreightStyle
`json:"freightStyle" bson:"freightStyle" `
// 商家运费计算方式
...
@@ -45,14 +80,49 @@ type FreightConfig struct {
...
@@ -45,14 +80,49 @@ type FreightConfig struct {
type
FreightStyle
string
type
FreightStyle
string
const
FreightStyleDefault
FreightStyle
=
"default"
// 默认运费计算方式(设置的运费)
const
FreightStyleCategory
FreightStyle
=
"category"
// 根据分类计算
const
FreightStylePrice
FreightStyle
=
"price"
// 根据页面价格计算
const
FreightStyleMinPrice
FreightStyle
=
"min_price"
// 根据价格满多少免运费
type
MarginConfig
struct
{
type
MarginConfig
struct
{
MarginStyle
MarginStyle
`json:"marginStyle" bson:"marginStyle"`
// 加价方式
MarginStyle
MarginStyle
`json:"marginStyle" bson:"marginStyle"`
// 加价方式
Margin
float64
`json:"margin" bson:"margin"`
// 加价率,加价方式为固定加价时使用
Margin
float64
`json:"margin" bson:"margin"`
// 加价率,加价方式为固定加价时使用
Ladders
[]
Ladder
`json:"ladders" bson:"ladders"`
// 阶梯加价,加价方式为阶梯加价时使用
Ladders
[]
Ladder
`json:"ladders" bson:"ladders"`
// 阶梯加价,加价方式为阶梯加价时使用
}
}
func
(
mc
*
MarginConfig
)
IsValidLadders
()
bool
{
if
mc
.
MarginStyle
==
MarginStyleLadder
{
if
len
(
mc
.
Ladders
)
<=
0
{
return
false
}
for
i
,
ladder
:=
range
mc
.
Ladders
{
// 除了最后一个阶梯,其他阶梯的最大值必须设置值
if
i
<
len
(
mc
.
Ladders
)
-
1
&&
ladder
.
Max
<=
0
{
return
false
}
// 阶梯的最小值必须大于等于0
if
ladder
.
Min
<
0
{
return
false
}
// 阶梯的最大值必须大于最小值
if
ladder
.
Min
>=
ladder
.
Max
{
return
false
}
// 阶梯的加价率必须大于0小于等于1
if
ladder
.
Margin
<=
0
||
ladder
.
Margin
>
1
{
return
false
}
}
}
return
true
}
type
MarginStyle
string
type
MarginStyle
string
const
MarginStyleFixed
MarginStyle
=
"fixed"
// 默认加价方式,固定加价一个比例;值为0.1,即加价10%
const
MarginStyleLadder
MarginStyle
=
"ladder"
// 阶梯加价
type
Ladder
struct
{
type
Ladder
struct
{
Min
float64
`json:"min" bson:"min"`
// 最小值
Min
float64
`json:"min" bson:"min"`
// 最小值
Max
float64
`json:"max" bson:"max"`
// 最大值
Max
float64
`json:"max" bson:"max"`
// 最大值
...
...
internal/pkg/database/mongo/types/memo.go
0 → 100644
View file @
6bc3863e
package
types
import
"time"
type
Operation
string
type
Memo
struct
{
Operator
string
`bson:"operator"`
Operation
Operation
`bson:"operation"`
Remark
string
`bson:"remark"`
CreateAt
time
.
Time
`bson:"createAt"`
}
type
Memos
[]
Memo
internal/pkg/database/mongo/types/seller.go
deleted
100644 → 0
View file @
46fba849
package
types
import
(
"git.chillcy.com/golang/colorway/pkg/platform"
"git.chillcy.com/golang/colorway/pkg/store"
)
type
Seller
struct
{
Platform
platform
.
Platform
`json:"platform" bson:"platform"`
// 销售平台
Store
store
.
Store
`json:"store" bson:"store"`
// 销售平台具体店铺
}
internal/rpc/internal/svc/convert/platform_store_sku.go
0 → 100644
View file @
6bc3863e
package
convert
import
(
"errors"
"fmt"
"git.chillcy.com/golang/chillcy/pkg/sdk/pc3"
"git.chillcy.com/golang/colorway/internal/pkg/database/mongo"
productModel
"git.chillcy.com/golang/colorway/internal/pkg/database/mongo/model/product"
sitePlatformPriceConfigModel
"git.chillcy.com/golang/colorway/internal/pkg/database/mongo/model/site_platform_price_config"
"github.com/zeromicro/go-zero/core/logx"
"log"
"math"
"time"
)
type
PlatformStoreSku
struct
{
mongoManager
*
mongo
.
Manager
}
func
(
receiver
*
PlatformStoreSku
)
Convert
(
p
productModel
.
Product
)
productModel
.
ProductColorSkuPlatformStoreSkus
{
var
platformStoreSkus
[]
productModel
.
ProductColorSkuPlatformStoreSkus
for
_
,
color
:=
range
p
.
Colors
{
for
_
,
sku
:=
range
color
.
Skus
{
sitePlatformPriceConfigs
:=
receiver
.
mongoManager
.
SitePlatformPriceConfigModel
.
GetCacheMany
(
func
(
document
sitePlatformPriceConfigproductModel
.
SitePlatformPriceConfig
)
bool
{
return
document
.
Site
==
sku
.
SiteId
})
categoryIds
:=
p
.
Category
.
GetIds
()
for
_
,
sitePlatformPriceConfig
:=
range
sitePlatformPriceConfigs
{
platformPriceDetail
,
err
:=
r
.
calculatePlatformPrice
(
ctx
,
localSkuModel
,
pc3SkuModel
,
categories
,
priceConfig
,
svcProductModel
)
if
err
!=
nil
{
return
nil
,
err
}
if
platformPriceDetail
!=
nil
{
skuPriceList
=
append
(
skuPriceList
,
*
platformPriceDetail
)
}
}
}
}
err
=
r
.
dataRepo
.
BatchUpsertSkuPrice
(
ctx
,
skuPriceList
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"BatchUpsertSkuPrice:%w"
,
err
)
}
}
func
(
receiver
*
PlatformStoreSku
)
calculatePlatformPrice
(
localSkuModel
*
productModel
.
Sku
,
pc3SkuModel
pc3
.
ModelSku
,
categories
[]
string
,
priceConfig
sitePlatformPriceConfigModel
.
SitePlatformPriceConfig
,
svcProductModel
*
ProductModel
)
(
productModel
.
ProductColorSkuPlatformStoreSku
,
error
)
{
var
sku
productModel
.
ProductColorSkuPlatformStoreSku
if
!
priceConfig
.
IsValid
()
{
return
sku
,
fmt
.
Errorf
(
"路线价格配置不合法"
)
}
sku
,
err
:=
r
.
calculateRoutePrice
(
ctx
,
svcProductModel
,
localSkuModel
,
pc3SkuModel
,
categories
,
priceConfig
.
RoutePriceConfig
,
priceConfig
.
Seller
)
if
err
!=
nil
{
return
sku
,
err
}
return
sku
,
nil
}
func
(
receiver
*
PlatformStoreSku
)
calculateRoutePrice
(
svcProductModel
*
ProductModel
,
localSkuModel
*
model
.
Sku
,
pc3SkuModel
pc3
.
ModelSku
,
categories
[]
string
,
routeConfig
embed
.
RoutePriceConfig
,
seller
embed
.
Seller
)
(
*
model
.
SkuPrice
,
error
)
{
adapter
,
err
:=
priceRouteAdapter
.
SelectAdapter
(
routeConfig
.
Route
)
if
err
!=
nil
{
return
nil
,
err
}
rateKey
:=
pc3SkuModel
.
PriceDetail
.
Currency
+
"_"
+
string
(
routeConfig
.
Currency
)
currencyRate
,
err
:=
r
.
rateConfig
.
GetRate
(
rateKey
,
seller
.
Platform
)
if
err
!=
nil
||
currencyRate
==
0
{
currencyRate
,
err
=
r
.
updateOrSetRate
(
rateKey
,
seller
.
Platform
)
if
err
!=
nil
{
return
nil
,
errors
.
New
(
"无法获取汇率信息"
)
}
}
oldSkuPriceRecord
,
err
:=
r
.
dataRepo
.
GetOneSkuPrice
(
ctx
,
localSkuModel
.
Id
,
seller
.
Platform
,
seller
.
Store
,
routeConfig
.
Route
)
if
err
!=
nil
&&
!
errors
.
Is
(
err
,
mongo
.
ErrNoDocuments
)
{
return
nil
,
err
}
subjectRate
,
subjectId
,
err
:=
r
.
getSubjectRateAndSubject
(
pc3SkuModel
,
svcProductModel
,
seller
.
Platform
)
if
err
!=
nil
{
return
nil
,
err
}
// 固定毛利
margin
:=
1.0
if
oldSkuPriceRecord
!=
nil
&&
oldSkuPriceRecord
.
FixMargin
!=
nil
&&
*
oldSkuPriceRecord
.
FixMargin
!=
0
{
margin
=
1
+
(
*
oldSkuPriceRecord
.
FixMargin
/
100
)
}
else
{
margin
,
err
=
r
.
calculateMargin
(
routeConfig
,
svcProductModel
,
pc3SkuModel
,
seller
)
if
err
!=
nil
{
return
nil
,
err
}
}
margin
=
math2
.
Round
(
math
.
Max
(
1.0
,
margin
),
3
)
// 保底1.0
freight
,
err
:=
r
.
calculateFreight
(
pc3SkuModel
,
categories
,
routeConfig
.
FreightConfig
,
seller
.
Platform
)
if
err
!=
nil
{
return
nil
,
err
}
priceDetail
:=
embed
.
RoutePriceDetail
{
Route
:
routeConfig
.
Route
,
Currency
:
string
(
routeConfig
.
Currency
),
OriginCurrency
:
pc3SkuModel
.
PriceDetail
.
Currency
,
Rate
:
currencyRate
,
Margin
:
margin
,
SubjectRate
:
subjectRate
,
Subject
:
subjectId
,
DiscountRate
:
pc3SkuModel
.
PriceDetail
.
Discount
,
TotalDiscount
:
pc3SkuModel
.
PriceDetail
.
Discount
*
subjectRate
,
TaxRate
:
1
+
routeConfig
.
TaxRate
,
Freight
:
freight
,
Express
:
r
.
calculateExpress
(
categories
,
routeConfig
.
ExpressConfig
),
}
// 计算最终价格
priceDetail
.
Price
,
err
=
adapter
.
GetPrice
(
pc3SkuModel
.
PriceDetail
.
Now
,
priceDetail
,
platform
.
Platform
(
seller
.
Platform
))
if
err
!=
nil
{
return
nil
,
err
}
rateKey
=
priceDetail
.
Currency
+
"_"
+
string
(
embed
.
CurrencyCNY
)
cnyRate
,
err
:=
r
.
rateConfig
.
GetRate
(
rateKey
,
seller
.
Platform
)
if
err
!=
nil
||
cnyRate
==
0
{
cnyRate
,
err
=
r
.
updateOrSetRate
(
rateKey
,
seller
.
Platform
)
if
err
!=
nil
{
log
.
Println
(
rateKey
+
"无法获取汇率信息:"
,
err
)
}
}
record
:=
model
.
SkuPrice
{
SkuId
:
localSkuModel
.
Id
,
Mid
:
svcProductModel
.
Id
,
Platform
:
seller
.
Platform
,
Store
:
seller
.
Store
,
Qty
:
localSkuModel
.
Quantity
,
Route
:
priceDetail
.
Route
,
Currency
:
priceDetail
.
Currency
,
OriginCurrency
:
priceDetail
.
OriginCurrency
,
Price
:
priceDetail
.
Price
,
Rate
:
priceDetail
.
Rate
,
CnyRate
:
cnyRate
,
Margin
:
priceDetail
.
Margin
,
SubjectRate
:
priceDetail
.
SubjectRate
,
Subject
:
priceDetail
.
Subject
,
DiscountRate
:
priceDetail
.
DiscountRate
,
TotalDiscount
:
priceDetail
.
TotalDiscount
,
TaxRate
:
priceDetail
.
TaxRate
,
Freight
:
priceDetail
.
Freight
,
Express
:
priceDetail
.
Express
,
}
if
oldSkuPriceRecord
!=
nil
{
now
:=
time
.
Now
()
change
:=
math2
.
Round
((
priceDetail
.
Price
-
oldSkuPriceRecord
.
Price
)
/
oldSkuPriceRecord
.
Price
,
4
)
record
.
Id
=
oldSkuPriceRecord
.
Id
record
.
FixedQty
=
oldSkuPriceRecord
.
FixedQty
if
math
.
Abs
(
change
)
>
0.0001
{
record
.
ChangeRate
=
&
change
record
.
ChangeAt
=
&
now
}
}
return
&
record
,
nil
}
internal/rpc/internal/svc/priceRouteAdapter/IAdapter.go
0 → 100644
View file @
6bc3863e
package
priceRouteAdapter
import
(
"git.chillcy.com/golang/chillcy/pkg/platform"
"git.chillcy.com/golang/colorway/pkg/types"
)
type
IAdapter
interface
{
IsMatch
(
route
types
.
Route
)
bool
GetPrice
(
now
float64
,
config
RoutePriceDetail
,
plt
platform
.
Platform
)
(
float64
,
error
)
}
internal/rpc/internal/svc/priceRouteAdapter/b2bAdapter.go
0 → 100644
View file @
6bc3863e
package
priceRouteAdapter
import
(
"fmt"
math2
"git.chillcy.com/golang/chillcy/pkg/math"
"git.chillcy.com/golang/chillcy/pkg/platform"
"git.chillcy.com/golang/colorway/pkg/types"
"github.com/zeromicro/go-zero/core/logx"
)
type
B2BAdapter
struct
{
}
func
NewB2BAdapter
()
*
B2BAdapter
{
return
&
B2BAdapter
{}
}
func
(
c
*
B2BAdapter
)
IsMatch
(
route
types
.
Route
)
bool
{
return
route
==
types
.
RouteBB
||
route
==
types
.
RouteComplex
}
func
(
c
*
B2BAdapter
)
GetPrice
(
now
float64
,
config
RoutePriceDetail
,
plt
platform
.
Platform
)
(
float64
,
error
)
{
//minValue := now*
// config.Rate*
// config.SubjectRate + config.Freight + config.Express
finalValue
:=
(
now
*
config
.
Rate
*
config
.
SubjectRate
*
config
.
Margin
+
config
.
Freight
+
config
.
Express
)
*
config
.
TaxRate
msg
:=
fmt
.
Sprintf
(
"b2bAdapter 平台:%v 计算价格: (PriceDetail.Now:%v * Rate:%v * SubjectRate:%v * Margin:%v + Freight:%v + Express:%v) * TaxRate:%v = %v"
,
plt
,
now
,
config
.
Rate
,
config
.
SubjectRate
,
config
.
Margin
,
config
.
Freight
,
config
.
Express
,
config
.
TaxRate
,
finalValue
,
)
logx
.
Debug
(
msg
)
return
math2
.
Round
(
finalValue
,
2
),
nil
}
internal/rpc/internal/svc/priceRouteAdapter/b2cAdapter.go
0 → 100644
View file @
6bc3863e
package
priceRouteAdapter
import
(
"fmt"
math2
"git.chillcy.com/golang/chillcy/pkg/math"
"git.chillcy.com/golang/chillcy/pkg/platform"
"git.chillcy.com/golang/colorway/pkg/types"
"github.com/zeromicro/go-zero/core/logx"
"math"
)
type
B2CAdapter
struct
{
}
func
NewB2CAdapter
()
*
B2CAdapter
{
return
&
B2CAdapter
{}
}
func
(
c
*
B2CAdapter
)
IsMatch
(
route
types
.
Route
)
bool
{
return
route
==
types
.
RouteCC
||
route
==
types
.
RouteBC
}
func
(
c
*
B2CAdapter
)
GetPrice
(
now
float64
,
config
RoutePriceDetail
,
plt
platform
.
Platform
)
(
float64
,
error
)
{
//minValue := (now*
// config.Rate*
// config.SubjectRate*+config.Freight + config.Express) *
// config.TaxRate
finalValue
:=
(
now
*
config
.
Rate
*
config
.
SubjectRate
*
config
.
Margin
+
config
.
Freight
+
config
.
Express
)
*
config
.
TaxRate
//finalValue = math.Max(minValue, finalValue)
// 天猫2c 推给天猫的价 = 固定汇率算的价 * 1.005 ( 如1000 则推给 天猫 1005)
if
plt
==
platform
.
PlatformTmall2c
{
finalValue
=
finalValue
*
1.005
}
// 根据平台向上取整或者向上取9
finalValue
=
c
.
roundUpToNine
(
finalValue
,
plt
)
msg
:=
fmt
.
Sprintf
(
"b2cAdapter 平台:%v 计算价格: (PriceDetail.Now:%v * Rate:%v * SubjectRate:%v * Margin:%v + Freight:%v + Express:%v) * TaxRate:%v = %v"
,
plt
,
now
,
config
.
Rate
,
config
.
SubjectRate
,
config
.
Margin
,
config
.
Freight
,
config
.
Express
,
config
.
TaxRate
,
finalValue
,
)
logx
.
Debug
(
msg
)
return
math2
.
Round
(
finalValue
,
2
),
nil
}
func
(
c
*
B2CAdapter
)
roundUpToNine
(
value
float64
,
pf
platform
.
Platform
)
float64
{
ceil
:=
math
.
Ceil
(
value
)
if
pf
!=
platform
.
PlatformMezzanine
{
return
ceil
}
if
ceil
>
value
&&
math
.
Mod
(
ceil
,
10
)
!=
9
{
ceil
+=
9
-
math
.
Mod
(
ceil
,
10
)
}
return
ceil
}
internal/rpc/internal/svc/priceRouteAdapter/selector.go
0 → 100644
View file @
6bc3863e
package
priceRouteAdapter
import
(
"git.chillcy.com/golang/colorway/pkg/types"
"github.com/pkg/errors"
)
func
SelectAdapter
(
route
types
.
Route
)
(
IAdapter
,
error
)
{
allAdapter
:=
[]
IAdapter
{
NewB2CAdapter
(),
NewB2BAdapter
(),
}
for
_
,
adapter
:=
range
allAdapter
{
if
adapter
.
IsMatch
(
route
)
{
return
adapter
,
nil
}
}
return
nil
,
errors
.
New
(
"未支持的路线,无法计算价格"
)
}
internal/rpc/internal/svc/priceRouteAdapter/types.go
0 → 100644
View file @
6bc3863e
package
priceRouteAdapter
import
"go.mongodb.org/mongo-driver/bson/primitive"
type
RoutePriceDetail
struct
{
Route
string
`bson:"route"`
// 线路
Currency
string
`bson:"currency"`
// 销售平台的币种
OriginCurrency
string
`bson:"originCurrency"`
// 原始币种
Price
float64
`bson:"price"`
// 最终价格
Rate
float64
`bson:"rate"`
// OriginCurrency -> Currency 的汇率
Margin
float64
`bson:"margin"`
// 加价率
SubjectRate
float64
`bson:"subjectRate"`
// 专题系数
Subject
*
primitive
.
ObjectID
`bson:"subjectID"`
// 绑定的专题id
DiscountRate
float64
`bson:"discountRate"`
// 商家系数
TotalDiscount
float64
`bson:"totalDiscount"`
// 总折扣
TaxRate
float64
`bson:"taxRate"`
// 税率
Freight
float64
`bson:"freight"`
// 商家运费
Express
float64
`bson:"express"`
// 跨境费
}
pkg/model/generate.go
deleted
100644 → 0
View file @
46fba849
package
model
//go:generate goctl model mysql
pkg/
platform
/platform.go
→
pkg/
types
/platform.go
View file @
6bc3863e
package
platform
package
types
type
Platform
string
type
Platform
string
const
(
const
(
Mezzanine
Platform
=
"mezzanine"
Platform
Mezzanine
Platform
=
"mezzanine"
Tmall2b
Platform
=
"tmall2b"
Platform
Tmall2b
Platform
=
"tmall2b"
Taobao
Platform
=
"taobao"
Platform
Taobao
Platform
=
"taobao"
Poizon2b
Platform
=
"poizon2b"
P
latformP
oizon2b
Platform
=
"poizon2b"
OldPoizon
Platform
=
"oldpoizon"
Platform
OldPoizon
Platform
=
"oldpoizon"
Jd
Platform
=
"jingdong"
Platform
Jd
Platform
=
"jingdong"
Im2b
Platform
=
"im2b"
Platform
Im2b
Platform
=
"im2b"
Tmall2c
Platform
=
"tmall"
Platform
Tmall2c
Platform
=
"tmall"
B2B
Platform
=
"b2b"
Platform
B2B
Platform
=
"b2b"
Open
Platform
=
"open"
Platform
Open
Platform
=
"open"
)
)
func
(
p
Platform
)
GetName
()
string
{
func
(
p
Platform
)
GetName
()
string
{
switch
p
{
switch
p
{
case
Mezzanine
:
case
Platform
Mezzanine
:
return
"迷衣"
return
"迷衣"
case
Tmall2b
:
case
Platform
Tmall2b
:
return
"天猫ToB"
return
"天猫ToB"
case
Taobao
:
case
Platform
Taobao
:
return
"淘宝"
return
"淘宝"
case
Poizon2b
:
case
P
latformP
oizon2b
:
return
"得物"
return
"得物"
case
OldPoizon
:
case
Platform
OldPoizon
:
return
"旧得物"
return
"旧得物"
case
Jd
:
case
Platform
Jd
:
return
"京东"
return
"京东"
case
Im2b
:
case
Platform
Im2b
:
return
"ImToB"
return
"ImToB"
case
Tmall2c
:
case
Platform
Tmall2c
:
return
"天猫"
return
"天猫"
case
B2B
:
case
Platform
B2B
:
return
"B2B"
return
"B2B"
case
Open
:
case
Platform
Open
:
return
"开放平台"
return
"开放平台"
}
}
return
string
(
p
)
return
string
(
p
)
...
@@ -43,16 +43,16 @@ func (p Platform) GetName() string {
...
@@ -43,16 +43,16 @@ func (p Platform) GetName() string {
func
GetAllPlatforms
()
[]
Platform
{
func
GetAllPlatforms
()
[]
Platform
{
return
[]
Platform
{
return
[]
Platform
{
Mezzanine
,
Platform
Mezzanine
,
Tmall2b
,
Platform
Tmall2b
,
Taobao
,
Platform
Taobao
,
Poizon2b
,
P
latformP
oizon2b
,
Jd
,
Platform
Jd
,
Im2b
,
Platform
Im2b
,
Tmall2c
,
Platform
Tmall2c
,
B2B
,
Platform
B2B
,
Open
,
Platform
Open
,
OldPoizon
,
Platform
OldPoizon
,
}
}
}
}
...
...
pkg/types/route.go
0 → 100644
View file @
6bc3863e
package
types
type
Route
string
const
RouteBC
Route
=
"BC"
// BC路线
const
RouteCC
Route
=
"CC"
// CC路线
const
RouteBB
Route
=
"B2B"
// B2B路线
const
RouteComplex
=
"Complex"
// 复杂路线
pkg/types/seller.go
0 → 100644
View file @
6bc3863e
package
types
type
Seller
struct
{
Platform
Platform
`json:"platform" bson:"platform"`
// 销售平台
Store
Store
`json:"store" bson:"store"`
// 销售平台具体店铺
}
pkg/
store
/store.go
→
pkg/
types
/store.go
View file @
6bc3863e
package
store
package
types
type
Store
string
type
Store
string
const
(
const
(
MezzanineApp
Store
=
"mezzanine_app"
Store
MezzanineApp
Store
=
"mezzanine_app"
MezzanineMiniApp
Store
=
"mezzanine_mini_app"
Store
MezzanineMiniApp
Store
=
"mezzanine_mini_app"
Tmall2bHK
Store
=
"tmall2b_hk"
Store
Tmall2bHK
Store
=
"tmall2b_hk"
Tmall2bUS
Store
=
"tmall2b_us"
Store
Tmall2bUS
Store
=
"tmall2b_us"
Tmall2bEUR
Store
=
"tmall2b_eur"
Store
Tmall2bEUR
Store
=
"tmall2b_eur"
Poizon2bStore1
Store
=
"mezzanine1"
Store
Poizon2bStore1
Store
=
"mezzanine1"
Poizon2bStore2
Store
=
"mezzanine2"
Store
Poizon2bStore2
Store
=
"mezzanine2"
JDStore2015
Store
=
"150558"
Store
JDStore2015
Store
=
"150558"
JDStore2017
Store
=
"208456"
Store
JDStore2017
Store
=
"208456"
JDStoreGongxiao
Store
=
"208456gx"
Store
JDStoreGongxiao
Store
=
"208456gx"
JDStore2019
Store
=
"754589"
Store
JDStore2019
Store
=
"754589"
JDStore2024
Store
=
"13888912"
Store
JDStore2024
Store
=
"13888912"
Im2b
Store
=
"im2b"
Store
Im2b
Store
=
"im2b"
Tmall2cStore1
Store
=
"mezzanine"
Store
Tmall2cStore1
Store
=
"mezzanine"
B2bStore1
Store
=
"alfamoda"
Store
B2bStore1
Store
=
"alfamoda"
B2bStore2
Store
=
"alfa_mp"
Store
B2bStore2
Store
=
"alfa_mp"
TbStore1
Store
=
"taobao_store1"
Store
TbStore1
Store
=
"taobao_store1"
TbStore2
Store
=
"taobao_store2"
Store
TbStore2
Store
=
"taobao_store2"
TbStore3
Store
=
"taobao_store3"
Store
TbStore3
Store
=
"taobao_store3"
TbStore4
Store
=
"taobao_store4"
Store
TbStore4
Store
=
"taobao_store4"
TbStore5
Store
=
"taobao_store5"
Store
TbStore5
Store
=
"taobao_store5"
TbStore6
Store
=
"taobao_store6"
Store
TbStore6
Store
=
"taobao_store6"
TbStore7
Store
=
"taobao_store7"
Store
TbStore7
Store
=
"taobao_store7"
TbStore8
Store
=
"taobao_store8"
Store
TbStore8
Store
=
"taobao_store8"
TbStore9
Store
=
"taobao_store9"
Store
TbStore9
Store
=
"taobao_store9"
OpenStore1
Store
=
"open_store1"
Store
OpenStore1
Store
=
"open_store1"
OldPoizon1
Store
=
"oldpoizon1"
Store
OldPoizon1
Store
=
"oldpoizon1"
OldPoizon2
Store
=
"oldpoizon2"
Store
OldPoizon2
Store
=
"oldpoizon2"
)
)
func
GetAllStores
()
[]
Store
{
func
GetAllStores
()
[]
Store
{
return
[]
Store
{
return
[]
Store
{
MezzanineApp
,
Store
MezzanineApp
,
Tmall2bHK
,
Store
Tmall2bHK
,
Tmall2bUS
,
Store
Tmall2bUS
,
Tmall2bEUR
,
Store
Tmall2bEUR
,
Poizon2bStore1
,
Store
Poizon2bStore1
,
Poizon2bStore2
,
Store
Poizon2bStore2
,
Im2b
,
Store
Im2b
,
Tmall2cStore1
,
Store
Tmall2cStore1
,
JDStore2015
,
Store
JDStore2015
,
JDStore2017
,
Store
JDStore2017
,
JDStoreGongxiao
,
Store
JDStoreGongxiao
,
JDStore2019
,
Store
JDStore2019
,
JDStore2024
,
Store
JDStore2024
,
B2bStore1
,
Store
B2bStore1
,
B2bStore2
,
Store
B2bStore2
,
TbStore1
,
Store
TbStore1
,
TbStore2
,
Store
TbStore2
,
TbStore3
,
Store
TbStore3
,
TbStore4
,
Store
TbStore4
,
TbStore5
,
Store
TbStore5
,
TbStore6
,
Store
TbStore6
,
TbStore7
,
Store
TbStore7
,
TbStore8
,
Store
TbStore8
,
TbStore9
,
Store
TbStore9
,
OpenStore1
,
Store
OpenStore1
,
OldPoizon1
,
Store
OldPoizon1
,
OldPoizon2
,
Store
OldPoizon2
,
}
}
}
}
func
(
store
Store
)
GetStoreName
()
string
{
func
(
store
Store
)
GetStoreName
()
string
{
switch
store
{
switch
store
{
case
MezzanineApp
:
case
Store
MezzanineApp
:
return
"迷衣App"
return
"迷衣App"
case
MezzanineMiniApp
:
case
Store
MezzanineMiniApp
:
return
"迷衣小程序"
return
"迷衣小程序"
case
Tmall2bHK
:
case
Store
Tmall2bHK
:
return
"天猫ToB HK"
return
"天猫ToB HK"
case
Tmall2bUS
:
case
Store
Tmall2bUS
:
return
"天猫ToB US"
return
"天猫ToB US"
case
Tmall2bEUR
:
case
Store
Tmall2bEUR
:
return
"天猫ToB EUR"
return
"天猫ToB EUR"
case
Poizon2bStore1
:
case
Store
Poizon2bStore1
:
return
"得物一店"
return
"得物一店"
case
Poizon2bStore2
:
case
Store
Poizon2bStore2
:
return
"得物二店"
return
"得物二店"
case
Im2b
:
case
Store
Im2b
:
return
"ImToB"
return
"ImToB"
case
JDStore2015
:
case
Store
JDStore2015
:
return
"XIYANGHUI2015"
return
"XIYANGHUI2015"
case
JDStore2017
:
case
Store
JDStore2017
:
return
"XIYANGHUI2017"
return
"XIYANGHUI2017"
case
JDStoreGongxiao
:
case
Store
JDStoreGongxiao
:
return
"京东供销"
return
"京东供销"
case
JDStore2019
:
case
Store
JDStore2019
:
return
"XIYANGHUI2019"
return
"XIYANGHUI2019"
case
Tmall2cStore1
:
case
Store
Tmall2cStore1
:
return
"迷衣时尚海外旗舰店"
return
"迷衣时尚海外旗舰店"
case
TbStore1
:
case
Store
TbStore1
:
return
"huzhijie1991"
return
"huzhijie1991"
case
TbStore2
:
case
Store
TbStore2
:
return
"足尚潮鞋店"
return
"足尚潮鞋店"
case
TbStore3
:
case
Store
TbStore3
:
return
"冰蕙儿"
return
"冰蕙儿"
case
TbStore4
:
case
Store
TbStore4
:
return
"mezzanine"
return
"mezzanine"
case
TbStore5
:
case
Store
TbStore5
:
return
"西洋汇"
return
"西洋汇"
case
TbStore6
:
case
Store
TbStore6
:
return
"huangjiawei44"
return
"huangjiawei44"
case
TbStore7
:
case
Store
TbStore7
:
return
"soulsoulsu"
return
"soulsoulsu"
case
TbStore8
:
case
Store
TbStore8
:
return
"ys狼牙俱乐部"
return
"ys狼牙俱乐部"
case
TbStore9
:
case
Store
TbStore9
:
return
"旧店铺"
return
"旧店铺"
case
B2bStore1
:
case
Store
B2bStore1
:
return
"ALFAMODA"
return
"ALFAMODA"
case
B2bStore2
:
case
Store
B2bStore2
:
return
"ALFA-MP"
return
"ALFA-MP"
case
OpenStore1
:
case
Store
OpenStore1
:
return
"开放平台"
return
"开放平台"
case
OldPoizon1
:
case
Store
OldPoizon1
:
return
"旧得物一店"
return
"旧得物一店"
case
OldPoizon2
:
case
Store
OldPoizon2
:
return
"旧得物二店"
return
"旧得物二店"
}
}
return
string
(
store
)
return
string
(
store
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment