Toggle navigation
Toggle navigation
This project
Loading...
Sign in
wangshusheng
/
YOHOBUYPC
·
Commits
Go to a project
GitLab
Go to dashboard
Project
Activity
Files
Commits
Pipelines
0
Builds
0
Graphs
Milestones
Issues
0
Merge Requests
0
Members
Labels
Wiki
Forks
Network
Create a new issue
Download as
Email Patches
Plain Diff
Browse Files
Authored by
hf
9 years ago
Commit
8641e3caab6cea9aa0d6b8de49415390379c21d8
1 parent
ebc0ff04
code review by fei.hong: do format new arrival codes
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
12 deletions
library/LibModels/Web/Product/SearchData.php
library/LibModels/Web/Product/SearchData.php
View file @
8641e3c
...
...
@@ -133,6 +133,7 @@ class SearchData extends \LibModels\Wap\Product\SearchData
return
Yohobuy
::
get
(
self
::
getUrl
(
'search'
),
$param
,
$cache
);
}
/**
* 根据分类列表获取商品信息
*
...
...
@@ -157,20 +158,48 @@ class SearchData extends \LibModels\Wap\Product\SearchData
// }
// return $data;
/* 2016/01/26 code review by fei.hong: 优化合并misort参数, 减少调用搜索的次数 */
$sortIds
=
''
;
$viewNum
=
0
;
foreach
(
$sortList
as
$value
)
{
$viewNum
+=
intval
(
$value
[
'viewNum'
]);
$sortIds
.=
$value
[
'misort'
]
.
','
;
/* code review by fei.hong: 2016/01/26 优化合并misort参数, 减少调用搜索接口的次数 */
$data
=
array
();
// 按照时间降序排的参数
$params
[
'order'
]
=
'shelve_time:desc'
;
// 获取新品的接口URL,以数组列表返回
$urlList
=
self
::
getNewArrivalUrl
(
$sortList
,
$params
);
// 并行调用搜索新品接口
$searchd
=
Yohobuy
::
getMulti
(
$urlList
);
// 该变量用于记录数组最后一个值的索引
$lastIndex
=
0
;
// 业务逻辑:按照指定品类排序显示
foreach
(
$sortList
as
$key
=>
$value
)
{
$lastIndex
=
$value
[
'viewNum'
]
-
1
;
// 业务逻辑:一个品类不满指定个数时,前台不显示
if
(
!
empty
(
$searchd
[
$key
])
&&
isset
(
$searchd
[
$key
][
'product_list'
][
$lastIndex
]))
{
$data
=
array_merge
(
$data
,
$searchd
[
$key
][
'product_list'
]);
}
}
$params
[
'viewNum'
]
=
$viewNum
;
$params
[
'misort'
]
=
rtrim
(
$sortIds
,
','
);
$searchd
=
self
::
searchElasticByCondition
(
$params
);
if
(
empty
(
$searchd
[
'data'
][
'product_list'
]))
{
return
array
();
// 用完清空不使用的变量
$searchd
=
array
();
return
$data
;
}
/**
* 获取推荐新品的接口URL列表
*
* @param array $sortList 分类列表
* @param array $params 附加参数
* @return arary
*/
public
static
function
getNewArrivalUrl
(
$sortList
,
$params
)
{
$urlList
=
array
();
$option
=
array
();
foreach
(
$sortList
as
$key
=>
$value
)
{
$option
=
$params
+
$value
;
$urlList
[
$key
]
=
Yohobuy
::
httpBuildQuery
(
self
::
getUrl
(
'search'
),
$option
);
}
return
$
searchd
[
'data'
][
'product_list'
]
;
return
$
urlList
;
}
/**
...
...
Please
register
or
login
to post a comment