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
bc3d33f5
Commit
bc3d33f5
authored
Jul 02, 2025
by
zhengyaoqiu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(colorway): 商品依据权重转换
parent
dc3ad202
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
118 additions
and
4 deletions
+118
-4
product.go
internal/rpc/internal/svc/convert/product.go
+118
-4
No files found.
internal/rpc/internal/svc/convert/product.go
View file @
bc3d33f5
package
convert
import
(
"git.chillcy.com/golang/chillcy/pkg/slice"
"git.chillcy.com/golang/chillcy/project/pc4/pkg/rpc/pb/pc4"
model
"git.chillcy.com/golang/colorway/internal/pkg/database/mongo/product"
"git.chillcy.com/golang/colorway/internal/rpc/internal/svc/cache"
...
...
@@ -18,6 +19,8 @@ func NewProduct(cache *cache.Cache) *Product {
func
(
receiver
*
Product
)
Convert
(
designerProducts
[]
*
pc4
.
DesignerProduct
)
model
.
Products
{
var
ps
model
.
Products
for
_
,
designerProduct
:=
range
designerProducts
{
sourceIds
:=
getSourceIds
(
designerProduct
)
ws
:=
receiver
.
getWeightSelect
(
sourceIds
)
once
:=
sync
.
Once
{}
p
:=
model
.
Product
{}
styleNumber
:=
designerProduct
.
GetDesignerId
()
...
...
@@ -40,24 +43,83 @@ func (receiver *Product) Convert(designerProducts []*pc4.DesignerProduct) model.
p
.
MadeIn
=
product
.
GetDetail
()
.
GetMadeIn
()
p
.
HsCode
=
product
.
GetDetail
()
.
GetHsCode
()
p
.
InfoSelect
=
product
.
GetId
()
p
.
Category
=
getCategory
(
product
.
GetCategoriesV2
())
for
_
,
composition
:=
range
product
.
GetDetail
()
.
GetCompositions
()
{
p
.
Compositions
=
append
(
p
.
Compositions
,
model
.
ProductComposition
{
Part
:
composition
.
GetPart
(),
Material
:
composition
.
GetMaterial
(),
Value
:
composition
.
GetValue
(),
})
}
p
.
Fits
=
product
.
GetDetail
()
.
GetFits
()
for
_
,
g
:=
range
product
.
GetGenders
()
{
p
.
Genders
=
append
(
p
.
Genders
,
model
.
ProductGender
(
g
))
}
p
.
Colors
=
buildProductColors
(
designerProduct
.
GetColorProducts
(),
designerProduct
.
GetDesignerId
())
p
.
Models
=
product
.
GetDetail
()
.
GetModels
()
})
if
ws
.
Title
.
sourceId
==
product
.
GetSourceId
()
{
p
.
Title
=
model
.
ProductTitle
{
En
:
product
.
GetTitleEn
(),
Cn
:
product
.
GetTitleCn
(),
}
}
if
ws
.
Category
.
sourceId
==
product
.
GetSourceId
()
{
p
.
Category
=
getCategory
(
product
.
GetCategoriesV2
())
}
if
ws
.
Compositions
.
sourceId
==
product
.
GetSourceId
()
{
for
_
,
composition
:=
range
product
.
GetDetail
()
.
GetCompositions
()
{
p
.
Compositions
=
append
(
p
.
Compositions
,
model
.
ProductComposition
{
Part
:
composition
.
GetPart
(),
Material
:
composition
.
GetMaterial
(),
Value
:
composition
.
GetValue
(),
})
}
}
if
ws
.
Care
.
sourceId
==
product
.
GetSourceId
()
{
p
.
Care
=
product
.
GetDetail
()
.
GetCare
()
}
if
ws
.
Description
.
sourceId
==
product
.
GetSourceId
()
{
p
.
Description
=
product
.
GetDetail
()
.
GetDescription
()
}
if
ws
.
Fits
.
sourceId
==
product
.
GetSourceId
()
{
p
.
Fits
=
product
.
GetDetail
()
.
GetFits
()
}
if
ws
.
Models
.
sourceId
==
product
.
GetSourceId
()
{
p
.
Models
=
product
.
GetDetail
()
.
GetModels
()
}
if
ws
.
Season
.
sourceId
==
product
.
GetSourceId
()
{
p
.
Season
=
product
.
GetSeason
()
}
}
}
p
.
Colors
=
buildProductColors
(
designerProduct
.
GetColorProducts
(),
designerProduct
.
GetDesignerId
(),
ws
)
ps
=
append
(
ps
,
p
)
}
return
ps
}
func
buildProductColors
(
colorProducts
[]
*
pc4
.
ColorProduct
,
styleNumber
string
)
model
.
ProductColors
{
func
getCategory
(
category
*
pc4
.
CategoryV2
)
model
.
ProductCategory
{
pc
:=
model
.
ProductCategory
{}
pc
.
Id
=
category
.
GetCategoryId
()
pc
.
Name
=
category
.
GetCategoryName
()
if
category
.
GetChildren
()
==
nil
{
return
pc
}
for
_
,
c
:=
range
category
.
GetChildren
()
{
pc
.
Children
=
append
(
pc
.
Children
,
getCategory
(
c
))
}
return
pc
}
func
buildProductColors
(
colorProducts
[]
*
pc4
.
ColorProduct
,
styleNumber
string
,
ws
weightSelect
)
model
.
ProductColors
{
var
pcs
model
.
ProductColors
for
_
,
colorProduct
:=
range
colorProducts
{
pcs
=
append
(
pcs
,
buildProductColor
(
colorProduct
,
styleNumber
))
pcs
=
append
(
pcs
,
buildProductColor
(
colorProduct
,
styleNumber
,
ws
))
}
return
pcs
}
func
buildProductColor
(
colorProduct
*
pc4
.
ColorProduct
,
styleNumber
string
)
model
.
ProductColor
{
func
buildProductColor
(
colorProduct
*
pc4
.
ColorProduct
,
styleNumber
string
,
ws
weightSelect
)
model
.
ProductColor
{
pc
:=
model
.
ProductColor
{}
once
:=
&
sync
.
Once
{}
for
_
,
productAndSkus
:=
range
colorProduct
.
GetProductAndSkusList
()
{
...
...
@@ -71,6 +133,11 @@ func buildProductColor(colorProduct *pc4.ColorProduct, styleNumber string) model
pc
.
InfoSelect
=
product
.
GetId
()
pc
.
Images
=
product
.
GetColor
()
.
GetImages
()
})
if
ws
.
Image
.
sourceId
==
product
.
GetSourceId
()
{
pc
.
Images
=
product
.
GetColor
()
.
GetImages
()
}
for
_
,
sku
:=
range
productAndSkus
.
GetSkus
()
{
pc
.
Skus
=
append
(
pc
.
Skus
,
model
.
ProductColorSku
{
Pc3SkuId
:
sku
.
GetId
(),
...
...
@@ -88,3 +155,50 @@ func buildProductColor(colorProduct *pc4.ColorProduct, styleNumber string) model
}
return
pc
}
func
(
receiver
*
Product
)
getWeightSelect
(
sourceIds
[]
string
)
weightSelect
{
sourceItems
:=
receiver
.
cache
.
Source
.
GetSourceItems
()
ws
:=
weightSelect
{}
for
_
,
item
:=
range
sourceItems
{
if
!
slice
.
Contains
(
sourceIds
,
item
.
Id
)
{
// 不在所需要合并商品中的货源跳过
continue
}
if
ws
.
Image
.
weight
<
item
.
CombineWeight
.
Image
{
ws
.
Image
.
sourceId
=
item
.
Id
ws
.
Image
.
weight
=
item
.
CombineWeight
.
Image
}
if
ws
.
Title
.
weight
<
item
.
CombineWeight
.
Title
{
ws
.
Title
.
sourceId
=
item
.
Id
ws
.
Title
.
weight
=
item
.
CombineWeight
.
Title
}
if
ws
.
Category
.
weight
<
item
.
CombineWeight
.
Category
{
ws
.
Category
.
sourceId
=
item
.
Id
ws
.
Category
.
weight
=
item
.
CombineWeight
.
Category
}
if
ws
.
Compositions
.
weight
<
item
.
CombineWeight
.
Compositions
{
ws
.
Compositions
.
sourceId
=
item
.
Id
ws
.
Compositions
.
weight
=
item
.
CombineWeight
.
Compositions
}
if
ws
.
Care
.
weight
<
item
.
CombineWeight
.
Care
{
ws
.
Care
.
sourceId
=
item
.
Id
ws
.
Care
.
weight
=
item
.
CombineWeight
.
Care
}
if
ws
.
Description
.
weight
<
item
.
CombineWeight
.
Description
{
ws
.
Description
.
sourceId
=
item
.
Id
ws
.
Description
.
weight
=
item
.
CombineWeight
.
Description
}
if
ws
.
Fits
.
weight
<
item
.
CombineWeight
.
Fits
{
ws
.
Fits
.
sourceId
=
item
.
Id
ws
.
Fits
.
weight
=
item
.
CombineWeight
.
Fits
}
if
ws
.
Models
.
weight
<
item
.
CombineWeight
.
Models
{
ws
.
Models
.
sourceId
=
item
.
Id
ws
.
Models
.
weight
=
item
.
CombineWeight
.
Models
}
if
ws
.
Season
.
weight
<
item
.
CombineWeight
.
Season
{
ws
.
Season
.
sourceId
=
item
.
Id
ws
.
Season
.
weight
=
item
.
CombineWeight
.
Season
}
}
return
ws
}
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