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
5138157b
authored
Aug 10, 2021
by
mushishixian
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
商品标签
parent
0cf52465
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
135 additions
and
67 deletions
.gitignore
model/ly_sku.go
pkg/vars/sku.go
service/service_ladder_price.go
service/service_ly.go
service/service_tags.go
service/service_zy.go
.gitignore
View file @
5138157b
...
...
@@ -18,4 +18,5 @@ cmd.exe~
/cmd/http
/doc/spuTest
/doc/test3
/.history
model/ly_sku.go
View file @
5138157b
...
...
@@ -66,6 +66,7 @@ type LySku struct {
GiftActivity
GiftActivity
`json:"gift_activity"`
ActivityInfo
PriceActivity
`json:"activity_info"`
StandardBrand
StandardBrand
`json:"standard_brand"`
GoodsTag
GoodsTag
`json:"goods_tag"`
}
type
PriceActivity
struct
{
...
...
@@ -96,6 +97,13 @@ type StandardBrand struct {
BrandLogo
string
`json:"brand_logo,omitempty"`
}
type
GoodsTag
struct
{
GoodsLabel
int
`json:"goods_label,omitempty"`
GoodsLabelName
string
`json:"goods_label_name,omitempty"`
GoodsTag
[]
int
`json:"goods_tag,omitempty"`
GoodsTagNames
[]
string
`json:"goods_tag_names,omitempty"`
}
//为什么不直接映射到结构,而要用gjson,因为redis存的数据结构不一定正常,可能类型不一致
func
InitSkuData
(
sku
string
)
(
data
LySku
)
{
goodsSn
:=
gjson
.
Get
(
sku
,
"goods_sn"
)
.
String
()
...
...
pkg/vars/sku.go
0 → 100644
View file @
5138157b
package
vars
//商品类型字段
var
GoodsLabel
=
map
[
int
]
string
{
1
:
"国内现货"
,
2
:
"猎芯期货"
,
3
:
"国际现货"
,
}
//商品标签对应的展示
//1精选,2原厂直供,3认证,4当天发货
var
GoodsTags
=
map
[
int
]
string
{
1
:
"精选"
,
2
:
"原厂直供"
,
3
:
"认证"
,
4
:
"当天发货"
,
}
service/service_ladder_price.go
View file @
5138157b
...
...
@@ -10,11 +10,6 @@ import (
)
type
LadderPriceService
struct
{
}
func
adderprice
()
{
}
/**
...
...
@@ -24,100 +19,100 @@ func adderprice() {
* @param integer $currency 币种 1人民币 2美元
* @return [type]
*/
func
(
LP
*
LadderPriceService
)
GetPriceInfoByNum
(
ladderPriceRequest
model
.
LadderPriceRequest
,
goodsInfo
map
[
string
]
interface
{})
(
map
[
string
]
interface
{},
*
e
.
ApiError
)
{
func
(
LP
*
LadderPriceService
)
GetPriceInfoByNum
(
ladderPriceRequest
model
.
LadderPriceRequest
,
goodsInfo
map
[
string
]
interface
{})
(
map
[
string
]
interface
{},
*
e
.
ApiError
)
{
//此service 对 商详数据的操作都是使用的 gjson包
res
:=
make
(
map
[
string
]
interface
{})
res
:=
make
(
map
[
string
]
interface
{})
goodsJsonResult
,
err
:=
LP
.
getGoodsInfo
(
goodsInfo
,
ladderPriceRequest
.
GoodsId
)
if
(
err
!=
nil
)
{
return
res
,
err
goodsJsonResult
,
err
:=
LP
.
getGoodsInfo
(
goodsInfo
,
ladderPriceRequest
.
GoodsId
)
if
err
!=
nil
{
return
res
,
err
}
costly
:=
ladderPriceRequest
.
Costly
//这个字段暂时不知道什么意思
costly
:=
ladderPriceRequest
.
Costly
//这个字段暂时不知道什么意思
//根据num 从 多个阶梯价数组 获取到对应的阶梯价
ladderPriceOne
,
err
:=
LP
.
getLadderPrice
(
goodsJsonResult
,
ladderPriceRequest
.
GoodsId
,
ladderPriceRequest
.
Num
,
costly
)
ladderPriceOne
,
err
:=
LP
.
getLadderPrice
(
goodsJsonResult
,
ladderPriceRequest
.
GoodsId
,
ladderPriceRequest
.
Num
,
costly
)
num
:=
ladderPriceRequest
.
Num
purchases
:=
ladderPriceOne
.
Get
(
"purchases"
)
.
Int
();
if
purchases
>
ladderPriceRequest
.
Num
{
num
=
purchases
num
:=
ladderPriceRequest
.
Num
purchases
:=
ladderPriceOne
.
Get
(
"purchases"
)
.
Int
()
if
purchases
>
ladderPriceRequest
.
Num
{
num
=
purchases
}
goodsType
:=
goodsJsonResult
.
Get
(
"goods_type"
)
.
Int
()
acType
:=
goodsJsonResult
.
Get
(
"ac_type"
)
.
Int
()
if
((
goodsType
==
1
||
goodsType
==
2
)
&&
acType
!=
1
&&
ladderPriceRequest
.
Currency
!=
1
){
//美元
res
[
"price_us"
]
=
ladderPriceOne
.
Get
(
"price_us"
)
.
Float
()
res
[
"price_us_total"
]
=
common
.
MyRound
(
gconv
.
Float64
(
res
[
"price_us"
])
*
gconv
.
Float64
(
num
),
4
)
goodsInfo
[
"ac_type"
]
=
0
}
else
{
//人民币
res
[
"price_cn"
]
=
ladderPriceOne
.
Get
(
"price_cn"
)
.
Float
()
res
[
"price_cn_total"
]
=
common
.
MyRound
(
gconv
.
Float64
(
res
[
"price_cn"
])
*
gconv
.
Float64
(
num
),
4
)
//人民币原价总价
priceAc
:=
ladderPriceOne
.
Get
(
"price_ac"
)
.
Float
()
if
priceAc
!=
0
{
res
[
"price_ac"
]
=
priceAc
res
[
"price_ac_total"
]
=
common
.
MyRound
(
priceAc
*
gconv
.
Float64
(
num
),
4
)
goodsType
:=
goodsJsonResult
.
Get
(
"goods_type"
)
.
Int
()
acType
:=
goodsJsonResult
.
Get
(
"ac_type"
)
.
Int
()
if
(
goodsType
==
1
||
goodsType
==
2
)
&&
acType
!=
1
&&
ladderPriceRequest
.
Currency
!=
1
{
//美元
res
[
"price_us"
]
=
ladderPriceOne
.
Get
(
"price_us"
)
.
Float
()
res
[
"price_us_total"
]
=
common
.
MyRound
(
gconv
.
Float64
(
res
[
"price_us"
])
*
gconv
.
Float64
(
num
),
4
)
goodsInfo
[
"ac_type"
]
=
0
}
else
{
//人民币
res
[
"price_cn"
]
=
ladderPriceOne
.
Get
(
"price_cn"
)
.
Float
()
res
[
"price_cn_total"
]
=
common
.
MyRound
(
gconv
.
Float64
(
res
[
"price_cn"
])
*
gconv
.
Float64
(
num
),
4
)
//人民币原价总价
priceAc
:=
ladderPriceOne
.
Get
(
"price_ac"
)
.
Float
()
if
priceAc
!=
0
{
res
[
"price_ac"
]
=
priceAc
res
[
"price_ac_total"
]
=
common
.
MyRound
(
priceAc
*
gconv
.
Float64
(
num
),
4
)
}
}
ladder
:=
make
([]
map
[
string
]
interface
{},
0
)
a
:=
goodsJsonResult
.
Get
(
"ladder_price"
)
.
String
()
err1
:=
json
.
Unmarshal
([]
byte
(
a
),
&
ladder
)
//json Unmarshal一下,为了让返回格式没那么多斜划线
if
(
err1
!=
nil
)
{
return
res
,
e
.
NewApiError
(
"json.Unmarshal ladder_price 报错"
+
err1
.
Error
())
ladder
:=
make
([]
map
[
string
]
interface
{},
0
)
a
:=
goodsJsonResult
.
Get
(
"ladder_price"
)
.
String
()
err1
:=
json
.
Unmarshal
([]
byte
(
a
),
&
ladder
)
//json Unmarshal一下,为了让返回格式没那么多斜划线
if
err1
!=
nil
{
return
res
,
e
.
NewApiError
(
"json.Unmarshal ladder_price 报错"
+
err1
.
Error
())
}
res
[
"ladder_price"
]
=
ladder
res
[
"goods_info"
]
=
goodsInfo
[
ladderPriceRequest
.
GoodsId
]
res
[
"num"
]
=
num
return
res
,
nil
res
[
"ladder_price"
]
=
ladder
res
[
"goods_info"
]
=
goodsInfo
[
ladderPriceRequest
.
GoodsId
]
res
[
"num"
]
=
num
return
res
,
nil
}
func
(
LP
*
LadderPriceService
)
getGoodsInfo
(
goodsInfo
map
[
string
]
interface
{},
goodsId
string
)
(
gjson
.
Result
,
*
e
.
ApiError
)
{
func
(
LP
*
LadderPriceService
)
getGoodsInfo
(
goodsInfo
map
[
string
]
interface
{},
goodsId
string
)
(
gjson
.
Result
,
*
e
.
ApiError
)
{
var
info
gjson
.
Result
goodsInfoJson
:=
""
goodsInfoJson
:=
""
//把商品详情数据转化为json,方便用gjson处理
if
byteS
,
err
:=
json
.
Marshal
(
goodsInfo
);
err
!=
nil
{
if
byteS
,
err
:=
json
.
Marshal
(
goodsInfo
);
err
!=
nil
{
return
info
,
e
.
NewApiError
(
err
.
Error
())
}
else
{
goodsInfoJson
=
string
(
byteS
)
}
else
{
goodsInfoJson
=
string
(
byteS
)
}
goodsResult
:=
gjson
.
Get
(
goodsInfoJson
,
goodsId
)
if
(
goodsResult
.
Exists
()
!=
true
)
{
goodsResult
:=
gjson
.
Get
(
goodsInfoJson
,
goodsId
)
if
goodsResult
.
Exists
()
!=
true
{
return
info
,
e
.
NewApiError
(
"未找到对应SKU"
,
20001
)
}
return
goodsResult
,
nil
}
func
(
LP
*
LadderPriceService
)
getLadderPrice
(
goodsJsonResult
gjson
.
Result
,
goodsId
string
,
num
int64
,
costly
int
)
(
gjson
.
Result
,
*
e
.
ApiError
)
{
func
(
LP
*
LadderPriceService
)
getLadderPrice
(
goodsJsonResult
gjson
.
Result
,
goodsId
string
,
num
int64
,
costly
int
)
(
gjson
.
Result
,
*
e
.
ApiError
)
{
var
res
gjson
.
Result
ladderPriceS
:=
goodsJsonResult
.
Get
(
"ladder_price"
)
if
(
len
(
ladderPriceS
.
Array
())
>
0
)
{
var
price
=
gjson
.
Result
{}
for
k
,
item
:=
range
ladderPriceS
.
Array
()
{
purchases
:=
item
.
Get
(
"purchases"
)
.
Int
()
if
(
k
==
0
)
{
price
=
item
//默认最小数量
var
res
gjson
.
Result
ladderPriceS
:=
goodsJsonResult
.
Get
(
"ladder_price"
)
if
len
(
ladderPriceS
.
Array
())
>
0
{
var
price
=
gjson
.
Result
{}
for
k
,
item
:=
range
ladderPriceS
.
Array
()
{
purchases
:=
item
.
Get
(
"purchases"
)
.
Int
()
if
k
==
0
{
price
=
item
//默认最小数量
}
if
(
gconv
.
Int
(
costly
)
==
1
){
//这一句没懂 Costly 代表什么意思
if
gconv
.
Int
(
costly
)
==
1
{
//这一句没懂 Costly 代表什么意思
break
}
if
(
purchases
<=
num
)
{
price
=
item
if
purchases
<=
num
{
price
=
item
}
}
if
(
price
.
Exists
()
==
false
)
{
return
res
,
e
.
NewApiError
(
"这个SKU没有阶梯价"
,
504003
)
if
price
.
Exists
()
==
false
{
return
res
,
e
.
NewApiError
(
"这个SKU没有阶梯价"
,
504003
)
}
return
price
,
nil
return
price
,
nil
}
else
{
return
res
,
e
.
NewApiError
(
"这个SKU没有阶梯价"
,
104002
)
}
else
{
return
res
,
e
.
NewApiError
(
"这个SKU没有阶梯价"
,
104002
)
}
}
func
NewLadderPriceService
()
*
LadderPriceService
{
func
NewLadderPriceService
()
*
LadderPriceService
{
return
&
LadderPriceService
{}
}
\ No newline at end of file
}
service/service_ly.go
View file @
5138157b
...
...
@@ -160,6 +160,9 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
// sku.Stock = 0
//}
var
TagService
TagsService
sku
.
GoodsTag
=
TagService
.
GetTags
(
sku
.
GoodsId
)
//用spuInfo补全信息
sku
=
ls
.
CombineSup
(
sku
,
spu
)
//最后一步,将sku的全部信息放到有序map里面
...
...
service/service_tags.go
0 → 100644
View file @
5138157b
package
service
import
(
"github.com/gomodule/redigo/redis"
"github.com/tidwall/gjson"
"go_sku_server/model"
"go_sku_server/pkg/gredis"
"go_sku_server/pkg/vars"
)
//标签相关服务,包括goods_label
type
TagsService
struct
{
}
//获取Spu的属性
func
(
ts
*
TagsService
)
GetTags
(
skuId
string
)
(
goodsTags
model
.
GoodsTag
)
{
redisCon
:=
gredis
.
Conn
(
"default_r"
)
goodsTagsStr
,
_
:=
redis
.
String
(
redisCon
.
Do
(
"HGET"
,
"goods_tag"
,
skuId
))
goodsLabel
:=
""
if
goodsTagsStr
!=
""
{
//goods_label
goodsLabelType
:=
int
(
gjson
.
Get
(
goodsTagsStr
,
"goods_label"
)
.
Int
())
goodsLabelMap
:=
vars
.
GoodsLabel
goodsLabel
=
goodsLabelMap
[
goodsLabelType
]
goodsTags
.
GoodsLabelName
=
goodsLabel
goodsTags
.
GoodsLabel
=
goodsLabelType
//goods_tag
var
tags
[]
int
var
tagNames
[]
string
for
_
,
tagResult
:=
range
gjson
.
Get
(
goodsTagsStr
,
"tags"
)
.
Array
()
{
tagName
:=
vars
.
GoodsTags
[
int
(
tagResult
.
Int
())]
tagNames
=
append
(
tagNames
,
tagName
)
tags
=
append
(
tags
,
int
(
tagResult
.
Int
()))
}
goodsTags
.
GoodsTagNames
=
tagNames
goodsTags
.
GoodsTag
=
tags
}
return
goodsTags
}
service/service_zy.go
View file @
5138157b
...
...
@@ -289,6 +289,10 @@ func (qs *ZiyingService) ZyGoodsDetail(ctx *gin.Context, goodsIds []string, ch c
}
}
//获取标签信息
var
tagService
TagsService
A
.
Set
(
"goods_tag"
,
tagService
.
GetTags
(
goodsId
))
//最后写入sync map
(
GoodsRes
)
.
Store
(
goodsId
,
A
)
}
...
...
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