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
d91ee4fe
authored
Feb 02, 2023
by
SUDPTDUBLXEROFX\Administrator
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
optimum
parent
d4d72263
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
98 additions
and
94 deletions
conf/dev/database.ini
conf/dev/redis.ini
service/optimum_service.go
conf/dev/database.ini
View file @
d91ee4fe
...
@@ -4,7 +4,7 @@ mode = debug
...
@@ -4,7 +4,7 @@ mode = debug
[spu]
[spu]
user_name
=
spu
user_name
=
spu
password
=
spu
password
=
spu
host
=
192.168.1.23
8
host
=
192.168.1.23
4
database
=
liexin_spu
database
=
liexin_spu
table_prefix
=
lie_
table_prefix
=
lie_
type
=
mysql
type
=
mysql
...
...
conf/dev/redis.ini
View file @
d91ee4fe
;redis连接信息
;redis连接信息
[default_redis_read]
[default_redis_read]
host
=
192.168.1.23
4
:6379
host
=
192.168.1.23
5
:6379
password
=
icDb29mLy2s
password
=
icDb29mLy2s
max_idle
=
500
max_idle
=
500
max_active
=
500
max_active
=
500
idle_timeout
=
20
idle_timeout
=
20
[default_redis_write]
[default_redis_write]
host
=
192.168.1.23
4
:6379
host
=
192.168.1.23
5
:6379
password
=
icDb29mLy2s
password
=
icDb29mLy2s
max_idle
=
500
max_idle
=
500
max_active
=
500
max_active
=
500
idle_timeout
=
20
idle_timeout
=
20
[api_redis]
[api_redis]
host
=
192.168.1.23
4
:6379
host
=
192.168.1.23
5
:6379
password
=
icDb29mLy2s
password
=
icDb29mLy2s
max_idle
=
50
max_idle
=
50
max_active
=
100
max_active
=
100
...
...
service/optimum_service.go
View file @
d91ee4fe
...
@@ -25,7 +25,7 @@ var REQUEST map[string]string //接收所有参数
...
@@ -25,7 +25,7 @@ var REQUEST map[string]string //接收所有参数
var
REQUEST_ATTR
map
[
string
][]
string
//接收属性搜索
var
REQUEST_ATTR
map
[
string
][]
string
//接收属性搜索
/*
/*
整理接收数组参数
整理接收数组参数
*/
*/
func
(
qs
*
OptimumService
)
getQueryAttr
(
ctx
*
gin
.
Context
)
{
func
(
qs
*
OptimumService
)
getQueryAttr
(
ctx
*
gin
.
Context
)
{
//接收参数,接收参数搜索
//接收参数,接收参数搜索
REQUEST
=
make
(
map
[
string
]
string
)
REQUEST
=
make
(
map
[
string
]
string
)
...
@@ -37,16 +37,16 @@ func (qs *OptimumService) getQueryAttr(ctx *gin.Context) {
...
@@ -37,16 +37,16 @@ func (qs *OptimumService) getQueryAttr(ctx *gin.Context) {
ev
:=
REQUEST
[
"attr"
]
ev
:=
REQUEST
[
"attr"
]
if
ev
!=
""
{
//存在属性搜索
if
ev
!=
""
{
//存在属性搜索
slice1
:=
php2go
.
Explode
(
"^"
,
ev
)
;
slice1
:=
php2go
.
Explode
(
"^"
,
ev
)
for
_
,
proa
:=
range
slice1
{
for
_
,
proa
:=
range
slice1
{
prob
:=
php2go
.
Explode
(
"_"
,
proa
)
;
prob
:=
php2go
.
Explode
(
"_"
,
proa
)
attr_name_id
:=
prob
[
0
]
;
//属性名称
attr_name_id
:=
prob
[
0
]
//属性名称
attr_value_ids
:=
php2go
.
Explode
(
"||"
,
prob
[
1
])
attr_value_ids
:=
php2go
.
Explode
(
"||"
,
prob
[
1
])
REQUEST_ATTR
[
attr_name_id
]
=
attr_value_ids
REQUEST_ATTR
[
attr_name_id
]
=
attr_value_ids
}
}
}
}
common
.
PrintDebugHtml
(
ctx
,
REQUEST
)
common
.
PrintDebugHtml
(
ctx
,
REQUEST
)
common
.
PrintDebugHtml
(
ctx
,
REQUEST_ATTR
)
common
.
PrintDebugHtml
(
ctx
,
REQUEST_ATTR
)
}
}
/*
/*
...
@@ -80,86 +80,92 @@ func (qs *OptimumService) GetOptimumAttr(ctx *gin.Context) (results model.LyResp
...
@@ -80,86 +80,92 @@ func (qs *OptimumService) GetOptimumAttr(ctx *gin.Context) (results model.LyResp
qs
.
getQueryAttr
(
ctx
)
qs
.
getQueryAttr
(
ctx
)
//获取查询条件
//获取查询条件
queryString
,
err
:=
query
.
GetOptimumAttrQuery
(
ctx
,
&
REQUEST_ATTR
,
1
)
queryString
,
err
:=
query
.
GetOptimumAttrQuery
(
ctx
,
&
REQUEST_ATTR
,
1
)
if
err
!=
nil
{
if
err
!=
nil
{
results
.
ErrorCode
=
1001
;
results
.
ErrorCode
=
1001
results
.
ErrorMsg
=
err
.
Error
()
results
.
ErrorMsg
=
err
.
Error
()
return
return
}
}
//查询es
//查询es
esResult
,
err
:=
es
.
CurlES
(
"goods_optimum"
,
queryString
)
esResult
,
err
:=
es
.
CurlES
(
"goods_optimum"
,
queryString
)
if
err
!=
nil
{
if
err
!=
nil
{
results
.
ErrorCode
=
1002
;
results
.
ErrorCode
=
1002
results
.
ErrorMsg
=
err
.
Error
()
results
.
ErrorMsg
=
err
.
Error
()
return
return
}
}
common
.
PrintDebugHtml
(
ctx
,
esResult
)
common
.
PrintDebugHtml
(
ctx
,
esResult
)
//判断返回总条数
//判断返回总条数
total
:=
gjson
.
Get
(
esResult
,
"hits.total"
)
.
Int
()
total
:=
gjson
.
Get
(
esResult
,
"hits.total"
)
.
Int
()
if
total
==
0
{
if
total
==
0
{
results
.
ErrorCode
=
0
;
results
.
ErrorCode
=
0
results
.
ErrorMsg
=
"查询没有数据"
results
.
ErrorMsg
=
"查询没有数据"
return
return
}
}
//拼接返回数据
//拼接返回数据
A
:=
orderedmap
.
New
()
//初始化有序map,拼接data 数据
A
:=
orderedmap
.
New
()
//初始化有序map,拼接data 数据
results
.
ErrorCode
=
0
;
results
.
ErrorCode
=
0
results
.
ErrorMsg
=
"查询成功"
;
results
.
ErrorMsg
=
"查询成功"
A
.
Set
(
"total"
,
total
)
//查询总条数
A
.
Set
(
"total"
,
total
)
//查询总条数
aggs
:=
orderedmap
.
New
()
//拼接aggs
aggs
:=
orderedmap
.
New
()
//拼接aggs
aggregations
:=
gjson
.
Get
(
esResult
,
"aggregations"
)
.
Map
()
aggregations
:=
gjson
.
Get
(
esResult
,
"aggregations"
)
.
Map
()
redisConn
:=
gredis
.
Conn
(
"search_r"
)
redisConn
:=
gredis
.
Conn
(
"search_r"
)
//brand_id,存在品牌统计数据
//brand_id,存在品牌统计数据
brandIdGroup
:=
gjson
.
Get
(
aggregations
[
"brand_id"
]
.
String
(),
"buckets"
)
.
Array
()
brandIdGroup
:=
gjson
.
Get
(
aggregations
[
"brand_id"
]
.
String
(),
"buckets"
)
.
Array
()
if
len
(
aggregations
)
>
0
{
if
len
(
aggregations
)
>
0
{
brandArr
:=
make
([]
string
,
0
)
brandArr
:=
make
([]
string
,
0
)
for
_
,
v
:=
range
brandIdGroup
{
for
_
,
v
:=
range
brandIdGroup
{
valueMap
:=
v
.
Map
()
valueMap
:=
v
.
Map
()
brandId
:=
valueMap
[
"key"
]
.
String
()
brandId
:=
valueMap
[
"key"
]
.
String
()
brandName
,
_
:=
redis
.
String
(
redisConn
.
Do
(
"Hget"
,
"brand"
,
brandId
))
//todo 标准品牌
brand_name_json
,
_
:=
redis
.
String
(
redisConn
.
Do
(
"Hget"
,
"standard_brand"
,
brandId
))
brandName
:=
gjson
.
Get
(
brand_name_json
,
"brand_name"
)
.
String
()
if
brandName
==
""
{
brandName
,
_
=
redis
.
String
(
redisConn
.
Do
(
"Hget"
,
"brand"
,
brandId
))
}
ischeck
:=
"0"
//是否选中
ischeck
:=
"0"
//是否选中
if
php2go
.
InArray
(
brandId
,
REQUEST_ATTR
[
"brand"
])
{
if
php2go
.
InArray
(
brandId
,
REQUEST_ATTR
[
"brand"
])
{
ischeck
=
"1"
ischeck
=
"1"
}
}
brandArr
=
append
(
brandArr
,
brandId
+
"€"
+
brandName
+
"€"
+
ischeck
)
brandArr
=
append
(
brandArr
,
brandId
+
"€"
+
brandName
+
"€"
+
ischeck
)
}
}
aggs
.
Set
(
"brand€品牌"
,
brandArr
)
aggs
.
Set
(
"brand€品牌"
,
brandArr
)
}
}
//拼接属性统计
//拼接属性统计
attrsAttrNameBuckets
:=
gjson
.
Get
(
aggregations
[
"attrs"
]
.
String
(),
"attr_name.buckets"
)
.
Array
()
attrsAttrNameBuckets
:=
gjson
.
Get
(
aggregations
[
"attrs"
]
.
String
(),
"attr_name.buckets"
)
.
Array
()
if
len
(
attrsAttrNameBuckets
)
>
0
{
if
len
(
attrsAttrNameBuckets
)
>
0
{
for
_
,
vbuckets
:=
range
attrsAttrNameBuckets
{
for
_
,
vbuckets
:=
range
attrsAttrNameBuckets
{
vbucketsMap
:=
vbuckets
.
Map
()
vbucketsMap
:=
vbuckets
.
Map
()
attr_name
:=
vbucketsMap
[
"key"
]
.
String
()
//属性名称: 电容
attr_name
:=
vbucketsMap
[
"key"
]
.
String
()
//属性名称: 电容
attr_name_id
,
_
:=
gredis
.
String
(
redisConn
.
Do
(
"HGET"
,
config
.
Get
(
"redis_all.class_attr_by_val"
)
.
String
(),
attr_name
))
//属性id
attr_name_id
,
_
:=
gredis
.
String
(
redisConn
.
Do
(
"HGET"
,
config
.
Get
(
"redis_all.class_attr_by_val"
)
.
String
(),
attr_name
))
//属性id
attrValueBuckets
:=
gjson
.
Get
(
vbuckets
.
String
(),
"attr_value.buckets"
)
.
Array
()
//属性值数组: 1V
attrValueBuckets
:=
gjson
.
Get
(
vbuckets
.
String
(),
"attr_value.buckets"
)
.
Array
()
//属性值数组: 1V
attrValueArr
:=
make
([]
string
,
0
)
attrValueArr
:=
make
([]
string
,
0
)
for
_
,
v
:=
range
attrValueBuckets
{
for
_
,
v
:=
range
attrValueBuckets
{
valueMap
:=
v
.
Map
()
valueMap
:=
v
.
Map
()
attr_value_name
:=
valueMap
[
"key"
]
.
String
()
//属性值:1V
attr_value_name
:=
valueMap
[
"key"
]
.
String
()
//属性值:1V
attr_value_id
,
_
:=
gredis
.
String
(
redisConn
.
Do
(
"HGET"
,
config
.
Get
(
"redis_all.class_attr_value_by_val"
)
.
String
(),
attr_value_name
))
//属性值id
attr_value_id
,
_
:=
gredis
.
String
(
redisConn
.
Do
(
"HGET"
,
config
.
Get
(
"redis_all.class_attr_value_by_val"
)
.
String
(),
attr_value_name
))
//属性值id
ischeck
:=
"0"
//是否选中redigo
ischeck
:=
"0"
//是否选中redigo
if
php2go
.
InArray
(
attr_value_id
,
REQUEST_ATTR
[
attr_name_id
])
{
if
php2go
.
InArray
(
attr_value_id
,
REQUEST_ATTR
[
attr_name_id
])
{
ischeck
=
"1"
ischeck
=
"1"
}
}
attrValueArr
=
append
(
attrValueArr
,
attr_value_id
+
"€"
+
attr_value_name
+
"€"
+
ischeck
)
attrValueArr
=
append
(
attrValueArr
,
attr_value_id
+
"€"
+
attr_value_name
+
"€"
+
ischeck
)
}
}
aggs
.
Set
(
attr_name_id
+
"€"
+
attr_name
,
attrValueArr
)
aggs
.
Set
(
attr_name_id
+
"€"
+
attr_name
,
attrValueArr
)
}
}
}
}
A
.
Set
(
"aggs"
,
aggs
)
A
.
Set
(
"aggs"
,
aggs
)
results
.
Data
=
A
results
.
Data
=
A
return
return
...
@@ -167,44 +173,43 @@ func (qs *OptimumService) GetOptimumAttr(ctx *gin.Context) (results model.LyResp
...
@@ -167,44 +173,43 @@ func (qs *OptimumService) GetOptimumAttr(ctx *gin.Context) (results model.LyResp
/*
/*
返回供应商详情
返回供应商详情
*/
*/
func
(
qs
*
OptimumService
)
GetOptimumAttrInfo
(
ctx
*
gin
.
Context
)
(
results
model
.
LyResponse
)
{
func
(
qs
*
OptimumService
)
GetOptimumAttrInfo
(
ctx
*
gin
.
Context
)
(
results
model
.
LyResponse
)
{
//修复分页数据
//修复分页数据
if
gconv
.
Int64
(
ctx
.
Request
.
FormValue
(
"page"
))
*
gconv
.
Int64
(
ctx
.
Request
.
FormValue
(
"page_size"
))
>
10000
{
if
gconv
.
Int64
(
ctx
.
Request
.
FormValue
(
"page"
))
*
gconv
.
Int64
(
ctx
.
Request
.
FormValue
(
"page_size"
))
>
10000
{
results
.
ErrorCode
=
0
;
results
.
ErrorCode
=
0
results
.
ErrorMsg
=
"查询es没有数据,分页查询不得超出10000条"
results
.
ErrorMsg
=
"查询es没有数据,分页查询不得超出10000条"
return
return
}
}
//索引字典
//索引字典
qs
.
getQueryAttr
(
ctx
)
qs
.
getQueryAttr
(
ctx
)
//获取查询条件
//获取查询条件
queryString
,
err
:=
query
.
GetOptimumAttrQuery
(
ctx
,
&
REQUEST_ATTR
,
2
)
queryString
,
err
:=
query
.
GetOptimumAttrQuery
(
ctx
,
&
REQUEST_ATTR
,
2
)
if
err
!=
nil
{
if
err
!=
nil
{
results
.
ErrorCode
=
1001
;
results
.
ErrorCode
=
1001
results
.
ErrorMsg
=
err
.
Error
()
results
.
ErrorMsg
=
err
.
Error
()
return
return
}
}
esResult
,
err
:=
es
.
CurlES
(
"goods_optimum"
,
queryString
)
esResult
,
err
:=
es
.
CurlES
(
"goods_optimum"
,
queryString
)
if
err
!=
nil
{
if
err
!=
nil
{
results
.
ErrorCode
=
0
;
results
.
ErrorCode
=
0
results
.
ErrorMsg
=
"查询es没有数据"
results
.
ErrorMsg
=
"查询es没有数据"
return
return
}
}
common
.
PrintDebugHtml
(
ctx
,
esResult
)
common
.
PrintDebugHtml
(
ctx
,
esResult
)
goodsIds
:=
make
([]
string
,
0
)
//goods_id
goodsIds
:=
make
([]
string
,
0
)
//goods_id
attrs
:=
make
(
map
[
string
][]
map
[
string
]
string
)
//属性
attrs
:=
make
(
map
[
string
][]
map
[
string
]
string
)
//属性
gjArray
:=
gjson
.
Get
(
esResult
,
"hits.hits.#._source"
)
.
Array
()
gjArray
:=
gjson
.
Get
(
esResult
,
"hits.hits.#._source"
)
.
Array
()
for
_
,
item
:=
range
gjArray
{
for
_
,
item
:=
range
gjArray
{
goods_id
:=
item
.
Get
(
"goods_id"
)
.
String
()
goods_id
:=
item
.
Get
(
"goods_id"
)
.
String
()
goodsIds
=
append
(
goodsIds
,
goods_id
)
goodsIds
=
append
(
goodsIds
,
goods_id
)
temp
:=
make
([]
map
[
string
]
string
,
0
)
temp
:=
make
([]
map
[
string
]
string
,
0
)
for
_
,
attr
:=
range
item
.
Get
(
"attrs"
)
.
Array
()
{
for
_
,
attr
:=
range
item
.
Get
(
"attrs"
)
.
Array
()
{
temp
=
append
(
temp
,
map
[
string
]
string
{
temp
=
append
(
temp
,
map
[
string
]
string
{
"attr_name"
:
attr
.
Get
(
"attr_name"
)
.
String
(),
"attr_name"
:
attr
.
Get
(
"attr_name"
)
.
String
(),
"attr_value"
:
attr
.
Get
(
"attr_value"
)
.
String
(),
"attr_value"
:
attr
.
Get
(
"attr_value"
)
.
String
(),
})
})
}
}
attrs
[
goods_id
]
=
temp
attrs
[
goods_id
]
=
temp
...
@@ -213,39 +218,38 @@ func (qs *OptimumService) GetOptimumAttrInfo(ctx *gin.Context) (results model.Ly
...
@@ -213,39 +218,38 @@ func (qs *OptimumService) GetOptimumAttrInfo(ctx *gin.Context) (results model.Ly
//判断返回总条数
//判断返回总条数
total
:=
gjson
.
Get
(
esResult
,
"hits.total"
)
.
Int
()
total
:=
gjson
.
Get
(
esResult
,
"hits.total"
)
.
Int
()
if
total
==
0
{
if
total
==
0
{
results
.
ErrorCode
=
0
;
results
.
ErrorCode
=
0
results
.
ErrorMsg
=
"查询没有数据"
results
.
ErrorMsg
=
"查询没有数据"
return
return
}
}
//拼接返回数据
//拼接返回数据
A
:=
orderedmap
.
New
()
//初始化有序map,拼接data 数据
A
:=
orderedmap
.
New
()
//初始化有序map,拼接data 数据
results
.
ErrorCode
=
0
;
results
.
ErrorCode
=
0
results
.
ErrorMsg
=
"查询成功"
;
results
.
ErrorMsg
=
"查询成功"
page
:=
PageClear
(
ctx
,
total
);
page
:=
PageClear
(
ctx
,
total
)
page
[
"took"
]
=
gjson
.
Get
(
esResult
,
"took"
)
.
Int
()
page
[
"took"
]
=
gjson
.
Get
(
esResult
,
"took"
)
.
Int
()
A
.
Set
(
"page"
,
page
)
//分页信息
A
.
Set
(
"page"
,
page
)
//分页信息
//aggs := orderedmap.New() //拼接aggs
//aggs := orderedmap.New() //拼接aggs
common
.
PrintDebugHtml
(
ctx
,
goodsIds
)
common
.
PrintDebugHtml
(
ctx
,
goodsIds
)
//组装商品详情
//组装商品详情
endArr
:=
make
([]
model
.
DullGoodsData
,
0
)
endArr
:=
make
([]
model
.
DullGoodsData
,
0
)
goodsList
,
_
:=
GetGoodsInfo
(
ctx
,
goodsIds
)
goodsList
,
_
:=
GetGoodsInfo
(
ctx
,
goodsIds
)
for
_
,
v
:=
range
goodsList
{
for
_
,
v
:=
range
goodsList
{
GoodsUrl
:=
""
GoodsUrl
:=
""
BrandUrl
:=
""
BrandUrl
:=
""
referer
:=
ctx
.
GetHeader
(
"Referer"
)
referer
:=
ctx
.
GetHeader
(
"Referer"
)
if
referer
!=
""
{
if
referer
!=
""
{
dome
:=
strings
.
Split
(
referer
,
".com"
)
dome
:=
strings
.
Split
(
referer
,
".com"
)
if
len
(
dome
)
>
0
{
if
len
(
dome
)
>
0
{
if
v
.
SupplierName
==
"猎芯自营"
{
if
v
.
SupplierName
==
"猎芯自营"
{
GoodsUrl
=
dome
[
0
]
+
".com/item/"
+
v
.
GoodsId
+
".html"
GoodsUrl
=
dome
[
0
]
+
".com/item/"
+
v
.
GoodsId
+
".html"
BrandUrl
=
dome
[
0
]
+
".com/v3/brand/list/"
+
strconv
.
Itoa
(
v
.
BrandId
)
+
".html"
BrandUrl
=
dome
[
0
]
+
".com/v3/brand/list/"
+
strconv
.
Itoa
(
v
.
BrandId
)
+
".html"
}
else
{
}
else
{
GoodsUrl
=
dome
[
0
]
+
".com/goods_"
+
v
.
GoodsId
+
".html"
GoodsUrl
=
dome
[
0
]
+
".com/goods_"
+
v
.
GoodsId
+
".html"
BrandUrl
=
dome
[
0
]
+
".com/v3/brand/list/"
+
strconv
.
Itoa
(
v
.
BrandId
)
+
".html"
BrandUrl
=
dome
[
0
]
+
".com/v3/brand/list/"
+
strconv
.
Itoa
(
v
.
BrandId
)
+
".html"
}
}
}
}
}
}
...
@@ -264,56 +268,56 @@ func (qs *OptimumService) GetOptimumAttrInfo(ctx *gin.Context) (results model.Ly
...
@@ -264,56 +268,56 @@ func (qs *OptimumService) GetOptimumAttrInfo(ctx *gin.Context) (results model.Ly
v
.
MplStr
=
common
.
NumberToHtml
(
v
.
Mpl
)
v
.
MplStr
=
common
.
NumberToHtml
(
v
.
Mpl
)
MultipleStr
:=
common
.
NumberToHtml
(
Multiple
)
MultipleStr
:=
common
.
NumberToHtml
(
Multiple
)
endArr
=
append
(
endArr
,
model
.
DullGoodsData
{
endArr
=
append
(
endArr
,
model
.
DullGoodsData
{
ApiGoods
:
v
,
ApiGoods
:
v
,
GoodsUrl
:
GoodsUrl
,
GoodsUrl
:
GoodsUrl
,
BrandUrl
:
BrandUrl
,
BrandUrl
:
BrandUrl
,
Attrs
:
attrs
[
v
.
GoodsId
],
Attrs
:
attrs
[
v
.
GoodsId
],
MultipleStr
:
MultipleStr
,
MultipleStr
:
MultipleStr
,
})
})
}
}
A
.
Set
(
"goods_lists"
,
endArr
)
A
.
Set
(
"goods_lists"
,
endArr
)
results
.
Data
=
A
;
results
.
Data
=
A
return
return
}
}
//處理分頁信息
//處理分頁信息
func
PageClear
(
ctx
*
gin
.
Context
,
total
int64
)
map
[
string
]
interface
{}
{
func
PageClear
(
ctx
*
gin
.
Context
,
total
int64
)
map
[
string
]
interface
{}
{
page_size
:=
ctx
.
Request
.
FormValue
(
"page_size"
)
page_size
:=
ctx
.
Request
.
FormValue
(
"page_size"
)
if
page_size
==
""
{
if
page_size
==
""
{
page_size
=
"10"
;
page_size
=
"10"
}
}
totalPage
:=
math
.
Ceil
(
float64
(
total
)
/
common
.
MyFloat64
(
page_size
))
totalPage
:=
math
.
Ceil
(
float64
(
total
)
/
common
.
MyFloat64
(
page_size
))
if
total
>
10000
{
if
total
>
10000
{
total
=
10000
total
=
10000
}
}
page
:=
make
(
map
[
string
]
interface
{},
0
)
page
:=
make
(
map
[
string
]
interface
{},
0
)
if
totalPage
>
1
{
if
totalPage
>
1
{
p
:=
ctx
.
Request
.
FormValue
(
"page"
)
p
:=
ctx
.
Request
.
FormValue
(
"page"
)
if
p
==
""
{
if
p
==
""
{
p
=
"1"
p
=
"1"
}
}
//如果是自营同步输出
//如果是自营同步输出
//自定義分頁
//自定義分頁
page
[
"orgin_search"
]
=
REQUEST
page
[
"orgin_search"
]
=
REQUEST
page
[
"total"
]
=
strconv
.
FormatInt
(
total
,
10
)
page
[
"total"
]
=
strconv
.
FormatInt
(
total
,
10
)
page
[
"current_page"
]
=
p
page
[
"current_page"
]
=
p
page
[
"offset"
]
=
page_size
page
[
"offset"
]
=
page_size
if
total
==
10000
{
if
total
==
10000
{
page
[
"total_page"
]
=
math
.
Ceil
(
float64
(
total
)
/
common
.
MyFloat64
(
page_size
))
page
[
"total_page"
]
=
math
.
Ceil
(
float64
(
total
)
/
common
.
MyFloat64
(
page_size
))
}
else
{
}
else
{
page
[
"total_page"
]
=
strconv
.
FormatInt
(
int64
(
totalPage
),
10
)
page
[
"total_page"
]
=
strconv
.
FormatInt
(
int64
(
totalPage
),
10
)
}
}
pageData
:=
make
(
map
[
int
]
int
,
0
)
pageData
:=
make
(
map
[
int
]
int
,
0
)
pInt
:=
int
(
1
)
pInt
:=
int
(
1
)
var
err
error
var
err
error
pInt
,
err
=
strconv
.
Atoi
(
p
)
pInt
,
err
=
strconv
.
Atoi
(
p
)
if
err
!=
nil
{
if
err
!=
nil
{
pInt
=
int
(
1
)
pInt
=
int
(
1
)
}
}
...
@@ -322,19 +326,19 @@ func PageClear(ctx *gin.Context,total int64) map[string]interface{}{
...
@@ -322,19 +326,19 @@ func PageClear(ctx *gin.Context,total int64) map[string]interface{}{
}
}
checkPage
:=
gconv
.
Int
(
page
[
"total_page"
])
checkPage
:=
gconv
.
Int
(
page
[
"total_page"
])
if
pInt
>=
checkPage
{
if
pInt
>=
checkPage
{
for
i
:=
pInt
-
10
;
i
<=
pInt
;
i
++
{
for
i
:=
pInt
-
10
;
i
<=
pInt
;
i
++
{
//原始查询参数拼接
//原始查询参数拼接
pageData
[
i
]
=
i
pageData
[
i
]
=
i
}
}
}
else
{
}
else
{
pageNum
:=
0
pageNum
:=
0
for
i
:=
1
;
i
<=
checkPage
;
i
++
{
for
i
:=
1
;
i
<=
checkPage
;
i
++
{
if
pageNum
==
10
{
if
pageNum
==
10
{
break
break
}
}
if
pInt
>
6
&&
pInt
<=
checkPage
{
if
pInt
>
6
&&
pInt
<=
checkPage
{
//大于10页只获取中间10页
//大于10页只获取中间10页
if
i
<
pInt
-
5
||
i
>
pInt
+
5
{
if
i
<
pInt
-
5
||
i
>
pInt
+
5
{
continue
continue
}
}
}
}
...
@@ -343,7 +347,7 @@ func PageClear(ctx *gin.Context,total int64) map[string]interface{}{
...
@@ -343,7 +347,7 @@ func PageClear(ctx *gin.Context,total int64) map[string]interface{}{
}
}
}
}
page
[
"page_data"
]
=
common
.
MapSort
(
pageData
)
page
[
"page_data"
]
=
common
.
MapSort
(
pageData
)
}
else
{
}
else
{
page
[
"total"
]
=
total
page
[
"total"
]
=
total
page
[
"total_page"
]
=
totalPage
page
[
"total_page"
]
=
totalPage
page
[
"page_data"
]
=
""
page
[
"page_data"
]
=
""
...
...
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