Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
杨树贤
/
bom_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
afadd21c
authored
Jun 09, 2020
by
mushishixian
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
修复
parent
3c05f0a9
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
6 deletions
internal/logic/match.go
internal/logic/match.go
View file @
afadd21c
...
...
@@ -165,10 +165,34 @@ func getUpdateGoodsData(bomId int, bomItems []model.BomItem, deliveryType, sort
return
}
index
:=
configs
.
ESSetting
.
GoodsIndexName
//如果是大陆收货(type=1),就要包含专卖和自营
var
ziyingGoodsMapList
[]
GoodsMap
//如果是大陆收货(type=1),就要包含专卖,其中自营单独查
if
deliveryType
==
1
{
index
=
index
+
",zhuanmai,liexin_ziying"
//先去自营查一遍
ziyingGoodsMapList
,
err
=
search
(
"liexin_ziying"
,
bomId
,
bomItems
,
deliveryType
,
sort
,
client
,
rawSearch
)
if
err
!=
nil
{
return
nil
,
err
}
index
=
index
+
",zhuanmai"
}
//查完以后去除已经匹配的自营商品,然后去搜索联营的商品
bomItems
=
removeZiyingMatchBomItem
(
ziyingGoodsMapList
,
bomItems
)
lianyingGoodsMapList
,
_
:=
search
(
index
,
bomId
,
bomItems
,
deliveryType
,
sort
,
client
,
rawSearch
)
goodsMapList
=
append
(
ziyingGoodsMapList
,
lianyingGoodsMapList
...
)
return
}
func
removeZiyingMatchBomItem
(
ziyingGoodsMapList
[]
GoodsMap
,
bomItems
[]
model
.
BomItem
)
(
result
[]
model
.
BomItem
)
{
for
_
,
bomItem
:=
range
bomItems
{
if
!
checkInGoodsMap
(
bomItem
,
ziyingGoodsMapList
)
{
result
=
append
(
result
,
bomItem
)
}
}
return
}
func
search
(
index
string
,
bomId
int
,
bomItems
[]
model
.
BomItem
,
deliveryType
,
sort
int
,
client
*
es
.
Client
,
rawSearch
bool
)
(
goodsMapList
[]
GoodsMap
,
err
error
)
{
//先去自营查一遍
search
:=
client
.
MultiSearch
()
.
Index
(
index
)
//多重搜索,第一次先去精确匹配
for
_
,
bom
:=
range
bomItems
{
...
...
@@ -180,7 +204,7 @@ func getUpdateGoodsData(bomId int, bomItems []model.BomItem, deliveryType, sort
}
}
//构建一个goods_name对应的bomItems列表
searchRequest
:=
getSearchParams
(
bom
.
GoodsName
,
bom
.
BrandName
,
sort
,
bom
.
Number
,
rawSearch
)
searchRequest
:=
getSearchParams
(
index
,
bom
.
GoodsName
,
bom
.
BrandName
,
sort
,
bom
.
Number
,
rawSearch
)
search
.
Add
(
searchRequest
)
}
res
,
err
:=
search
.
Do
(
context
.
Background
())
...
...
@@ -220,9 +244,9 @@ func getUpdateGoodsData(bomId int, bomItems []model.BomItem, deliveryType, sort
}
//构建请求参数
func
getSearchParams
(
goodsName
,
brandName
string
,
sort
,
number
int
,
flag
bool
)
(
searchRequest
*
es
.
SearchRequest
)
{
func
getSearchParams
(
index
,
goodsName
,
brandName
string
,
sort
,
number
int
,
flag
bool
)
(
searchRequest
*
es
.
SearchRequest
)
{
query
:=
getTermQuery
(
goodsName
,
brandName
,
number
,
flag
)
source
:=
es
.
NewSearchSource
()
.
IndexBoost
(
"liexin_ziying"
,
2
)
.
Query
(
query
)
source
:=
es
.
NewSearchSource
()
.
Query
(
query
)
if
sort
==
1
{
source
.
Sort
(
"sort"
,
false
)
source
.
Sort
(
"stock"
,
false
)
...
...
@@ -230,7 +254,9 @@ func getSearchParams(goodsName, brandName string, sort, number int, flag bool) (
}
//要去判断sort,sort=2是按照价格排序
if
sort
==
2
{
if
index
!=
"liexin_ziying"
{
source
.
Sort
(
"single_price_sort"
,
false
)
}
source
.
Sort
(
"single_price"
,
true
)
//sort=3是按照库存排序
}
else
if
sort
==
3
{
...
...
@@ -264,7 +290,7 @@ func getTermQuery(goodsName, brandName string, number int, flag bool) (query *es
field
:=
"auto_goods_name"
query
=
query
.
Must
(
es
.
NewTermQuery
(
field
,
goodsName
))
}
query
=
query
.
Filter
(
es
.
NewTermQuery
(
"status"
,
1
))
//
query = query.Filter(es.NewTermQuery("status", 1))
//query = query.Filter(es.NewRangeQuery("single_price").Gt(0))
//src, err := query.Source()
//if err != 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