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
ba09e550
authored
Oct 10, 2020
by
mushishixian
Browse files
Options
_('Browse Files')
Download
Plain Diff
修复
parents
e82002d5
ae00a568
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
84 additions
and
2 deletions
service/service_ly.go
service/service_ly.go
View file @
ba09e550
package
service
import
(
"fmt"
"github.com/gomodule/redigo/redis"
"github.com/iancoleman/orderedmap"
"github.com/syyongx/php2go"
"github.com/tidwall/gjson"
"goods_machining/model"
"goods_machining/pkg/gredis"
"strings"
"sync"
)
type
LyService
struct
{
}
/*
自
营数据详情
联
营数据详情
*/
func
(
qs
*
LyService
)
LyGoodsDetail
(
goodsIds
[]
string
,
wg
*
sync
.
WaitGroup
)
(
results
model
.
LyResponse
)
{
redisConn
:=
gredis
.
Conn
(
"search_r"
)
defer
func
()
{
wg
.
Done
()
redisConn
.
Close
()
}()
//批量获取商品详情
skuArr
:=
gredis
.
HgetPi
(
"search_r"
,
"sku"
,
goodsIds
)
//为了性能着想,这边也先去批量获取spu的信息
spuList
:=
qs
.
getSpuList
(
goodsIds
)
fmt
.
Println
(
spuList
)
for
goodsId
,
info
:=
range
skuArr
{
A
:=
orderedmap
.
New
()
//初始化有序map,拼接data 数据
A
.
Set
(
"packing"
,
""
)
//读取包装字段的缓存
if
gjson
.
Get
(
info
,
"supplier_id"
)
.
Int
()
==
7
{
//sku_raw_map哪里写入(成意写的)
packing
,
err
:=
redis
.
String
(
redisConn
.
Do
(
"HGET"
,
"SKU_RAW_MAP"
,
goodsId
))
if
err
==
nil
{
A
.
Set
(
"packing"
,
gjson
.
Get
(
packing
,
"pack"
)
.
String
())
}
}
A
.
Set
(
"goods_id"
,
goodsId
)
//去获取spu的信息
spuInfo
:=
spuList
[
goodsId
]
spuLargeImage
:=
gjson
.
Get
(
spuInfo
,
"images_l"
)
.
String
()
A
.
Set
(
"images_l"
,
spuLargeImage
)
if
spuLargeImage
!=
""
&&
php2go
.
Strlen
(
spuLargeImage
)
<
5
{
A
.
Set
(
"images_l"
,
""
)
}
pdf
:=
gjson
.
Get
(
spuInfo
,
"pdf"
)
.
String
()
A
.
Set
(
"pdf"
,
pdf
)
if
pdf
==
""
||
(
php2go
.
Strlen
(
spuLargeImage
)
<
5
)
{
A
.
Set
(
"pdf"
,
""
)
}
//商品图片不存在用大图代替
goodsImage
:=
gjson
.
Get
(
info
,
"goods_images"
)
.
String
()
A
.
Set
(
"goods_images"
,
goodsImage
)
if
goodsImage
==
""
&&
spuLargeImage
!=
""
{
goodsImage
=
spuLargeImage
A
.
Set
(
"goods_images"
,
spuLargeImage
)
}
//加上是否是rocelec图片的判断,如果是的话,就将图片设置为空
if
strings
.
Contains
(
goodsImage
,
"rocelec"
)
{
A
.
Set
(
"goods_images"
,
""
)
}
goodsName
:=
gjson
.
Get
(
info
,
"goods_name"
)
.
String
()
A
.
Set
(
"goods_name"
,
goodsName
)
if
goodsName
==
""
{
A
.
Set
(
"goods_name"
,
gjson
.
Get
(
spuInfo
,
"spu_name"
))
}
//获取品牌名称
brandId
:=
gjson
.
Get
(
spuInfo
,
"brand_id"
)
.
String
()
brandName
,
_
:=
redis
.
String
(
redisConn
.
Do
(
"HGET"
,
"brand"
,
brandId
))
A
.
Set
(
"brand_name"
,
brandName
)
//todo 条件判断
//获取税务信息
if
true
{
//仅提供价格和库存
}
//(*goodsRes)[goodsId] = A
}
return
}
func
(
qs
*
LyService
)
getSpuList
(
goodsIds
[]
string
)
(
spuList
map
[
string
]
string
)
{
redisConn
:=
gredis
.
Conn
(
"search_r"
)
defer
redisConn
.
Close
()
//批量获取spu详情
spuList
=
gredis
.
HgetPi
(
"search_r"
,
"sku"
,
goodsIds
)
return
}
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