Authored by Rock Zhang

Merge branch 'test' into develop

Conflicts:
	library/Plugin/DataProcess/ListProcess.php
... ... @@ -39,5 +39,7 @@ class CacheConfig
const KEY_ACTION_PRODUCT_BRAND_DOMAINS = 'key_action_product_brand_domains'; // 所有品牌域名列表
const KEY_ACTION_PRODUCT_BRAND_NAMES = 'key_action_product_brand_names'; // 所有品牌名称列表
const KEY_ACTION_PRODUCT_BRAND_LOGO = 'key_action_product_brand_logo'; // 品牌信息
const KEY_ACTION_INDEX_SEARCH = 'key_action_search_search'; // 搜索的数据
}
... ...
... ... @@ -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);
}
}
... ...
... ... @@ -15,7 +15,7 @@ class ListProcess
* @param $data
* @return array 处理之后的商品数据
*/
public static function getListData($data)
public static function getListData($data, $returnFilter = true)
{
$result = array('new'=>array(), 'filter'=>array());
... ... @@ -23,8 +23,7 @@ class ListProcess
{
$result['new'] = self::getProductData($data['product_list']);
}
if(isset($data['filter']))
{
if ($returnFilter && isset($data['filter'])) {
$result['filter'] = self::getFilterData($data['filter']);
}
... ...
... ... @@ -193,7 +193,7 @@ class Helpers
// 如果$productData['default_images']为空,就取$productData['goods_list']中第一个,为空就不处理
if (empty($productData['default_images'])) {
$productData['default_images'] = $productData['goods_list'][0];
$productData['default_images'] = $productData['goods_list'][0]['images_url'];
}
$result = array();
... ...
<?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(
... ... @@ -20,13 +24,11 @@ class Images
),
'yhb-head' => 'head.static.yhbimg.com'
);
private static $staticDomain = array(
'bucket' => ''
);
private static $qiniuDomain = 'yhfair.qiniudn.com';
/**
* 缩略图模板
* @param $fileName
... ... @@ -39,7 +41,7 @@ class Images
{
return self::url($fileName, $bucket, $mode);
}
/**
*
* @param unknown $fileName
... ... @@ -48,13 +50,13 @@ class Images
*/
public static function getSourceUrl($fileName, $bucket = 'yhfair')
{
if(stripos($fileName, 'http://') === 0){
if (stripos($fileName, 'http://') === 0) {
return $fileName;
}
$domain = self::getDomain($bucket, $fileName);
return 'http://' . $domain . '/' . $bucket . $fileName;
}
/**
* 根据尺寸获得图片url
* @param unknown $fileName
... ... @@ -64,14 +66,17 @@ class Images
* @param string $bucket
* @return mixed
*/
public static function getImageUrl($fileName, $width, $height, $mode = 1, $bucket = 'goodsimg')
public static function getImageUrl($fileName, $width, $height, $mode = 2, $bucket = 'goodsimg')
{
if (stripos($fileName, 'http://') !== 0){
$fileName = self::template($fileName, $bucket, $mode);
}
return strtr($fileName, array('{width}' => $width, '{height}' => $height, '{mode}' => $mode));
if (!is_string($fileName)) {
return self::template(self::$default_image, $bucket, $mode);
}
if (stripos($fileName, 'http://') !== 0) {
$fileName = self::template($fileName, $bucket, $mode);
}
return strtr($fileName, array('{width}' => $width, '{height}' => $height, '{mode}' => $mode));
}
/**
* 获取图片URL模板
* @param $fileName
... ... @@ -84,13 +89,13 @@ class Images
$domain = self::getDomain($bucket, $fileName);
return self::getImgTemplateUrl($bucket . $fileName, $mode, $domain);
}
public static function getDomain($bucket, $fileName)
{
$domain = '';
if(!empty(self::$domainList[$bucket])){
if (!empty(self::$domainList[$bucket])) {
$domain = self::$domainList[$bucket];
}else{
} else {
$node = mb_substr($fileName, 15, 2);
if (!empty(self::$domainList[$node])) {
$domainList = self::$domainList[$node];
... ... @@ -100,7 +105,7 @@ class Images
}
return $domain;
}
/**
* 获取模板的图片地址
* @param $fileName
... ... @@ -118,13 +123,13 @@ class Images
$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();
... ... @@ -135,7 +140,8 @@ class Images
if (empty($ops)) {
return $url;
}
return $url . "?imageView/" . implode('/', $ops);
}
}
\ No newline at end of file
}
... ...
... ... @@ -237,25 +237,6 @@ server
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Accept-Encoding "gzip";
}
# # 子域名
# if ($host = "sale.test.yoho.cn" ) {
# proxy_redirect off;
# proxy_pass http://61.155.222.162;
# proxy_set_header Host cuxiao.m.yohobuy.com;
# proxy_set_header X-Real-IP $remote_addr;
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# proxy_set_header Accept-Encoding "gzip";
# }
# if ($host = "cuxiao.test.yoho.cn" ) {
# proxy_redirect off;
# proxy_pass http://101.201.176.121;
# proxy_set_header Host cuxiao.m.yohobuy.com;
# proxy_set_header X-Real-IP $remote_addr;
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# proxy_set_header Accept-Encoding "gzip";
# }
#location ~* \.html$ {
# root /Data/code/git/yohobuy/assets;
... ... @@ -274,18 +255,18 @@ server
location =/sitemap.xml {
expires 1d;
}
location=/robots.txt {
location =/robots.txt {
expires 1d;
}
location / {
proxy_redirect off;
proxy_pass http://yohobuy;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Accept-Encoding "gzip";
}
#location / {
# proxy_redirect off;
# proxy_pass http://yohobuy;
# proxy_set_header Host $host;
# proxy_set_header X-Real-IP $remote_addr;
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# proxy_set_header Accept-Encoding "gzip";
# }
}
... ... @@ -310,4 +291,33 @@ server
expires 30d;
}
}
server
{
listen 80;
server_name sale.test.yoho.cn;
location / {
proxy_redirect off;
proxy_pass http://61.155.222.163;
proxy_set_header Host sale.m.yohobuy.com;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Accept-Encoding "gzip";
}
}
server
{
listen 80;
server_name cuxiao.test.yoho.cn;
location / {
proxy_redirect off;
proxy_pass http://101.201.176.121;
proxy_set_header Host cuxiao.m.yohobuy.com;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Accept-Encoding "gzip";
}
}
\ No newline at end of file
... ...
... ... @@ -148,7 +148,7 @@ class SearchController extends AbstractAction
$this->setTitle('搜索');
$this->setNavHeader('搜索', true, SITE_MAIN);
}
// 右下角的购物车链接
$data['goodList']['cartUrl'] = Helpers::url('/cart/index/index', null);
... ... @@ -182,8 +182,13 @@ class SearchController extends AbstractAction
{
$data = array();
if ($this->isAjax()) {
// 过滤请求参数
do {
/* 判断是不是AJAX请求 */
if (!$this->isAjax()) {
break;
}
/* 过滤请求参数 */
$condition = filter_input_array(INPUT_GET, array(
'query' => FILTER_DEFAULT,
'brand' => FILTER_VALIDATE_INT,
... ... @@ -195,55 +200,45 @@ class SearchController extends AbstractAction
'price' => FILTER_VALIDATE_INT,
'discount' => FILTER_DEFAULT,
'gender' => FILTER_DEFAULT,
'p_d' => FILTER_DEFAULT,), false);
'p_d' => FILTER_DEFAULT,
'page' => FILTER_VALIDATE_INT, ), false);
// 转义分类
if (isset($condition['sort'])) {
$condition['sort'] = rawurldecode($condition['sort']);
}
// 转换折扣
if (isset($condition['discount'])) {
$condition['p_d'] = rawurldecode($condition['discount']);
unset($condition['discount']);
}
// 转义性别
if (isset($condition['gender'])) {
$condition['gender'] = rawurldecode($condition['gender']);
}
// 转换排序方式
$page = $this->get('page', 1);
$orderVal = $this->get('order', 0);
$type = $this->get('type', '');
$order = Helpers::transOrder($orderVal, $type);
// 查询品类或品牌数据
if (!isset($condition['query'])) {
$condition['order'] = $order;
$condition['page'] = $page;
// 搜索品类
if (!isset($condition['brand'])) {
$data += Product\ListModel::getClassData($condition);
}
// 搜索品牌
else {
$title = '';
$data += Product\ListModel::getBrandData($condition, $title);
}
if (isset($data['filter'])) {
unset($data['filter']);
}
}
// 查询数据
else {
$listData = SearchData::searchByCondition($condition, $order, $page);
// 处理返回的数据
if (isset($listData['data'])) {
if (isset($listData['data']['filter'])) {
unset($listData['data']['filter']);
}
$data = ListProcess::getListData($listData['data']);
}
$listData = array();
}
}
$order = $this->get('order', 0);
$condition['order'] = Helpers::transOrder($order, $type);
// /* 模糊搜索关键词 */
// if (isset($condition['query'])) {
// $data = Product\SearchModel::getSearchData($condition);
// break;
// }
//
// /* 精确搜索品牌 */
// if (isset($condition['brand'])) {
// $title = '';
// $data = Product\ListModel::getBrandData($condition, $title);
// break;
// }
//
// /* 精确搜索品类 */
// $data = Product\ListModel::getClassData($condition);
$data = Product\SearchModel::getSearchData($condition);
} while (false);
if (empty($data['new'])) {
echo ' ';
... ...
... ... @@ -3,7 +3,6 @@
namespace Category;
use LibModels\Wap\Category\BrandData;
use Configs\CacheConfig;
use Plugin\Helpers;
/**
... ...
... ... @@ -47,7 +47,7 @@ class ListModel
$listData = ClassData::filterClassData($condition);
// 处理返回的数据
if (isset($listData['code']) && $listData['code'] === 200) {
$result = ListProcess::getListData($listData['data']);
$result = ListProcess::getListData($listData['data'], false);
}
if (USE_CACHE) {
... ... @@ -121,7 +121,7 @@ class ListModel
$listData = BrandData::filterBrandData($condition);
// 处理返回的数据
if (isset($listData['code']) && $listData['code'] === 200) {
$result = ListProcess::getListData($listData['data']);
$result = ListProcess::getListData($listData['data'], false);
if (!empty($listData['data']['brand'])) {
$result['brandWay'] = array(
'url' => 'http://' . $listData['data']['brand']['brand_domain'] . SUB_DOMAIN,
... ...
<?php
namespace Product;
use Configs\CacheConfig;
use LibModels\Wap\Product\SearchData;
use Plugin\DataProcess\ListProcess;
/**
* 搜索相关的模板数据模型
*
* @name Search
* @package Product
* @copyright yoho.inc
* @version 1.0 (2015-11-1 14:35:52)
*/
class SearchModel
{
/**
* 获取搜索的数据
*
* @param array $condition 查询条件
* @return array
*/
public static function getSearchData($condition)
{
$result = array();
if (USE_CACHE) {
$key = CacheConfig::KEY_ACTION_INDEX_SEARCH;
if (!empty($condition)) {
$key .= http_build_query($condition, null, '&');
}
// 先尝试获取一级缓存(master), 有数据则直接返回.
$result = Cache::get($key, 'master');
if (!empty($result)) {
return $result;
}
}
// 调用接口查询数据 (使用新的 Elastic Engine)
$listData = SearchData::searchElasticByCondition($condition);
// 调用接口查询数据 (使用老的 Sphinx Engine)
// $listData = SearchData::searchByCondition($condition);
// 处理返回的数据
if (isset($listData['code']) && $listData['code'] === 200) {
$result = ListProcess::getListData($listData['data'], false);
}
if (USE_CACHE) {
// 接口调用异常时, 不害怕,从我们的二级缓存(slave)里再取数据.
if (empty($result)) {
$result = Cache::get($key, 'slave');
}
// 接口调用正常,数据封装完成, 则设置一级(master)和二级(slave)数据缓存
else {
Cache::set($key, $result, 600); // 缓存10分钟
}
}
return $result;
}
}
... ...
[common]
;;默认项目
application.directory = APPLICATION_PATH "/application"
;;website library
application.library = ROOT_PATH "/library"
;;默认模块
application.modules = "Index,Category,Channel,Guang,Passport,Product,Cart"
;;加载
application.bootstrap = APPLICATION_PATH "/application/Bootstrap.php"
;;view文件的扩展名
application.view.ext = "phtml"
;;默认layouts
application.layout.path = APPLICATION_PATH "/application/layouts"
;;layouts 默认文件
application.layout.default = "default"
;;默认Controller
application.dispatcher.defaultController = "index"
;;默认Action
application.dispatcher.defaultAction = "index"
;;初始化命名空间
application.namespaces = "Action,Api,Configs,LibModels,Plugin"
;;使用composer
composer.autoload = 0
composer.path = APPLICATION_PATH "/library/Package"
yaf.use_namespace = 1
;;调试模式
[preview : common]
application.debug = False
application.servers.config = APPLICATION_PATH "/configs/core"
;出错的时候是否抛出异常
application.dispatcher.throwException = False
;是否使用默认的异常 捕获Controller, 如果开启, 在有未捕获的异常的时候,
;控制权会交给ErrorController的errorAction 方法,
;可以通过$request->getException()获得此异常对象
application.dispatcher.catchException = False
;模板预编译目录,该目录需要有读写权限
application.template.compile = ROOT_PATH "/compile/m.yohobuy.com"
application.template.path = ROOT_PATH "/template/m.yohobuy.com/actions"
application.template.partials = ROOT_PATH "/template/m.yohobuy.com/partials"
application.template.ext = ".phtml"
;静态HTML页面的存放目录, 该目录需要有读写权限
application.assets.path = ROOT_PATH "/assets"
; 应用的版本号
application.version = "0.0.6"
; 网站SEO信息
application.seo.title = "Yoho!Buy有货"
application.seo.keywords = "Yoho! 有货官网,潮流志,潮流男装,潮牌,美国潮牌,日本潮牌,香港潮牌,潮牌店,新品首发,欧美潮流,全球购,代购,时尚,流行,特卖,B2C,正品,购物网站,网上购物,货到付款"
application.seo.description = "YOHO! 有货,年轻人潮流购物中心,中国最大的潮流商品购物网站。100%品牌正品保证,支持货到付款。作为YOHO!旗下的购物平台,汇集了全球潮流时尚商品和中国最流行的商品,也是国内最大的原创文化商品平台,也是香港,台湾地区流行商品的集中地。同时包含日本、韩国等众多国外潮流品牌,带给您全新潮流购物体验。"
... ...