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
e7f4c5d6
Commit
e7f4c5d6
authored
Jul 01, 2025
by
zhengyaoqiu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(colorway): PC3商品转换
parent
53636eac
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
301 additions
and
32 deletions
+301
-32
colorspu.go
internal/pkg/database/model/colorspu.go
+3
-2
completespu.go
internal/pkg/database/model/completespu.go
+1
-2
sku.go
internal/pkg/database/model/sku.go
+3
-2
uploadlogic.go
internal/rpc/internal/logic/product/uploadlogic.go
+2
-6
product.go
internal/rpc/internal/svc/convert/product.go
+0
-20
spu.go
internal/rpc/internal/svc/convert/spu.go
+289
-0
servicecontext.go
internal/rpc/internal/svc/servicecontext.go
+3
-0
No files found.
internal/pkg/database/model/colorspu.go
View file @
e7f4c5d6
...
...
@@ -7,11 +7,12 @@ type ColorSpu struct {
CompleteSpuStyleNumber
string
`gorm:"uniqueIndex:style; size:50; not null"`
ColorCode
string
`gorm:"uniqueIndex:style; size:50; not null"`
Color
Color
`gorm:"embedded;embeddedPrefix:color_"`
InfoSelect
string
`gorm:"not null; size:24"`
// 商品信息默认选择哪个商品
// 外键
// 多对一
Skus
[]
Sku
`gorm:"foreignKey:ColorSpuStyleNumber,ColorSpuColorCode; references:CompleteSpuStyleNumber,ColorCode; constraint:OnUpdate:CASCADE,OnDelete:CASCADE"`
Images
[]
Image
`gorm:"foreignKey:ColorSpuStyleNumber,ColorSpuColorCode; references:CompleteSpuStyleNumber,ColorCode; constraint:OnUpdate:CASCADE,OnDelete:CASCADE"`
Skus
Skus
`gorm:"foreignKey:ColorSpuStyleNumber,ColorSpuColorCode; references:CompleteSpuStyleNumber,ColorCode; constraint:OnUpdate:CASCADE,OnDelete:CASCADE"`
Images
Images
`gorm:"foreignKey:ColorSpuStyleNumber,ColorSpuColorCode; references:CompleteSpuStyleNumber,ColorCode; constraint:OnUpdate:CASCADE,OnDelete:CASCADE"`
}
type
ColorSpus
[]
ColorSpu
...
...
internal/pkg/database/model/completespu.go
View file @
e7f4c5d6
...
...
@@ -12,13 +12,12 @@ type CompleteSpu struct {
Care
string
`gorm:"type:text"`
MadeIn
string
`gorm:"size:50"`
HsCode
string
`gorm:"size:50"`
InfoSelect
string
`gorm:"not null; size:24"`
// 商品信息默认选择哪个商品
// 外键
// 多对一
ColorSpus
ColorSpus
`gorm:"foreignKey:CompleteSpuStyleNumber; references:StyleNumber; constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
Products
Products
`gorm:"foreignKey:CompleteSpuStyleNumber; references:StyleNumber; constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
Compositions
Compositions
`gorm:"foreignKey:CompleteSpuStyleNumber; references:StyleNumber; constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
Skus
Skus
`gorm:"foreignKey:ColorSpuStyleNumber; references:StyleNumber; constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
Models
Models
`gorm:"foreignKey:CompleteSpuStyleNumber; references:StyleNumber; constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
Fits
Fits
`gorm:"foreignKey:CompleteSpuStyleNumber; references:StyleNumber; constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
// 多对多
...
...
internal/pkg/database/model/sku.go
View file @
e7f4c5d6
...
...
@@ -5,10 +5,11 @@ import "gorm.io/gorm"
type
Sku
struct
{
gorm
.
Model
Pc3SkuId
string
`gorm:"uniqueIndex; not null; size:24"`
Pc3ProductId
string
`gorm:"not null; size:24"`
ColorSpuStyleNumber
string
`gorm:"size:50; not null"`
ColorSpuColorCode
string
`gorm:"size:50; not null"`
Source
string
`gorm:"size:50; not null"`
Site
string
`gorm:"size:50; not null"`
Source
Id
string
`gorm:"size:50; not null"`
Site
Id
string
`gorm:"size:50; not null"`
Size
string
`gorm:"size:50; not null"`
Stock
int
`gorm:"not null"`
Price
float64
`gorm:"type:decimal(10,2); not null"`
...
...
internal/rpc/internal/logic/product/uploadlogic.go
View file @
e7f4c5d6
...
...
@@ -32,11 +32,7 @@ func (l *UploadLogic) Upload(in *colorway.ProductUploadRequest) (*colorway.Produ
if
err
!=
nil
{
return
nil
,
err
}
sourceItems
:=
l
.
svcCtx
.
Cache
.
Source
.
GetSourceItems
()
for
_
,
designerProduct
:=
range
productList
.
GetDesignerProducts
()
{
designerProduct
.
GetDesignerId
()
}
log
.
Println
(
productList
,
sourceItems
)
completeSpus
:=
l
.
svcCtx
.
SpuConvert
.
Convert
(
productList
.
GetDesignerProducts
())
log
.
Println
(
completeSpus
)
return
&
colorway
.
ProductUploadResponse
{},
nil
}
internal/rpc/internal/svc/convert/product.go
deleted
100644 → 0
View file @
53636eac
package
convert
import
(
"git.chillcy.com/golang/chillcy/project/pc4/pkg/rpc/pb/pc4"
"git.chillcy.com/golang/colorway/internal/pkg/database/model"
)
type
Result
struct
{
CompleteSpus
model
.
CompleteSpus
ColorSpus
model
.
ColorSpus
}
type
Product
struct
{}
func
(
receiver
Product
)
Convert
(
designerProducts
[]
*
pc4
.
DesignerProduct
)
{
for
_
,
designerProduct
:=
range
designerProducts
{
designerProduct
.
GetDesignerId
()
designerProduct
.
GetColorProducts
()
}
}
internal/rpc/internal/svc/convert/spu.go
0 → 100644
View file @
e7f4c5d6
package
convert
import
(
"git.chillcy.com/golang/chillcy/pkg/slice"
"git.chillcy.com/golang/chillcy/project/pc4/pkg/rpc/pb/pc4"
"git.chillcy.com/golang/colorway/internal/pkg/database/model"
"git.chillcy.com/golang/colorway/internal/rpc/internal/svc/cache"
"sync"
)
type
Spu
struct
{
cache
*
cache
.
Cache
}
func
NewSpu
(
cache
*
cache
.
Cache
)
*
Spu
{
return
&
Spu
{
cache
:
cache
}
}
func
(
receiver
*
Spu
)
Convert
(
designerProducts
[]
*
pc4
.
DesignerProduct
)
model
.
CompleteSpus
{
var
completeSpus
model
.
CompleteSpus
for
_
,
designerProduct
:=
range
designerProducts
{
completeSpus
=
append
(
completeSpus
,
receiver
.
buildCompleteSpu
(
designerProduct
))
}
return
completeSpus
}
type
weight
struct
{
sourceId
string
weight
int
}
type
weightSelect
struct
{
Image
weight
Title
weight
Category
weight
Compositions
weight
Care
weight
Description
weight
Fits
weight
Models
weight
Season
weight
}
func
(
receiver
*
Spu
)
buildCompleteSpu
(
designerProduct
*
pc4
.
DesignerProduct
)
model
.
CompleteSpu
{
sourceIds
:=
getSourceIds
(
designerProduct
)
ws
:=
receiver
.
getWeightSelect
(
sourceIds
)
completeSpu
:=
model
.
CompleteSpu
{}
completeSpu
.
StyleNumber
=
designerProduct
.
GetDesignerId
()
once
:=
sync
.
Once
{}
for
_
,
colorProduct
:=
range
designerProduct
.
GetColorProducts
()
{
for
_
,
productAndSkus
:=
range
colorProduct
.
GetProductAndSkusList
()
{
product
:=
productAndSkus
.
GetProduct
()
once
.
Do
(
func
()
{
// 默认商品数据选择
completeSpu
.
InfoSelect
=
product
.
GetId
()
completeSpu
.
Title
=
model
.
Title
{
En
:
product
.
GetTitleEn
(),
Cn
:
product
.
GetTitleCn
(),
}
completeSpu
.
Description
=
product
.
GetDetail
()
.
GetDescription
()
completeSpu
.
Season
=
product
.
GetSeason
()
completeSpu
.
BrandId
=
product
.
GetBrandId
()
completeSpu
.
Care
=
product
.
GetDetail
()
.
GetCare
()
completeSpu
.
MadeIn
=
product
.
GetDetail
()
.
GetMadeIn
()
completeSpu
.
HsCode
=
product
.
GetDetail
()
.
GetHsCode
()
completeSpu
.
Compositions
=
buildCompositions
(
product
.
GetDetail
()
.
GetCompositions
(),
product
.
GetDesignerId
())
completeSpu
.
Models
=
buildModels
(
product
.
GetDetail
()
.
GetModels
(),
product
.
GetDesignerId
())
completeSpu
.
Fits
=
buildFits
(
product
.
GetDetail
()
.
GetFits
(),
product
.
GetDesignerId
())
for
_
,
g
:=
range
product
.
GetGenders
()
{
completeSpu
.
Genders
=
append
(
completeSpu
.
Genders
,
model
.
Gender
{
Code
:
g
,
})
}
completeSpu
.
Categories
=
buildCategories
(
product
.
GetCategoryIds
())
})
// 分权重商品信息选择覆盖默认
if
product
.
GetSourceId
()
==
ws
.
Title
.
sourceId
{
completeSpu
.
Title
=
model
.
Title
{
En
:
product
.
GetTitleEn
(),
Cn
:
product
.
GetTitleCn
(),
}
}
if
product
.
GetSourceId
()
==
ws
.
Description
.
sourceId
{
completeSpu
.
Description
=
product
.
GetDetail
()
.
GetDescription
()
}
if
product
.
GetSourceId
()
==
ws
.
Season
.
sourceId
{
completeSpu
.
Season
=
product
.
GetSeason
()
}
if
product
.
GetSourceId
()
==
ws
.
Care
.
sourceId
{
completeSpu
.
Care
=
product
.
GetDetail
()
.
GetCare
()
}
if
product
.
GetSourceId
()
==
ws
.
Compositions
.
sourceId
{
completeSpu
.
Compositions
=
buildCompositions
(
product
.
GetDetail
()
.
GetCompositions
(),
product
.
GetDesignerId
())
}
if
product
.
GetSourceId
()
==
ws
.
Models
.
sourceId
{
completeSpu
.
Models
=
buildModels
(
product
.
GetDetail
()
.
GetModels
(),
product
.
GetDesignerId
())
}
if
product
.
GetSourceId
()
==
ws
.
Fits
.
sourceId
{
completeSpu
.
Fits
=
buildFits
(
product
.
GetDetail
()
.
GetFits
(),
product
.
GetDesignerId
())
}
if
product
.
GetSourceId
()
==
ws
.
Category
.
sourceId
{
completeSpu
.
Categories
=
buildCategories
(
product
.
GetCategoryIds
())
}
}
}
completeSpu
.
ColorSpus
=
buildColorSpus
(
designerProduct
.
GetColorProducts
(),
designerProduct
.
GetDesignerId
(),
ws
)
return
completeSpu
}
func
buildCategories
(
cs
[]
string
)
model
.
Categories
{
var
categories
model
.
Categories
for
_
,
c
:=
range
cs
{
categories
=
append
(
categories
,
model
.
Category
{
Code
:
c
,
Name
:
""
,
ParentCode
:
""
,
})
}
return
categories
}
func
buildFits
(
fs
[]
string
,
styleNumber
string
)
model
.
Fits
{
var
fits
model
.
Fits
for
_
,
f
:=
range
fs
{
fits
=
append
(
fits
,
model
.
Fit
{
CompleteSpuStyleNumber
:
styleNumber
,
Content
:
f
,
})
}
return
fits
}
func
buildModels
(
ms
[]
string
,
styleNumber
string
)
model
.
Models
{
var
models
model
.
Models
for
_
,
m
:=
range
ms
{
models
=
append
(
models
,
model
.
Model
{
CompleteSpuStyleNumber
:
styleNumber
,
Content
:
m
,
})
}
return
models
}
func
buildCompositions
(
cs
[]
*
pc4
.
Composition
,
styleNumber
string
)
model
.
Compositions
{
var
compositions
model
.
Compositions
for
_
,
c
:=
range
cs
{
compositions
=
append
(
compositions
,
model
.
Composition
{
CompleteSpuStyleNumber
:
styleNumber
,
Part
:
c
.
GetPart
(),
Material
:
c
.
GetMaterial
(),
Value
:
c
.
GetValue
(),
})
}
return
compositions
}
func
buildColorSpus
(
colorProducts
[]
*
pc4
.
ColorProduct
,
styleNumber
string
,
ws
weightSelect
)
model
.
ColorSpus
{
var
colorSpus
model
.
ColorSpus
for
_
,
colorProduct
:=
range
colorProducts
{
colorSpu
:=
buildColorSpu
(
colorProduct
,
styleNumber
,
ws
)
colorSpus
=
append
(
colorSpus
,
colorSpu
)
}
return
colorSpus
}
func
buildColorSpu
(
colorProduct
*
pc4
.
ColorProduct
,
styleNumber
string
,
ws
weightSelect
)
model
.
ColorSpu
{
colorSpu
:=
model
.
ColorSpu
{}
colorSpu
.
CompleteSpuStyleNumber
=
styleNumber
colorSpu
.
ColorCode
=
colorProduct
.
GetColorNumber
()
once
:=
sync
.
Once
{}
for
_
,
productAndSkus
:=
range
colorProduct
.
GetProductAndSkusList
()
{
product
:=
productAndSkus
.
GetProduct
()
once
.
Do
(
func
()
{
colorSpu
.
InfoSelect
=
product
.
GetId
()
colorSpu
.
Color
=
model
.
Color
{
Id
:
product
.
GetColor
()
.
GetId
(),
Name
:
product
.
GetColor
()
.
GetName
(),
BasicId
:
product
.
GetColor
()
.
GetBasicColorId
(),
BasicName
:
product
.
GetColor
()
.
GetBasicColorName
(),
}
colorSpu
.
Images
=
getImages
(
product
.
GetColor
()
.
GetImages
(),
styleNumber
,
colorProduct
.
GetColorNumber
())
})
if
product
.
GetSourceId
()
==
ws
.
Image
.
sourceId
{
colorSpu
.
Images
=
getImages
(
product
.
GetColor
()
.
GetImages
(),
styleNumber
,
colorProduct
.
GetColorNumber
())
}
}
colorSpu
.
Skus
=
buildSkus
(
colorProduct
.
GetProductAndSkusList
(),
styleNumber
,
colorProduct
.
GetColorNumber
())
return
colorSpu
}
func
getImages
(
imageUrls
[]
string
,
styleNumber
,
colorCode
string
)
model
.
Images
{
var
images
model
.
Images
for
_
,
imageUrl
:=
range
imageUrls
{
images
=
append
(
images
,
model
.
Image
{
ColorSpuStyleNumber
:
styleNumber
,
ColorSpuColorCode
:
colorCode
,
Url
:
imageUrl
,
})
}
return
images
}
func
buildSkus
(
productAndSkusList
[]
*
pc4
.
ProductAndSkus
,
styleNumber
,
colorCode
string
)
model
.
Skus
{
var
skus
model
.
Skus
for
_
,
productAndSkus
:=
range
productAndSkusList
{
for
_
,
pSku
:=
range
productAndSkus
.
GetSkus
()
{
sku
:=
model
.
Sku
{}
sku
.
Pc3SkuId
=
pSku
.
GetId
()
sku
.
Pc3ProductId
=
productAndSkus
.
GetProduct
()
.
GetId
()
sku
.
ColorSpuStyleNumber
=
styleNumber
sku
.
ColorSpuColorCode
=
colorCode
sku
.
SourceId
=
productAndSkus
.
GetProduct
()
.
GetSourceId
()
sku
.
SiteId
=
productAndSkus
.
GetProduct
()
.
GetSiteId
()
sku
.
Size
=
pSku
.
GetRawSize
()
sku
.
Stock
=
int
(
pSku
.
GetStock
())
sku
.
Price
=
pSku
.
GetPriceDetail
()
.
GetNow
()
sku
.
Currency
=
pSku
.
GetPriceDetail
()
.
GetCurrency
()
skus
=
append
(
skus
,
sku
)
}
}
return
skus
}
func
getSourceIds
(
designerProduct
*
pc4
.
DesignerProduct
)
[]
string
{
var
sourceIds
[]
string
for
_
,
colorProduct
:=
range
designerProduct
.
GetColorProducts
()
{
for
_
,
productAndSkus
:=
range
colorProduct
.
GetProductAndSkusList
()
{
sourceIds
=
append
(
sourceIds
,
productAndSkus
.
GetProduct
()
.
GetSourceId
())
}
}
return
sourceIds
}
func
(
receiver
*
Spu
)
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
}
internal/rpc/internal/svc/servicecontext.go
View file @
e7f4c5d6
...
...
@@ -7,6 +7,7 @@ import (
"git.chillcy.com/golang/colorway/internal/pkg/database"
"git.chillcy.com/golang/colorway/internal/rpc/internal/config"
"git.chillcy.com/golang/colorway/internal/rpc/internal/svc/cache"
"git.chillcy.com/golang/colorway/internal/rpc/internal/svc/convert"
"github.com/zeromicro/go-zero/zrpc"
)
...
...
@@ -15,6 +16,7 @@ type ServiceContext struct {
DatabaseManager
*
database
.
Manager
Pc4RpcService
Pc4RpcService
Cache
*
cache
.
Cache
SpuConvert
*
convert
.
Spu
}
func
NewServiceContext
(
c
config
.
Config
)
*
ServiceContext
{
...
...
@@ -41,6 +43,7 @@ func NewServiceContext(c config.Config) *ServiceContext {
Source
:
svc
.
Pc4RpcService
.
Source
,
})
svc
.
Cache
=
cache
.
GetCache
()
svc
.
SpuConvert
=
convert
.
NewSpu
(
svc
.
Cache
)
return
svc
}
...
...
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