|
|
<?php
|
|
|
|
|
|
namespace LibModels\Wap\Product;
|
|
|
|
|
|
use Api\Yohobuy;
|
|
|
use Api\Sign;
|
|
|
|
|
|
/**
|
|
|
* 搜索有关数据操作类
|
|
|
*
|
|
|
* @name SearchData
|
|
|
* @package Library/LibModels/wap/Product
|
|
|
* @copyright yoho.inc
|
|
|
* @version 1.0 (2015-10-8)
|
|
|
* @author gtskk <rocky.zhang@yoho.cn>
|
|
|
*/
|
|
|
class SearchData
|
|
|
{
|
|
|
|
|
|
/**
|
|
|
* 获取搜索的服务地址
|
|
|
*
|
|
|
* 备注:此处是根据环境来确定使用阿里云内网还是外网的URL
|
|
|
*
|
|
|
* @return string
|
|
|
*/
|
|
|
private static function getSearchUrl()
|
|
|
{
|
|
|
defined('APPLICATION_ENV') || define('APPLICATION_ENV', 'developer');
|
|
|
switch (APPLICATION_ENV) {
|
|
|
case 'release':
|
|
|
return 'http://100.98.132.63/yohosearch/search.json';
|
|
|
case 'test':
|
|
|
case 'preview':
|
|
|
case 'developer':
|
|
|
default:
|
|
|
return 'http://101.200.31.165/yohosearch/search.json';
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 模糊搜索提供的关键词
|
|
|
*
|
|
|
* @param string $keyword 关键词
|
|
|
* @return array 根据给定关键词搜索到的结果,包括数据数目count和提供的关键词keyword
|
|
|
*/
|
|
|
public static function searchFuzzyDatas($keyword)
|
|
|
{
|
|
|
// 构建必传参数
|
|
|
$param = Yohobuy::param();
|
|
|
|
|
|
$param['keyword'] = $keyword;
|
|
|
$param['method'] = 'app.search.fuzzy';
|
|
|
$param['client_secret'] = Sign::getSign($param);
|
|
|
|
|
|
return Yohobuy::get(Yohobuy::API_URL, $param);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 根据给定查询数据搜索数据列表 (老的)
|
|
|
*
|
|
|
* @param string $query 查询条件, 默认为null
|
|
|
* @param string $brand 品牌,默认为null
|
|
|
* @param string $gender 性别,默认为null,"1,3"表示男, "2,3"表示女, "1,2,3"表示全部
|
|
|
* @param integer $color 颜色id
|
|
|
* @param integer $size 尺码id
|
|
|
* @param integer $price 价格
|
|
|
* @param string $p_d 折扣,默认为null
|
|
|
* @param string $sort 商品所属品类,默认为null
|
|
|
* @param string $order 排序方式,默认为按照时间倒序排列s_t_desc,
|
|
|
* s_t_asc表示按时间正序排列,
|
|
|
* s_p_asc表示按价格正序排列,
|
|
|
* s_p_desc表示按价格倒序排列,
|
|
|
* p_d_asc表示按折扣正序排列,
|
|
|
* p_d_desc表示按折扣倒序排列
|
|
|
* @param integer $page 指定查询是多少页,默认为第一页
|
|
|
* @param integer $limit 指定查询多少个,默认是60个
|
|
|
* @param integer $channel表示哪个频道,1表示男生,2表示女生,3表示潮童,4表示创意生活
|
|
|
* @return array 搜索到的数据
|
|
|
*/
|
|
|
public static function searchByCondition($condition)
|
|
|
{
|
|
|
$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(Yohobuy::API_URL, $param);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 根据给定查询数据搜索数据列表 (新的)
|
|
|
*
|
|
|
* @param string $query 查询条件, 默认为null
|
|
|
* @param string $brand 品牌,默认为null
|
|
|
* @param string $gender 性别,默认为null,"1,3"表示男, "2,3"表示女, "1,2,3"表示全部
|
|
|
* @param integer $color 颜色id
|
|
|
* @param integer $size 尺码id
|
|
|
* @param integer $price 价格
|
|
|
* @param string $p_d 折扣,默认为null
|
|
|
* @param string $sort 商品所属品类,默认为null
|
|
|
* @param string $order 排序方式,默认为按照时间倒序排列s_t_desc,
|
|
|
* s_t_asc表示按时间正序排列,
|
|
|
* s_p_asc表示按价格正序排列,
|
|
|
* s_p_desc表示按价格倒序排列,
|
|
|
* p_d_asc表示按折扣正序排列,
|
|
|
* p_d_desc表示按折扣倒序排列
|
|
|
* @param integer $page 指定查询是多少页,默认为第一页
|
|
|
* @param integer $limit 指定查询多少个,默认是60个
|
|
|
* @param integer $channel表示哪个频道,1表示男生,2表示女生,3表示潮童,4表示创意生活
|
|
|
* @return array 搜索到的数据
|
|
|
*/
|
|
|
public static function searchElasticByCondition($condition, $cache = false)
|
|
|
{
|
|
|
// 排序数据映射表
|
|
|
$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',
|
|
|
'p_d_desc' => 'discount:desc',
|
|
|
'p_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表示不在
|
|
|
$param['sales'] = 'Y'; // 只搜索销售的产品
|
|
|
$param['stocknumber'] = 1; // 过滤掉已售罄的商品
|
|
|
// $param['needFilter'] = 1; // 是否需要返回筛选条件
|
|
|
if (!isset($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;
|
|
|
}
|
|
|
|
|
|
return Yohobuy::get(self::getSearchUrl(), $param, $cache);
|
|
|
}
|
|
|
|
|
|
} |
|
|
<?php
|
|
|
|
|
|
namespace LibModels\Wap\Product;
|
|
|
|
|
|
use Api\Yohobuy;
|
|
|
use Api\Sign;
|
|
|
|
|
|
/**
|
|
|
* 搜索有关数据操作类
|
|
|
*
|
|
|
* @name SearchData
|
|
|
* @package Library/LibModels/wap/Product
|
|
|
* @copyright yoho.inc
|
|
|
* @version 1.0 (2015-10-8)
|
|
|
* @author gtskk <rocky.zhang@yoho.cn>
|
|
|
*/
|
|
|
class SearchData
|
|
|
{
|
|
|
|
|
|
/**
|
|
|
* 获取搜索的服务地址
|
|
|
*
|
|
|
* 备注:此处是根据环境来确定使用阿里云内网还是外网的URL
|
|
|
*
|
|
|
* @return string
|
|
|
*/
|
|
|
private static function getSearchUrl()
|
|
|
{
|
|
|
defined('APPLICATION_ENV') || define('APPLICATION_ENV', 'developer');
|
|
|
switch (APPLICATION_ENV) {
|
|
|
case 'release':
|
|
|
return 'http://100.98.132.63/yohosearch/search.json';
|
|
|
case 'test':
|
|
|
case 'preview':
|
|
|
case 'developer':
|
|
|
default:
|
|
|
return 'http://101.200.31.165/yohosearch/search.json';
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 模糊搜索提供的关键词
|
|
|
*
|
|
|
* @param string $keyword 关键词
|
|
|
* @return array 根据给定关键词搜索到的结果,包括数据数目count和提供的关键词keyword
|
|
|
*/
|
|
|
public static function searchFuzzyDatas($keyword)
|
|
|
{
|
|
|
// 构建必传参数
|
|
|
$param = Yohobuy::param();
|
|
|
|
|
|
$param['keyword'] = $keyword;
|
|
|
$param['method'] = 'app.search.fuzzy';
|
|
|
$param['client_secret'] = Sign::getSign($param);
|
|
|
|
|
|
return Yohobuy::get(Yohobuy::API_URL, $param);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 根据给定查询数据搜索数据列表 (老的)
|
|
|
*
|
|
|
* @param string $query 查询条件, 默认为null
|
|
|
* @param string $brand 品牌,默认为null
|
|
|
* @param string $gender 性别,默认为null,"1,3"表示男, "2,3"表示女, "1,2,3"表示全部
|
|
|
* @param integer $color 颜色id
|
|
|
* @param integer $size 尺码id
|
|
|
* @param integer $price 价格
|
|
|
* @param string $p_d 折扣,默认为null
|
|
|
* @param string $sort 商品所属品类,默认为null
|
|
|
* @param string $order 排序方式,默认为按照时间倒序排列s_t_desc,
|
|
|
* s_t_asc表示按时间正序排列,
|
|
|
* s_p_asc表示按价格正序排列,
|
|
|
* s_p_desc表示按价格倒序排列,
|
|
|
* p_d_asc表示按折扣正序排列,
|
|
|
* p_d_desc表示按折扣倒序排列
|
|
|
* @param integer $page 指定查询是多少页,默认为第一页
|
|
|
* @param integer $limit 指定查询多少个,默认是60个
|
|
|
* @param integer $channel表示哪个频道,1表示男生,2表示女生,3表示潮童,4表示创意生活
|
|
|
* @return array 搜索到的数据
|
|
|
*/
|
|
|
public static function searchByCondition($condition)
|
|
|
{
|
|
|
$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(Yohobuy::API_URL, $param);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 根据给定查询数据搜索数据列表 (新的)
|
|
|
*
|
|
|
* @param string $query 查询条件, 默认为null
|
|
|
* @param string $brand 品牌,默认为null
|
|
|
* @param string $gender 性别,默认为null,"1,3"表示男, "2,3"表示女, "1,2,3"表示全部
|
|
|
* @param integer $color 颜色id
|
|
|
* @param integer $size 尺码id
|
|
|
* @param integer $price 价格
|
|
|
* @param string $p_d 折扣,默认为null
|
|
|
* @param string $sort 商品所属品类,默认为null
|
|
|
* @param string $order 排序方式,默认为按照时间倒序排列s_t_desc,
|
|
|
* s_t_asc表示按时间正序排列,
|
|
|
* s_p_asc表示按价格正序排列,
|
|
|
* s_p_desc表示按价格倒序排列,
|
|
|
* p_d_asc表示按折扣正序排列,
|
|
|
* p_d_desc表示按折扣倒序排列
|
|
|
* @param integer $page 指定查询是多少页,默认为第一页
|
|
|
* @param integer $limit 指定查询多少个,默认是60个
|
|
|
* @param integer $channel表示哪个频道,1表示男生,2表示女生,3表示潮童,4表示创意生活
|
|
|
* @return array 搜索到的数据
|
|
|
*/
|
|
|
public static function searchElasticByCondition($condition, $cache = false)
|
|
|
{
|
|
|
// 排序数据映射表
|
|
|
$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',
|
|
|
'p_d_desc' => 'discount:desc',
|
|
|
'p_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表示不在
|
|
|
$param['sales'] = 'Y'; // 只搜索销售的产品
|
|
|
$param['stocknumber'] = 1; // 过滤掉已售罄的商品
|
|
|
// $param['needFilter'] = 1; // 是否需要返回筛选条件
|
|
|
if (!isset($condition['order'])) {
|
|
|
$param['order'] = $orderMaps['s_t_desc'];
|
|
|
} else {
|
|
|
$param['order'] = $orderMaps[$condition['order']];
|
|
|
}
|
|
|
if (!isset($condition['page'])) {
|
|
|
$param['page'] = 1;
|
|
|
}
|
|
|
|
|
|
if(isset($condition['viewNum'])) {
|
|
|
$param['viewNum'] = $condition['viewNum'];
|
|
|
} else if (!isset($condition['limit'])) {
|
|
|
$param['viewNum'] = 60;
|
|
|
} else {
|
|
|
$param['viewNum'] = $condition['limit'];
|
|
|
unset($condition['limit']);
|
|
|
}
|
|
|
if (!empty($condition)) {
|
|
|
$param += $condition;
|
|
|
}
|
|
|
|
|
|
return Yohobuy::get(self::getSearchUrl(), $param, $cache);
|
|
|
}
|
|
|
|
|
|
} |
...
|
...
|
|