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
9365927c
authored
Jul 24, 2020
by
mushishixian
Browse files
Options
_('Browse Files')
Download
Plain Diff
fix
parents
bed4ba30
2239aea7
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
369 additions
and
66 deletions
controller/get_data_controller.go
controller/ly_mouser_controller.go
controller/ziyin_controller.go
go.mod
model/goods.go
pkg/common/function.go
pkg/common/page.go
requests/common_request.go
routes/router.go
service/ly/common.go
service/ly/mouser.go
service/ziyin_service.go
test/test7.go
controller/get_data_controller.go
View file @
9365927c
...
...
@@ -6,13 +6,16 @@ import (
"github.com/ichunt2019/logger"
"github.com/syyongx/php2go"
"github.com/tidwall/gjson"
"search_server/model"
"search_server/pkg/common"
"search_server/pkg/config"
"search_server/pkg/es"
"search_server/pkg/gredis"
"search_server/requests"
"search_server/service"
"search_server/service/ly"
"search_server/service/transformer"
"strconv"
"strings"
)
...
...
@@ -33,6 +36,11 @@ func GetDataIndex(c *gin.Context) {
c
.
JSON
(
200
,
common
.
ErrorResponse
(
1
,
"供应商id有误"
))
return
}
common
.
PrintDebugHtml
(
c
,
&
r
.
Flag
,
r
.
SupplierId
)
common
.
PrintDebugHtml
(
c
,
&
r
.
Flag
,
r
.
Keyword
)
if
r
.
SupplierId
!=
""
&&
r
.
IsSort
==
2
{
//所有供应商列表
//如果供应商不在合并供应商列表,则实时更新数据
...
...
@@ -45,6 +53,9 @@ func GetDataIndex(c *gin.Context) {
logger
.
Error
(
"%s"
,
err
.
Error
())
}
if
res
{
//增加联营外链请求
outLinkDiv
(
&
r
.
SupplierId
,
&
supplierName
,
&
r
.
Keyword
)
//增加
_
,
err
:=
redis
.
Bool
(
redisCon
.
Do
(
"INCR"
,
config
.
Get
(
"redis_all.SEARCH_API_TOTAL_PRE"
)
.
String
()
+
r
.
SupplierName
))
if
err
!=
nil
{
logger
.
Error
(
"%s"
,
err
.
Error
())
...
...
@@ -74,6 +85,32 @@ func GetDataIndex(c *gin.Context) {
return
}
/*
联营外链请求
@param supplierId 渠道id
@param supplierName 渠道名称
@param keyword 关键词
*/
func
outLinkDiv
(
supplierId
*
string
,
supplierName
*
string
,
keyWord
*
string
){
var
apiData
map
[
string
]
*
model
.
LyClearGoodsList
=
nil
switch
*
supplierName
{
case
"mouser"
:
//调外链拿数据mouser外链请求更新修改
apiData
=
ly
.
OutLinkMouser
(
keyWord
,
"1"
)
break
;
}
if
apiData
!=
nil
{
//供应商详情
supplierId
,
_
:=
strconv
.
ParseInt
(
*
supplierId
,
10
,
64
)
lycon
:=
ly
.
CommonLyService
{}
lycon
.
GetSkuByGoodsSn
(
apiData
,
&
model
.
SUPPLIER_REDIS_INFO
{
SupplierId
:
supplierId
,
SupplierNickname
:
*
supplierName
,
})
}
}
//获取查询es的条件语句
func
getDataQueryStr
(
r
requests
.
GetDataIndexRequest
,
supplierList
[]
string
)
string
{
getDataService
:=
service
.
GetDataService
{}
...
...
controller/ly_mouser_controller.go
0 → 100644
View file @
9365927c
package
controller
import
(
"github.com/gin-gonic/gin"
"search_server/model"
"search_server/pkg/common"
"search_server/service/ly"
"fmt"
"strings"
)
//搜索型号
func
GetMouserData
(
c
*
gin
.
Context
)
{
_REQUEST
:=
make
(
map
[
string
]
string
,
0
);
c
.
MultipartForm
()
for
requestName
,
requstValue
:=
range
c
.
Request
.
Form
{
if
requstValue
[
0
]
!=
""
{
_REQUEST
[
requestName
]
=
strings
.
TrimSpace
(
requstValue
[
0
])
}
}
goodsName
:=
_REQUEST
[
"goods_name"
]
if
goodsName
==
""
{
c
.
String
(
1001
,
"goods_name不得为空"
)
return
}
fmt
.
Println
(
goodsName
)
//调外链拿数据
apiData
:=
ly
.
OutLinkMouser
(
&
goodsName
,
"-1"
)
//供应商详情
lycon
:=
new
(
ly
.
CommonLyService
)
err
:=
lycon
.
GetSkuByGoodsSn
(
apiData
,
&
model
.
SUPPLIER_REDIS_INFO
{
SupplierId
:
14
,
SupplierNickname
:
"mouser"
,
})
errCode
:=
0
if
!
err
{
errCode
=
1
}
c
.
JSON
(
200
,
common
.
BomResponse
{
ErrCode
:
errCode
,
ErrMsg
:
"查询成功"
,
Data
:
apiData
,
})
}
controller/ziyin_controller.go
View file @
9365927c
...
...
@@ -18,7 +18,7 @@ func Zyh(ctx *gin.Context){
zyhRequest
[
requestName
]
=
strings
.
TrimSpace
(
requstValue
[
0
])
}
}
fmt
.
Println
(
zyhRequest
)
//
fmt.Println(zyhRequest)
zyServiceImpl
:=
service
.
NewZyServiceImpl
()
...
...
go.mod
View file @
9365927c
...
...
@@ -32,6 +32,7 @@ require (
github.com/tidwall/gjson v1.6.0
github.com/uniplaces/carbon v0.1.6
go.uber.org/zap v1.14.1 // indirect
golang.org/x/tools v0.0.0-20191216173652-a0e659d51361
google.golang.org/genproto v0.0.0-20200527145253-8367513e4ece // indirect
google.golang.org/grpc v1.29.1 // indirect
google.golang.org/protobuf v1.24.0
...
...
model/goods.go
View file @
9365927c
...
...
@@ -72,6 +72,11 @@ type ApiGoods struct {
type
ZiyinGoodsInfo
struct
{
GoodsNameOrg
string
`json:"goods_name_org"`
SampleStatus
string
`json:"sample_status"`
SampleMaxNumber
string
`json:"sample_max_number"`
SampleClassId
string
`json:"sample_class_id"`
SampleClassIdName
string
`json:"sample_class_id_name"`
Quota
int
`json:"quota"`
DullGoodsData
}
...
...
pkg/common/function.go
View file @
9365927c
package
common
import
(
"bytes"
"crypto/md5"
crand
"crypto/rand"
"encoding/hex"
"encoding/json"
"fmt"
"github.com/gin-gonic/gin"
"github.com/syyongx/php2go"
"math/big"
"math/rand"
...
...
@@ -17,6 +21,31 @@ import (
"time"
)
/*
格式化数据直接输出浏览器
@parm ctx gin上下文
@parm flag 是否调试标志
@parm data 打印调试内容
@parm jsondata 需要json输出的内容
*/
func
PrintDebugHtml
(
ctx
*
gin
.
Context
,
flag
*
string
,
jsonStr
interface
{})
{
if
*
flag
!=
"101"
&&
jsonStr
!=
""
{
return
}
ctx
.
Header
(
"Content-Type"
,
"text/html; charset=utf-8"
)
jsonData
,
err
:=
json
.
Marshal
(
jsonStr
)
if
err
!=
nil
{
fmt
.
Println
(
"错误:-----"
,
err
)
}
var
str
bytes
.
Buffer
_
=
json
.
Indent
(
&
str
,
[]
byte
(
string
(
jsonData
)),
""
,
" "
)
fmt
.
Println
(
"formated: "
,
str
.
String
())
ctx
.
String
(
200
,
"</br>"
)
ctx
.
String
(
200
,
str
.
String
())
}
// Md5 md5()
func
Md5
(
str
string
)
string
{
hash
:=
md5
.
New
()
...
...
pkg/common/page.go
0 → 100644
View file @
9365927c
package
common
import
"math"
//分页方法,根据传递过来的页数,每页数,总数,返回分页的内容 7个页数 前 1,2,3,4,5 后 的格式返回,小于5页返回具体页数
func
Paginator
(
page
,
prepage
int
,
nums
int64
)
map
[
string
]
interface
{}
{
var
firstpage
int
//前一页地址
var
lastpage
int
//后一页地址
//根据nums总数,和prepage每页数量 生成分页总数
totalpages
:=
int
(
math
.
Ceil
(
float64
(
nums
)
/
float64
(
prepage
)))
//page总数
if
page
>
totalpages
{
page
=
totalpages
}
if
page
<=
0
{
page
=
1
}
var
pages
[]
int
switch
{
case
page
>=
totalpages
-
5
&&
totalpages
>
5
:
//最后5页
start
:=
totalpages
-
5
+
1
firstpage
=
page
-
1
lastpage
=
int
(
math
.
Min
(
float64
(
totalpages
),
float64
(
page
+
1
)))
pages
=
make
([]
int
,
5
)
for
i
,
_
:=
range
pages
{
pages
[
i
]
=
start
+
i
}
case
page
>=
3
&&
totalpages
>
5
:
start
:=
page
-
3
+
1
pages
=
make
([]
int
,
5
)
firstpage
=
page
-
3
for
i
,
_
:=
range
pages
{
pages
[
i
]
=
start
+
i
}
firstpage
=
page
-
1
lastpage
=
page
+
1
default
:
pages
=
make
([]
int
,
int
(
math
.
Min
(
5
,
float64
(
totalpages
))))
for
i
,
_
:=
range
pages
{
pages
[
i
]
=
i
+
1
}
firstpage
=
int
(
math
.
Max
(
float64
(
1
),
float64
(
page
-
1
)))
lastpage
=
page
+
1
//fmt.Println(pages)
}
paginatorMap
:=
make
(
map
[
string
]
interface
{})
paginatorMap
[
"pages"
]
=
pages
paginatorMap
[
"totalpages"
]
=
totalpages
paginatorMap
[
"firstpage"
]
=
firstpage
paginatorMap
[
"lastpage"
]
=
lastpage
paginatorMap
[
"currpage"
]
=
page
return
paginatorMap
}
\ No newline at end of file
requests/common_request.go
View file @
9365927c
...
...
@@ -2,16 +2,17 @@ package requests
//使用根据供应商获取商品信息方法的通用请求
type
GetGoodsBySupplierRequest
struct
{
Keyword
string
`form:"keyword"`
SupplierName
string
`form:"supplier_name"`
Stock
int
`form:"stock"`
SupplierId
string
`form:"supplier_id"`
Keyword
string
`form:"keyword"`
SupplierName
string
`form:"supplier_name"`
Stock
int
`form:"stock"`
SupplierId
string
`form:"supplier_id"`
Offset
int
`form:"offset"`
FollowHit
int
`form:"follow_hit"`
CheckButton
int
`form:"check_button"`
GoodsNameEq
string
`form:"goods_name/eq"`
IsExact
int
`form:"is_exact"`
BrandId
string
`form:"brand_id"`
Flag
string
`form:"flag"`
//调试标志
AvailRank
int
`form:"avail_rank"`
SingleRank
int
`form:"single_rank"`
StockRank
int
`form:"stock_rank"`
...
...
routes/router.go
View file @
9365927c
...
...
@@ -18,6 +18,7 @@ func InitRouter() *gin.Engine {
r
.
POST
(
"/search/bom/autospu"
,
controller
.
AutoSpu
)
r
.
POST
(
"/search/bom/recommend"
,
controller
.
Recommend
)
r
.
POST
(
"search/ZiYing/zyh"
,
controller
.
Zyh
)
r
.
GET
(
"search/ZiYing/zyh"
,
controller
.
Zyh
)
r
.
POST
(
"search/mouser/GetMouserData"
,
controller
.
GetMouserData
)
r
.
GET
(
"search/mouser/GetMouserData"
,
controller
.
GetMouserData
)
...
...
service/ly/common.go
View file @
9365927c
...
...
@@ -50,28 +50,8 @@ func (t *CommonLyService) LyServerRun(){
t
.
flag
=
strings
.
TrimSpace
(
requstValue
[
0
])
}
}
if
t
.
flag
==
"101"
{
t
.
ctx
.
Header
(
"Content-Type"
,
"text/html; charset=utf-8"
)
}
}
/*
格式化数据直接输出浏览器
*/
func
PrintHtml
(
ctx
*
gin
.
Context
,
flag
*
string
,
data
string
,
jsondata
interface
{})
{
if
*
flag
==
"101"
{
if
jsondata
!=
""
{
jsonData
,
err
:=
json
.
Marshal
(
jsondata
)
if
err
!=
nil
{
fmt
.
Println
(
"错误:-----"
,
err
)
}
else
{
ctx
.
JSON
(
200
,
data
+
"</br>"
+
string
(
jsonData
))
}
}
else
{
ctx
.
JSON
(
200
,
data
+
"</br>"
)
}
}
}
/*
联营入口
...
...
@@ -83,7 +63,7 @@ func (t *CommonLyService) GetSkuByGoodsSn(goodsList map[string]*model.LyClearGoo
t
.
LyServerRun
();
//初始化变量
if
len
(
goodsList
)
==
0
{
PrintHtml
(
t
.
ctx
,
&
t
.
flag
,
"没有数据"
,
"
"
)
common
.
PrintDebugHtml
(
t
.
ctx
,
&
t
.
flag
,
"没有数据
"
)
return
true
}
...
...
@@ -99,21 +79,9 @@ func (t *CommonLyService) GetSkuByGoodsSn(goodsList map[string]*model.LyClearGoo
snSku
:=
php2go
.
Md5
(
strings
.
ToLower
(
goodsSn
))
skuId
,
_
:=
gredis
.
String
(
redisWrite
.
Do
(
"HGET"
,
config
.
Get
(
"redis_all.SKU_UNIQUE_JUDGE"
)
.
String
(),
snSku
))
//查询唯一值,反查sku_id
//PrintHtml(t.ctx,&t.flag,"snSku:"+snSku+" 查询得出sku"+skuId+" info",info)
//jsonData,err := json.Marshal(map[string]interface{}{
// "dddd":"333333",
// "ninifa":"333333",
// "3333":"333333",
// "gagaga":"333333",
//})
common
.
PrintDebugHtml
(
t
.
ctx
,
&
t
.
flag
,
info
)
common
.
PrintDebugHtml
(
t
.
ctx
,
&
t
.
flag
,
"snSku:"
+
snSku
+
" 查询得出sku"
+
skuId
+
" info"
)
jsonData
,
err
:=
json
.
Marshal
(
info
)
if
err
!=
nil
{
fmt
.
Println
(
"错误:-----"
,
err
)
}
else
{
t
.
ctx
.
JSON
(
200
,
string
(
jsonData
))
}
continue
;
/**********新增sku**************/
skuFlag
:=
false
;
//是否新增或者更新db+redis,为true则新增
if
skuId
==
""
{
//redis没有此sku,创建
...
...
service/ly/mouser.go
View file @
9365927c
...
...
@@ -13,6 +13,9 @@ const Mouser_api_url string = "https://api.mouser.com/api/v1/search/partnumber?a
//mouser请求外链
func
OutLinkMouser
(
goodsName
*
string
,
flag
string
)
map
[
string
]
*
model
.
LyClearGoodsList
{
if
*
goodsName
==
""
{
return
nil
}
var
result
string
;
if
flag
==
"-1"
{
//调试
...
...
@@ -89,4 +92,4 @@ func OutLinkMouser(goodsName *string,flag string) map[string]*model.LyClearGoods
//fmt.Println(productList)
return
productList
}
\ No newline at end of file
}
service/ziyin_service.go
View file @
9365927c
...
...
@@ -10,6 +10,7 @@ import (
"github.com/syyongx/php2go"
"github.com/tidwall/gjson"
"gopkg.in/olivere/elastic.v5"
"math"
"regexp"
"search_server/middleware"
"search_server/model"
...
...
@@ -24,6 +25,9 @@ import (
type
ZyServiceImpl
struct
{}
var
isAdmin
bool
var
zy_orgin_search
=
make
(
map
[
string
]
string
)
/*
自营搜索
...
...
@@ -33,10 +37,11 @@ func (this *ZyServiceImpl) Zyh(ctx *gin.Context, req map[string]string) (rsp *mo
need_aggs
bool
_type
byte
)
if
req
[
"need_aggs"
]
!=
""
{
need_aggs
=
false
}
else
{
isAdmin
=
true
if
req
[
"need_aggs"
]
==
"1"
{
need_aggs
=
true
}
else
{
need_aggs
=
false
}
need_aggs
=
need_aggs
...
...
@@ -125,6 +130,7 @@ func zy(req map[string]string,_type byte,isCheck byte) (rsp *model.ZyhResponse){
}
req2
:=
make
(
map
[
string
]
string
,
0
)
req2
=
common
.
CopyMapString
(
req
)
zy_orgin_search
=
common
.
CopyMapString
(
req
)
//原始搜索數據
delete
(
req2
,
"class_id/condition"
)
rsp
=
searchZiYingGoods
(
req2
,
true
,
zhyClassList
,
classLight
,
_type
)
//fmt.Printf("返回數據:%+v",rsp)
...
...
@@ -147,8 +153,9 @@ func searchZiYingGoods( req map[string]string,zy bool,classList *model.ZhyClassL
is_sample
bool
redisConn
redis
.
Conn
response
map
[
string
]
interface
{}
responseDataList
[]
interface
{}
defaultSort
bool
)
defer
func
()
{
redisConn
.
Close
()
}()
...
...
@@ -156,7 +163,9 @@ func searchZiYingGoods( req map[string]string,zy bool,classList *model.ZhyClassL
rsp
=
&
model
.
ZyhResponse
{}
rsp
.
ErrorMsg
=
""
rsp
.
ErrorCode
=
0
defaultSort
=
true
response
=
make
(
map
[
string
]
interface
{},
0
)
responseDataList
=
make
([]
interface
{},
0
)
keyword
=
""
goods_name_arr
=
make
([]
string
,
0
)
...
...
@@ -219,37 +228,45 @@ func searchZiYingGoods( req map[string]string,zy bool,classList *model.ZhyClassL
//有货排序
if
avail_rank
,
ok
:=
req
[
"avail_rank"
];
ok
&&
strings
.
TrimSpace
(
avail_rank
)
==
"1"
{
avail_rank
=
strings
.
TrimSpace
(
avail_rank
)
source
.
Sort
(
"sort"
,
true
)
source
.
Sort
(
"sort"
,
false
)
////desc
query
.
Must
(
elastic
.
NewTermQuery
(
"sort"
,
31
))
defaultSort
=
false
}
//价格排序
if
single_rank
,
ok
:=
req
[
"single_rank"
];
ok
&&
single_rank
!=
""
{
switch
{
case
single_rank
==
"1"
:
source
.
Sort
(
"single_price"
,
fals
e
)
//asc
source
.
Sort
(
"single_price"
,
tru
e
)
//asc
case
single_rank
==
"2"
:
source
.
Sort
(
"single_price"
,
tru
e
)
//desc
source
.
Sort
(
"single_price"
,
fals
e
)
//desc
}
defaultSort
=
false
}
//库存排序
if
stock_rank
,
ok
:=
req
[
"stock_rank"
];
ok
&&
stock_rank
!=
""
{
switch
{
case
strings
.
TrimSpace
(
stock_rank
)
==
"1"
:
source
.
Sort
(
"stock"
,
tru
e
)
//desc
source
.
Sort
(
"stock"
,
fals
e
)
//desc
case
strings
.
TrimSpace
(
stock_rank
)
==
"2"
:
source
.
Sort
(
"stock"
,
fals
e
)
//asc
source
.
Sort
(
"stock"
,
tru
e
)
//asc
}
defaultSort
=
false
}
//综合排序
if
com_rank
,
ok
:=
req
[
"com_rank"
];
ok
&&
strings
.
TrimSpace
(
com_rank
)
==
"1"
{
source
.
Sort
(
"sort"
,
true
)
//desc
source
.
Sort
(
"single_price"
,
false
)
//asc
source
.
Sort
(
"sort"
,
true
)
//asc
source
.
Sort
(
"single_price"
,
false
)
//desc
defaultSort
=
false
}
if
defaultSort
{
source
.
Sort
(
"sort"
,
false
)
//desc
}
}
length
:=
int64
(
10
)
if
offset
,
ok
:=
req
[
"offset"
];
ok
{
if
offsetInt
,
err
:=
strconv
.
ParseInt
(
offset
,
10
,
64
);
err
!=
nil
&&
offsetInt
>
0
{
...
...
@@ -280,7 +297,7 @@ func searchZiYingGoods( req map[string]string,zy bool,classList *model.ZhyClassL
source
.
Query
(
query
)
queryJson
,
_
:=
elastic
.
NewSearchRequest
()
.
Source
(
source
)
.
Body
()
//
fmt.Println(queryJson)
fmt
.
Println
(
queryJson
)
result
,
err
:=
es
.
CurlES
(
config
.
Get
(
"ZIYING_CONFIG.Index"
)
.
String
(),
queryJson
)
if
err
!=
nil
{
log
.
Error
(
err
)
...
...
@@ -341,7 +358,7 @@ func searchZiYingGoods( req map[string]string,zy bool,classList *model.ZhyClassL
}
case
"packing"
:
Self_UnitAliasInfo
,
err
:=
redis
.
String
(
redisConn
.
Do
(
"Hget"
,
"Self_UnitAlias"
,
aggregationsKeyBuckets
[
"key"
]))
fmt
.
Println
(
"packing"
,
aggregationsKeyBuckets
[
"key"
],
Self_UnitAliasInfo
)
//
fmt.Println("packing",aggregationsKeyBuckets["key"],Self_UnitAliasInfo)
if
err
==
nil
{
aggregationsKeyBucketsStr
=
Self_UnitAliasInfo
}
...
...
@@ -405,7 +422,7 @@ func searchZiYingGoods( req map[string]string,zy bool,classList *model.ZhyClassL
hitsHits
:=
gjson
.
Get
(
result
,
"hits.hits"
)
.
Array
()
if
hitsTotal
>
0
&&
len
(
hits2_source
)
>
0
{
goodsIds
:=
gjson
.
Get
(
result
,
"hits.hits.#._id"
)
.
Array
()
fmt
.
Println
(
"goodsIds"
,
goodsIds
)
//
fmt.Println("goodsIds",goodsIds)
goodsIdsStrArr
:=
make
([]
string
,
0
)
for
_
,
v
:=
range
goodsIds
{
goodsIdsStrArr
=
append
(
goodsIdsStrArr
,
v
.
String
())
...
...
@@ -419,19 +436,157 @@ func searchZiYingGoods( req map[string]string,zy bool,classList *model.ZhyClassL
//goods_id := esGoodsInfo.Map()["_id"].Int()
goods_id_str
:=
esGoodsInfo
.
Map
()[
"_id"
]
.
String
()
//整理自营数据参数
_
,
ok
:=
dullZiYingGoodsInfo
(
goods_id_str
,
keyword
,
goods_name_arr
,
goodsList
)
if
ok
{
goodsInfo
,
ok
:=
dullZiYingGoodsInfo
(
goods_id_str
,
keyword
,
goods_name_arr
,
goodsList
)
if
!
ok
{
continue
}
//获取可领取样片数量
quota
,
err
:=
redis
.
String
(
redisConn
.
Do
(
"Hget"
,
"Self_sample_list"
,
goods_id_str
))
if
err
==
nil
&&
quota
!=
""
{
quotaValInt
:=
gjson
.
Get
(
quota
,
"quota"
)
.
Int
()
if
quotaValInt
>
0
{
goodsInfo
.
Quota
=
int
(
quotaValInt
)
}
else
{
goodsInfo
.
Quota
=
1
}
}
//存在样品数据
if
_
,
ok
:=
source
[
"sample_max_number"
];
ok
{
goodsInfo
.
SampleStatus
=
source
[
"sample_status"
]
.
String
()
goodsInfo
.
SampleMaxNumber
=
source
[
"sample_max_number"
]
.
String
()
goodsInfo
.
SampleClassId
=
source
[
"sample_class_id"
]
.
String
()
sampleInfo
,
err
:=
redis
.
String
(
redisConn
.
Do
(
"Hget"
,
"Self_sample_class_list"
,
source
[
"sample_class_id"
]
.
String
()))
if
err
==
nil
{
goodsInfo
.
SampleClassIdName
=
gjson
.
Get
(
sampleInfo
,
"class_name"
)
.
String
()
}
}
responseDataList
=
append
(
responseDataList
,
goodsInfo
)
}
if
len
(
responseDataList
)
>
0
{
response
[
"data"
]
=
map
[
string
]
interface
{}{
"data_list"
:
responseDataList
,
}
}
}
referer
:=
middleware
.
Context
.
GetHeader
(
"Referer"
)
if
flag
<=
0
&&
referer
!=
""
&&
php2go
.
Stripos
(
referer
,
"/s/?k="
,
0
)
==
-
1
{
pagesize
:=
length
totalPage
:=
math
.
Ceil
(
float64
(
hitsTotal
)
/
float64
(
pagesize
))
var
total
int64
if
totalPage
>
1
{
if
hitsTotal
>
10000
{
total
=
10000
}
else
{
total
=
hitsTotal
}
_zy_orgin_search
:=
zy_orgin_search
p
:=
_zy_orgin_search
[
"p"
]
if
p
==
""
{
p
=
"1"
}
offset
:=
_zy_orgin_search
[
"offset"
]
offsetInt
,
err
:=
strconv
.
Atoi
(
offset
)
if
err
==
nil
&&
offsetInt
>
0
{
offset
=
strconv
.
FormatInt
(
int64
(
offsetInt
),
10
)
}
else
{
offset
=
"10"
}
if
isAdmin
{
//如果是自营同步输出
//自定義分頁
delete
(
_zy_orgin_search
,
"callback"
)
delete
(
_zy_orgin_search
,
"PHPSESSID"
)
delete
(
_zy_orgin_search
,
"hcy_test"
)
delete
(
_zy_orgin_search
,
"Array"
)
page
:=
make
(
map
[
string
]
interface
{},
0
)
page
[
"orgin_search"
]
=
_zy_orgin_search
page
[
"total"
]
=
strconv
.
FormatInt
(
total
,
10
)
page
[
"current_page"
]
=
p
page
[
"offset"
]
=
offset
if
totalPage
>
1000
{
page
[
"total_page"
]
=
"1000"
}
else
{
page
[
"total_page"
]
=
strconv
.
FormatInt
(
int64
(
totalPage
),
10
)
}
pageData
:=
make
(
map
[
int
]
int
,
0
)
pInt
:=
int
(
1
)
pInt
,
err
=
strconv
.
Atoi
(
p
)
if
err
!=
nil
{
pInt
=
int
(
1
)
}
if
pInt
>
1000
{
pInt
=
1000
}
if
pInt
>
996
{
for
i
:=
pInt
-
10
;
i
<=
pInt
;
i
++
{
//原始查询参数拼接
pageData
[
i
]
=
i
}
}
else
{
pageNum
:=
0
for
i
:=
1
;
i
<=
int
(
totalPage
);
i
++
{
if
pageNum
==
10
{
break
}
if
pInt
>
6
&&
pInt
<=
996
{
//大于10页只获取中间10页
if
i
<
pInt
-
5
||
i
>
pInt
+
5
{
continue
}
}
fmt
.
Println
(
"i:"
,
i
)
pageData
[
i
]
=
i
pageNum
++
}
}
page
[
"page_data"
]
=
pageData
response
[
"page"
]
=
page
}
else
{
//非同步输出自己输出分页样式
page
,
err
:=
strconv
.
Atoi
(
p
)
if
err
!=
nil
{
page
=
int
(
1
)
}
pageSize
:=
10
if
page
<
1
{
page
=
1
}
if
pageSize
<
1
{
pageSize
=
10
}
paging
:=
common
.
Paginator
(
page
,
pageSize
,
365
)
pageHtml
:=
makePageInfo
(
paging
,
page
)
response
[
"page"
]
=
pageHtml
}
}
else
{
response
[
"page"
]
=
map
[
string
]
interface
{}{
"total"
:
totalPage
}
}
}
rsp
.
Data
=
response
return
rsp
}
func
makePageInfo
(
paginator
map
[
string
]
interface
{},
currentPage
int
)
string
{
pageHtml
:=
""
pageHtml
+=
`<div class="pagination">`
pageHtml
+=
fmt
.
Sprintf
(
`<a class="prev" href="/product-%d.html">«</a> `
,
paginator
[
"firstpage"
])
pages
:=
paginator
[
"pages"
]
.
([]
int
)
for
_
,
page
:=
range
pages
{
if
currentPage
==
page
{
pageHtml
+=
fmt
.
Sprintf
(
`<span>%d</span>`
,
page
)
}
else
{
pageHtml
+=
fmt
.
Sprintf
(
`<a class="am-active"><a href="/product-%d.html">%d</a>`
,
page
,
page
)
}
}
pageHtml
+=
fmt
.
Sprintf
(
`<a class="prev" href="/product-%d.html">»</a> `
,
paginator
[
"lastpage"
])
pageHtml
+=
`</div>`
return
pageHtml
}
func
makeQuery
(
query
*
elastic
.
BoolQuery
,
source
*
elastic
.
SearchSource
,
conditions
[]
string
,
goods_temp_status
*
int
,
searchValue
*
string
,
keyword
*
string
,
is_sample
*
bool
)
bool
{
...
...
@@ -527,7 +682,7 @@ func makeQuery(query *elastic.BoolQuery,source *elastic.SearchSource,conditions
}
}
goods_name_arr
:=
append
(
term_v
,
goods_name_cn
...
)
fmt
.
Println
(
"goods_name_arr"
,
goods_name_arr
)
//
fmt.Println("goods_name_arr",goods_name_arr)
*
keyword
=
*
searchValue
for
_
,
v
:=
range
term_v
{
if
v
!=
""
{
...
...
@@ -626,11 +781,11 @@ func makeQuery(query *elastic.BoolQuery,source *elastic.SearchSource,conditions
if
attrs_matchs
,
ok
:=
gjson
.
Parse
(
*
searchValue
)
.
Value
()
.
(
map
[
string
]
interface
{});
ok
{
fmt
.
Println
(
attrs_matchs
)
//
fmt.Println(attrs_matchs)
for
attr_name
,
attr_value
:=
range
attrs_matchs
{
filterNestedAttrsBoolQuery
:=
elastic
.
NewBoolQuery
()
fmt
.
Println
(
attr_name
)
fmt
.
Println
(
attr_value
)
//
fmt.Println(attr_name)
//
fmt.Println(attr_value)
filterNestedAttrsBoolQuery
.
Must
(
elastic
.
NewTermQuery
(
"attrs.attr_name"
,
attr_name
),
elastic
.
NewTermQuery
(
"attrs.attr_value"
,
attr_value
))
query
.
Must
(
elastic
.
NewNestedQuery
(
"attrs"
,
filterNestedAttrsBoolQuery
))
}
...
...
@@ -737,7 +892,7 @@ func dullZiYingGoodsInfo(goods_id_str string,keyword string,goods_name_arr []str
ziyinGoodsInfo
.
SkuName
=
reg
.
ReplaceAllString
(
ziyinGoodsInfo
.
GoodsName
,
"<b class='f-red'>"
+
strings
.
ToUpper
(
keyword
)
+
"</b>"
)
}
}
else
{
if
ziyinGoodsInfo
.
SkuName
!
=
""
{
if
ziyinGoodsInfo
.
SkuName
=
=
""
{
ziyinGoodsInfo
.
SkuName
=
ziyinGoodsInfo
.
GoodsName
}
else
{
ziyinGoodsInfo
.
SkuName
=
ziyinGoodsInfo
.
SkuName
...
...
@@ -759,7 +914,7 @@ func dullZiYingGoodsInfo(goods_id_str string,keyword string,goods_name_arr []str
}
ziyinGoodsInfo
.
LastSearchTime
=
common
.
GetLastSearchTime
(
goods_id_str
)
go
transformer
.
ShowSku
(
model
.
DullGoodsData
{
ApiGoods
:
ziyinGoodsInfo
.
ApiGoods
})
//
go transformer.ShowSku(model.DullGoodsData{ApiGoods:ziyinGoodsInfo.ApiGoods})
if
keyword
!=
"---"
{
dullGoodsData
,
err
:=
transformer
.
MetGoodsInfo
(
ziyinGoodsInfo
.
DullGoodsData
)
if
err
==
nil
{
...
...
test/test7.go
0 → 100644
View file @
9365927c
package
main
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