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
38af2c53
authored
Jul 17, 2020
by
mushishixian
Browse files
Options
_('Browse Files')
Download
Plain Diff
Merge branch 'ysx-quote-20200628' into dev
parents
7fe143a7
1d3cd9aa
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
139 additions
and
60 deletions
controller/get_data_controller.go
model/sku.go
pkg/es/es.go
pkg/message/dingding.go
routes/router.go
service/query/quote_query.go
service/quote_service.go
service/sku_service.go
service/transformer/goods_transformer.go
service/transformer/quote_transformer.go
test/test.go
controller/get_data_controller.go
View file @
38af2c53
...
...
@@ -36,11 +36,12 @@ func GetDataIndex(c *gin.Context) {
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"
)
defer
redisCon
.
Close
()
//获取stockFlag
res
,
err
:=
redis
.
Bool
(
redisCon
.
Do
(
"SADD"
,
"search_keyword_member"
,
r
.
Keyword
+
"_"
+
r
.
SupplierName
))
fmt
.
Println
(
r
.
Keyword
+
"_"
+
r
.
SupplierName
)
if
err
!=
nil
{
fmt
.
Println
(
err
)
}
...
...
model/sku.go
0 → 100644
View file @
38af2c53
package
model
pkg/es/es.go
View file @
38af2c53
...
...
@@ -73,7 +73,7 @@ func BulkES(param string) (result string, err error) {
func
CurlESMSearch
(
queryJson
string
)
(
result
string
,
err
error
)
{
endpoints
:=
config
.
Get
(
"es.urls"
)
.
Strings
(
","
)
//随机获取一个节点进行请求
req
.
Debug
=
tru
e
req
.
Debug
=
fals
e
esUrl
:=
endpoints
[
rand
.
Intn
(
len
(
endpoints
))]
params
:=
req
.
BodyJSON
(
queryJson
)
resp
,
err
:=
req
.
Post
(
esUrl
+
"/_msearch"
,
params
)
...
...
pkg/message/dingding.go
View file @
38af2c53
...
...
@@ -39,7 +39,7 @@ func DingDingPush(content string) (result DingDingResponse, err error) {
"Content-Type"
:
"application/json"
,
"charset"
:
"UTF-8"
,
})
if
resp
==
nil
{
if
resp
==
nil
{
return
}
result
.
Errcode
=
int
(
gjson
.
Get
(
resp
.
String
(),
"errcode"
)
.
Int
())
...
...
routes/router.go
View file @
38af2c53
package
routes
import
(
"fmt"
"github.com/gin-gonic/gin"
"search_server/controller"
"search_server/middleware"
...
...
@@ -28,8 +29,11 @@ func InitRouter() *gin.Engine {
r
.
POST
(
"/search/quote/getDataPur"
,
controller
.
GetDataPur
)
//GetData控制器相关
r
.
GET
(
"/search/get_data
/index
"
,
controller
.
GetDataIndex
)
r
.
POST
(
"/search/get_data
/index
"
,
controller
.
GetDataIndex
)
r
.
GET
(
"/search/get_data"
,
controller
.
GetDataIndex
)
r
.
POST
(
"/search/get_data"
,
controller
.
GetDataIndex
)
r
.
GET
(
"/test"
,
func
(
c
*
gin
.
Context
)
{
fmt
.
Println
(
c
.
Query
(
"test"
))
})
return
r
}
service/query/quote_query.go
View file @
38af2c53
package
query
import
(
"fmt"
"github.com/gomodule/redigo/redis"
"github.com/syyongx/php2go"
"github.com/uniplaces/carbon"
...
...
@@ -33,6 +34,7 @@ func GetSupplierIndex(supplierId string) (supplierIndex string) {
return
}
//根据供应商名称查询商品的ES查询
func
GetGoodsBySupplierNameQuery
(
r
requests
.
GetGoodsBySupplierRequest
)
(
string
,
error
)
{
query
:=
elastic
.
NewBoolQuery
()
subQuery
:=
elastic
.
NewBoolQuery
()
...
...
@@ -44,7 +46,6 @@ func GetGoodsBySupplierNameQuery(r requests.GetGoodsBySupplierRequest) (string,
stockFlag
,
_
:=
redis
.
Int
(
redisCon
.
Do
(
"GET"
,
"StockSwitch"
))
//todo : type=goods
keywordSlice
:=
strings
.
Split
(
strings
.
ToUpper
(
strings
.
TrimSpace
(
r
.
Keyword
)),
" "
)
r1
,
_
:=
regexp
.
Compile
(
`/[\x{4e00}-\x{9fff}]+/u`
)
//去除中文?
removeCnKeyword
:=
r1
.
ReplaceAllString
(
r
.
Keyword
,
""
)
...
...
@@ -168,7 +169,6 @@ func GetGoodsBySupplierNameQuery(r requests.GetGoodsBySupplierRequest) (string,
source
.
Query
(
query
)
searchRequest
:=
elastic
.
NewSearchRequest
()
.
Source
(
source
)
.
Preference
(
"_primary_first"
)
return
searchRequest
.
Body
()
}
...
...
@@ -332,6 +332,6 @@ func GetGoodsBySupplierIdQuery(r requests.GetGoodsBySupplierRequest) (string, er
}
source
.
Query
(
query
)
searchRequest
:=
elastic
.
NewSearchRequest
()
.
Source
(
source
)
.
Preference
(
"_primary_first"
)
fmt
.
Println
(
searchRequest
.
Body
())
return
searchRequest
.
Body
()
}
service/quote_service.go
View file @
38af2c53
...
...
@@ -2,7 +2,6 @@ package service
import
(
"encoding/json"
"fmt"
"github.com/imroc/req"
"github.com/syyongx/php2go"
"github.com/tidwall/gjson"
...
...
@@ -44,8 +43,6 @@ func (qs *QuoteService) GetGoodsBySupplier(r requests.GetGoodsBySupplierRequest)
func
(
qs
*
QuoteService
)
GetGoodsBySupplierName
(
r
requests
.
GetGoodsBySupplierRequest
)
(
result
map
[
string
]
interface
{},
err
error
)
{
supplierIndex
:=
r
.
SupplierName
queryString
,
err
:=
query
.
GetGoodsBySupplierNameQuery
(
r
)
fmt
.
Println
(
supplierIndex
)
fmt
.
Println
(
queryString
)
esResult
,
err
:=
es
.
CurlES
(
supplierIndex
,
queryString
)
if
err
!=
nil
{
return
...
...
@@ -53,6 +50,9 @@ func (qs *QuoteService) GetGoodsBySupplierName(r requests.GetGoodsBySupplierRequ
goodsIds
:=
GetGoodsIdsByEs
(
esResult
)
goodsList
,
err
:=
GetGoodsInfo
(
goodsIds
)
dullData
,
err
:=
transformer
.
DullDataInfo
(
r
.
Keyword
,
goodsList
)
quoteTransformer
:=
transformer
.
QuoteTransformer
{}
//还要去转一下阶梯价比例
dullData
=
quoteTransformer
.
TransformLadderPrice
(
dullData
)
result
=
GetReturnSupplierData
(
dullData
)
result
[
"total"
]
=
gjson
.
Get
(
esResult
,
"hits.total"
)
.
Int
()
result
[
"took"
]
=
gjson
.
Get
(
esResult
,
"took"
)
.
Int
()
...
...
service/sku_service.go
View file @
38af2c53
package
service
import
(
"search_server/middleware"
"search_server/model"
"strings"
)
//推送搜索关键词
func
ShowSku
(
goods
model
.
DullGoodsData
)
{
goodsIdLen
:=
len
(
goods
.
GoodsId
)
if
goods
.
GoodsId
==
""
||
goods
.
BrandName
==
""
||
goods
.
SupplierName
==
""
{
return
}
referer
:=
middleware
.
Context
.
Request
.
Header
.
Get
(
"referer"
)
if
strings
.
Contains
(
referer
,
"www.ichunt.com/s/?k"
)
{
if
goods
.
ProviderName
!=
""
{
goods
.
BrandName
=
goods
.
ProviderName
}
if
goods
.
CompanyName
!=
""
{
goods
.
SupplierName
=
goods
.
CompanyName
}
result
:=
make
(
map
[
string
]
string
)
result
[
"goods_id"
]
=
goods
.
GoodsId
//todo : brand_name正则转换
result
[
"brand_name"
]
=
goods
.
BrandName
if
goods
.
SupplierId
==
17
{
result
[
"supplier_name"
]
=
goods
.
SupplierName
+
"-"
+
goods
.
Canal
result
[
"supplier_type"
]
=
goods
.
SupplierName
}
else
if
goods
.
CompanyName
!=
""
&&
goods
.
ProviderName
!=
""
{
result
[
"supplier_name"
]
=
"撮合-"
+
goods
.
SupplierName
result
[
"supplier_type"
]
=
"撮合"
}
else
{
result
[
"supplier_name"
]
=
goods
.
SupplierName
result
[
"supplier_type"
]
=
goods
.
SupplierName
}
//todo : goods_name正则替换
result
[
"goods_name"
]
=
goods
.
GoodsName
if
(
goodsIdLen
<
19
||
goods
.
SupplierId
==
10000
)
&&
result
[
"supplier_type"
]
!=
"撮合"
{
result
[
"keyword"
]
=
strings
.
TrimSpace
(
"keyword"
)
}
result
[
"adtag"
],
_
=
middleware
.
Context
.
Cookie
(
"adtag"
)
if
goodsIdLen
<
19
{
result
[
"status"
]
=
"1"
}
}
type
SkuService
struct
{
}
service/transformer/goods_transformer.go
View file @
38af2c53
package
transformer
import
(
"encoding/json"
"fmt"
"github.com/gomodule/redigo/redis"
"github.com/tidwall/gjson"
"regexp"
"search_server/dao"
"search_server/middleware"
"search_server/model"
...
...
@@ -10,6 +13,7 @@ import (
"search_server/pkg/config"
"search_server/pkg/gredis"
"strings"
"time"
)
//处理商品信息数据
...
...
@@ -46,8 +50,7 @@ func DullDataInfo(keyword string, goodsListMap map[string]model.ApiGoods) (resul
goods
.
LastSearchTime
=
common
.
GetLastSearchTime
(
goods
.
GoodsId
)
//关税信息
goods
.
CustomsTax
=
common
.
GetCustomsTax
(
goods
.
GoodsName
,
goods
.
BrandName
)
//todo : showsku方法
ShowSku
(
goods
)
//价格等信息混淆
if
keyword
!=
"---"
{
goods
,
err
=
MetGoodsInfo
(
goods
)
...
...
@@ -281,3 +284,81 @@ func MetGoodsInfo(data model.DullGoodsData) (result model.DullGoodsData, err err
return
data
,
err
}
}
//推送搜索商品信息
func
ShowSku
(
goods
model
.
DullGoodsData
)
{
//绑定需要接收的参数
type
ShowSkuParams
struct
{
GoodsNameEq
string
`form:"goods_name/eq"`
Keyword
string
`form:"keyword"`
}
var
params
ShowSkuParams
middleware
.
Context
.
Bind
(
&
params
)
goodsIdLen
:=
len
(
goods
.
GoodsId
)
if
goods
.
GoodsId
==
""
||
goods
.
BrandName
==
""
||
goods
.
SupplierName
==
""
{
return
}
referer
:=
middleware
.
Context
.
Request
.
Header
.
Get
(
"referer"
)
//if strings.Contains(referer, "www.ichunt.com/s/?k") {
if
strings
.
Contains
(
referer
,
""
)
{
if
goods
.
ProviderName
!=
""
{
goods
.
BrandName
=
goods
.
ProviderName
}
if
goods
.
CompanyName
!=
""
{
goods
.
SupplierName
=
goods
.
CompanyName
}
r
:=
regexp
.
MustCompile
(
`<b .+?>(.+?)<\/b>`
)
result
:=
make
(
map
[
string
]
interface
{})
result
[
"goods_id"
]
=
goods
.
GoodsId
//brand_name正则转换
goods
.
BrandName
=
r
.
ReplaceAllString
(
goods
.
BrandName
,
`${1}`
)
result
[
"brand_name"
]
=
goods
.
BrandName
if
goods
.
SupplierId
==
17
{
result
[
"supplier_name"
]
=
goods
.
SupplierName
+
"-"
+
goods
.
Canal
result
[
"supplier_type"
]
=
goods
.
SupplierName
}
else
if
goods
.
CompanyName
!=
""
&&
goods
.
ProviderName
!=
""
{
result
[
"supplier_name"
]
=
"撮合-"
+
goods
.
SupplierName
result
[
"supplier_type"
]
=
"撮合"
}
else
{
result
[
"supplier_name"
]
=
goods
.
SupplierName
result
[
"supplier_type"
]
=
goods
.
SupplierName
}
//goods_name正则替换
goods
.
GoodsName
=
r
.
ReplaceAllString
(
goods
.
GoodsName
,
`${1}`
)
result
[
"goods_name"
]
=
goods
.
GoodsName
if
(
goodsIdLen
<
19
||
goods
.
SupplierId
==
10000
)
&&
result
[
"supplier_type"
]
!=
"撮合"
{
result
[
"keyword"
]
=
strings
.
TrimSpace
(
params
.
GoodsNameEq
)
}
else
{
if
params
.
Keyword
!=
""
{
result
[
"keyword"
]
=
strings
.
TrimSpace
(
params
.
Keyword
)
}
else
{
result
[
"keyword"
]
=
goods
.
GoodsName
}
}
//价格记录
if
len
(
goods
.
LadderPrice
)
>
0
{
result
[
"ladder_price"
]
=
goods
.
LadderPrice
}
else
{
result
[
"ladder_price"
]
=
[]
string
{}
}
//moq
result
[
"moq"
]
=
goods
.
Moq
result
[
"show_time"
]
=
time
.
Now
()
.
Unix
()
//cookie获取
result
[
"adtag"
],
_
=
middleware
.
Context
.
Cookie
(
"adtag"
)
//状态判断
if
goodsIdLen
<
19
{
result
[
"status"
]
=
1
}
else
{
if
goods
.
Status
==
1
{
result
[
"status"
]
=
1
}
else
{
result
[
"status"
]
=
2
}
}
res
,
_
:=
json
.
Marshal
(
result
)
fmt
.
Println
(
string
(
res
))
//mq.PushMsg("search_show_sku_list", string(res))
}
}
service/transformer/quote_transformer.go
View file @
38af2c53
...
...
@@ -48,3 +48,21 @@ func (qt *QuoteTransformer) TransformCollectData(keyword, supplierName string, c
}
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 @
38af2c53
...
...
@@ -4,8 +4,8 @@ import (
"flag"
"fmt"
"github.com/syyongx/php2go"
"reflect"
"search_server/boot"
"search_server/pkg/mq"
)
func
StrRandom
(
lenNum
int
)
string
{
...
...
@@ -29,5 +29,23 @@ func main() {
if
err
:=
boot
.
Boot
(
path
);
err
!=
nil
{
fmt
.
Println
(
err
)
}
mq
.
PushMsg
(
"xian_test"
,
"test"
)
a
:=
[]
int
{
1
,
2
,
3
}
fmt
.
Println
(
InterfaceSlice
(
a
))
}
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