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
e18ca191
authored
Aug 04, 2022
by
mushishixian
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
在途库存显示
parent
a06f158d
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
76 additions
and
2 deletions
model/ly_sku.go
pkg/vars/sku.go
service/service_ly.go
service/service_stock_info.go
model/ly_sku.go
View file @
e18ca191
...
@@ -67,6 +67,7 @@ type LySku struct {
...
@@ -67,6 +67,7 @@ type LySku struct {
ActivityInfo
PriceActivity
`json:"activity_info"`
ActivityInfo
PriceActivity
`json:"activity_info"`
StandardBrand
StandardBrand
`json:"standard_brand"`
StandardBrand
StandardBrand
`json:"standard_brand"`
GoodsTag
GoodsTag
`json:"goods_tag"`
GoodsTag
GoodsTag
`json:"goods_tag"`
StockInfo
interface
{}
`json:"stock_info"`
}
}
type
PriceActivity
struct
{
type
PriceActivity
struct
{
...
@@ -104,6 +105,13 @@ type GoodsTag struct {
...
@@ -104,6 +105,13 @@ type GoodsTag struct {
GoodsTagNames
[]
string
`json:"goods_tag_names,omitempty"`
GoodsTagNames
[]
string
`json:"goods_tag_names,omitempty"`
}
}
type
StockInfo
struct
{
Period
string
`json:"period" bson:"period"`
PeriodTime
int
`json:"-" bson:"period_time"`
PeriodTimeFormat
string
`json:"period_time"`
Stock
int
`json:"stock" bson:"stock"`
}
//为什么不直接映射到结构,而要用gjson,因为redis存的数据结构不一定正常,可能类型不一致
//为什么不直接映射到结构,而要用gjson,因为redis存的数据结构不一定正常,可能类型不一致
func
InitSkuData
(
sku
string
)
(
data
LySku
)
{
func
InitSkuData
(
sku
string
)
(
data
LySku
)
{
goodsSn
:=
gjson
.
Get
(
sku
,
"goods_sn"
)
.
String
()
goodsSn
:=
gjson
.
Get
(
sku
,
"goods_sn"
)
.
String
()
...
...
pkg/vars/sku.go
View file @
e18ca191
...
@@ -15,3 +15,11 @@ var GoodsTags = map[int]string{
...
@@ -15,3 +15,11 @@ var GoodsTags = map[int]string{
3
:
"认证"
,
3
:
"认证"
,
4
:
"当天发货"
,
4
:
"当天发货"
,
}
}
var
StockInfoSupplierMap
=
map
[
int64
]
string
{
6
:
"element14"
,
7
:
"digikey"
,
14
:
"mouser"
,
21
:
"rs"
,
1672
:
"master"
,
}
service/service_ly.go
View file @
e18ca191
package
service
package
service
import
(
import
(
"fmt"
"go_sku_server/model"
"go_sku_server/model"
"go_sku_server/pkg/gredis"
"go_sku_server/pkg/gredis"
"go_sku_server/service/sorter"
"go_sku_server/service/sorter"
...
@@ -37,7 +36,10 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
...
@@ -37,7 +36,10 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
redisConn
.
Close
()
redisConn
.
Close
()
}()
}()
fast
:=
ctx
.
Request
.
FormValue
(
"power[fast]"
)
fast
:=
ctx
.
Request
.
FormValue
(
"power[fast]"
)
//是否展示属性
showAttr
:=
ctx
.
Request
.
FormValue
(
"show_attr"
)
showAttr
:=
ctx
.
Request
.
FormValue
(
"show_attr"
)
//是否展示在途库存
showStockInfo
:=
ctx
.
Request
.
FormValue
(
"show_stock_info"
)
//批量获取商品详情
//批量获取商品详情
skuArr
:=
gredis
.
Hmget
(
"default_r"
,
"sku"
,
goodsIds
)
skuArr
:=
gredis
.
Hmget
(
"default_r"
,
"sku"
,
goodsIds
)
//为了性能着想,这边也先去批量获取spu的信息
//为了性能着想,这边也先去批量获取spu的信息
...
@@ -85,7 +87,6 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
...
@@ -85,7 +87,6 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
brandId
:=
gjson
.
Get
(
spu
,
"brand_id"
)
.
Int
()
brandId
:=
gjson
.
Get
(
spu
,
"brand_id"
)
.
Int
()
brandName
,
_
:=
redis
.
String
(
redisConn
.
Do
(
"HGET"
,
"brand"
,
brandId
))
brandName
,
_
:=
redis
.
String
(
redisConn
.
Do
(
"HGET"
,
"brand"
,
brandId
))
sku
.
BrandName
=
brandName
sku
.
BrandName
=
brandName
fmt
.
Println
(
showAttr
)
//获取税务信息
//获取税务信息
if
fast
!=
"1"
{
//仅提供价格和库存
if
fast
!=
"1"
{
//仅提供价格和库存
if
sku
.
GoodsName
!=
""
&&
brandId
!=
0
{
if
sku
.
GoodsName
!=
""
&&
brandId
!=
0
{
...
@@ -101,6 +102,16 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
...
@@ -101,6 +102,16 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
}
}
}
}
if
showStockInfo
==
"1"
&&
sku
.
OldGoodsId
!=
0
{
sku
.
StockInfo
=
ls
.
getStockInfo
(
sku
.
SupplierId
,
sku
.
OldGoodsId
)
}
//格式化为对象返回
if
sku
.
StockInfo
==
nil
{
type
StockInfoResult
struct
{
}
sku
.
StockInfo
=
new
(
StockInfoResult
)
}
//获取供应链标准品牌
//获取供应链标准品牌
//什么是供应链的标准品牌 供应链那边报关的时候要求他们的标准品牌,所以要吧自己的品牌映射上去
//什么是供应链的标准品牌 供应链那边报关的时候要求他们的标准品牌,所以要吧自己的品牌映射上去
//继来那边对接的标准品牌(下单的时候)
//继来那边对接的标准品牌(下单的时候)
...
...
service/service_stock_info.go
0 → 100644
View file @
e18ca191
package
service
import
(
"go_sku_server/model"
"go_sku_server/pkg/logger"
"go_sku_server/pkg/mongo"
"go_sku_server/pkg/vars"
"time"
"gopkg.in/mgo.v2"
"gopkg.in/mgo.v2/bson"
)
//在途库存服务
type
StockInfoService
struct
{
}
func
(
ss
*
LyService
)
getStockInfo
(
supplierId
,
oldGoodsId
int64
)
interface
{}
{
var
stockInfo
model
.
StockInfo
//去mongodb获取在途库存信息
mongodb
:=
mongo
.
Conn
(
"default"
)
defer
func
()
{
mongodb
.
Close
()
}()
//还要判断去哪个集合取值
collectionName
:=
vars
.
StockInfoSupplierMap
[
supplierId
]
type
Goods
struct
{
StockInfo
model
.
StockInfo
`bson:"stock_info"`
}
var
goods
Goods
err
:=
mongodb
.
DB
(
"ichunt"
)
.
C
(
collectionName
)
.
Find
(
bson
.
M
{
"goods_id"
:
int
(
oldGoodsId
)})
.
One
(
&
goods
)
if
err
!=
nil
&&
err
!=
mgo
.
ErrNotFound
{
logger
.
Select
(
"sku_query"
)
.
Error
(
err
.
Error
())
}
stockInfo
=
goods
.
StockInfo
if
stockInfo
.
PeriodTime
>
0
{
stockInfo
.
PeriodTimeFormat
=
time
.
Unix
(
int64
(
stockInfo
.
PeriodTime
),
0
)
.
Format
(
"2006-01-02"
)
}
if
stockInfo
.
Stock
!=
0
||
stockInfo
.
PeriodTime
!=
0
{
return
stockInfo
}
return
nil
}
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