...
|
...
|
@@ -16,20 +16,27 @@ use Api\Sign; |
|
|
*/
|
|
|
class SearchData
|
|
|
{
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 阿里云外网
|
|
|
* 获取搜索的服务地址
|
|
|
*
|
|
|
* @var string
|
|
|
* 备注:此处是根据环境来确定使用阿里云内网还是外网的URL
|
|
|
*
|
|
|
* @return string
|
|
|
*/
|
|
|
protected static $_searchurl = 'http://101.200.31.165/yohosearch/search.json';
|
|
|
|
|
|
// /**
|
|
|
// * 阿里云内网
|
|
|
// *
|
|
|
// * @var string
|
|
|
// */
|
|
|
// protected static $_searchurl = 'http://100.98.132.63/yohosearch/search.json';
|
|
|
private static function getSearchUrl()
|
|
|
{
|
|
|
defined('APPLICATION_ENV') || define('APPLICATION_ENV', 'developer');
|
|
|
switch (APPLICATION_ENV) {
|
|
|
case 'release':
|
|
|
case 'test':
|
|
|
case 'preview':
|
|
|
return 'http://100.98.132.63/yohosearch/search.json';
|
|
|
case 'developer':
|
|
|
default:
|
|
|
return 'http://101.200.31.165/yohosearch/search.json';
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 模糊搜索提供的关键词
|
...
|
...
|
@@ -50,7 +57,7 @@ class SearchData |
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 根据给定查询数据搜索数据列表
|
|
|
* 根据给定查询数据搜索数据列表 (老的)
|
|
|
*
|
|
|
* @param string $query 查询条件, 默认为null
|
|
|
* @param string $brand 品牌,默认为null
|
...
|
...
|
@@ -71,47 +78,29 @@ class SearchData |
|
|
* @param integer $channel表示哪个频道,1表示男生,2表示女生,3表示潮童,4表示创意生活
|
|
|
* @return array 搜索到的数据
|
|
|
*/
|
|
|
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)
|
|
|
public static function searchByCondition($condition)
|
|
|
{
|
|
|
// 排序数据映射表
|
|
|
$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;
|
|
|
is_null($gender) || $param['gender'] = $gender;
|
|
|
is_null($color) || $param['color'] = $color;
|
|
|
is_null($size) || $param['size'] = $size;
|
|
|
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['order'] = $order_map[$order];
|
|
|
$param['page'] = $page;
|
|
|
$param['viewNum'] = $limit; // 每页记录数
|
|
|
$param['status'] = 1; // 是否上架,1表示在架,2表示不在
|
|
|
$param = Yohobuy::param();
|
|
|
$param['method'] = 'app.search.li';
|
|
|
if (!isset($condition['order'])) {
|
|
|
$param['order'] = 's_t_desc';
|
|
|
}
|
|
|
if (!isset($condition['page'])) {
|
|
|
$param['page'] = 1;
|
|
|
}
|
|
|
if (!isset($condition['limit'])) {
|
|
|
$param['limit'] = 60;
|
|
|
}
|
|
|
if (!empty($condition)) {
|
|
|
$param += $condition;
|
|
|
}
|
|
|
$param['client_secret'] = Sign::getSign($param);
|
|
|
|
|
|
return Yohobuy::get(self::$_searchurl, $param);
|
|
|
return Yohobuy::get(Yohobuy::API_URL, $param);
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 根据给定查询数据搜索数据列表
|
|
|
* 根据给定查询数据搜索数据列表 (新的)
|
|
|
*
|
|
|
* @param string $query 查询条件, 默认为null
|
|
|
* @param string $brand 品牌,默认为null
|
...
|
...
|
@@ -132,19 +121,47 @@ class SearchData |
|
|
* @param integer $channel表示哪个频道,1表示男生,2表示女生,3表示潮童,4表示创意生活
|
|
|
* @return array 搜索到的数据
|
|
|
*/
|
|
|
public static function searchByCondition($condition, $order = 's_t_desc', $page = 1, $limit = 60)
|
|
|
public static function searchElasticByCondition($condition)
|
|
|
{
|
|
|
$param = Yohobuy::param();
|
|
|
$param['method'] = 'app.search.li';
|
|
|
$param['order'] = $order;
|
|
|
$param['page'] = $page;
|
|
|
$param['limit'] = $limit;
|
|
|
// 排序数据映射表
|
|
|
$orderMaps = 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();
|
|
|
$param['status'] = 1; // 是否上架,1表示在架,2表示不在
|
|
|
if (!isset($orderMaps[ $condition['order'] ] )) {
|
|
|
$param['order'] = $orderMaps['s_t_desc'];
|
|
|
} else {
|
|
|
$param['order'] = $orderMaps[ $condition['order'] ];
|
|
|
}
|
|
|
if (!isset($condition['page'])) {
|
|
|
$param['page'] = 1;
|
|
|
}
|
|
|
if (!isset($condition['limit'])) {
|
|
|
$param['viewNum'] = 60;
|
|
|
} else {
|
|
|
$param['viewNum'] = $condition['limit'];
|
|
|
unset($condition['limit']);
|
|
|
}
|
|
|
if (!empty($condition)) {
|
|
|
$param += $condition;
|
|
|
}
|
|
|
$param['client_secret'] = Sign::getSign($param);
|
|
|
|
|
|
return Yohobuy::get(Yohobuy::API_URL, $param, 600); // 有缓存10分钟
|
|
|
return Yohobuy::get(self::getSearchUrl(), $param);
|
|
|
}
|
|
|
|
|
|
} |
...
|
...
|
|