Toggle navigation
Toggle navigation
This project
Loading...
Sign in
fe
/
YOHOBUYPC
·
Commits
Go to a project
GitLab
Go to group
Project
Activity
Files
Commits
Pipelines
0
Builds
0
Graphs
Milestones
Issues
0
Merge Requests
2
Members
Labels
Wiki
Forks
Network
Create a new issue
Download as
Email Patches
Plain Diff
Browse Files
Authored by
Rock Zhang
9 years ago
Commit
def8e3fcb51d6bdda551f7a47a8e98d0b33bbd9e
1 parent
fb0cb5e2
修改搜索为新的Search接口,并变换商品数据处理方式
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
208 additions
and
10 deletions
library/LibModels/Wap/Product/SearchData.php
library/Plugin/DataProcess/ListProcess.php
library/Plugin/Helpers.php
library/Plugin/Images.php
library/LibModels/Wap/Product/SearchData.php
View file @
def8e3f
...
...
@@ -15,6 +15,7 @@ use Api\Sign;
*/
class
SearchData
{
protected
static
$_searchurl
=
'http://101.200.31.165/yohosearch/search.json'
;
/**
* 模糊搜索提供的关键词
...
...
@@ -58,8 +59,25 @@ class SearchData
*/
public
static
function
searchLiDatas
(
$query
=
null
,
$brand
=
null
,
$gender
=
null
,
$color
=
null
,
$size
=
null
,
$price
=
null
,
$p_d
=
null
,
$sort
=
null
,
$order
=
's_t_desc'
,
$page
=
1
,
$limit
=
60
,
$channel
=
null
)
{
// 构建必传参数
$param
=
Yohobuy
::
param
();
// 排序数据映射表
$order_map
=
array
(
's_t_desc'
=>
'shelve_time:desc'
,
's_t_asc'
=>
'shelve_time:asc'
,
's_p_asc'
=>
'sales_price:asc'
,
's_p_desc'
=>
'sales_price:desc'
,
's_d_desc'
=>
'discount:desc'
,
's_d_asc'
=>
'discount:asc'
,
'skn_desc'
=>
'product_skn:desc'
,
'skn_asc'
=>
'product_skn:asc'
,
'activities_desc'
=>
'activities.order_by:desc'
,
'activities_asc'
=>
'activities.order_by:asc'
,
's_n_asc'
=>
'sales_num:asc'
,
's_n_desc'
=>
'sales_num:desc'
,
'activities_id_desc'
=>
'activities.activity_id:desc'
,
'activities_id_asc'
=>
'activities.activity_id:asc'
,
);
$param
=
array
();
is_null
(
$query
)
||
$param
[
'query'
]
=
$query
;
is_null
(
$brand
)
||
$param
[
'brand'
]
=
$brand
;
...
...
@@ -69,14 +87,13 @@ class SearchData
is_null
(
$price
)
||
$param
[
'price'
]
=
$price
;
is_null
(
$p_d
)
||
$param
[
'p_d'
]
=
$p_d
;
is_null
(
$sort
)
||
$param
[
'sort'
]
=
$sort
;
is_null
(
$channel
)
||
$param
[
'channel'
]
=
$channel
;
$param
[
'method'
]
=
'app.search.li'
;
$param
[
'order'
]
=
$order
;
// is_null($channel) || $param['channel'] = $channel;
$param
[
'order'
]
=
$order_map
[
$order
];
$param
[
'page'
]
=
$page
;
$param
[
'limit'
]
=
$limit
;
$param
[
'client_secret'
]
=
Sign
::
getSign
(
$param
);
$param
[
'viewNum'
]
=
$limit
;
// 每页记录数
$param
[
'status'
]
=
1
;
// 是否上架,1表示在架,2表示不在
return
Yohobuy
::
get
(
Yohobuy
::
API_URL
,
$param
);
return
Yohobuy
::
get
(
self
::
$_searchurl
,
$param
);
}
}
...
...
library/Plugin/DataProcess/ListProcess.php
View file @
def8e3f
...
...
@@ -45,7 +45,7 @@ class ListProcess
foreach
(
$data
as
$value
)
{
$products
[]
=
Helpers
::
formatProduct
(
$value
);
$products
[]
=
Helpers
::
formatProduct
(
$value
,
true
,
true
,
true
,
true
);
}
return
$products
;
...
...
library/Plugin/Helpers.php
View file @
def8e3f
...
...
@@ -44,9 +44,10 @@ class Helpers
* @param bool $showTag 控制是否显示标签
* @param bool $showNew 控制是否显示NEW图标
* @param bool $showSale 控制是否显示SALE图标
* @param bool $fromSearch 是否是搜索页搜出来的商品数据
* @return array | false
*/
public
static
function
formatProduct
(
$productData
,
$showTags
=
true
,
$showNew
=
true
,
$showSale
=
true
)
public
static
function
formatProduct
(
$productData
,
$showTags
=
true
,
$showNew
=
true
,
$showSale
=
true
,
$fromSearch
=
false
)
{
// 商品信息有问题,则不显示
if
(
!
isset
(
$productData
[
'product_skn'
]))
{
...
...
@@ -61,6 +62,13 @@ class Helpers
$result
=
array
();
$result
[
'id'
]
=
$productData
[
'product_skn'
];
$result
[
'product_id'
]
=
$productData
[
'product_id'
];
// 如果是来自搜索页搜索出来的图片要先处理一下
if
(
$fromSearch
&&
$productData
[
'default_images'
])
{
$productData
[
'default_images'
]
=
Images
::
template
(
$productData
[
'default_images'
],
'goodsimg'
);
}
$result
[
'thumb'
]
=
self
::
getImageUrl
(
$productData
[
'default_images'
],
235
,
314
);
$result
[
'name'
]
=
$productData
[
'product_name'
];
$result
[
'price'
]
=
$productData
[
'market_price'
];
...
...
library/Plugin/Images.php
0 → 100644
View file @
def8e3f
<?php
/**
* User: Zip
* Date: 15/10/28
* Time: 下午13:08
*/
namespace
Plugin
;
class
Images
{
private
static
$domain
=
'.static.yhbimg.com'
;
private
static
$default_image
=
'/2015/08/25/02/01dd632a6e07bfef457ce4beda21dd6413.png'
;
private
static
$domainList
=
array
(
'01'
=>
array
(
'img10.static.yhbimg.com'
,
'img11.static.yhbimg.com'
,
),
'02'
=>
array
(
'img12.static.yhbimg.com'
,
'img13.static.yhbimg.com'
),
'yhb-head'
=>
'head.static.yhbimg.com'
);
private
static
$staticDomain
=
array
(
'bucket'
=>
''
);
private
static
$qiniuDomain
=
'yhfair.qiniudn.com'
;
/**
* 缩略图模板
* @param $fileName
* @param $bucket
* @param string $position ()
* @param string $background
* @return string
*/
static
function
template
(
$fileName
,
$bucket
=
'yhfair'
,
$mode
=
1
)
{
return
self
::
url
(
$fileName
,
$bucket
,
$mode
);
}
/**
*
* @param unknown $fileName
* @param string $bucket
* @return string
*/
public
static
function
getSourceUrl
(
$fileName
,
$bucket
=
'yhfair'
)
{
if
(
preg_match
(
'|http://|'
,
$fileName
)){
return
$fileName
;
}
$domain
=
self
::
getDomain
(
$bucket
,
$fileName
);
return
'http://'
.
$domain
.
'/'
.
$bucket
.
$fileName
;
}
/**
* 根据尺寸获得图片url
* @param unknown $fileName
* @param unknown $width
* @param unknown $height
* @param number $mode
* @param string $bucket
* @return mixed
*/
public
static
function
getImageUrl
(
$fileName
,
$width
,
$height
,
$mode
=
1
,
$bucket
=
'yhfair'
){
if
(
!
preg_match
(
'|http://|'
,
$fileName
)){
$fileName
=
self
::
template
(
$fileName
,
$bucket
,
$mode
);
}
return
str_replace
(
'{width}'
,
$width
,
str_replace
(
'{height}'
,
$height
,
str_replace
(
'{mode}'
,
$mode
,
$fileName
)));
}
/**
* 缩略图模板
* @param $fileName
* @param $bucket
* @param string $position ()
* @param string $background
* @return string
*/
static
function
template2
(
$fileName
,
$bucket
,
$position
=
'center'
,
$background
=
'd2hpdGU='
)
{
$domain
=
self
::
getDomain
(
$bucket
,
$fileName
);
$key
=
$bucket
.
$fileName
;
return
self
::
MakeBaseUrl
(
$domain
,
$key
)
.
'?imageMogr2/thumbnail/{width}x{height}/extent/{width}x{height}/background/'
.
$background
.
'/position/'
.
$position
.
'/quality/90'
;
}
/**
* 获取图片URL模板
* @param $fileName
* @param int $mode
* @param string $bucket
* @return string
*/
public
static
function
url
(
$fileName
,
$bucket
=
'yhfair'
,
$mode
=
1
)
{
$domain
=
self
::
getDomain
(
$bucket
,
$fileName
);
return
self
::
getImgTemplateUrl
(
$bucket
.
$fileName
,
$mode
,
$domain
);
}
public
static
function
getDomain
(
$bucket
,
$fileName
)
{
$domain
=
''
;
if
(
!
empty
(
self
::
$domainList
[
$bucket
])){
$domain
=
self
::
$domainList
[
$bucket
];
}
else
{
$node
=
mb_substr
(
$fileName
,
15
,
2
);
if
(
!
empty
(
self
::
$domainList
[
$node
]))
{
$domainList
=
self
::
$domainList
[
$node
];
$nodeNum
=
sprintf
(
'%u'
,
crc32
(
$fileName
))
%
count
(
$domainList
);
$domain
=
$domainList
[
$nodeNum
];
}
}
return
$domain
;
}
/**
* 获取模板的图片地址
* @param $fileName
* @param int $width
* @param int $height
* @param int $mode
* @param null $domain
* @return string
*/
private
static
function
getImgTemplateUrl
(
$fileName
,
$mode
=
1
,
$domain
=
null
)
{
if
(
$domain
==
null
)
{
$domain
=
self
::
$qiniuDomain
;
}
$baseUrl
=
self
::
MakeBaseUrl
(
$domain
,
$fileName
);
return
self
::
MakeTemplateRequest
(
$baseUrl
);
}
private
static
function
MakeBaseUrl
(
$domain
,
$key
)
// => $baseUrl
{
$keyEsc
=
str_replace
(
"%2F"
,
"/"
,
rawurlencode
(
$key
));
return
"http://
$domain
/
$keyEsc
"
;
}
private
static
function
MakeTemplateRequest
(
$url
)
{
$ops
=
array
();
$ops
[]
=
'{mode}'
;
$ops
[]
=
'w/{width}'
;
$ops
[]
=
'h/{height}'
;
if
(
empty
(
$ops
))
{
return
$url
;
}
return
$url
.
"?imageView/"
.
implode
(
'/'
,
$ops
);
}
/**
* 获取老的图片地址
* @param $fileName
* @param $bucket
* @param $width
* @param $height
* @param string $position
* @param string $background
* @return mixed
*/
public
static
function
getUrl
(
$fileName
,
$width
,
$height
,
$bucket
,
$position
=
'center'
,
$background
=
'd2hpdGU='
)
{
if
(
empty
(
$fileName
)){
$fileName
=
self
::
$default_image
;
}
$url
=
self
::
template2
(
$fileName
,
$bucket
,
$position
,
$background
);
return
str_replace
(
array
(
'{width}'
,
'{height}'
),
array
(
$width
,
$height
),
$url
);
}
}
\ No newline at end of file
...
...
Please
register
or
login
to post a comment