Authored by yangyang

修改brands页面为并行调接口

<?php
namespace Plugin;
use Plugin\Paging;
use LibModels\Web\Product\BrandData;
use Api\Yohobuy;
use Api\Sign;
/**
* 搜索辅助类
*/
... ... @@ -110,6 +112,8 @@ class HelperSearch
$result['leftContent'][]['newSales'] = isset($data['recent']) ? self::recentShelve($data['recent']) : array();
//全部折扣
$result['leftContent'][]['allDiscount'] = isset($data['discount']) ? self::getDiscount($data['discount']['discount']) : array();
//品牌banner
$result['brandBanner'] = isset($data['banner']) && isset($data['brand']) ? self::getBannerFormat($data['banner'],$data['brand']) : array();
//总记录数
$result['totalCount'] = $data['product']['total'];
//分页
... ... @@ -1212,6 +1216,36 @@ class HelperSearch
return Yohobuy::httpBuildQuery(self::getUrl('recent'), $param);
}
/**
* 并行调接口url获取(获取品牌数据)
*/
public static function getBrandUrl($customOptions = array())
{
// 构建必传参数
$param = Yohobuy::param();
$param['brand_id'] = $customOptions['brandId'];
$param['uid'] = $customOptions['uid'];
$param['method'] = 'app.brand.getBrandIntro';
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::httpBuildQuery(Yohobuy::API_URL, $param);
}
/**
* 并行调接口url获取(获取品牌banner数据)
*/
public static function getBannerUrl($customOptions = array())
{
// 构建必传参数
$param = Yohobuy::param();
$param['brand_id'] = $customOptions['brandId'];
$param['method'] = 'app.brand.banner';
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::httpBuildQuery(Yohobuy::API_URL, $param);
}
/**
* 并行调接口url获取(获取用户浏览记录)
*/
... ... @@ -1272,4 +1306,36 @@ class HelperSearch
return 'http://101.200.31.165/yohosearch/search.json';
}
}
/**
* 获取品牌首页banner条
*
* @return array 品牌banner条数据
*/
public static function getBannerFormat($banner, $brand)
{
// 根据品牌Id获取品牌banner图
if (isset($banner['banner'])) {
$bannerImg = Helpers::getImageUrl($banner['banner'], '', 150);
}
$is_favorite = false;
$shopName = false;
if(isset($brand)){
// 获取是否收藏
if ($brand['is_favorite'] == 'Y') {
$is_favorite = true;
} elseif ($brand['is_favorite'] == 'N') {
$is_favorite = false;
}
}
// 返回banner数据
return array(
'bannerHeight' => '150',
'coled' => $is_favorite,
'banner' => $bannerImg
);
}
}
... ...
... ... @@ -71,7 +71,7 @@ class Bootstrap extends Bootstrap_Abstract
$controller = 'Index';
$action = 'Index';
// 二级域名
if (2 === $level) {
if (3 === $level) {
$subDomain = strval($hostParts[0]);
switch (strtolower($subDomain)) {
case 'www': // 主站
... ...
... ... @@ -2,11 +2,10 @@
namespace Product;
use Plugin\Helpers;
use Api\Yohobuy;
use Plugin\HelperSearch;
use LibModels\Web\Product\BrandData;
use LibModels\Wap\Product\SearchData;
use LibModels\Web\Product\SearchData as WebProduct;
use Product\SearchModel;
/**
* 品牌首页模板数据模型
... ... @@ -15,114 +14,31 @@ use LibModels\Web\Product\SearchData as WebProduct;
*/
class BrandsModel
{
const URL_BRAND_INDEX = '/product/index/brand';
public static $shopName;
public static $home;
/**
* 搜索品牌数据
*
* @param $condition array
* 搜索数据的条件
* @param $condition array 搜索数据的条件
* @param $options array
* @return array
*/
public static function getBrandSearchData($condition, $options, $domain, $uid, $brandId,$node)
public static function getBrandSearchData($condition, $options)
{
// 调用商品搜索接口
$data = SearchData::searchElasticByCondition($condition);
// 并行调用品牌相关接口并封装数据
$data = self::getBrandData($condition, $options);
//获取品牌banner数据
$banner = self::getBannerByDomain($domain, $brandId, $uid = '');
$brandName = self::$shopName;
$options['brandName'] = $brandName;
if (isset($data['code']) && $data['code'] === 200) {
//获取分类列表数据
$param = array();
$param['brand'] = $condition['brand'];
$classes = WebProduct::getClassesData($param);
if (isset($classes['code']) && $classes['code'] === 200) {
$data['data']['filter']['group_sort'] = $classes['data']['sort'];
}
//用户浏览记录
// 组织模板数据
$list = HelperSearch::getList($data, $options);
//合并商品搜索数据与品牌banner数据
$list = array_merge_recursive($list,$banner);
$data = array(
//初始化js
'productListPage' => true,
'list' => $list
);
} else {
$data = array();
}
//获取品牌系列数据
$adNav = self::getAdNav($condition['brand']);
$data['list']['leftContent'][] = array('picLink' => $adNav);
$adNav = self::getAdNav($options['brandId']);
$data['leftContent'][] = array('picLink' => $adNav);
//获取静态内容(20141219-100447)
if($node){
$nodeContent = HelperSearch::formatNodeContent($node);
$data['list']['leftContent'][]['picLink']['list'] = $nodeContent;
//获取静态内容(eg:20141219-100447)
if($options['node']){
$nodeContent = HelperSearch::formatNodeContent($options['node']);
$data['leftContent'][]['picLink']['list'] = $nodeContent;
}
return $data;
}
/**
* 获取品牌首页banner条
* @string $domain 品牌域名
* @int $brandId 品牌id
* @int $uid 用户id
*
* @return array 品牌banner条数据
*/
public static function getBannerByDomain($domain, $brandId, $uid = '')
{
// 构造品牌主页url
self::$home = Helpers::url('', '', $domain) . self::URL_BRAND_INDEX;
// 根据品牌Id获取品牌banner图
$bannerImg = BrandData::getBrandBanner($brandId);
if (isset($bannerImg['data'])) {
$bannerImg = Helpers::getImageUrl($bannerImg['data']['banner'], '', 150);
}
// 根据品牌Id获取品牌(简介)、收藏
$intro = BrandData::getBrandIntro($brandId, $uid);
$is_favorite = false;
$shopName = false;
if(isset($intro['data'])){
// 获取是否收藏
if ($intro['data']['is_favorite'] == 'Y') {
$is_favorite = true;
} elseif ($intro['data']['is_favorite'] == 'N') {
$is_favorite = false;
}
// 获取品牌名
self::$shopName = $intro['data']['brand_name'];
}
// 返回banner数据
return array(
'brandBanner' => array(
'bannerHeight' => '150',
'coled' => $is_favorite,
'banner' => $bannerImg
)
);
}
//获取品牌系列数据
public static function getAdNav($brandId, $status = 1)
{
... ... @@ -131,13 +47,50 @@ class BrandsModel
$result = array();
if (isset($advNav['data']) && $advNav['code'] === 200) {
foreach ($advNav['data'] as $key => $value) {
$result['list'][$key]['href'] = self::$home . '?folder_id=' . $value['id'];
$result['list'][$key]['href'] = '?folder_id=' . $value['id'];
$result['list'][$key]['src'] = $value['brand_sort_ico'];
}
$result['picTitle'] = '经典系列';
}
$result['picTitle'] = '经典系列';
return $result;
}
/**
* 根据条件获取搜索数据
* @param array $customCondition
* @param array $customOptions
* @return array
*/
public static function getBrandData($customCondition = array(), $customOptions = array())
{
$urlList = array();
//获取$condition和$option 筛选条件和排序条件
$searchCondition = SearchModel::searchCondition($customCondition, $customOptions);
// 组合搜索商品url
$urlList['product'] = HelperSearch::getProductUrl($searchCondition['condition']);
// 组合搜索分类url
$urlList['sort'] = HelperSearch::getClassesUrl($searchCondition['condition']);
//组合搜索品牌url
$urlList['brand'] = HelperSearch::getBrandUrl($customOptions);
//组合获取品牌banner url
$urlList['banner'] = HelperSearch::getBannerUrl($customOptions);
//组合用户浏览记录url
//$urlList['reviewUrl'] = HelperSearch::getReviewUrl($searchCondition['condition']);
//批量调接口
$result = Yohobuy::getMulti($urlList, array(), true);
//组织模板数据格式
$data = HelperSearch::getList($result, $searchCondition['options']);
return $data;
}
}
... ...
... ... @@ -24,7 +24,7 @@ class SearchModel
* @param $option
* @return mixed
*/
public static function SearchCondition($param, $option)
public static function searchCondition($param = array(), $option = array())
{
/* 过滤请求参数 */
$condition = filter_input_array(INPUT_GET, array(
... ... @@ -119,6 +119,7 @@ class SearchModel
$options = array_merge($options, $option);
$data['condition'] = $condition;
$data['options'] = $options;
return $data;
}
... ...
<?php
use Action\WebAction;
use LibModels\Web\Product\BrandData;
use Product\SearchModel;
class IndexController extends WebAction
{
/**
* 品牌首页
*/
... ... @@ -26,18 +24,26 @@ class IndexController extends WebAction
$this->go(SITE_MAIN);
}
//品牌ID参数
//品牌ID参数
$condition = array();
$condition['brand'] = $brandId;
/* 过滤请求参数 */
SearchModel::SearchCondition($condition);
//$options参数数组
$options = array();
$options['brandName'] = $domain;
$options['uid'] = $uid;
$options['brandId'] = $brandId;
$options['node'] = $node;
//调用模型获得数据
$data = Product\BrandsModel::getBrandSearchData($condition, $options);
$data = array(
//初始化js
'searchListPage' => true,
'list' => $data
);
$data = Product\BrandsModel::getBrandSearchData($params,$options,$domain,$uid,$brandId,$node);
$cate = array('boys','girls','kids','lifestyle');
$this->setWebNavHeader($cate[$gender-1]);
$this->setWebNavHeader();
//渲染模板
$this->_view->display('list',$data);
}
... ...