Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
杨树贤
/
search_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
55ae9a08
authored
Jul 03, 2020
by
mushishixian
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
获取商品信息的方法
parent
ed8542df
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
54 additions
and
38 deletions
model/goods.go
service/bom_service.go
service/goods_service.go
test/test.go
model/goods.go
View file @
55ae9a08
package
model
type
ApiGoods
struct
{
GoodsI
D
string
`json:"goods_id"`
GoodsI
d
string
`json:"goods_id"`
GoodsName
string
`json:"goods_name"`
GoodsType
int
`json:"goods_type"`
SupplierI
D
int
`json:"supplier_id"`
Moq
int
`json:"moq"`
Mpq
int
`json:"mpq"`
Stock
int
`json:"stock"`
GoodsType
int
64
`json:"goods_type"`
SupplierI
d
int64
`json:"supplier_id"`
Moq
int
64
`json:"moq"`
Mpq
int
64
`json:"mpq"`
Stock
int
64
`json:"stock"`
HkDeliveryTime
string
`json:"hk_delivery_time"`
CnDeliveryTime
string
`json:"cn_delivery_time"`
LadderPrice
[]
LadderPrice
`json:"ladder_price"`
BrandName
string
`json:"brand_name"`
SupplierName
string
`json:"supplier_name"`
BrandI
D
int
`json:"brand_id"`
IsBuy
int
`json:"is_buy"`
Mpl
int
`json:"mpl"`
Status
int
`json:"status"`
BrandI
d
int64
`json:"brand_id"`
IsBuy
int
64
`json:"is_buy"`
Mpl
int
64
`json:"mpl"`
Status
int
64
`json:"status"`
Pdf
string
`json:"pdf"`
Encap
string
`json:"encap"`
AcType
int
`json:"ac_type"`
AcType
int
64
`json:"ac_type"`
//ErpTax bool `json:"erp_tax"`
}
type
LadderPrice
struct
{
Purchases
int
`json:"purchases"`
Purchases
int
64
`json:"purchases"`
PriceUs
float64
`json:"price_us"`
PriceCn
float64
`json:"price_cn"`
PriceAc
float64
`json:"price_ac"`
...
...
service/bom_service.go
View file @
55ae9a08
...
...
@@ -101,7 +101,8 @@ func Recommend(req *common.RecommendRequest) (rsp *common.BomResponse) {
goodsIdList
=
append
(
goodsIdList
,
goodsId
)
}
goodsIdListStr
=
strings
.
Join
(
goodsIdList
,
","
)
goodsList
,
err
:=
GetGoodsInfoByApi
(
goodsIdListStr
,
1
)
goodsService
:=
GoodsService
{}
goodsList
,
err
:=
goodsService
.
GetGoodsInfoByApi
(
goodsIdListStr
)
response
.
Data
=
goodsList
response
.
Flag
=
req
.
Flag
return
&
response
...
...
service/goods_service.go
View file @
55ae9a08
...
...
@@ -12,26 +12,45 @@ import (
"search_server/pkg/config"
"search_server/pkg/es"
"search_server/pkg/gredis"
"search_server/protopb/bom"
"search_server/requests"
"strings"
)
//获取商品信息
//需要传入userId用于判断是否登陆
func
GetGoodsInfoByApi
(
goodsIdsStr
string
,
userId
int
)
(
goodsList
[]
*
bom
.
GoodsModel
,
err
error
)
{
type
GoodsService
struct
{
}
//获取商品信息,需要传入userId用于判断是否登陆
func
(
gs
*
GoodsService
)
GetGoodsInfo
(
goodsIdsStr
string
,
userId
int
)
(
goodsListMap
map
[
string
]
*
model
.
ApiGoods
,
err
error
)
{
isNewCustomer
,
isMember
:=
CheckIsNewCustomer
(
userId
)
goodsServerUrl
:=
config
.
Get
(
"goods.api_url"
)
.
String
()
params
:=
req
.
Param
{
"goods_id"
:
goodsIdsStr
,
"power[newCustomer]"
:
isNewCustomer
,
"power[member]"
:
isMember
,
}
//fmt.Println(goodsIdsStr)
_
,
goodsListMap
,
err
=
CurlGoodsInfo
(
goodsIdsStr
,
params
)
return
}
//获取商品信息
func
(
gs
*
GoodsService
)
GetGoodsInfoByApi
(
goodsIdsStr
string
)
(
goodsList
[]
*
model
.
ApiGoods
,
err
error
)
{
params
:=
req
.
Param
{
"goods_id"
:
goodsIdsStr
,
}
goodsList
,
_
,
err
=
CurlGoodsInfo
(
goodsIdsStr
,
params
)
fmt
.
Println
(
goodsList
[
0
]
.
BrandId
)
return
}
//isMap:是否以字典形式返回值,默认是数组
func
CurlGoodsInfo
(
goodsIdsStr
string
,
params
req
.
Param
)
(
goodsList
[]
*
model
.
ApiGoods
,
goodsListMap
map
[
string
]
*
model
.
ApiGoods
,
err
error
)
{
//req.Debug = true
goodsServerUrl
:=
config
.
Get
(
"goods.api_url"
)
.
String
()
resp
,
err
:=
req
.
Post
(
goodsServerUrl
+
"/synchronization"
,
params
)
if
err
!=
nil
{
return
}
goodsListMap
=
make
(
map
[
string
]
*
model
.
ApiGoods
,
1000
)
//先判断返回的data是不是字典,不是字典代表可能是返回字符串了
if
gjson
.
Get
(
resp
.
String
(),
"data"
)
.
IsObject
()
{
//排序操作
...
...
@@ -39,9 +58,9 @@ func GetGoodsInfoByApi(goodsIdsStr string, userId int) (goodsList []*bom.GoodsMo
for
_
,
goodsId
:=
range
goodsIdList
{
for
_
,
data
:=
range
gjson
.
Get
(
resp
.
String
(),
"data"
)
.
Map
()
{
if
goodsId
==
data
.
Get
(
"goods_id"
)
.
String
()
{
//还要去判断是否是
bool
//还要去判断是否是
false,因为商品服务可能返回 "1000":false 这样子的形式
if
data
.
IsObject
()
{
var
goods
bom
.
GoodsModel
var
goods
model
.
ApiGoods
goods
.
GoodsName
=
data
.
Get
(
"goods_name"
)
.
String
()
goods
.
GoodsId
=
data
.
Get
(
"goods_id"
)
.
String
()
goods
.
BrandId
=
data
.
Get
(
"goods_id"
)
.
Int
()
...
...
@@ -51,7 +70,7 @@ func GetGoodsInfoByApi(goodsIdsStr string, userId int) (goodsList []*bom.GoodsMo
goods
.
Moq
=
data
.
Get
(
"moq"
)
.
Int
()
goods
.
SupplierName
=
data
.
Get
(
"supplier_name"
)
.
String
()
goods
.
BrandName
=
data
.
Get
(
"brand_name"
)
.
String
()
goods
.
HkDeliveryT
yp
e
=
data
.
Get
(
"hk_delivery_time"
)
.
String
()
goods
.
HkDeliveryT
im
e
=
data
.
Get
(
"hk_delivery_time"
)
.
String
()
goods
.
CnDeliveryTime
=
data
.
Get
(
"cn_delivery_time"
)
.
String
()
goods
.
IsBuy
=
data
.
Get
(
"is_buy"
)
.
Int
()
goods
.
Mpl
=
data
.
Get
(
"mpl"
)
.
Int
()
...
...
@@ -60,18 +79,21 @@ func GetGoodsInfoByApi(goodsIdsStr string, userId int) (goodsList []*bom.GoodsMo
goods
.
Status
=
data
.
Get
(
"status"
)
.
Int
()
goods
.
GoodsType
=
data
.
Get
(
"goods_type"
)
.
Int
()
goods
.
AcType
=
data
.
Get
(
"ac_type"
)
.
Int
()
ladderPrice
:=
make
([]
*
bom
.
LadderPrice
,
0
)
ladderPrice
:=
make
([]
model
.
LadderPrice
,
0
)
for
_
,
price
:=
range
data
.
Get
(
"ladder_price"
)
.
Array
()
{
ladder
:=
bom
.
LadderPrice
{
ladder
:=
model
.
LadderPrice
{
Purchases
:
price
.
Get
(
"purchases"
)
.
Int
(),
PriceUs
:
float32
(
price
.
Get
(
"price_us"
)
.
Float
()
),
PriceCn
:
float32
(
price
.
Get
(
"price_cn"
)
.
Float
()
),
PriceAc
:
float32
(
price
.
Get
(
"price_ac"
)
.
Float
()
),
PriceUs
:
price
.
Get
(
"price_us"
)
.
Float
(
),
PriceCn
:
price
.
Get
(
"price_cn"
)
.
Float
(
),
PriceAc
:
price
.
Get
(
"price_ac"
)
.
Float
(
),
}
ladderPrice
=
append
(
ladderPrice
,
&
ladder
)
ladderPrice
=
append
(
ladderPrice
,
ladder
)
}
goods
.
LadderPrice
=
ladderPrice
goodsList
=
append
(
goodsList
,
&
goods
)
goodsListMap
[
goodsId
]
=
&
goods
}
else
{
goodsListMap
[
goodsId
]
=
nil
}
}
}
...
...
test/test.go
View file @
55ae9a08
...
...
@@ -4,7 +4,7 @@ import (
"flag"
"fmt"
"search_server/boot"
"search_server/
pkg/mysql
"
"search_server/
service
"
)
func
main
()
{
...
...
@@ -14,13 +14,6 @@ func main() {
if
err
:=
boot
.
Boot
(
path
);
err
!=
nil
{
fmt
.
Println
(
err
)
}
type
Result
struct
{
BinId
int
`json:"bin_id"`
Bin
string
`json:"bin"`
}
var
result
[]
Result
mysql
.
Connection
(
"bom"
)
.
Raw
(
"SELECT * FROM lie_bin"
)
.
Scan
(
&
result
)
//mysql.Connection()("bom").Table("bin").Find(&result)
fmt
.
Println
(
result
)
//fmt.Println(model.GetExcludeBrandIds(1))
service1
:=
service
.
GoodsService
{}
fmt
.
Println
(
service1
.
GetGoodsInfoByApi
(
"1151005920927710088,1150961641855982990,1150961724815213435"
))
}
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