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
1d3cd9aa
authored
Jul 17, 2020
by
mushishixian
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
getData
parent
91fb86ec
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
46 additions
and
11 deletions
controller/get_data_controller.go
pkg/es/es.go
routes/router.go
service/quote_service.go
service/transformer/quote_transformer.go
test/test.go
controller/get_data_controller.go
View file @
1d3cd9aa
...
@@ -36,11 +36,12 @@ func GetDataIndex(c *gin.Context) {
...
@@ -36,11 +36,12 @@ func GetDataIndex(c *gin.Context) {
if
r
.
SupplierId
!=
""
&&
r
.
IsSort
==
2
{
if
r
.
SupplierId
!=
""
&&
r
.
IsSort
==
2
{
//所有供应商列表
//所有供应商列表
//如果供应商不在合并供应商列表,则实时更新数据
//如果供应商不在合并供应商列表,则实时更新数据
if
supplierName
!=
""
&&
!
php2go
.
InArray
(
r
.
S
upplierName
,
supplierList
)
{
if
supplierName
!=
""
&&
!
php2go
.
InArray
(
s
upplierName
,
supplierList
)
{
redisCon
:=
gredis
.
Conn
(
"search_w"
)
redisCon
:=
gredis
.
Conn
(
"search_w"
)
defer
redisCon
.
Close
()
defer
redisCon
.
Close
()
//获取stockFlag
//获取stockFlag
res
,
err
:=
redis
.
Bool
(
redisCon
.
Do
(
"SADD"
,
"search_keyword_member"
,
r
.
Keyword
+
"_"
+
r
.
SupplierName
))
res
,
err
:=
redis
.
Bool
(
redisCon
.
Do
(
"SADD"
,
"search_keyword_member"
,
r
.
Keyword
+
"_"
+
r
.
SupplierName
))
fmt
.
Println
(
r
.
Keyword
+
"_"
+
r
.
SupplierName
)
if
err
!=
nil
{
if
err
!=
nil
{
fmt
.
Println
(
err
)
fmt
.
Println
(
err
)
}
}
...
...
pkg/es/es.go
View file @
1d3cd9aa
...
@@ -73,7 +73,7 @@ func BulkES(param string) (result string, err error) {
...
@@ -73,7 +73,7 @@ func BulkES(param string) (result string, err error) {
func
CurlESMSearch
(
queryJson
string
)
(
result
string
,
err
error
)
{
func
CurlESMSearch
(
queryJson
string
)
(
result
string
,
err
error
)
{
endpoints
:=
config
.
Get
(
"es.urls"
)
.
Strings
(
","
)
endpoints
:=
config
.
Get
(
"es.urls"
)
.
Strings
(
","
)
//随机获取一个节点进行请求
//随机获取一个节点进行请求
req
.
Debug
=
tru
e
req
.
Debug
=
fals
e
esUrl
:=
endpoints
[
rand
.
Intn
(
len
(
endpoints
))]
esUrl
:=
endpoints
[
rand
.
Intn
(
len
(
endpoints
))]
params
:=
req
.
BodyJSON
(
queryJson
)
params
:=
req
.
BodyJSON
(
queryJson
)
resp
,
err
:=
req
.
Post
(
esUrl
+
"/_msearch"
,
params
)
resp
,
err
:=
req
.
Post
(
esUrl
+
"/_msearch"
,
params
)
...
...
routes/router.go
View file @
1d3cd9aa
...
@@ -29,8 +29,8 @@ func InitRouter() *gin.Engine {
...
@@ -29,8 +29,8 @@ func InitRouter() *gin.Engine {
r
.
POST
(
"/search/quote/getDataPur"
,
controller
.
GetDataPur
)
r
.
POST
(
"/search/quote/getDataPur"
,
controller
.
GetDataPur
)
//GetData控制器相关
//GetData控制器相关
r
.
GET
(
"/search/get_data
/index
"
,
controller
.
GetDataIndex
)
r
.
GET
(
"/search/get_data"
,
controller
.
GetDataIndex
)
r
.
POST
(
"/search/get_data
/index
"
,
controller
.
GetDataIndex
)
r
.
POST
(
"/search/get_data"
,
controller
.
GetDataIndex
)
r
.
GET
(
"/test"
,
func
(
c
*
gin
.
Context
)
{
r
.
GET
(
"/test"
,
func
(
c
*
gin
.
Context
)
{
fmt
.
Println
(
c
.
Query
(
"test"
))
fmt
.
Println
(
c
.
Query
(
"test"
))
...
...
service/quote_service.go
View file @
1d3cd9aa
...
@@ -50,6 +50,9 @@ func (qs *QuoteService) GetGoodsBySupplierName(r requests.GetGoodsBySupplierRequ
...
@@ -50,6 +50,9 @@ func (qs *QuoteService) GetGoodsBySupplierName(r requests.GetGoodsBySupplierRequ
goodsIds
:=
GetGoodsIdsByEs
(
esResult
)
goodsIds
:=
GetGoodsIdsByEs
(
esResult
)
goodsList
,
err
:=
GetGoodsInfo
(
goodsIds
)
goodsList
,
err
:=
GetGoodsInfo
(
goodsIds
)
dullData
,
err
:=
transformer
.
DullDataInfo
(
r
.
Keyword
,
goodsList
)
dullData
,
err
:=
transformer
.
DullDataInfo
(
r
.
Keyword
,
goodsList
)
quoteTransformer
:=
transformer
.
QuoteTransformer
{}
//还要去转一下阶梯价比例
dullData
=
quoteTransformer
.
TransformLadderPrice
(
dullData
)
result
=
GetReturnSupplierData
(
dullData
)
result
=
GetReturnSupplierData
(
dullData
)
result
[
"total"
]
=
gjson
.
Get
(
esResult
,
"hits.total"
)
.
Int
()
result
[
"total"
]
=
gjson
.
Get
(
esResult
,
"hits.total"
)
.
Int
()
result
[
"took"
]
=
gjson
.
Get
(
esResult
,
"took"
)
.
Int
()
result
[
"took"
]
=
gjson
.
Get
(
esResult
,
"took"
)
.
Int
()
...
...
service/transformer/quote_transformer.go
View file @
1d3cd9aa
...
@@ -48,3 +48,21 @@ func (qt *QuoteTransformer) TransformCollectData(keyword, supplierName string, c
...
@@ -48,3 +48,21 @@ func (qt *QuoteTransformer) TransformCollectData(keyword, supplierName string, c
}
}
return
return
}
}
//提供给客服报价系统专用
func
(
qt
*
QuoteTransformer
)
TransformLadderPrice
(
dullData
[]
model
.
DullGoodsData
)
(
result
[]
model
.
DullGoodsData
)
{
for
key
,
data
:=
range
dullData
{
if
len
(
data
.
LadderPrice
)
>
0
{
for
k
,
price
:=
range
data
.
LadderPrice
{
if
price
.
PriceUs
!=
0
{
if
data
.
SupplierId
==
6
{
dullData
[
key
]
.
LadderPrice
[
k
]
.
PriceUs
=
data
.
OriginalPrice
[
k
]
.
PriceUs
*
data
.
PriceHkxs
}
else
{
dullData
[
key
]
.
LadderPrice
[
k
]
.
PriceUs
=
data
.
OriginalPrice
[
k
]
.
PriceUs
*
data
.
ApiGoods
.
Coefficient
.
ExtraRatio
}
}
}
}
}
return
dullData
}
test/test.go
View file @
1d3cd9aa
...
@@ -4,7 +4,7 @@ import (
...
@@ -4,7 +4,7 @@ import (
"flag"
"flag"
"fmt"
"fmt"
"github.com/syyongx/php2go"
"github.com/syyongx/php2go"
"re
gexp
"
"re
flect
"
"search_server/boot"
"search_server/boot"
)
)
...
@@ -29,10 +29,23 @@ func main() {
...
@@ -29,10 +29,23 @@ func main() {
if
err
:=
boot
.
Boot
(
path
);
err
!=
nil
{
if
err
:=
boot
.
Boot
(
path
);
err
!=
nil
{
fmt
.
Println
(
err
)
fmt
.
Println
(
err
)
}
}
temp
:=
1
a
:=
[]
int
{
1
,
2
,
3
}
result
:=
float64
(
temp
)
fmt
.
Println
(
InterfaceSlice
(
a
))
fmt
.
Println
(
result
)
}
r
:=
regexp
.
MustCompile
(
`<b .+?>(.+?)<\/b>`
)
name
:=
r
.
ReplaceAllString
(
`<b>219038021wdksa;ldas</b>`
,
`${1}`
)
fmt
.
Println
(
name
)
func
InterfaceSlice
(
slice
interface
{})
[]
interface
{}
{
s
:=
reflect
.
ValueOf
(
slice
)
if
s
.
Kind
()
!=
reflect
.
Slice
{
panic
(
"InterfaceSlice() given a non-slice type"
)
}
ret
:=
make
([]
interface
{},
s
.
Len
())
for
i
:=
0
;
i
<
s
.
Len
();
i
++
{
ret
[
i
]
=
s
.
Index
(
i
)
.
Interface
()
}
return
ret
}
}
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