Authored by hf

do modify search action to check is brand or category

@@ -164,6 +164,19 @@ class AbstractAction extends Controller_Abstract @@ -164,6 +164,19 @@ class AbstractAction extends Controller_Abstract
164 } 164 }
165 165
166 /** 166 /**
  167 + * 跳转到指定的URL
  168 + *
  169 + * @param string $url 链接地址
  170 + * @return void
  171 + */
  172 + protected function go($url)
  173 + {
  174 + headers_sent() || header('Location: ' . $url);
  175 +
  176 + exit();
  177 + }
  178 +
  179 + /**
167 * 设置Cookie 180 * 设置Cookie
168 * 181 *
169 * @param string $name cookie的名字 182 * @param string $name cookie的名字
@@ -259,26 +272,6 @@ class AbstractAction extends Controller_Abstract @@ -259,26 +272,6 @@ class AbstractAction extends Controller_Abstract
259 return $udid; 272 return $udid;
260 } 273 }
261 274
262 - /**  
263 - * 获取当前登录的用户名字  
264 - *  
265 - * @return int  
266 - * @todo  
267 - */  
268 - protected function getUname()  
269 - {  
270 - if (!$this->_uname) {  
271 - $cookie = $this->getCookie('_UID');  
272 - if (!empty($cookie)) {  
273 - $cookieList = explode('::', $cookie);  
274 - if (isset($cookieList[0])) {  
275 - $this->_uname = $cookieList[0];  
276 - }  
277 - }  
278 - }  
279 - return $this->_uname;  
280 - }  
281 -  
282 /* 275 /*
283 * 设置网站SEO的标题 276 * 设置网站SEO的标题
284 * 277 *
@@ -71,7 +71,7 @@ class Yohobuy @@ -71,7 +71,7 @@ class Yohobuy
71 'os_version' => 'yohobuy:h5', 71 'os_version' => 'yohobuy:h5',
72 'private_key' => self::$privateKeyList[$clientType], 72 'private_key' => self::$privateKeyList[$clientType],
73 'screen_size' => '720x1280', 73 'screen_size' => '720x1280',
74 - 'v' => '6', 74 + 'v' => '7',
75 ); 75 );
76 return $param; 76 return $param;
77 } 77 }
@@ -9,8 +9,8 @@ class CacheConfig @@ -9,8 +9,8 @@ class CacheConfig
9 { 9 {
10 /* 公共的数据缓存 */ 10 /* 公共的数据缓存 */
11 const KEY_COMMON_SIDE_NAV = 'key_common_side_nav'; // 公共的侧边栏 11 const KEY_COMMON_SIDE_NAV = 'key_common_side_nav'; // 公共的侧边栏
12 -  
13 - const KEY_CATEGORY_CLASSES_DATA = 'key_category_classes_data'; // 品类数据 12 + const KEY_COMMON_CATEGORY_CLASSES = 'key_common_category_classes'; // 公共的品类数据
  13 + const KEY_COMMON_CATEGORY_CLASSES_NAMES = 'key_common_category_classes_names'; // 公共的品类名称列表
14 14
15 /* 控制器方法中的数据缓存 */ 15 /* 控制器方法中的数据缓存 */
16 const KEY_ACTION_INDEX_INDEX = 'key_action_index_index'; // 频道选择 16 const KEY_ACTION_INDEX_INDEX = 'key_action_index_index'; // 频道选择
@@ -33,6 +33,7 @@ class CacheConfig @@ -33,6 +33,7 @@ class CacheConfig
33 33
34 const KEY_ACTION_PRODUCT_INDEX = 'key_action_product_index'; // 品类商品列表 34 const KEY_ACTION_PRODUCT_INDEX = 'key_action_product_index'; // 品类商品列表
35 const KEY_ACTION_PRODUCT_BRAND = 'key_action_product_brand'; // 品类商品列表 35 const KEY_ACTION_PRODUCT_BRAND = 'key_action_product_brand'; // 品类商品列表
36 - const KEY_ACTION_PRODUCT_BRAND_DOMAINS = 'key_action_product_brand_DOMAINS'; // 所有品牌域名列表 36 + const KEY_ACTION_PRODUCT_BRAND_DOMAINS = 'key_action_product_brand_domains'; // 所有品牌域名列表
  37 + const KEY_ACTION_PRODUCT_BRAND_NAMES = 'key_action_product_brand_names'; // 所有品牌名称列表
37 38
38 } 39 }
  1 +<?php
  2 +
  3 +namespace LibModels\Wap\Product;
  4 +
  5 +use Api\Yohobuy;
  6 +use Api\Sign;
  7 +
  8 +/**
  9 + * 商品品牌相关的数据模型
  10 + *
  11 + * @name BrandData
  12 + * @package
  13 + * @copyright yoho.inc
  14 + * @version 1.0 (2015-10-28 11:12:35)
  15 + * @author fei.hong <fei.hong@yoho.cn>
  16 + */
  17 +class BrandData
  18 +{
  19 +
  20 + /**
  21 + * 收藏
  22 + *
  23 + * @param int $id 品牌ID
  24 + * @param int $uid 用户ID
  25 + * @return array
  26 + */
  27 + public static function favorite($id, $uid)
  28 + {
  29 + $param = Yohobuy::param();
  30 + $param['method'] = 'app.favorite.add';
  31 + $param['id'] = $id;
  32 + $param['uid'] = $uid;
  33 + $param['type'] = 'brand';
  34 + $param['client_secret'] = Sign::getSign($param);
  35 +
  36 + return Yohobuy::post(Yohobuy::API_URL, $param, true);
  37 + }
  38 +
  39 + /**
  40 + * 取消收藏
  41 + *
  42 + * @param int $id 品牌ID
  43 + * @param int $uid 用户ID
  44 + * @return array
  45 + */
  46 + public static function favoriteCancel($id, $uid)
  47 + {
  48 + $param = Yohobuy::param();
  49 + $param['method'] = 'app.favorite.cancel';
  50 + $param['fav_id'] = $id;
  51 + $param['uid'] = $uid;
  52 + $param['type'] = 'brand';
  53 + $param['client_secret'] = Sign::getSign($param);
  54 +
  55 + return Yohobuy::post(Yohobuy::API_URL, $param, true);
  56 + }
  57 +
  58 +}
1 <?php 1 <?php
  2 +
2 namespace LibModels\Wap\Product; 3 namespace LibModels\Wap\Product;
3 4
4 use Api\Yohobuy; 5 use Api\Yohobuy;
@@ -16,67 +17,102 @@ use Api\Sign; @@ -16,67 +17,102 @@ use Api\Sign;
16 class SearchData 17 class SearchData
17 { 18 {
18 19
19 - /**  
20 - * 模糊搜索提供的关键词  
21 - *  
22 - * @param string $keyword 关键词  
23 - * @return array 根据跟定关键词搜索到的结果,包括数据数目count和提供的关键词keyword  
24 - */  
25 - public static function searchFuzzyDatas($keyword)  
26 - {  
27 - // 构建必传参数  
28 - $param = Yohobuy::param(); 20 + /**
  21 + * 模糊搜索提供的关键词
  22 + *
  23 + * @param string $keyword 关键词
  24 + * @return array 根据跟定关键词搜索到的结果,包括数据数目count和提供的关键词keyword
  25 + */
  26 + public static function searchFuzzyDatas($keyword)
  27 + {
  28 + // 构建必传参数
  29 + $param = Yohobuy::param();
29 30
30 - $param['keyword'] = $keyword;  
31 - $param['method'] = 'app.search.fuzzy'; 31 + $param['keyword'] = $keyword;
  32 + $param['method'] = 'app.search.fuzzy';
32 $param['client_secret'] = Sign::getSign($param); 33 $param['client_secret'] = Sign::getSign($param);
33 - 34 +
34 return Yohobuy::get(Yohobuy::API_URL, $param); 35 return Yohobuy::get(Yohobuy::API_URL, $param);
35 - } 36 + }
36 37
37 - /**  
38 - * 根据跟定查询数据搜索数据列表  
39 - *  
40 - * @param string $query 查询条件, 默认为null  
41 - * @param string $brand 品牌,默认为null  
42 - * @param string $gender 性别,默认为null,"1,3"表示男, "2,3"表示女, "1,2,3"表示全部  
43 - * @param integer $color 颜色id  
44 - * @param integer $size 尺码id  
45 - * @param integer $price 价格  
46 - * @param string $p_d 折扣,默认为null  
47 - * @param string $sort 商品所属品类,默认为null  
48 - * @param string $order 排序方式,默认为按照时间倒序排列s_t_desc,  
49 - * s_t_asc表示按时间正序排列,  
50 - * s_p_asc表示按价格正序排列,  
51 - * s_p_desc表示按价格倒序排列,  
52 - * p_d_asc表示按折扣正序排列,  
53 - * p_d_desc表示按折扣倒序排列  
54 - * @param integer $page 指定查询是多少页,默认为第一页  
55 - * @param integer $limit 指定查询多少个,默认是60个  
56 - * @param integer $channel表示哪个频道,1表示男生,2表示女生,3表示潮童,4表示创意生活  
57 - * @return array 搜索到的数据  
58 - */  
59 - 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)  
60 - {  
61 - // 构建必传参数  
62 - $param = Yohobuy::param(); 38 + /**
  39 + * 根据跟定查询数据搜索数据列表
  40 + *
  41 + * @param string $query 查询条件, 默认为null
  42 + * @param string $brand 品牌,默认为null
  43 + * @param string $gender 性别,默认为null,"1,3"表示男, "2,3"表示女, "1,2,3"表示全部
  44 + * @param integer $color 颜色id
  45 + * @param integer $size 尺码id
  46 + * @param integer $price 价格
  47 + * @param string $p_d 折扣,默认为null
  48 + * @param string $sort 商品所属品类,默认为null
  49 + * @param string $order 排序方式,默认为按照时间倒序排列s_t_desc,
  50 + * s_t_asc表示按时间正序排列,
  51 + * s_p_asc表示按价格正序排列,
  52 + * s_p_desc表示按价格倒序排列,
  53 + * p_d_asc表示按折扣正序排列,
  54 + * p_d_desc表示按折扣倒序排列
  55 + * @param integer $page 指定查询是多少页,默认为第一页
  56 + * @param integer $limit 指定查询多少个,默认是60个
  57 + * @param integer $channel表示哪个频道,1表示男生,2表示女生,3表示潮童,4表示创意生活
  58 + * @return array 搜索到的数据
  59 + */
  60 + 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)
  61 + {
  62 + // 构建必传参数
  63 + $param = Yohobuy::param();
63 64
64 - is_null($query) || $param['query'] = $query;  
65 - is_null($brand) || $param['brand'] = $brand;  
66 - is_null($gender) || $param['gender'] = $gender;  
67 - is_null($color) || $param['color'] = $color;  
68 - is_null($size) || $param['size'] = $size;  
69 - is_null($price) || $param['price'] = $price;  
70 - is_null($p_d) || $param['p_d'] = $p_d;  
71 - is_null($sort) || $param['sort'] = $sort;  
72 - is_null($channel) || $param['channel'] = $channel;  
73 - $param['method'] = 'app.search.li';  
74 - $param['order'] = $order;  
75 - $param['page'] = $page;  
76 - $param['limit'] = $limit; 65 + is_null($query) || $param['query'] = $query;
  66 + is_null($brand) || $param['brand'] = $brand;
  67 + is_null($gender) || $param['gender'] = $gender;
  68 + is_null($color) || $param['color'] = $color;
  69 + is_null($size) || $param['size'] = $size;
  70 + is_null($price) || $param['price'] = $price;
  71 + is_null($p_d) || $param['p_d'] = $p_d;
  72 + is_null($sort) || $param['sort'] = $sort;
  73 + is_null($channel) || $param['channel'] = $channel;
  74 + $param['method'] = 'app.search.li';
  75 + $param['order'] = $order;
  76 + $param['page'] = $page;
  77 + $param['limit'] = $limit;
77 $param['client_secret'] = Sign::getSign($param); 78 $param['client_secret'] = Sign::getSign($param);
78 - 79 +
79 return Yohobuy::get(Yohobuy::API_URL, $param); 80 return Yohobuy::get(Yohobuy::API_URL, $param);
80 - } 81 + }
81 82
  83 + /**
  84 + * 根据跟定查询数据搜索数据列表
  85 + *
  86 + * @param string $query 查询条件, 默认为null
  87 + * @param string $brand 品牌,默认为null
  88 + * @param string $gender 性别,默认为null,"1,3"表示男, "2,3"表示女, "1,2,3"表示全部
  89 + * @param integer $color 颜色id
  90 + * @param integer $size 尺码id
  91 + * @param integer $price 价格
  92 + * @param string $p_d 折扣,默认为null
  93 + * @param string $sort 商品所属品类,默认为null
  94 + * @param string $order 排序方式,默认为按照时间倒序排列s_t_desc,
  95 + * s_t_asc表示按时间正序排列,
  96 + * s_p_asc表示按价格正序排列,
  97 + * s_p_desc表示按价格倒序排列,
  98 + * p_d_asc表示按折扣正序排列,
  99 + * p_d_desc表示按折扣倒序排列
  100 + * @param integer $page 指定查询是多少页,默认为第一页
  101 + * @param integer $limit 指定查询多少个,默认是60个
  102 + * @param integer $channel表示哪个频道,1表示男生,2表示女生,3表示潮童,4表示创意生活
  103 + * @return array 搜索到的数据
  104 + */
  105 + public static function searchByCondition($condition, $order = 's_t_desc', $page = 1, $limit = 60)
  106 + {
  107 + $param = Yohobuy::param();
  108 + $param['method'] = 'app.search.li';
  109 + $param['order'] = $order;
  110 + $param['page'] = $page;
  111 + $param['limit'] = $limit;
  112 + $param += $condition;
  113 + $param['client_secret'] = Sign::getSign($param);
  114 +
  115 + return Yohobuy::get(Yohobuy::API_URL, $param, 600); // 有缓存10分钟
  116 + }
  117 +
82 } 118 }
@@ -32,8 +32,15 @@ class Helpers @@ -32,8 +32,15 @@ class Helpers
32 case 'search': // 搜索 32 case 'search': // 搜索
33 $url = 'http://search' . SUB_DOMAIN; 33 $url = 'http://search' . SUB_DOMAIN;
34 break; 34 break;
  35 + case 'index': // 默认
  36 + $url = '';
  37 + break;
  38 + default:
  39 + $url = 'http://' . $module . SUB_DOMAIN;
  40 + }
  41 + if (!empty($param)) {
  42 + $url .= $uri . '?' . http_build_query($param, null, '&');
35 } 43 }
36 - $url .= $uri . '?' . http_build_query($param, null, '&');  
37 44
38 return $url; 45 return $url;
39 } 46 }
@@ -33,45 +33,6 @@ http { @@ -33,45 +33,6 @@ http {
33 autoindex_exact_size on; 33 autoindex_exact_size on;
34 autoindex_localtime on; 34 autoindex_localtime on;
35 35
36 - server {  
37 - listen 80;  
38 - server_name localhost;  
39 -  
40 - #charset koi8-r;  
41 -  
42 - #access_log logs/host.access.log main;  
43 -  
44 - location / {  
45 - root /cygdrive/E/nginx/html;  
46 - index index.html index.htm;  
47 - }  
48 -  
49 - #error_page 404 /404.html;  
50 -  
51 - # redirect server error pages to the static page /50x.html  
52 - #  
53 - error_page 500 502 503 504 /50x.html;  
54 - location = /50x.html {  
55 - root html;  
56 - }  
57 -  
58 - # proxy the PHP scripts to Apache listening on 127.0.0.1:80  
59 - #  
60 - #location ~ \.php$ {  
61 - # proxy_pass http://127.0.0.1;  
62 - #}  
63 -  
64 - # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000  
65 - #  
66 - # deny access to .htaccess files, if Apache's document root  
67 - # concurs with nginx's one  
68 - #  
69 - #location ~ /\.ht {  
70 - # deny all;  
71 - #}  
72 - }  
73 -  
74 -  
75 # another virtual host using mix of IP-, name-, and port-based configuration 36 # another virtual host using mix of IP-, name-, and port-based configuration
76 # 37 #
77 #server { 38 #server {
@@ -108,7 +69,7 @@ http { @@ -108,7 +69,7 @@ http {
108 # } 69 # }
109 #} 70 #}
110 71
111 - # Զļ 72 + # �����Զ���������ļ�
112 #include /nginx/conf/vhosts/yohoboys.conf; 73 #include /nginx/conf/vhosts/yohoboys.conf;
113 #include /nginx/conf/vhosts/yohogirls.conf; 74 #include /nginx/conf/vhosts/yohogirls.conf;
114 #include /nginx/conf/vhosts/yohostore.conf; 75 #include /nginx/conf/vhosts/yohostore.conf;
@@ -4,6 +4,7 @@ @@ -4,6 +4,7 @@
4 CustomLog "/Data/logs/apache/access.buy.test.yoho.cn.log" combined 4 CustomLog "/Data/logs/apache/access.buy.test.yoho.cn.log" combined
5 ErrorLog "/Data/logs/apache/error.buy.test.yoho.cn.log" 5 ErrorLog "/Data/logs/apache/error.buy.test.yoho.cn.log"
6 ServerName buy.test.yoho.cn 6 ServerName buy.test.yoho.cn
  7 + ServerAlias *.test.yoho.cn
7 DocumentRoot "/Data/code/git/yohobuy/yohobuy/m.yohobuy.com/public" 8 DocumentRoot "/Data/code/git/yohobuy/yohobuy/m.yohobuy.com/public"
8 RewriteEngine on 9 RewriteEngine on
9 RewriteCond %{REQUEST_FILENAME} !-f 10 RewriteCond %{REQUEST_FILENAME} !-f
1 server 1 server
2 { 2 {
3 listen 80; 3 listen 80;
4 - server_name buy.test.yoho.cn; 4 + server_name buy.test.yoho.cn *.test.yoho.cn;
5 5
6 #access_log /Data/logs/access.buy.test.yoho.cn.log combined; 6 #access_log /Data/logs/access.buy.test.yoho.cn.log combined;
7 error_log /Data/logs/error.buy.test.yoho.cn.log warn; 7 error_log /Data/logs/error.buy.test.yoho.cn.log warn;
@@ -54,7 +54,7 @@ var $listNav = $('#list-nav'), @@ -54,7 +54,7 @@ var $listNav = $('#list-nav'),
54 end: false 54 end: false
55 } 55 }
56 }, 56 },
57 - $pre, //纪录进入筛选前的active 57 + $pre = $listNav.find('.active'), //纪录进入筛选前的active项,初始为选中
58 searching; 58 searching;
59 59
60 /** 60 /**
@@ -157,7 +157,7 @@ function search(opt) { @@ -157,7 +157,7 @@ function search(opt) {
157 157
158 $.ajax({ 158 $.ajax({
159 type: 'GET', 159 type: 'GET',
160 - url: '/product/list/search', 160 + url: '/index/search/search',
161 data: setting, 161 data: setting,
162 success: function(data) { 162 success: function(data) {
163 var noResult = '<p class="no-result">未找到相关搜索结果</p>', 163 var noResult = '<p class="no-result">未找到相关搜索结果</p>',
@@ -3,7 +3,7 @@ @@ -3,7 +3,7 @@
3 {{# goodList}} 3 {{# goodList}}
4 {{# search}} 4 {{# search}}
5 <div id="search-input" class="search-input"> 5 <div id="search-input" class="search-input">
6 - <form action="/product/list/index" method="get"> 6 + <form action={{url}} method="get">
7 <i class="search-icon iconfont">&#xe60f;</i> 7 <i class="search-icon iconfont">&#xe60f;</i>
8 <input type="text" value={{default}} name="query"> 8 <input type="text" value={{default}} name="query">
9 <i class="clear-input iconfont hide">&#xe61a;</i> 9 <i class="clear-input iconfont hide">&#xe61a;</i>
@@ -3,7 +3,7 @@ @@ -3,7 +3,7 @@
3 {{# goodList}} 3 {{# goodList}}
4 {{# search}} 4 {{# search}}
5 <div id="search-input" class="search-input"> 5 <div id="search-input" class="search-input">
6 - <form action="/product/list/index" method="get"> 6 + <form action={{url}} method="get">
7 <i class="search-icon iconfont">&#xe60f;</i> 7 <i class="search-icon iconfont">&#xe60f;</i>
8 <input type="text" value={{default}} name="query"> 8 <input type="text" value={{default}} name="query">
9 <i class="clear-input iconfont hide">&#xe61a;</i> 9 <i class="clear-input iconfont hide">&#xe61a;</i>
@@ -2,11 +2,15 @@ @@ -2,11 +2,15 @@
2 2
3 use Action\AbstractAction; 3 use Action\AbstractAction;
4 use LibModels\Wap\Product\SearchData; 4 use LibModels\Wap\Product\SearchData;
  5 +use Plugin\DataProcess\ListProcess;
  6 +use Plugin\Helpers;
  7 +
5 /** 8 /**
6 * 搜索页 9 * 搜索页
7 */ 10 */
8 class SearchController extends AbstractAction 11 class SearchController extends AbstractAction
9 { 12 {
  13 +
10 /** 14 /**
11 * 搜索首页 15 * 搜索首页
12 */ 16 */
@@ -45,107 +49,173 @@ class SearchController extends AbstractAction @@ -45,107 +49,173 @@ class SearchController extends AbstractAction
45 ) 49 )
46 ); 50 );
47 $this->_view->display('index', array( 51 $this->_view->display('index', array(
48 - 'search' => $data,  
49 - 'searchPage' => true, 52 + 'search' => $data,
  53 + 'searchPage' => true,
50 'pageFooter' => true 54 'pageFooter' => true
51 )); 55 ));
52 } 56 }
53 - 57 +
54 /** 58 /**
55 * 搜索列表页 59 * 搜索列表页
56 */ 60 */
57 public function listAction() 61 public function listAction()
58 { 62 {
59 - $query = $this->get('query', null);  
60 - $brand = $this->get('brand', null);  
61 - $gender = $this->getCookie('_Channel', 'boys');  
62 - $p_d = $this->get('p_d', null);  
63 - $misort = $this->get('misort', null);  
64 - $msort = $this->get('msort', null);  
65 -  
66 - $data = array(  
67 - 'pageHeader' => array(  
68 - 'navBack' => true,  
69 - 'navTitle' => '搜索',  
70 - 'navHome' => '/'  
71 - ),  
72 - 'goodListPage' => true,  
73 - 'goodList' => array(  
74 - 'brand' => 0,  
75 - 'msort' => 0,  
76 - 'gender' => $gender,  
77 - 'price' => 0,  
78 - 'size' => 0,  
79 - 'discount' => ''  
80 - )  
81 - );  
82 -  
83 - // 首先查询是否属于内置品类  
84 - $classes = ClassModel::getClassesArr();  
85 - $classFlag = array_search($query, $classes);  
86 - if($classFlag !== false)// 属于内部品类  
87 - {  
88 - $data['pageHeader']['navTitle'] = '所有'.$query; 63 + // 过滤请求参数
  64 + $condition = filter_input_array(INPUT_GET, array(
  65 + 'query' => FILTER_DEFAULT,
  66 + 'brand' => FILTER_VALIDATE_INT,
  67 + 'sort' => FILTER_DEFAULT,
  68 + 'msort' => FILTER_VALIDATE_INT,
  69 + 'misort' => FILTER_VALIDATE_INT,
  70 + 'color' => FILTER_VALIDATE_INT,
  71 + 'size' => FILTER_VALIDATE_INT,
  72 + 'price' => FILTER_VALIDATE_INT,
  73 + 'discount' => FILTER_VALIDATE_INT,
  74 + 'gender' => FILTER_DEFAULT,
  75 + 'p_d' => FILTER_DEFAULT,), false);
  76 +
  77 + $query = isset($condition['query']) ? strtolower(trim($condition['query'])) : null;
  78 +
  79 + // 标识用户是否有输入搜索内容
  80 + $haveQuery = $query !== null;
  81 + // 标识用户搜的是不是一级品类
  82 + $isQueryFirstClass = false;
  83 + // 标识用户搜的是不是二级品类
  84 + $isQuerySecondClass = false;
  85 +
  86 + /* 判断是不是品牌, 是品牌跳到品牌列表页(显示搜索框) */
  87 + if ($haveQuery) {
  88 + $domain = null;
  89 + $brandNames = Product\ListModel::getAllBrandNames();
  90 +
  91 + do {
  92 + /* 精确查品牌域名 */
  93 + if (isset($brandNames[$query])) {
  94 + $domain = $query;
  95 + break;
  96 + }
  97 +
  98 + /* 精确查品牌名称 */
  99 + $domains = array_keys($brandNames, $query, true);
  100 + if (isset($domains[0])) {
  101 + $domain = $domains[0];
  102 + break;
  103 + }
  104 +
  105 + /* 模糊查品牌域名 */
  106 + foreach ($brandNames as $key => $domains) {
  107 + if (strpos($key, $query) !== false) {
  108 + $domain = $key;
  109 + break;
  110 + }
  111 + }
  112 + } while (false);
  113 +
  114 + // 清空变量做释放
  115 + $brandNames = array();
  116 +
  117 + // 跳转到品牌商品列表页
  118 + if ($domain !== null) {
  119 + $url = Helpers::url('', array(
  120 + 'from' => 'search',
  121 + 'query' => $query,
  122 + 'gender' => $condition['gender']
  123 + ), $domain);
  124 + $this->go($url);
  125 + }
89 } 126 }
  127 +
  128 +
  129 + /* 判断是不是品类, 是品类加导航标题(不显示搜索框) */
  130 + if ($haveQuery) {
  131 + $classNames = Category\ClassModel::getClassNames();
90 132
91 - // 如果存在搜索字符串就显示搜索栏  
92 - if(!is_null($query) && $classFlag === false)  
93 - {  
94 - $data['search'] = array(  
95 - 'default' => $query  
96 - ); 133 + do {
  134 + /* 精确查一级品类 */
  135 + $sorts = array_keys($classNames['first'], $query, true);
  136 + if (isset($sorts[0])) {
  137 + $isQueryFirstClass = true;
  138 + break;
  139 + }
  140 +
  141 + /* 精确查二级品类 */
  142 + $sorts = array_keys($classNames['second'], $query, true);
  143 + if (isset($sorts[0])) {
  144 + $isQuerySecondClass = true;
  145 + break;
  146 + }
  147 + }
  148 + while (false);
  149 +
  150 + $classNames = array();
97 } 151 }
98 -  
99 - // 转换性别  
100 - $this->genderTrans($gender); 152 +
  153 + $data = array();
  154 + // 搜索是一级品类
  155 + if ($isQueryFirstClass) {
  156 + $this->setTitle('全部' . $query);
  157 + $this->setNavHeader('全部' . $query, true, SITE_MAIN);
  158 + }
  159 + // 搜索是二级品类
  160 + elseif ($isQuerySecondClass) {
  161 + $this->setTitle($query);
  162 + $this->setNavHeader($query, true, SITE_MAIN);
  163 + }
  164 + // 搜索其它内容
  165 + else {
  166 + if ($haveQuery) {
  167 + $data['goodList']['search']['default'] = $query;
  168 + $data['goodList']['search']['default'] = $query;
  169 + }
  170 + $this->setTitle('搜索');
  171 + $this->setNavHeader('搜索', true, SITE_MAIN);
  172 + }
  173 +
  174 + $data['goodListPage'] = true;
  175 + $data['goodList'] = $condition;
101 176
102 // 查询数据 177 // 查询数据
103 - $listData = SearchData::searchLiDatas($query, $brand, $gender, $p_d, $misort, $msort); 178 + $listData = SearchData::searchByCondition($condition);
104 // 处理返回的数据 179 // 处理返回的数据
105 - if (isset($listData['code']) && $listData['code'] === 200) {  
106 - $tmpData = $listData['data'];  
107 -  
108 - // 如果存在品牌信息就显示品牌字段  
109 - if(isset($tmpData['brand']) && !empty($tmpData['brand']))  
110 - {  
111 - $brandData = $tmpData['brand'];  
112 - $data['brandWay'] = array(  
113 - 'url' => '/product/list/brand?brand='.$brandData['id'],  
114 - 'thumb' => Helpers::getImageUrl($brandData['brand_ico'], 75, 40),  
115 - 'name' => $brandData['brand_name']  
116 - );  
117 -  
118 - // 设置品牌默认值  
119 - $data['goodList']['brand'] = $brandData['id'];  
120 - }  
121 -  
122 - $data['goodList'] += ListProcess::getListData($tmpData); 180 + if (!empty($listData['data']['brand'])) {
  181 + $brandData = $listData['data']['brand'];
  182 + $data['brandWay'] = array(
  183 + 'url' => 'http://'. $brandData['brand_domain'] . SUB_DOMAIN,
  184 + 'thumb' => Helpers::getImageUrl($brandData['brand_ico'], 75, 40),
  185 + 'name' => $brandData['brand_name']
  186 + );
  187 + // 设置品牌默认值
  188 + $data['goodList']['brand'] = $brandData['id'];
  189 + $data['goodList'] += ListProcess::getListData($listData['data']);
123 } 190 }
  191 + $listData = array();
124 192
125 $this->_view->display('list', $data); 193 $this->_view->display('list', $data);
126 } 194 }
127 -  
128 - /** 195 +
  196 + /**
129 * Ajax异步筛选请求 197 * Ajax异步筛选请求
130 */ 198 */
131 public function searchAction() 199 public function searchAction()
132 { 200 {
133 - if($this->isAjax())  
134 - {  
135 - $query = $this->get('query', null);  
136 - $brand = $this->get('brand', null);  
137 - $gender = $this->get('gender', null);  
138 - $color = $this->get('color', null);  
139 - $size = $this->get('size', null);  
140 - $price = $this->get('price', null);  
141 - $p_d = $this->get('discount', null);  
142 - $sort = $this->get('msort', null);  
143 -  
144 - // 转换性别  
145 - $this->genderTrans($gender); 201 + if ($this->isAjax()) {
  202 + // 过滤请求参数
  203 + $condition = filter_input_array(INPUT_GET, array(
  204 + 'query' => FILTER_DEFAULT,
  205 + 'brand' => FILTER_VALIDATE_INT,
  206 + 'sort' => FILTER_VALIDATE_INT,
  207 + 'msort' => FILTER_VALIDATE_INT,
  208 + 'misort' => FILTER_VALIDATE_INT,
  209 + 'color' => FILTER_VALIDATE_INT,
  210 + 'size' => FILTER_VALIDATE_INT,
  211 + 'price' => FILTER_VALIDATE_INT,
  212 + 'discount' => FILTER_DEFAULT,
  213 + 'gender' => FILTER_DEFAULT,
  214 + 'p_d' => FILTER_DEFAULT, ), false);
146 215
147 // 转换排序方式 216 // 转换排序方式
148 - $order = $this->get('order', null); 217 + $page = $this->get('page', 1);
  218 + $order = $this->get('order', 0);
149 $type = $this->get('type', ''); 219 $type = $this->get('type', '');
150 switch ($type) { 220 switch ($type) {
151 case 'price': 221 case 'price':
@@ -162,21 +232,19 @@ class SearchController extends AbstractAction @@ -162,21 +232,19 @@ class SearchController extends AbstractAction
162 232
163 $data = array(); 233 $data = array();
164 // 查询数据 234 // 查询数据
165 - $listData = SearchData::searchLiDatas($query, $brand, $gender, $color, $size, $price, $p_d, $sort, $order); 235 + $listData = SearchData::searchByCondition($condition, $order, $page);
166 // 处理返回的数据 236 // 处理返回的数据
167 - if (isset($listData['code']) && $listData['code'] === 200) {  
168 - $tmpData = $listData['data'];  
169 -  
170 - unset($tmpData['filter']);// 不要筛选条件的数据  
171 - $data = ListProcess::getListData($tmpData); 237 + if (isset($listData['data'])) {
  238 + if (isset($listData['data']['filter'])) {
  239 + unset($listData['data']['filter']);
  240 + }
  241 + $data = ListProcess::getListData($listData['data']);
172 } 242 }
  243 + $listData = array();
173 244
174 - if(empty($data))  
175 - { 245 + if (empty($data)) {
176 echo ' '; 246 echo ' ';
177 - }  
178 - else  
179 - { 247 + } else {
180 $this->_view->display('page', $data); 248 $this->_view->display('page', $data);
181 } 249 }
182 } 250 }
@@ -189,8 +257,7 @@ class SearchController extends AbstractAction @@ -189,8 +257,7 @@ class SearchController extends AbstractAction
189 */ 257 */
190 public function fuzzysearch() 258 public function fuzzysearch()
191 { 259 {
192 - if($this->isAjax())  
193 - { 260 + if ($this->isAjax()) {
194 $keyword = $this->post('keyword', ''); 261 $keyword = $this->post('keyword', '');
195 262
196 $result = SearchData::searchFuzzyDatas($keyword); 263 $result = SearchData::searchFuzzyDatas($keyword);
@@ -198,4 +265,5 @@ class SearchController extends AbstractAction @@ -198,4 +265,5 @@ class SearchController extends AbstractAction
198 $this->echoJson($result); 265 $this->echoJson($result);
199 } 266 }
200 } 267 }
201 -}  
  268 +
  269 +}
@@ -20,18 +20,18 @@ class ClassModel @@ -20,18 +20,18 @@ class ClassModel
20 { 20 {
21 21
22 /** 22 /**
23 - * 根据频道获取品牌一览数据 23 + * 根据频道获取品数据
24 * 24 *
25 - * @param int $channel 1表示男生频道, 2表示女生频道, 3表示潮童频道, 4表示创意生活频道  
26 * @return array 25 * @return array
27 */ 26 */
28 public static function getClassData() 27 public static function getClassData()
29 { 28 {
30 - $classes = array(); 29 + $result = array();
31 30
32 if (USE_CACHE) { 31 if (USE_CACHE) {
  32 + $key = CacheConfig::KEY_COMMON_CATEGORY_CLASSES;
33 // 先尝试获取一级缓存(master), 有数据则直接返回. 33 // 先尝试获取一级缓存(master), 有数据则直接返回.
34 - $result = Cache::get(CacheConfig::KEY_CATEGORY_CLASSES_DATA, 'master'); 34 + $result = Cache::get($key, 'master');
35 if (!empty($result)) { 35 if (!empty($result)) {
36 return $result; 36 return $result;
37 } 37 }
@@ -49,6 +49,8 @@ class ClassModel @@ -49,6 +49,8 @@ class ClassModel
49 break; 49 break;
50 } 50 }
51 51
  52 + $oneClass = array();
  53 + $item = array();
52 foreach ($data['data'] as $k => $v) { 54 foreach ($data['data'] as $k => $v) {
53 $oneClass = array('name' => $k, 'ca' => array()); 55 $oneClass = array('name' => $k, 'ca' => array());
54 if ($num === 1) { 56 if ($num === 1) {
@@ -64,9 +66,9 @@ class ClassModel @@ -64,9 +66,9 @@ class ClassModel
64 $subitem['name'] = $value['category_name']; 66 $subitem['name'] = $value['category_name'];
65 $subitem['id'] = $value['relation_parameter']['sort']; 67 $subitem['id'] = $value['relation_parameter']['sort'];
66 $subitem['url'] = Helpers::url('/', array( 68 $subitem['url'] = Helpers::url('/', array(
67 - 'sort' => $value['relation_parameter']['sort'],  
68 - 'sort_name' => $value['category_name']  
69 - ), 'list'); 69 + 'sort' => $value['relation_parameter']['sort'],
  70 + 'sort_name' => $value['category_name']
  71 + ), 'list');
70 72
71 $item['sub'][] = $subitem; 73 $item['sub'][] = $subitem;
72 } 74 }
@@ -75,80 +77,73 @@ class ClassModel @@ -75,80 +77,73 @@ class ClassModel
75 } 77 }
76 78
77 $num++; 79 $num++;
78 - $classes[] = $oneClass; 80 + $result[] = $oneClass;
79 } 81 }
80 82
81 if (USE_CACHE) { 83 if (USE_CACHE) {
82 // 接口调用异常时, 不害怕,从我们的二级缓存(slave)里再取数据. 84 // 接口调用异常时, 不害怕,从我们的二级缓存(slave)里再取数据.
83 - if (empty($classes)) {  
84 - $classes = Cache::get(CacheConfig::KEY_CATEGORY_CLASSES_DATA, 'slave'); 85 + if (empty($result)) {
  86 + $result = Cache::get($key, 'slave');
85 } 87 }
86 // 接口调用正常,数据封装完成, 则设置一级(master)和二级(slave)数据缓存 88 // 接口调用正常,数据封装完成, 则设置一级(master)和二级(slave)数据缓存
87 else { 89 else {
88 - Cache::set(CacheConfig::KEY_CATEGORY_CLASSES_DATA, $classes); 90 + Cache::set($key, $result);
89 } 91 }
90 } 92 }
91 } while (false); 93 } while (false);
92 94
93 - return $classes; 95 + return $result;
94 } 96 }
95 97
96 /** 98 /**
97 - * 返回品类构成的数组 99 + * 根据频道获取所有品类名称
98 * 100 *
99 - * @return array 键为品类查询sort参数,值为品类名称构成的数组 101 + * @return array(
  102 + * "first" => '一级品类',
  103 + * "second" => '二级品类',
  104 + * )
100 */ 105 */
101 - public static function getClassesArr() 106 + public static function getClassNames()
102 { 107 {
103 - $classes = array();  
104 - $classesData = self::getClassData(); 108 + $result = array('first' => array(), 'second' => array());
105 109
106 - foreach ($classesData as $val) {  
107 - foreach ($val['ca'] as $single) {  
108 - $classes[$single['id']] = $single['name'];  
109 - $classes += self::array_column($single['sub'], 'name', 'id'); 110 + if (USE_CACHE) {
  111 + $key = CacheConfig::KEY_COMMON_CATEGORY_CLASSES_NAMES;
  112 + // 先尝试获取一级缓存(master), 有数据则直接返回.
  113 + $result = Cache::get($key, 'master');
  114 + if (!empty($result)) {
  115 + return $result;
110 } 116 }
111 } 117 }
  118 +
  119 + $classes= ClassData::getClassesData();
  120 + if (!empty($classes['data'])) {
  121 + $id = 0;
  122 + foreach ($classes['data'] as $data) {
  123 + foreach ($data as $item) {
  124 + $id = $item['category_id'];
  125 + $result['first'][$id] = $item['category_name'];
  126 + foreach ($item['sub'] as $sub) {
  127 + $id = $sub['category_id'];
  128 + $result['second'][$id] = $sub['category_name'];
  129 + }
  130 + }
  131 + }
  132 + }
  133 + $classes = array();
112 134
113 - return $classes;  
114 - }  
115 -  
116 - /**  
117 - * 自定义array_column函数  
118 - *  
119 - * @return array 返回数组中指定的一列组成的数组  
120 - */  
121 -  
122 - /**  
123 - * 自定义array_column函数  
124 - * @param array $input 需要取出数组咧的多维数组  
125 - * @param string $columnKey 需要返回的列  
126 - * @param mixed $indexKey 作为返回数组的索引值  
127 - * @return array 从多维数组中返回单列数组  
128 - */  
129 - private static function array_column(array $input, $columnKey, $indexKey = null)  
130 - {  
131 - $array = array();  
132 - foreach ($input as $value) {  
133 - if (!isset($value[$columnKey])) {  
134 - trigger_error("Key \"$columnKey\" does not exist in array");  
135 - return false; 135 + if (USE_CACHE) {
  136 + // 接口调用异常时, 不害怕,从我们的二级缓存(slave)里再取数据.
  137 + if (empty($result)) {
  138 + $result = Cache::get($key, 'slave');
136 } 139 }
137 - if (is_null($indexKey)) {  
138 - $array[] = $value[$columnKey];  
139 - } else {  
140 - if (!isset($value[$indexKey])) {  
141 - trigger_error("Key \"$indexKey\" does not exist in array");  
142 - return false;  
143 - }  
144 - if (!is_scalar($value[$indexKey])) {  
145 - trigger_error("Key \"$indexKey\" does not contain scalar value");  
146 - return false;  
147 - }  
148 - $array[$value[$indexKey]] = $value[$columnKey]; 140 + // 接口调用正常,数据封装完成, 则设置一级(master)和二级(slave)数据缓存
  141 + else {
  142 + Cache::set($key, $result);
149 } 143 }
150 } 144 }
151 - return $array; 145 +
  146 + return $result;
152 } 147 }
153 148
154 } 149 }
@@ -44,7 +44,7 @@ class ListModel @@ -44,7 +44,7 @@ class ListModel
44 } 44 }
45 45
46 // 调用接口查询数据 46 // 调用接口查询数据
47 - $listData = ClassData::filterClassData($condition); 47 + $listData = ClassData::filterClassData($condition);
48 // 处理返回的数据 48 // 处理返回的数据
49 if (isset($listData['code']) && $listData['code'] === 200) { 49 if (isset($listData['code']) && $listData['code'] === 200) {
50 $result = ListProcess::getListData($listData['data']); 50 $result = ListProcess::getListData($listData['data']);
@@ -63,16 +63,19 @@ class ListModel @@ -63,16 +63,19 @@ class ListModel
63 63
64 return $result; 64 return $result;
65 } 65 }
66 - 66 +
67 /** 67 /**
68 - * 获取品牌商品列表数据 68 + * 获取品牌信息
69 * 69 *
  70 + * @param int $id 唯一的ID
  71 + * @param int $uid 用户ID
  72 + * @param string $title 网站标题
70 * @return array 73 * @return array
71 */ 74 */
72 - public static function getBrandData($condition, $id, $uid, &$title) 75 + public static function getBrandIntro($id, $uid, &$title)
73 { 76 {
74 $result = array(); 77 $result = array();
75 - 78 +
76 // 获取品牌介绍信息, 有缓存1小时 79 // 获取品牌介绍信息, 有缓存1小时
77 $introData = BrandData::getBrandIntro($id, $uid); 80 $introData = BrandData::getBrandIntro($id, $uid);
78 if (isset($introData['data']['brand_intro'])) { 81 if (isset($introData['data']['brand_intro'])) {
@@ -88,14 +91,28 @@ class ListModel @@ -88,14 +91,28 @@ class ListModel
88 $result['brandHome']['banner'] = Helpers::getImageUrl($bannerData['data']['banner'], 640, 75); 91 $result['brandHome']['banner'] = Helpers::getImageUrl($bannerData['data']['banner'], 640, 75);
89 } 92 }
90 93
  94 + return $result;
  95 + }
  96 +
  97 + /**
  98 + * 获取品牌商品列表数据
  99 + *
  100 + * @param array $condition 条件参数
  101 + * @param string $title 网站标题
  102 + * @return array
  103 + */
  104 + public static function getBrandData($condition, &$title)
  105 + {
  106 + $result = array();
  107 +
91 if (USE_CACHE) { 108 if (USE_CACHE) {
92 $key = CacheConfig::KEY_ACTION_PRODUCT_BRAND; 109 $key = CacheConfig::KEY_ACTION_PRODUCT_BRAND;
93 if (!empty($condition)) { 110 if (!empty($condition)) {
94 $key .= http_build_query($condition, null, '&'); 111 $key .= http_build_query($condition, null, '&');
95 } 112 }
96 // 先尝试获取一级缓存(master), 有数据则直接返回. 113 // 先尝试获取一级缓存(master), 有数据则直接返回.
97 - $result['goodList'] = Cache::get($key, 'master');  
98 - if (!empty($result['goodList'])) { 114 + $result = Cache::get($key, 'master');
  115 + if (!empty($result)) {
99 return $result; 116 return $result;
100 } 117 }
101 } 118 }
@@ -104,20 +121,28 @@ class ListModel @@ -104,20 +121,28 @@ class ListModel
104 $listData = BrandData::filterBrandData($condition); 121 $listData = BrandData::filterBrandData($condition);
105 // 处理返回的数据 122 // 处理返回的数据
106 if (isset($listData['code']) && $listData['code'] === 200) { 123 if (isset($listData['code']) && $listData['code'] === 200) {
107 - $result['goodList'] = ListProcess::getListData($listData['data']); 124 + $result = ListProcess::getListData($listData['data']);
  125 + if (!empty($listData['data']['brand'])) {
  126 + $result['brandWay'] = array(
  127 + 'url' => 'http://'. $listData['data']['brand_domain'] . SUB_DOMAIN,
  128 + 'thumb' => Helpers::getImageUrl($listData['data']['brand_ico'], 75, 40),
  129 + 'name' => $listData['data']['brand_name']
  130 + );
  131 + $title = $listData['data']['brand_name'];
  132 + }
108 } 133 }
109 134
110 if (USE_CACHE) { 135 if (USE_CACHE) {
111 // 接口调用异常时, 不害怕,从我们的二级缓存(slave)里再取数据. 136 // 接口调用异常时, 不害怕,从我们的二级缓存(slave)里再取数据.
112 - if (empty($result['goodList'])) {  
113 - $result['goodList'] = Cache::get($key, 'slave'); 137 + if (empty($result)) {
  138 + $result = Cache::get($key, 'slave');
114 } 139 }
115 // 接口调用正常,数据封装完成, 则设置一级(master)和二级(slave)数据缓存 140 // 接口调用正常,数据封装完成, 则设置一级(master)和二级(slave)数据缓存
116 else { 141 else {
117 - Cache::set($key, $result['goodList'], 600); // 缓存10分钟 142 + Cache::set($key, $result, 600); // 缓存10分钟
118 } 143 }
119 } 144 }
120 - 145 +
121 return $result; 146 return $result;
122 } 147 }
123 148
@@ -125,7 +150,7 @@ class ListModel @@ -125,7 +150,7 @@ class ListModel
125 * 获取所有的品牌名称列表 150 * 获取所有的品牌名称列表
126 * 151 *
127 * @return array( 152 * @return array(
128 - * 品牌ID => 品牌名(domain) 153 + * 品牌ID => 品牌名(domain)
129 * ) 154 * )
130 */ 155 */
131 public static function getAllBrandDomains() 156 public static function getAllBrandDomains()
@@ -133,7 +158,7 @@ class ListModel @@ -133,7 +158,7 @@ class ListModel
133 $result = array(); 158 $result = array();
134 159
135 if (USE_CACHE) { 160 if (USE_CACHE) {
136 - $key = CacheConfig::KEY_ACTION_PRODUCT_BRAND_ALLNAMES; 161 + $key = CacheConfig::KEY_ACTION_PRODUCT_BRAND_DOMAINS;
137 // 先尝试获取一级缓存(master), 有数据则直接返回. 162 // 先尝试获取一级缓存(master), 有数据则直接返回.
138 $result = Cache::get($key, 'master'); 163 $result = Cache::get($key, 'master');
139 if (!empty($result)) { 164 if (!empty($result)) {
@@ -146,14 +171,14 @@ class ListModel @@ -146,14 +171,14 @@ class ListModel
146 if (!empty($brand['data']['brands'])) { 171 if (!empty($brand['data']['brands'])) {
147 foreach ($brand['data']['brands'] as $value) { 172 foreach ($brand['data']['brands'] as $value) {
148 foreach ($value as $row) { 173 foreach ($value as $row) {
149 - $result[ $row['id'] ] = $row['brand_domain'] ; 174 + $result[$row['id']] = $row['brand_domain'];
150 } 175 }
151 } 176 }
152 } 177 }
153 // 更多关联的品牌 178 // 更多关联的品牌
154 if (!empty($brand['data']['morebrands'])) { 179 if (!empty($brand['data']['morebrands'])) {
155 foreach ($brand['data']['morebrands'] as $row) { 180 foreach ($brand['data']['morebrands'] as $row) {
156 - $result[ $row['id'] ] = $row['brand_domain']; 181 + $result[$row['id']] = $row['brand_domain'];
157 } 182 }
158 } 183 }
159 $brand = array(); 184 $brand = array();
@@ -165,7 +190,58 @@ class ListModel @@ -165,7 +190,58 @@ class ListModel
165 } 190 }
166 // 接口调用正常,数据封装完成, 则设置一级(master)和二级(slave)数据缓存 191 // 接口调用正常,数据封装完成, 则设置一级(master)和二级(slave)数据缓存
167 else { 192 else {
168 - Cache::set($key, $result, 600); // 缓存10分钟 193 + Cache::set($key, $result);
  194 + }
  195 + }
  196 +
  197 + return $result;
  198 + }
  199 +
  200 + /**
  201 + * 获取所有的品牌名称列表
  202 + *
  203 + * @return array(
  204 + * 品牌域名(domain) => 品牌名称(name)
  205 + * )
  206 + */
  207 + public static function getAllBrandNames()
  208 + {
  209 + $result = array();
  210 +
  211 + if (USE_CACHE) {
  212 + $key = CacheConfig::KEY_ACTION_PRODUCT_BRAND_NAMES;
  213 + // 先尝试获取一级缓存(master), 有数据则直接返回.
  214 + $result = Cache::get($key, 'master');
  215 + if (!empty($result)) {
  216 + return $result;
  217 + }
  218 + }
  219 +
  220 + $brand = BrandData::getBrandsData(null);
  221 + /* 按字母'A-Z'分组的品牌列表 */
  222 + if (!empty($brand['data']['brands'])) {
  223 + foreach ($brand['data']['brands'] as $value) {
  224 + foreach ($value as $row) {
  225 + $result[$row['brand_domain']] = strtolower($row['brand_name']);
  226 + }
  227 + }
  228 + }
  229 + // 更多关联的品牌
  230 + if (!empty($brand['data']['morebrands'])) {
  231 + foreach ($brand['data']['morebrands'] as $row) {
  232 + $result[$row['brand_domain']] = strtolower($row['brand_name']);
  233 + }
  234 + }
  235 + $brand = array();
  236 +
  237 + if (USE_CACHE) {
  238 + // 接口调用异常时, 不害怕,从我们的二级缓存(slave)里再取数据.
  239 + if (empty($result)) {
  240 + $result = Cache::get($key, 'slave');
  241 + }
  242 + // 接口调用正常,数据封装完成, 则设置一级(master)和二级(slave)数据缓存
  243 + else {
  244 + Cache::set($key, $result);
169 } 245 }
170 } 246 }
171 247
@@ -11,26 +11,39 @@ class PlusstarController extends AbstractAction @@ -11,26 +11,39 @@ class PlusstarController extends AbstractAction
11 { 11 {
12 12
13 /** 13 /**
14 - * 国际精选-品牌列表页 14 + * 国际优选-品牌列表页
  15 + * 明星原创-品牌列表页
15 * 16 *
16 * @param int gender "1,3"表示男, "2,3"表示女 17 * @param int gender "1,3"表示男, "2,3"表示女
  18 + * @param int type 1表示国际优选, 2表示明星原创
17 */ 19 */
18 public function indexAction() 20 public function indexAction()
19 { 21 {
20 - $this->setTitle('国际优选');  
21 - $this->setNavHeader('国际优选', true, SITE_MAIN);  
22 -  
23 $gender = $this->get('gender', '1,3'); 22 $gender = $this->get('gender', '1,3');
24 -  
25 - $data = Guang\PlusstarModel::getFirstBrands($gender);  
26 - $data['psList'] = true; // 控制模板中的JS使用  
27 -  
28 - $this->_view->display('index', $data); 23 + $type = $this->get('type', 1);
  24 + if ($type == '2') {
  25 + $this->setTitle('明星原创');
  26 + $this->setNavHeader('明星原创', true, SITE_MAIN);
  27 +
  28 + $data = Guang\PlusstarModel::getBrands($gender);
  29 + $data['psList'] = true; // 控制模板中的JS使用
  30 +
  31 + $this->_view->display('list', $data);
  32 + } else {
  33 + $this->setTitle('国际优选');
  34 + $this->setNavHeader('国际优选', true, SITE_MAIN);
  35 +
  36 + $data = Guang\PlusstarModel::getFirstBrands($gender);
  37 + $data['psList'] = true; // 控制模板中的JS使用
  38 +
  39 + $this->_view->display('index', $data);
  40 + }
29 } 41 }
30 42
31 /** 43 /**
32 * 明星原创-品牌列表页 44 * 明星原创-品牌列表页
33 * 45 *
  46 + * 备注:已不使用暂留着,可去掉
34 * @param int gender "1,3"表示男, "2,3"表示女 47 * @param int gender "1,3"表示男, "2,3"表示女
35 */ 48 */
36 public function listAction() 49 public function listAction()
@@ -79,7 +92,7 @@ class PlusstarController extends AbstractAction @@ -79,7 +92,7 @@ class PlusstarController extends AbstractAction
79 $data['ps']['likeUrl'] = false; //"http://guang.m.yohobuy.com/plustar/brandinfo?id=285&amp;openby:yohobuy={&quot;action&quot;:&quot;go.weblogin&quot;,&quot;params&quot;:{&quot;jumpurl&quot;:{&quot;url&quot;:&quot;http:\/\/guang.m.yohobuy.com\/plustar\/brandinfo&quot;,&quot;param&quot;:{&quot;id&quot;:285}},&quot;requesturl&quot;:{&quot;url&quot;:&quot;\/guang\/api\/v1\/favorite\/togglebrand&quot;,&quot;param&quot;:{&quot;brand_id&quot;:&quot;701&quot;}},&quot;priority&quot;:&quot;Y&quot;}}"; 92 $data['ps']['likeUrl'] = false; //"http://guang.m.yohobuy.com/plustar/brandinfo?id=285&amp;openby:yohobuy={&quot;action&quot;:&quot;go.weblogin&quot;,&quot;params&quot;:{&quot;jumpurl&quot;:{&quot;url&quot;:&quot;http:\/\/guang.m.yohobuy.com\/plustar\/brandinfo&quot;,&quot;param&quot;:{&quot;id&quot;:285}},&quot;requesturl&quot;:{&quot;url&quot;:&quot;\/guang\/api\/v1\/favorite\/togglebrand&quot;,&quot;param&quot;:{&quot;brand_id&quot;:&quot;701&quot;}},&quot;priority&quot;:&quot;Y&quot;}}";
80 $data['ps']['intro'] = empty($brandInfo['getBrandInfo']['data']['brand_intro']) ? '' : strtr(strip_tags($brandInfo['getBrandInfo']['data']['brand_intro']), array('&nbsp;' => ' ')); 93 $data['ps']['intro'] = empty($brandInfo['getBrandInfo']['data']['brand_intro']) ? '' : strtr(strip_tags($brandInfo['getBrandInfo']['data']['brand_intro']), array('&nbsp;' => ' '));
81 $data['ps']['newArrival'] = array(); 94 $data['ps']['newArrival'] = array();
82 - $data['ps']['newArrival']['moreUrl'] = '/product/list/brand?brand='.$id; // @todo 品牌列表页面 95 + $data['ps']['newArrival']['moreUrl'] = '/product/list/brand?brand=' . $id; // @todo 品牌列表页面
83 $data['ps']['newArrival']['naList'] = $brandInfo['getNewProduct']; 96 $data['ps']['newArrival']['naList'] = $brandInfo['getNewProduct'];
84 $data['ps']['infos'] = array(); 97 $data['ps']['infos'] = array();
85 98
1 <?php 1 <?php
2 2
3 use Action\AbstractAction; 3 use Action\AbstractAction;
4 -use LibModels\Wap\Category\BrandData;  
5 -use LibModels\Wap\Category\ClassData;  
6 -use Plugin\DataProcess\ListProcess;  
7 use Plugin\Helpers; 4 use Plugin\Helpers;
8 5
9 /** 6 /**
@@ -29,7 +26,7 @@ class IndexController extends AbstractAction @@ -29,7 +26,7 @@ class IndexController extends AbstractAction
29 // 过滤请求参数 26 // 过滤请求参数
30 $condition = filter_input_array(INPUT_GET, array( 27 $condition = filter_input_array(INPUT_GET, array(
31 'brand' => FILTER_VALIDATE_INT, 28 'brand' => FILTER_VALIDATE_INT,
32 - 'sort' => FILTER_VALIDATE_INT, 29 + 'sort' => FILTER_DEFAULT,
33 'msort' => FILTER_VALIDATE_INT, 30 'msort' => FILTER_VALIDATE_INT,
34 'misort' => FILTER_VALIDATE_INT, 31 'misort' => FILTER_VALIDATE_INT,
35 'color' => FILTER_VALIDATE_INT, 32 'color' => FILTER_VALIDATE_INT,
@@ -74,7 +71,7 @@ class IndexController extends AbstractAction @@ -74,7 +71,7 @@ class IndexController extends AbstractAction
74 */ 71 */
75 public function brandAction() 72 public function brandAction()
76 { 73 {
77 - /* 品牌域名参数 @see Bootstrap.php */ 74 + /* 品牌域名参数 @see Bootstrap.php */
78 $domain = $this->param('named'); 75 $domain = $this->param('named');
79 if (empty($domain)) { 76 if (empty($domain)) {
80 $this->error(); 77 $this->error();
@@ -86,12 +83,19 @@ class IndexController extends AbstractAction @@ -86,12 +83,19 @@ class IndexController extends AbstractAction
86 if (!isset($brandIds[0])) { 83 if (!isset($brandIds[0])) {
87 $this->error(); 84 $this->error();
88 } 85 }
  86 +
89 // 当前的登录用户UID 87 // 当前的登录用户UID
90 $uid = $this->getUid(); 88 $uid = $this->getUid();
91 - 89 + // 存标题信息
  90 + $title = '';
  91 +
  92 + /* 搜索框相关 */
  93 + $from = $this->get('from');
  94 + $query = $this->get('query');
  95 +
92 /* 过滤请求参数 */ 96 /* 过滤请求参数 */
93 $condition = filter_input_array(INPUT_GET, array( 97 $condition = filter_input_array(INPUT_GET, array(
94 - 'sort' => FILTER_VALIDATE_INT, 98 + 'sort' => FILTER_DEFAULT,
95 'msort' => FILTER_VALIDATE_INT, 99 'msort' => FILTER_VALIDATE_INT,
96 'misort' => FILTER_VALIDATE_INT, 100 'misort' => FILTER_VALIDATE_INT,
97 'color' => FILTER_VALIDATE_INT, 101 'color' => FILTER_VALIDATE_INT,
@@ -101,16 +105,25 @@ class IndexController extends AbstractAction @@ -101,16 +105,25 @@ class IndexController extends AbstractAction
101 'gender' => FILTER_DEFAULT, 105 'gender' => FILTER_DEFAULT,
102 'p_d' => FILTER_DEFAULT,), false); 106 'p_d' => FILTER_DEFAULT,), false);
103 $condition['brand'] = $brandIds[0]; 107 $condition['brand'] = $brandIds[0];
104 -  
105 - // 存标题信息  
106 - $title = '';  
107 108
108 - $data = Product\ListModel::getBrandData($condition, $brandIds[0], $uid, $title);  
109 - if (!empty($condition)) {  
110 - $data = array_merge($data, $condition);  
111 - }  
112 $data['goodListPage'] = true; 109 $data['goodListPage'] = true;
  110 + // 从搜索页过来的,显示搜索框, 和进入品牌引导信息
  111 + if ($from === 'search') {
  112 + $data['goodList'] = Product\ListModel::getBrandData($condition, $title);
  113 + $data['goodList']['brandWay'] = false;
  114 + $data['goodList']['search']['default'] = $query;
  115 + $data['goodList']['search']['url'] = Helpers::url('', null, 'search');
  116 + }
  117 + // 品牌一览过来的展示品牌介绍和LOGO
  118 + else {
  119 + $data['brandHome'] = Product\ListModel::getBrandIntro($brandIds[0], $uid, $title);
  120 + $data['goodList'] = Product\ListModel::getBrandData($condition, $title);
  121 + }
  122 + $data['goodList'] += $condition;
113 123
  124 + if ($title === '') {
  125 + $title = $domain;
  126 + }
114 $this->setTitle($title); 127 $this->setTitle($title);
115 $this->setNavHeader($title, true, SITE_MAIN); 128 $this->setNavHeader($title, true, SITE_MAIN);
116 129
1 <?php 1 <?php
2 2
  3 +use Action\AbstractAction;
  4 +use LibModels\Wap\Product\BrandData;
  5 +
3 /** 6 /**
  7 + * 商品操作相关的控制器
4 * 8 *
5 - * @name Opt  
6 - * @package 9 + * @name OptController
  10 + * @package product
7 * @copyright yoho.inc 11 * @copyright yoho.inc
8 * @version 1.0 (2015-10-27 19:13:28) 12 * @version 1.0 (2015-10-27 19:13:28)
9 * @author fei.hong <fei.hong@yoho.cn> 13 * @author fei.hong <fei.hong@yoho.cn>
10 */ 14 */
11 -class Opt 15 +class OptController extends AbstractAction
12 { 16 {
13 17
  18 + /**
  19 + * 品牌[店铺]收藏/取消收藏
  20 + *
  21 + * @param int id 品牌ID
  22 + * @param string opt 操作标识("ok":表示收藏,"cancel":表示取消收藏)
  23 + * @return json
  24 + */
  25 + public function favoriteBrandAction()
  26 + {
  27 + $result = array('code' => 400, 'message' => '未登录', 'data' => false);
  28 +
  29 + do {
  30 + /* 判断是否是AJAX请求 */
  31 + if (!$this->isAjax()) {
  32 + break;
  33 + }
  34 +
  35 + /* 判断品牌ID是否有效 */
  36 + $id = $this->post('id');
  37 + if (!is_numeric($id)) {
  38 + break;
  39 + }
  40 +
  41 + /* 判断用户是否登录 */
  42 + $uid = $this->getUdid();
  43 + if (!$uid) {
  44 + break;
  45 + }
  46 +
  47 + /* 取消收藏 */
  48 + $opt = $this->post('opt', 'ok');
  49 + if ($opt !== 'ok') {
  50 + $result = BrandData::favoriteCancel($id, $uid);
  51 + break;
  52 + }
  53 +
  54 + /* 收藏 */
  55 + $result = BrandData::favorite($id, $uid);
  56 + }
  57 + while (false);
  58 +
  59 + $this->echoJson($result);
  60 + }
  61 +
14 } 62 }
@@ -12,3 +12,17 @@ routes.author.route.module = Guang @@ -12,3 +12,17 @@ routes.author.route.module = Guang
12 routes.author.route.controller = Index 12 routes.author.route.controller = Index
13 routes.author.route.action = Editor 13 routes.author.route.action = Editor
14 14
  15 +; 国际优选
  16 +routes.author.type = "rewrite"
  17 +routes.author.match = "/plustar"
  18 +routes.author.route.module = Guang
  19 +routes.author.route.controller = Plusstar
  20 +routes.author.route.action = Index
  21 +
  22 +; 明星原创
  23 +routes.author.type = "rewrite"
  24 +routes.author.match = "/(plustar|plustar/index)"
  25 +routes.author.route.module = Guang
  26 +routes.author.route.controller = Plusstar
  27 +routes.author.route.action = Index
  28 +