Authored by yangyang

修改brands页面为并行调接口

1 <?php 1 <?php
2 2
3 namespace Plugin; 3 namespace Plugin;
  4 +
4 use Plugin\Paging; 5 use Plugin\Paging;
5 use LibModels\Web\Product\BrandData; 6 use LibModels\Web\Product\BrandData;
6 use Api\Yohobuy; 7 use Api\Yohobuy;
  8 +use Api\Sign;
7 /** 9 /**
8 * 搜索辅助类 10 * 搜索辅助类
9 */ 11 */
@@ -110,6 +112,8 @@ class HelperSearch @@ -110,6 +112,8 @@ class HelperSearch
110 $result['leftContent'][]['newSales'] = isset($data['recent']) ? self::recentShelve($data['recent']) : array(); 112 $result['leftContent'][]['newSales'] = isset($data['recent']) ? self::recentShelve($data['recent']) : array();
111 //全部折扣 113 //全部折扣
112 $result['leftContent'][]['allDiscount'] = isset($data['discount']) ? self::getDiscount($data['discount']['discount']) : array(); 114 $result['leftContent'][]['allDiscount'] = isset($data['discount']) ? self::getDiscount($data['discount']['discount']) : array();
  115 + //品牌banner
  116 + $result['brandBanner'] = isset($data['banner']) && isset($data['brand']) ? self::getBannerFormat($data['banner'],$data['brand']) : array();
113 //总记录数 117 //总记录数
114 $result['totalCount'] = $data['product']['total']; 118 $result['totalCount'] = $data['product']['total'];
115 //分页 119 //分页
@@ -1212,6 +1216,36 @@ class HelperSearch @@ -1212,6 +1216,36 @@ class HelperSearch
1212 return Yohobuy::httpBuildQuery(self::getUrl('recent'), $param); 1216 return Yohobuy::httpBuildQuery(self::getUrl('recent'), $param);
1213 } 1217 }
1214 1218
  1219 + /**
  1220 + * 并行调接口url获取(获取品牌数据)
  1221 + */
  1222 + public static function getBrandUrl($customOptions = array())
  1223 + {
  1224 + // 构建必传参数
  1225 + $param = Yohobuy::param();
  1226 + $param['brand_id'] = $customOptions['brandId'];
  1227 + $param['uid'] = $customOptions['uid'];
  1228 + $param['method'] = 'app.brand.getBrandIntro';
  1229 + $param['client_secret'] = Sign::getSign($param);
  1230 +
  1231 + return Yohobuy::httpBuildQuery(Yohobuy::API_URL, $param);
  1232 + }
  1233 +
  1234 + /**
  1235 + * 并行调接口url获取(获取品牌banner数据)
  1236 + */
  1237 + public static function getBannerUrl($customOptions = array())
  1238 + {
  1239 + // 构建必传参数
  1240 + $param = Yohobuy::param();
  1241 + $param['brand_id'] = $customOptions['brandId'];
  1242 + $param['method'] = 'app.brand.banner';
  1243 + $param['client_secret'] = Sign::getSign($param);
  1244 +
  1245 + return Yohobuy::httpBuildQuery(Yohobuy::API_URL, $param);
  1246 + }
  1247 +
  1248 +
1215 /** 1249 /**
1216 * 并行调接口url获取(获取用户浏览记录) 1250 * 并行调接口url获取(获取用户浏览记录)
1217 */ 1251 */
@@ -1272,4 +1306,36 @@ class HelperSearch @@ -1272,4 +1306,36 @@ class HelperSearch
1272 return 'http://101.200.31.165/yohosearch/search.json'; 1306 return 'http://101.200.31.165/yohosearch/search.json';
1273 } 1307 }
1274 } 1308 }
  1309 +
  1310 + /**
  1311 + * 获取品牌首页banner条
  1312 + *
  1313 + * @return array 品牌banner条数据
  1314 + */
  1315 + public static function getBannerFormat($banner, $brand)
  1316 + {
  1317 +
  1318 + // 根据品牌Id获取品牌banner图
  1319 + if (isset($banner['banner'])) {
  1320 + $bannerImg = Helpers::getImageUrl($banner['banner'], '', 150);
  1321 + }
  1322 +
  1323 + $is_favorite = false;
  1324 + $shopName = false;
  1325 + if(isset($brand)){
  1326 + // 获取是否收藏
  1327 + if ($brand['is_favorite'] == 'Y') {
  1328 + $is_favorite = true;
  1329 + } elseif ($brand['is_favorite'] == 'N') {
  1330 + $is_favorite = false;
  1331 + }
  1332 + }
  1333 +
  1334 + // 返回banner数据
  1335 + return array(
  1336 + 'bannerHeight' => '150',
  1337 + 'coled' => $is_favorite,
  1338 + 'banner' => $bannerImg
  1339 + );
  1340 + }
1275 } 1341 }
@@ -71,7 +71,7 @@ class Bootstrap extends Bootstrap_Abstract @@ -71,7 +71,7 @@ class Bootstrap extends Bootstrap_Abstract
71 $controller = 'Index'; 71 $controller = 'Index';
72 $action = 'Index'; 72 $action = 'Index';
73 // 二级域名 73 // 二级域名
74 - if (2 === $level) { 74 + if (3 === $level) {
75 $subDomain = strval($hostParts[0]); 75 $subDomain = strval($hostParts[0]);
76 switch (strtolower($subDomain)) { 76 switch (strtolower($subDomain)) {
77 case 'www': // 主站 77 case 'www': // 主站
@@ -2,11 +2,10 @@ @@ -2,11 +2,10 @@
2 2
3 namespace Product; 3 namespace Product;
4 4
5 -use Plugin\Helpers; 5 +use Api\Yohobuy;
6 use Plugin\HelperSearch; 6 use Plugin\HelperSearch;
7 use LibModels\Web\Product\BrandData; 7 use LibModels\Web\Product\BrandData;
8 -use LibModels\Wap\Product\SearchData;  
9 -use LibModels\Web\Product\SearchData as WebProduct; 8 +use Product\SearchModel;
10 9
11 /** 10 /**
12 * 品牌首页模板数据模型 11 * 品牌首页模板数据模型
@@ -15,114 +14,31 @@ use LibModels\Web\Product\SearchData as WebProduct; @@ -15,114 +14,31 @@ use LibModels\Web\Product\SearchData as WebProduct;
15 */ 14 */
16 class BrandsModel 15 class BrandsModel
17 { 16 {
18 -  
19 - const URL_BRAND_INDEX = '/product/index/brand';  
20 -  
21 - public static $shopName;  
22 - public static $home;  
23 -  
24 /** 17 /**
25 * 搜索品牌数据 18 * 搜索品牌数据
26 - *  
27 - * @param $condition array  
28 - * 搜索数据的条件 19 + * @param $condition array 搜索数据的条件
29 * @param $options array 20 * @param $options array
30 * @return array 21 * @return array
31 */ 22 */
32 - public static function getBrandSearchData($condition, $options, $domain, $uid, $brandId,$node) 23 + public static function getBrandSearchData($condition, $options)
33 { 24 {
34 - // 调用商品搜索接口  
35 - $data = SearchData::searchElasticByCondition($condition); 25 + // 并行调用品牌相关接口并封装数据
  26 + $data = self::getBrandData($condition, $options);
36 27
37 - //获取品牌banner数据  
38 - $banner = self::getBannerByDomain($domain, $brandId, $uid = '');  
39 - $brandName = self::$shopName;  
40 - $options['brandName'] = $brandName;  
41 -  
42 - if (isset($data['code']) && $data['code'] === 200) {  
43 - //获取分类列表数据  
44 - $param = array();  
45 - $param['brand'] = $condition['brand'];  
46 - $classes = WebProduct::getClassesData($param);  
47 - if (isset($classes['code']) && $classes['code'] === 200) {  
48 - $data['data']['filter']['group_sort'] = $classes['data']['sort'];  
49 - }  
50 -  
51 - //用户浏览记录  
52 -  
53 -  
54 - // 组织模板数据  
55 - $list = HelperSearch::getList($data, $options);  
56 -  
57 - //合并商品搜索数据与品牌banner数据  
58 - $list = array_merge_recursive($list,$banner);  
59 -  
60 - $data = array(  
61 - //初始化js  
62 - 'productListPage' => true,  
63 - 'list' => $list  
64 - );  
65 - } else {  
66 - $data = array();  
67 - }  
68 -  
69 //获取品牌系列数据 28 //获取品牌系列数据
70 - $adNav = self::getAdNav($condition['brand']);  
71 - $data['list']['leftContent'][] = array('picLink' => $adNav); 29 + $adNav = self::getAdNav($options['brandId']);
  30 + $data['leftContent'][] = array('picLink' => $adNav);
72 31
73 - //获取静态内容(20141219-100447)  
74 - if($node){  
75 - $nodeContent = HelperSearch::formatNodeContent($node);  
76 - $data['list']['leftContent'][]['picLink']['list'] = $nodeContent; 32 + //获取静态内容(eg:20141219-100447)
  33 + if($options['node']){
  34 + $nodeContent = HelperSearch::formatNodeContent($options['node']);
  35 + $data['leftContent'][]['picLink']['list'] = $nodeContent;
77 } 36 }
78 37
79 return $data; 38 return $data;
80 } 39 }
81 40
82 41
83 - /**  
84 - * 获取品牌首页banner条  
85 - * @string $domain 品牌域名  
86 - * @int $brandId 品牌id  
87 - * @int $uid 用户id  
88 - *  
89 - * @return array 品牌banner条数据  
90 - */  
91 - public static function getBannerByDomain($domain, $brandId, $uid = '')  
92 - {  
93 - // 构造品牌主页url  
94 - self::$home = Helpers::url('', '', $domain) . self::URL_BRAND_INDEX;  
95 - // 根据品牌Id获取品牌banner图  
96 - $bannerImg = BrandData::getBrandBanner($brandId);  
97 - if (isset($bannerImg['data'])) {  
98 - $bannerImg = Helpers::getImageUrl($bannerImg['data']['banner'], '', 150);  
99 - }  
100 - // 根据品牌Id获取品牌(简介)、收藏  
101 - $intro = BrandData::getBrandIntro($brandId, $uid);  
102 -  
103 - $is_favorite = false;  
104 - $shopName = false;  
105 - if(isset($intro['data'])){  
106 - // 获取是否收藏  
107 - if ($intro['data']['is_favorite'] == 'Y') {  
108 - $is_favorite = true;  
109 - } elseif ($intro['data']['is_favorite'] == 'N') {  
110 - $is_favorite = false;  
111 - }  
112 - // 获取品牌名  
113 - self::$shopName = $intro['data']['brand_name'];  
114 - }  
115 -  
116 - // 返回banner数据  
117 - return array(  
118 - 'brandBanner' => array(  
119 - 'bannerHeight' => '150',  
120 - 'coled' => $is_favorite,  
121 - 'banner' => $bannerImg  
122 - )  
123 - );  
124 - }  
125 -  
126 //获取品牌系列数据 42 //获取品牌系列数据
127 public static function getAdNav($brandId, $status = 1) 43 public static function getAdNav($brandId, $status = 1)
128 { 44 {
@@ -131,13 +47,50 @@ class BrandsModel @@ -131,13 +47,50 @@ class BrandsModel
131 $result = array(); 47 $result = array();
132 if (isset($advNav['data']) && $advNav['code'] === 200) { 48 if (isset($advNav['data']) && $advNav['code'] === 200) {
133 foreach ($advNav['data'] as $key => $value) { 49 foreach ($advNav['data'] as $key => $value) {
134 - $result['list'][$key]['href'] = self::$home . '?folder_id=' . $value['id']; 50 + $result['list'][$key]['href'] = '?folder_id=' . $value['id'];
135 $result['list'][$key]['src'] = $value['brand_sort_ico']; 51 $result['list'][$key]['src'] = $value['brand_sort_ico'];
136 } 52 }
  53 + $result['picTitle'] = '经典系列';
137 } 54 }
138 - $result['picTitle'] = '经典系列';  
139 55
140 return $result; 56 return $result;
141 } 57 }
142 58
  59 + /**
  60 + * 根据条件获取搜索数据
  61 + * @param array $customCondition
  62 + * @param array $customOptions
  63 + * @return array
  64 + */
  65 + public static function getBrandData($customCondition = array(), $customOptions = array())
  66 + {
  67 + $urlList = array();
  68 +
  69 + //获取$condition和$option 筛选条件和排序条件
  70 + $searchCondition = SearchModel::searchCondition($customCondition, $customOptions);
  71 +
  72 + // 组合搜索商品url
  73 + $urlList['product'] = HelperSearch::getProductUrl($searchCondition['condition']);
  74 +
  75 + // 组合搜索分类url
  76 + $urlList['sort'] = HelperSearch::getClassesUrl($searchCondition['condition']);
  77 +
  78 + //组合搜索品牌url
  79 + $urlList['brand'] = HelperSearch::getBrandUrl($customOptions);
  80 +
  81 + //组合获取品牌banner url
  82 + $urlList['banner'] = HelperSearch::getBannerUrl($customOptions);
  83 +
  84 + //组合用户浏览记录url
  85 + //$urlList['reviewUrl'] = HelperSearch::getReviewUrl($searchCondition['condition']);
  86 +
  87 + //批量调接口
  88 + $result = Yohobuy::getMulti($urlList, array(), true);
  89 +
  90 + //组织模板数据格式
  91 + $data = HelperSearch::getList($result, $searchCondition['options']);
  92 +
  93 +
  94 + return $data;
  95 + }
143 } 96 }
@@ -24,7 +24,7 @@ class SearchModel @@ -24,7 +24,7 @@ class SearchModel
24 * @param $option 24 * @param $option
25 * @return mixed 25 * @return mixed
26 */ 26 */
27 - public static function SearchCondition($param, $option) 27 + public static function searchCondition($param = array(), $option = array())
28 { 28 {
29 /* 过滤请求参数 */ 29 /* 过滤请求参数 */
30 $condition = filter_input_array(INPUT_GET, array( 30 $condition = filter_input_array(INPUT_GET, array(
@@ -119,6 +119,7 @@ class SearchModel @@ -119,6 +119,7 @@ class SearchModel
119 $options = array_merge($options, $option); 119 $options = array_merge($options, $option);
120 $data['condition'] = $condition; 120 $data['condition'] = $condition;
121 $data['options'] = $options; 121 $data['options'] = $options;
  122 +
122 return $data; 123 return $data;
123 } 124 }
124 125
1 <?php 1 <?php
2 use Action\WebAction; 2 use Action\WebAction;
3 use LibModels\Web\Product\BrandData; 3 use LibModels\Web\Product\BrandData;
4 -use Product\SearchModel;  
5 4
6 class IndexController extends WebAction 5 class IndexController extends WebAction
7 { 6 {
8 -  
9 /** 7 /**
10 * 品牌首页 8 * 品牌首页
11 */ 9 */
@@ -26,18 +24,26 @@ class IndexController extends WebAction @@ -26,18 +24,26 @@ class IndexController extends WebAction
26 $this->go(SITE_MAIN); 24 $this->go(SITE_MAIN);
27 } 25 }
28 26
29 - //品牌ID参数 27 + //品牌ID参数
30 $condition = array(); 28 $condition = array();
31 $condition['brand'] = $brandId; 29 $condition['brand'] = $brandId;
32 30
33 - /* 过滤请求参数 */  
34 - SearchModel::SearchCondition($condition); 31 + //$options参数数组
  32 + $options = array();
  33 + $options['brandName'] = $domain;
  34 + $options['uid'] = $uid;
  35 + $options['brandId'] = $brandId;
  36 + $options['node'] = $node;
35 37
  38 + //调用模型获得数据
  39 + $data = Product\BrandsModel::getBrandSearchData($condition, $options);
  40 + $data = array(
  41 + //初始化js
  42 + 'searchListPage' => true,
  43 + 'list' => $data
  44 + );
36 45
37 -  
38 - $data = Product\BrandsModel::getBrandSearchData($params,$options,$domain,$uid,$brandId,$node);  
39 - $cate = array('boys','girls','kids','lifestyle');  
40 - $this->setWebNavHeader($cate[$gender-1]); 46 + $this->setWebNavHeader();
41 //渲染模板 47 //渲染模板
42 $this->_view->display('list',$data); 48 $this->_view->display('list',$data);
43 } 49 }