Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
黄成意
/
go_sku_server
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
4d95c2a2
authored
Mar 25, 2024
by
杨树贤
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
展示spu详情
parent
9279af23
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
0 deletions
model/ly_sku.go
service/service_ly.go
model/ly_sku.go
View file @
4d95c2a2
...
@@ -77,6 +77,7 @@ type LySku struct {
...
@@ -77,6 +77,7 @@ type LySku struct {
GoodsTag
GoodsTag
`json:"goods_tag"`
GoodsTag
GoodsTag
`json:"goods_tag"`
StockInfo
interface
{}
`json:"stock_info"`
StockInfo
interface
{}
`json:"stock_info"`
SkuDetail
string
`json:"sku_detail"`
SkuDetail
string
`json:"sku_detail"`
SpuExtra
SpuExtra
`json:"spu_extra"`
Eccn
string
`json:"eccn"`
Eccn
string
`json:"eccn"`
DiscountRatio
DiscountRatio
`json:"discount_ratio"`
DiscountRatio
DiscountRatio
`json:"discount_ratio"`
PriceRatioSort
int
`json:"price_ratio_sort"`
PriceRatioSort
int
`json:"price_ratio_sort"`
...
@@ -141,6 +142,15 @@ type StockInfo struct {
...
@@ -141,6 +142,15 @@ type StockInfo struct {
Stock
int
`json:"stock" bson:"stock"`
Stock
int
`json:"stock" bson:"stock"`
}
}
type
SpuExtra
struct
{
ImageList
[]
struct
{
Name
string
`bson:"name" json:"name"`
Thumbnail
string
`bson:"thumbnail" json:"thumbnail"`
}
`bson:"image_list" json:"image_list"`
SpuDetail
string
`bson:"spu_detail" json:"spu_detail"`
SpuId
string
`bson:"spu_id" json:"spu_id"`
}
// 为什么不直接映射到结构,而要用gjson,因为redis存的数据结构不一定正常,可能类型不一致
// 为什么不直接映射到结构,而要用gjson,因为redis存的数据结构不一定正常,可能类型不一致
func
InitSkuData
(
sku
string
)
(
data
LySku
)
{
func
InitSkuData
(
sku
string
)
(
data
LySku
)
{
...
...
service/service_ly.go
View file @
4d95c2a2
...
@@ -48,6 +48,8 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
...
@@ -48,6 +48,8 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
showStockInfo
:=
ctx
.
Request
.
FormValue
(
"show_stock_info"
)
showStockInfo
:=
ctx
.
Request
.
FormValue
(
"show_stock_info"
)
//是否展示sku详情
//是否展示sku详情
showSkuDetail
:=
ctx
.
Request
.
FormValue
(
"show_sku_detail"
)
showSkuDetail
:=
ctx
.
Request
.
FormValue
(
"show_sku_detail"
)
//是否展示spu额外信息
showSpuExtra
:=
ctx
.
Request
.
FormValue
(
"show_spu_extra"
)
//批量获取商品详情
//批量获取商品详情
skuArr
:=
gredis
.
Hmget
(
"default_r"
,
"sku"
,
goodsIds
)
skuArr
:=
gredis
.
Hmget
(
"default_r"
,
"sku"
,
goodsIds
)
...
@@ -120,6 +122,11 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
...
@@ -120,6 +122,11 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
sku
.
SkuDetail
=
ls
.
GetSkuDetail
(
sku
.
GoodsId
)
sku
.
SkuDetail
=
ls
.
GetSkuDetail
(
sku
.
GoodsId
)
}
}
//是否需要返回spu额外信息
if
showSpuExtra
==
"1"
{
sku
.
SpuExtra
=
ls
.
GetSpuExtra
(
sku
.
SpuId
)
}
//格式化为对象返回
//格式化为对象返回
if
sku
.
StockInfo
==
nil
{
if
sku
.
StockInfo
==
nil
{
type
StockInfoResult
struct
{
type
StockInfoResult
struct
{
...
@@ -271,3 +278,17 @@ func (ls *LyService) GetSkuDetail(skuId string) string {
...
@@ -271,3 +278,17 @@ func (ls *LyService) GetSkuDetail(skuId string) string {
}
}
return
skuDetail
.
Detail
return
skuDetail
.
Detail
}
}
// 获取spu_extra
func
(
ls
*
LyService
)
GetSpuExtra
(
spuId
string
)
(
spuExtra
model
.
SpuExtra
)
{
mongodb
:=
mongo
.
Conn
(
"default"
)
defer
func
()
{
mongodb
.
Close
()
}()
err
:=
mongodb
.
DB
(
"ichunt"
)
.
C
(
"spu_extra"
)
.
Find
(
bson
.
M
{
"spu_id"
:
spuId
})
.
One
(
&
spuExtra
)
if
err
!=
nil
&&
err
!=
mgo
.
ErrNotFound
{
logger
.
Select
(
"sku_query"
)
.
Error
(
err
.
Error
())
}
return
spuExtra
}
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