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
e715f459
Commit
e715f459
authored
Jul 04, 2025
by
zhengyaoqiu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(colorway): 算价逻辑补充
parent
6313d9f2
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
147 additions
and
63 deletions
+147
-63
product_types.go
internal/pkg/database/mongo/model/product/product_types.go
+42
-10
uploadlogic.go
internal/rpc/internal/logic/product/uploadlogic.go
+4
-1
platform_store_sku.go
internal/rpc/internal/svc/convert/platform_store_sku.go
+56
-39
product.go
internal/rpc/internal/svc/convert/product.go
+45
-13
No files found.
internal/pkg/database/mongo/model/product/product_types.go
View file @
e715f459
...
@@ -32,6 +32,10 @@ type Product struct {
...
@@ -32,6 +32,10 @@ type Product struct {
CreateAt
time
.
Time
`bson:"createAt,omitempty" json:"createAt,omitempty"`
CreateAt
time
.
Time
`bson:"createAt,omitempty" json:"createAt,omitempty"`
}
}
func
(
receiver
Product
)
FindPlatformStoreSku
(
platform
types
.
Platform
,
store
types
.
Store
,
route
types
.
Route
,
skuId
string
)
(
ProductColorSkuPlatformStoreSku
,
bool
)
{
return
receiver
.
Colors
.
FindPlatformStoreSku
(
platform
,
store
,
route
,
skuId
)
}
type
Products
[]
Product
type
Products
[]
Product
type
ProductComposition
struct
{
type
ProductComposition
struct
{
...
@@ -76,21 +80,39 @@ type ProductColor struct {
...
@@ -76,21 +80,39 @@ type ProductColor struct {
type
ProductColors
[]
ProductColor
type
ProductColors
[]
ProductColor
func
(
receiver
ProductColors
)
FindPlatformStoreSku
(
platform
types
.
Platform
,
store
types
.
Store
,
route
types
.
Route
,
skuId
string
)
(
ProductColorSkuPlatformStoreSku
,
bool
)
{
for
_
,
color
:=
range
receiver
{
if
productColorSkuPlatformStoreSku
,
ok
:=
color
.
Skus
.
FindPlatformStoreSku
(
platform
,
store
,
route
,
skuId
);
ok
{
return
productColorSkuPlatformStoreSku
,
true
}
}
return
ProductColorSkuPlatformStoreSku
{},
false
}
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"`
SubjectIds
[]
string
`bson:"subjectIds"`
SubjectIds
[]
string
`bson:"subjectIds"`
P
roductColorSkuPlatformStoreSkus
[]
ProductColorSkuPlatformStoreSkus
`bson:"productColorSkuP
latformStoreSkus"`
P
latformStoreSkus
ProductColorSkuPlatformStoreSkus
`bson:"p
latformStoreSkus"`
}
}
type
ProductColorSkus
[]
ProductColorSku
type
ProductColorSkus
[]
ProductColorSku
func
(
receiver
ProductColorSkus
)
FindPlatformStoreSku
(
platform
types
.
Platform
,
store
types
.
Store
,
route
types
.
Route
,
skuId
string
)
(
ProductColorSkuPlatformStoreSku
,
bool
)
{
for
_
,
sku
:=
range
receiver
{
if
sku
.
Pc3SkuId
==
skuId
{
return
sku
.
PlatformStoreSkus
.
FindPlatformStoreSku
(
platform
,
store
,
route
)
}
}
return
ProductColorSkuPlatformStoreSku
{},
false
}
type
ProductTitle
struct
{
type
ProductTitle
struct
{
En
string
`bson:"en"`
En
string
`bson:"en"`
Cn
string
`bson:"cn"`
Cn
string
`bson:"cn"`
...
@@ -110,6 +132,7 @@ type ProductColorSkuPlatformStoreSku struct {
...
@@ -110,6 +132,7 @@ type ProductColorSkuPlatformStoreSku struct {
Price
float64
`bson:"price"`
// 最终价格
Price
float64
`bson:"price"`
// 最终价格
FixPrice
*
float64
`bson:"fixPrice,omitempty"`
// 固定价格
FixPrice
*
float64
`bson:"fixPrice,omitempty"`
// 固定价格
FixMargin
*
float64
`bson:"fixMargin,omitempty"`
// 固定加价率(影响计价)
FixMargin
*
float64
`bson:"fixMargin,omitempty"`
// 固定加价率(影响计价)
FixedQty
*
int
`bson:"fixedQty,omitempty"`
// 虚拟库存
Rate
float64
`bson:"rate"`
// OriginCurrency -> Currency 的汇率
Rate
float64
`bson:"rate"`
// OriginCurrency -> Currency 的汇率
CnyRate
float64
`bson:"cnyRate"`
// Currency -> CNY 的汇率
CnyRate
float64
`bson:"cnyRate"`
// Currency -> CNY 的汇率
Margin
float64
`bson:"margin"`
// 加价率
Margin
float64
`bson:"margin"`
// 加价率
...
@@ -126,3 +149,12 @@ type ProductColorSkuPlatformStoreSku struct {
...
@@ -126,3 +149,12 @@ type ProductColorSkuPlatformStoreSku struct {
}
}
type
ProductColorSkuPlatformStoreSkus
[]
ProductColorSkuPlatformStoreSku
type
ProductColorSkuPlatformStoreSkus
[]
ProductColorSkuPlatformStoreSku
func
(
receiver
ProductColorSkuPlatformStoreSkus
)
FindPlatformStoreSku
(
platform
types
.
Platform
,
store
types
.
Store
,
route
types
.
Route
)
(
ProductColorSkuPlatformStoreSku
,
bool
)
{
for
_
,
sku
:=
range
receiver
{
if
sku
.
Platform
==
platform
&&
sku
.
Store
==
store
&&
sku
.
Route
==
route
{
return
sku
,
true
}
}
return
ProductColorSkuPlatformStoreSku
{},
false
}
internal/rpc/internal/logic/product/uploadlogic.go
View file @
e715f459
...
@@ -31,7 +31,10 @@ func (l *UploadLogic) Upload(in *colorway.ProductUploadRequest) (*colorway.Produ
...
@@ -31,7 +31,10 @@ func (l *UploadLogic) Upload(in *colorway.ProductUploadRequest) (*colorway.Produ
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
ps
:=
l
.
svcCtx
.
ProductConvert
.
Convert
(
productList
.
GetDesignerProducts
())
ps
,
err
:=
l
.
svcCtx
.
ProductConvert
.
Convert
(
productList
.
GetDesignerProducts
())
if
err
!=
nil
{
return
nil
,
err
}
var
writeModels
[]
mongo
.
WriteModel
var
writeModels
[]
mongo
.
WriteModel
for
_
,
p
:=
range
ps
{
for
_
,
p
:=
range
ps
{
filter
:=
bson
.
M
{
filter
:=
bson
.
M
{
...
...
internal/rpc/internal/svc/convert/platform_store_sku.go
View file @
e715f459
This diff is collapsed.
Click to expand it.
internal/rpc/internal/svc/convert/product.go
View file @
e715f459
package
convert
package
convert
import
(
import
(
"context"
"errors"
"git.chillcy.com/golang/chillcy/pkg/gender"
"git.chillcy.com/golang/chillcy/pkg/gender"
"git.chillcy.com/golang/chillcy/pkg/slice"
"git.chillcy.com/golang/chillcy/pkg/slice"
"git.chillcy.com/golang/chillcy/project/pc4/pkg/rpc/pb/pc4"
"git.chillcy.com/golang/chillcy/project/pc4/pkg/rpc/pb/pc4"
"git.chillcy.com/golang/colorway/internal/pkg/database/mongo"
model
"git.chillcy.com/golang/colorway/internal/pkg/database/mongo/model/product"
model
"git.chillcy.com/golang/colorway/internal/pkg/database/mongo/model/product"
"git.chillcy.com/golang/colorway/internal/rpc/internal/svc/cache"
"git.chillcy.com/golang/colorway/internal/rpc/internal/svc/cache"
"git.chillcy.com/golang/colorway/internal/rpc/internal/svc/rate"
"go.mongodb.org/mongo-driver/bson"
mongo2
"go.mongodb.org/mongo-driver/mongo"
"sync"
"sync"
)
)
type
Product
struct
{
type
Product
struct
{
cache
*
cache
.
Cache
cache
*
cache
.
Cache
mongoManager
*
mongo
.
Manager
rate
rate
.
Rate
brandRankCache
cache
.
BrandRank
}
}
func
NewProduct
(
cache
*
cache
.
Cache
)
*
Product
{
func
NewProduct
(
cache
*
cache
.
Cache
,
mongoManager
*
mongo
.
Manager
,
rate
rate
.
Rate
,
brandRankCache
cache
.
BrandRank
)
*
Product
{
return
&
Product
{
cache
:
cache
}
return
&
Product
{
cache
:
cache
,
mongoManager
:
mongoManager
,
rate
:
rate
,
brandRankCache
:
brandRankCache
}
}
}
func
(
receiver
*
Product
)
Convert
(
designerProducts
[]
*
pc4
.
DesignerProduct
)
model
.
Products
{
func
(
receiver
*
Product
)
Convert
(
designerProducts
[]
*
pc4
.
DesignerProduct
)
(
model
.
Products
,
error
)
{
var
ps
model
.
Products
var
ps
model
.
Products
for
_
,
designerProduct
:=
range
designerProducts
{
for
_
,
designerProduct
:=
range
designerProducts
{
sourceIds
:=
getSourceIds
(
designerProduct
)
sourceIds
:=
getSourceIds
(
designerProduct
)
...
@@ -94,10 +103,23 @@ func (receiver *Product) Convert(designerProducts []*pc4.DesignerProduct) model.
...
@@ -94,10 +103,23 @@ func (receiver *Product) Convert(designerProducts []*pc4.DesignerProduct) model.
}
}
}
}
}
}
p
.
Colors
=
buildProductColors
(
designerProduct
.
GetColorProducts
(),
ws
,
designerProduct
.
GetDesignerId
())
var
oldProductPointer
*
model
.
Product
oldProduct
,
err
:=
receiver
.
mongoManager
.
ProductModel
.
FindOne
(
context
.
TODO
(),
bson
.
M
{
"styleId"
:
p
.
StyleId
})
if
err
!=
nil
&&
!
errors
.
Is
(
err
,
mongo2
.
ErrNoDocuments
)
{
return
nil
,
err
}
if
!
errors
.
Is
(
err
,
mongo2
.
ErrNoDocuments
)
{
oldProductPointer
=
&
oldProduct
}
platformStoreSkuConvert
:=
NewPlatformStoreSku
(
receiver
.
mongoManager
,
receiver
.
rate
,
receiver
.
brandRankCache
)
colors
,
err
:=
buildProductColors
(
designerProduct
.
GetColorProducts
(),
ws
,
oldProductPointer
,
platformStoreSkuConvert
)
if
err
!=
nil
{
return
nil
,
err
}
p
.
Colors
=
colors
ps
=
append
(
ps
,
p
)
ps
=
append
(
ps
,
p
)
}
}
return
ps
return
ps
,
nil
}
}
func
getCategory
(
category
*
pc4
.
CategoryV2
)
model
.
ProductCategory
{
func
getCategory
(
category
*
pc4
.
CategoryV2
)
model
.
ProductCategory
{
...
@@ -113,15 +135,19 @@ func getCategory(category *pc4.CategoryV2) model.ProductCategory {
...
@@ -113,15 +135,19 @@ func getCategory(category *pc4.CategoryV2) model.ProductCategory {
return
pc
return
pc
}
}
func
buildProductColors
(
colorProducts
[]
*
pc4
.
ColorProduct
,
ws
weightSelect
,
styleNumber
string
)
model
.
ProductColors
{
func
buildProductColors
(
colorProducts
[]
*
pc4
.
ColorProduct
,
ws
weightSelect
,
oldProductPointer
*
model
.
Product
,
platformStoreSkuConvert
*
PlatformStoreSku
)
(
model
.
ProductColors
,
error
)
{
var
pcs
model
.
ProductColors
var
pcs
model
.
ProductColors
for
_
,
colorProduct
:=
range
colorProducts
{
for
_
,
colorProduct
:=
range
colorProducts
{
pcs
=
append
(
pcs
,
buildProductColor
(
colorProduct
,
ws
,
styleNumber
))
pc
,
err
:=
buildProductColor
(
colorProduct
,
ws
,
oldProductPointer
,
platformStoreSkuConvert
)
if
err
!=
nil
{
return
nil
,
err
}
pcs
=
append
(
pcs
,
pc
)
}
}
return
pcs
return
pcs
,
nil
}
}
func
buildProductColor
(
colorProduct
*
pc4
.
ColorProduct
,
ws
weightSelect
,
styleNumber
string
)
model
.
ProductColor
{
func
buildProductColor
(
colorProduct
*
pc4
.
ColorProduct
,
ws
weightSelect
,
oldProductPointer
*
model
.
Product
,
platformStoreSkuConvert
*
PlatformStoreSku
)
(
model
.
ProductColor
,
error
)
{
pc
:=
model
.
ProductColor
{}
pc
:=
model
.
ProductColor
{}
once
:=
&
sync
.
Once
{}
once
:=
&
sync
.
Once
{}
for
_
,
productAndSkus
:=
range
colorProduct
.
GetProductAndSkusList
()
{
for
_
,
productAndSkus
:=
range
colorProduct
.
GetProductAndSkusList
()
{
...
@@ -142,7 +168,7 @@ func buildProductColor(colorProduct *pc4.ColorProduct, ws weightSelect, styleNum
...
@@ -142,7 +168,7 @@ func buildProductColor(colorProduct *pc4.ColorProduct, ws weightSelect, styleNum
}
}
for
_
,
sku
:=
range
productAndSkus
.
GetSkus
()
{
for
_
,
sku
:=
range
productAndSkus
.
GetSkus
()
{
pc
.
Skus
=
append
(
pc
.
Skus
,
model
.
ProductColorSku
{
pc
Sku
:=
model
.
ProductColorSku
{
Pc3SkuId
:
sku
.
GetId
(),
Pc3SkuId
:
sku
.
GetId
(),
Pc3ProductId
:
product
.
GetId
(),
Pc3ProductId
:
product
.
GetId
(),
SourceId
:
product
.
GetSourceId
(),
SourceId
:
product
.
GetSourceId
(),
...
@@ -152,10 +178,16 @@ func buildProductColor(colorProduct *pc4.ColorProduct, ws weightSelect, styleNum
...
@@ -152,10 +178,16 @@ func buildProductColor(colorProduct *pc4.ColorProduct, ws weightSelect, styleNum
Price
:
sku
.
GetPriceDetail
()
.
GetNow
(),
Price
:
sku
.
GetPriceDetail
()
.
GetNow
(),
Currency
:
sku
.
GetPriceDetail
()
.
GetCurrency
(),
Currency
:
sku
.
GetPriceDetail
()
.
GetCurrency
(),
SubjectIds
:
product
.
Subjects
,
SubjectIds
:
product
.
Subjects
,
})
}
psSkus
,
err
:=
platformStoreSkuConvert
.
Convert
(
product
,
sku
,
oldProductPointer
)
if
err
!=
nil
{
return
model
.
ProductColor
{},
err
}
pcSku
.
PlatformStoreSkus
=
psSkus
pc
.
Skus
=
append
(
pc
.
Skus
,
pcSku
)
}
}
}
}
return
pc
return
pc
,
nil
}
}
func
(
receiver
*
Product
)
getWeightSelect
(
sourceIds
[]
string
)
weightSelect
{
func
(
receiver
*
Product
)
getWeightSelect
(
sourceIds
[]
string
)
weightSelect
{
...
...
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