diff --git a/library/Action/AbstractAction.php b/library/Action/AbstractAction.php index aea7d3b..530b223 100644 --- a/library/Action/AbstractAction.php +++ b/library/Action/AbstractAction.php @@ -164,6 +164,19 @@ class AbstractAction extends Controller_Abstract } /** + * 跳转到指定的URL + * + * @param string $url 链接地址 + * @return void + */ + protected function go($url) + { + headers_sent() || header('Location: ' . $url); + + exit(); + } + + /** * 设置Cookie * * @param string $name cookie的名字 @@ -259,26 +272,6 @@ class AbstractAction extends Controller_Abstract return $udid; } - /** - * 获取当前登录的用户名字 - * - * @return int - * @todo - */ - protected function getUname() - { - if (!$this->_uname) { - $cookie = $this->getCookie('_UID'); - if (!empty($cookie)) { - $cookieList = explode('::', $cookie); - if (isset($cookieList[0])) { - $this->_uname = $cookieList[0]; - } - } - } - return $this->_uname; - } - /* * 设置网站SEO的标题 * diff --git a/library/Api/Yohobuy.php b/library/Api/Yohobuy.php index 3c7ad1a..2a1ed9f 100644 --- a/library/Api/Yohobuy.php +++ b/library/Api/Yohobuy.php @@ -71,7 +71,7 @@ class Yohobuy 'os_version' => 'yohobuy:h5', 'private_key' => self::$privateKeyList[$clientType], 'screen_size' => '720x1280', - 'v' => '6', + 'v' => '7', ); return $param; } diff --git a/library/Configs/CacheConfig.php b/library/Configs/CacheConfig.php index e9f1aae..00d6246 100644 --- a/library/Configs/CacheConfig.php +++ b/library/Configs/CacheConfig.php @@ -9,8 +9,8 @@ class CacheConfig { /* 公共的数据缓存 */ const KEY_COMMON_SIDE_NAV = 'key_common_side_nav'; // 公共的侧边栏 - - const KEY_CATEGORY_CLASSES_DATA = 'key_category_classes_data'; // 品类数据 + const KEY_COMMON_CATEGORY_CLASSES = 'key_common_category_classes'; // 公共的品类数据 + const KEY_COMMON_CATEGORY_CLASSES_NAMES = 'key_common_category_classes_names'; // 公共的品类名称列表 /* 控制器方法中的数据缓存 */ const KEY_ACTION_INDEX_INDEX = 'key_action_index_index'; // 频道选择 @@ -33,6 +33,7 @@ class CacheConfig const KEY_ACTION_PRODUCT_INDEX = 'key_action_product_index'; // 品类商品列表 const KEY_ACTION_PRODUCT_BRAND = 'key_action_product_brand'; // 品类商品列表 - const KEY_ACTION_PRODUCT_BRAND_DOMAINS = 'key_action_product_brand_DOMAINS'; // 所有品牌域名列表 + const KEY_ACTION_PRODUCT_BRAND_DOMAINS = 'key_action_product_brand_domains'; // 所有品牌域名列表 + const KEY_ACTION_PRODUCT_BRAND_NAMES = 'key_action_product_brand_names'; // 所有品牌名称列表 } diff --git a/library/LibModels/Wap/Product/BrandData.php b/library/LibModels/Wap/Product/BrandData.php new file mode 100644 index 0000000..9867646 --- /dev/null +++ b/library/LibModels/Wap/Product/BrandData.php @@ -0,0 +1,58 @@ +<?php + +namespace LibModels\Wap\Product; + +use Api\Yohobuy; +use Api\Sign; + +/** + * 商品品牌相关的数据模型 + * + * @name BrandData + * @package + * @copyright yoho.inc + * @version 1.0 (2015-10-28 11:12:35) + * @author fei.hong <fei.hong@yoho.cn> + */ +class BrandData +{ + + /** + * 收藏 + * + * @param int $id 品牌ID + * @param int $uid 用户ID + * @return array + */ + public static function favorite($id, $uid) + { + $param = Yohobuy::param(); + $param['method'] = 'app.favorite.add'; + $param['id'] = $id; + $param['uid'] = $uid; + $param['type'] = 'brand'; + $param['client_secret'] = Sign::getSign($param); + + return Yohobuy::post(Yohobuy::API_URL, $param, true); + } + + /** + * 取消收藏 + * + * @param int $id 品牌ID + * @param int $uid 用户ID + * @return array + */ + public static function favoriteCancel($id, $uid) + { + $param = Yohobuy::param(); + $param['method'] = 'app.favorite.cancel'; + $param['fav_id'] = $id; + $param['uid'] = $uid; + $param['type'] = 'brand'; + $param['client_secret'] = Sign::getSign($param); + + return Yohobuy::post(Yohobuy::API_URL, $param, true); + } + +} diff --git a/library/LibModels/Wap/Product/SearchData.php b/library/LibModels/Wap/Product/SearchData.php index 0620f2a..602ca73 100644 --- a/library/LibModels/Wap/Product/SearchData.php +++ b/library/LibModels/Wap/Product/SearchData.php @@ -1,4 +1,5 @@ <?php + namespace LibModels\Wap\Product; use Api\Yohobuy; @@ -16,67 +17,102 @@ use Api\Sign; class SearchData { - /** - * 模糊搜索提供的关键词 - * - * @param string $keyword 关键词 - * @return array 根据跟定关键词搜索到的结果,包括数据数目count和提供的关键词keyword - */ - public static function searchFuzzyDatas($keyword) - { - // 构建必传参数 - $param = Yohobuy::param(); + /** + * 模糊搜索提供的关键词 + * + * @param string $keyword 关键词 + * @return array 根据跟定关键词搜索到的结果,包括数据数目count和提供的关键词keyword + */ + public static function searchFuzzyDatas($keyword) + { + // 构建必传参数 + $param = Yohobuy::param(); - $param['keyword'] = $keyword; - $param['method'] = 'app.search.fuzzy'; + $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 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) - { - // 构建必传参数 - $param = Yohobuy::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 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) + { + // 构建必传参数 + $param = Yohobuy::param(); - 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['method'] = 'app.search.li'; - $param['order'] = $order; - $param['page'] = $page; - $param['limit'] = $limit; + 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['method'] = 'app.search.li'; + $param['order'] = $order; + $param['page'] = $page; + $param['limit'] = $limit; $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, $order = 's_t_desc', $page = 1, $limit = 60) + { + $param = Yohobuy::param(); + $param['method'] = 'app.search.li'; + $param['order'] = $order; + $param['page'] = $page; + $param['limit'] = $limit; + $param += $condition; + $param['client_secret'] = Sign::getSign($param); + + return Yohobuy::get(Yohobuy::API_URL, $param, 600); // 有缓存10分钟 + } + } diff --git a/library/LibModels/Wap/Product/ShopData.php b/library/LibModels/Wap/Product/ShopData.php deleted file mode 100644 index 8b13789..0000000 --- a/library/LibModels/Wap/Product/ShopData.php +++ /dev/null @@ -1 +0,0 @@ - diff --git a/library/Plugin/Helpers.php b/library/Plugin/Helpers.php index a898fc7..817b0e4 100644 --- a/library/Plugin/Helpers.php +++ b/library/Plugin/Helpers.php @@ -32,8 +32,15 @@ class Helpers case 'search': // 搜索 $url = 'http://search' . SUB_DOMAIN; break; + case 'index': // 默认 + $url = ''; + break; + default: + $url = 'http://' . $module . SUB_DOMAIN; + } + if (!empty($param)) { + $url .= $uri . '?' . http_build_query($param, null, '&'); } - $url .= $uri . '?' . http_build_query($param, null, '&'); return $url; } diff --git a/script/nginx/conf/nginx.conf b/script/nginx/conf/nginx.conf index 6e2aa08..ab7ff56 100644 --- a/script/nginx/conf/nginx.conf +++ b/script/nginx/conf/nginx.conf @@ -33,45 +33,6 @@ http { autoindex_exact_size on; autoindex_localtime on; - server { - listen 80; - server_name localhost; - - #charset koi8-r; - - #access_log logs/host.access.log main; - - location / { - root /cygdrive/E/nginx/html; - index index.html index.htm; - } - - #error_page 404 /404.html; - - # redirect server error pages to the static page /50x.html - # - error_page 500 502 503 504 /50x.html; - location = /50x.html { - root html; - } - - # proxy the PHP scripts to Apache listening on 127.0.0.1:80 - # - #location ~ \.php$ { - # proxy_pass http://127.0.0.1; - #} - - # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 - # - # deny access to .htaccess files, if Apache's document root - # concurs with nginx's one - # - #location ~ /\.ht { - # deny all; - #} - } - - # another virtual host using mix of IP-, name-, and port-based configuration # #server { @@ -108,7 +69,7 @@ http { # } #} - # �����Զ���������ļ� + # �����Զ���������ļ� #include /nginx/conf/vhosts/yohoboys.conf; #include /nginx/conf/vhosts/yohogirls.conf; #include /nginx/conf/vhosts/yohostore.conf; diff --git a/script/nginx/conf/vhosts/apache.test.yohobuy.conf b/script/nginx/conf/vhosts/apache.test.yohobuy.conf index 8ca25ce..45ee060 100644 --- a/script/nginx/conf/vhosts/apache.test.yohobuy.conf +++ b/script/nginx/conf/vhosts/apache.test.yohobuy.conf @@ -4,6 +4,7 @@ CustomLog "/Data/logs/apache/access.buy.test.yoho.cn.log" combined ErrorLog "/Data/logs/apache/error.buy.test.yoho.cn.log" ServerName buy.test.yoho.cn + ServerAlias *.test.yoho.cn DocumentRoot "/Data/code/git/yohobuy/yohobuy/m.yohobuy.com/public" RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f diff --git a/script/nginx/conf/vhosts/nginx.test.yohobuy.conf b/script/nginx/conf/vhosts/nginx.test.yohobuy.conf index 7790e27..43b9cb3 100644 --- a/script/nginx/conf/vhosts/nginx.test.yohobuy.conf +++ b/script/nginx/conf/vhosts/nginx.test.yohobuy.conf @@ -1,7 +1,7 @@ server { listen 80; - server_name buy.test.yoho.cn; + server_name buy.test.yoho.cn *.test.yoho.cn; #access_log /Data/logs/access.buy.test.yoho.cn.log combined; error_log /Data/logs/error.buy.test.yoho.cn.log warn; diff --git a/static/js/product/list.js b/static/js/product/list.js index d7553b8..f77522d 100644 --- a/static/js/product/list.js +++ b/static/js/product/list.js @@ -54,7 +54,7 @@ var $listNav = $('#list-nav'), end: false } }, - $pre, //纪录进入筛选前的active项 + $pre = $listNav.find('.active'), //纪录进入筛选前的active项,初始为选中项 searching; /** @@ -157,7 +157,7 @@ function search(opt) { $.ajax({ type: 'GET', - url: '/product/list/search', + url: '/index/search/search', data: setting, success: function(data) { var noResult = '<p class="no-result">未找到相关搜索结果</p>', diff --git a/template/m.yohobuy.com/actions/index/search/list.phtml b/template/m.yohobuy.com/actions/index/search/list.phtml index e40873f..51c90d2 100644 --- a/template/m.yohobuy.com/actions/index/search/list.phtml +++ b/template/m.yohobuy.com/actions/index/search/list.phtml @@ -3,7 +3,7 @@ {{# goodList}} {{# search}} <div id="search-input" class="search-input"> - <form action="/product/list/index" method="get"> + <form action={{url}} method="get"> <i class="search-icon iconfont"></i> <input type="text" value={{default}} name="query"> <i class="clear-input iconfont hide"></i> diff --git a/template/m.yohobuy.com/actions/product/index/index.phtml b/template/m.yohobuy.com/actions/product/index/index.phtml index c2dc5a6..2c38b7a 100644 --- a/template/m.yohobuy.com/actions/product/index/index.phtml +++ b/template/m.yohobuy.com/actions/product/index/index.phtml @@ -3,7 +3,7 @@ {{# goodList}} {{# search}} <div id="search-input" class="search-input"> - <form action="/product/list/index" method="get"> + <form action={{url}} method="get"> <i class="search-icon iconfont"></i> <input type="text" value={{default}} name="query"> <i class="clear-input iconfont hide"></i> diff --git a/yohobuy/m.yohobuy.com/application/controllers/Search.php b/yohobuy/m.yohobuy.com/application/controllers/Search.php index 37b650b..c120a7e 100644 --- a/yohobuy/m.yohobuy.com/application/controllers/Search.php +++ b/yohobuy/m.yohobuy.com/application/controllers/Search.php @@ -2,11 +2,15 @@ use Action\AbstractAction; use LibModels\Wap\Product\SearchData; +use Plugin\DataProcess\ListProcess; +use Plugin\Helpers; + /** * 搜索页 */ class SearchController extends AbstractAction { + /** * 搜索首页 */ @@ -45,107 +49,173 @@ class SearchController extends AbstractAction ) ); $this->_view->display('index', array( - 'search' => $data, - 'searchPage' => true, + 'search' => $data, + 'searchPage' => true, 'pageFooter' => true )); } - + /** * 搜索列表页 */ public function listAction() { - $query = $this->get('query', null); - $brand = $this->get('brand', null); - $gender = $this->getCookie('_Channel', 'boys'); - $p_d = $this->get('p_d', null); - $misort = $this->get('misort', null); - $msort = $this->get('msort', null); - - $data = array( - 'pageHeader' => array( - 'navBack' => true, - 'navTitle' => '搜索', - 'navHome' => '/' - ), - 'goodListPage' => true, - 'goodList' => array( - 'brand' => 0, - 'msort' => 0, - 'gender' => $gender, - 'price' => 0, - 'size' => 0, - 'discount' => '' - ) - ); - - // 首先查询是否属于内置品类 - $classes = ClassModel::getClassesArr(); - $classFlag = array_search($query, $classes); - if($classFlag !== false)// 属于内部品类 - { - $data['pageHeader']['navTitle'] = '所有'.$query; + // 过滤请求参数 + $condition = filter_input_array(INPUT_GET, array( + 'query' => FILTER_DEFAULT, + 'brand' => FILTER_VALIDATE_INT, + 'sort' => FILTER_DEFAULT, + 'msort' => FILTER_VALIDATE_INT, + 'misort' => FILTER_VALIDATE_INT, + 'color' => FILTER_VALIDATE_INT, + 'size' => FILTER_VALIDATE_INT, + 'price' => FILTER_VALIDATE_INT, + 'discount' => FILTER_VALIDATE_INT, + 'gender' => FILTER_DEFAULT, + 'p_d' => FILTER_DEFAULT,), false); + + $query = isset($condition['query']) ? strtolower(trim($condition['query'])) : null; + + // 标识用户是否有输入搜索内容 + $haveQuery = $query !== null; + // 标识用户搜的是不是一级品类 + $isQueryFirstClass = false; + // 标识用户搜的是不是二级品类 + $isQuerySecondClass = false; + + /* 判断是不是品牌, 是品牌跳到品牌列表页(显示搜索框) */ + if ($haveQuery) { + $domain = null; + $brandNames = Product\ListModel::getAllBrandNames(); + + do { + /* 精确查品牌域名 */ + if (isset($brandNames[$query])) { + $domain = $query; + break; + } + + /* 精确查品牌名称 */ + $domains = array_keys($brandNames, $query, true); + if (isset($domains[0])) { + $domain = $domains[0]; + break; + } + + /* 模糊查品牌域名 */ + foreach ($brandNames as $key => $domains) { + if (strpos($key, $query) !== false) { + $domain = $key; + break; + } + } + } while (false); + + // 清空变量做释放 + $brandNames = array(); + + // 跳转到品牌商品列表页 + if ($domain !== null) { + $url = Helpers::url('', array( + 'from' => 'search', + 'query' => $query, + 'gender' => $condition['gender'] + ), $domain); + $this->go($url); + } } + + + /* 判断是不是品类, 是品类加导航标题(不显示搜索框) */ + if ($haveQuery) { + $classNames = Category\ClassModel::getClassNames(); - // 如果存在搜索字符串就显示搜索栏 - if(!is_null($query) && $classFlag === false) - { - $data['search'] = array( - 'default' => $query - ); + do { + /* 精确查一级品类 */ + $sorts = array_keys($classNames['first'], $query, true); + if (isset($sorts[0])) { + $isQueryFirstClass = true; + break; + } + + /* 精确查二级品类 */ + $sorts = array_keys($classNames['second'], $query, true); + if (isset($sorts[0])) { + $isQuerySecondClass = true; + break; + } + } + while (false); + + $classNames = array(); } - - // 转换性别 - $this->genderTrans($gender); + + $data = array(); + // 搜索是一级品类 + if ($isQueryFirstClass) { + $this->setTitle('全部' . $query); + $this->setNavHeader('全部' . $query, true, SITE_MAIN); + } + // 搜索是二级品类 + elseif ($isQuerySecondClass) { + $this->setTitle($query); + $this->setNavHeader($query, true, SITE_MAIN); + } + // 搜索其它内容 + else { + if ($haveQuery) { + $data['goodList']['search']['default'] = $query; + $data['goodList']['search']['default'] = $query; + } + $this->setTitle('搜索'); + $this->setNavHeader('搜索', true, SITE_MAIN); + } + + $data['goodListPage'] = true; + $data['goodList'] = $condition; // 查询数据 - $listData = SearchData::searchLiDatas($query, $brand, $gender, $p_d, $misort, $msort); + $listData = SearchData::searchByCondition($condition); // 处理返回的数据 - if (isset($listData['code']) && $listData['code'] === 200) { - $tmpData = $listData['data']; - - // 如果存在品牌信息就显示品牌字段 - if(isset($tmpData['brand']) && !empty($tmpData['brand'])) - { - $brandData = $tmpData['brand']; - $data['brandWay'] = array( - 'url' => '/product/list/brand?brand='.$brandData['id'], - 'thumb' => Helpers::getImageUrl($brandData['brand_ico'], 75, 40), - 'name' => $brandData['brand_name'] - ); - - // 设置品牌默认值 - $data['goodList']['brand'] = $brandData['id']; - } - - $data['goodList'] += ListProcess::getListData($tmpData); + if (!empty($listData['data']['brand'])) { + $brandData = $listData['data']['brand']; + $data['brandWay'] = array( + 'url' => 'http://'. $brandData['brand_domain'] . SUB_DOMAIN, + 'thumb' => Helpers::getImageUrl($brandData['brand_ico'], 75, 40), + 'name' => $brandData['brand_name'] + ); + // 设置品牌默认值 + $data['goodList']['brand'] = $brandData['id']; + $data['goodList'] += ListProcess::getListData($listData['data']); } + $listData = array(); $this->_view->display('list', $data); } - - /** + + /** * Ajax异步筛选请求 */ public function searchAction() { - if($this->isAjax()) - { - $query = $this->get('query', null); - $brand = $this->get('brand', null); - $gender = $this->get('gender', null); - $color = $this->get('color', null); - $size = $this->get('size', null); - $price = $this->get('price', null); - $p_d = $this->get('discount', null); - $sort = $this->get('msort', null); - - // 转换性别 - $this->genderTrans($gender); + if ($this->isAjax()) { + // 过滤请求参数 + $condition = filter_input_array(INPUT_GET, array( + 'query' => FILTER_DEFAULT, + 'brand' => FILTER_VALIDATE_INT, + 'sort' => FILTER_VALIDATE_INT, + 'msort' => FILTER_VALIDATE_INT, + 'misort' => FILTER_VALIDATE_INT, + 'color' => FILTER_VALIDATE_INT, + 'size' => FILTER_VALIDATE_INT, + 'price' => FILTER_VALIDATE_INT, + 'discount' => FILTER_DEFAULT, + 'gender' => FILTER_DEFAULT, + 'p_d' => FILTER_DEFAULT, ), false); // 转换排序方式 - $order = $this->get('order', null); + $page = $this->get('page', 1); + $order = $this->get('order', 0); $type = $this->get('type', ''); switch ($type) { case 'price': @@ -162,21 +232,19 @@ class SearchController extends AbstractAction $data = array(); // 查询数据 - $listData = SearchData::searchLiDatas($query, $brand, $gender, $color, $size, $price, $p_d, $sort, $order); + $listData = SearchData::searchByCondition($condition, $order, $page); // 处理返回的数据 - if (isset($listData['code']) && $listData['code'] === 200) { - $tmpData = $listData['data']; - - unset($tmpData['filter']);// 不要筛选条件的数据 - $data = ListProcess::getListData($tmpData); + if (isset($listData['data'])) { + if (isset($listData['data']['filter'])) { + unset($listData['data']['filter']); + } + $data = ListProcess::getListData($listData['data']); } + $listData = array(); - if(empty($data)) - { + if (empty($data)) { echo ' '; - } - else - { + } else { $this->_view->display('page', $data); } } @@ -189,8 +257,7 @@ class SearchController extends AbstractAction */ public function fuzzysearch() { - if($this->isAjax()) - { + if ($this->isAjax()) { $keyword = $this->post('keyword', ''); $result = SearchData::searchFuzzyDatas($keyword); @@ -198,4 +265,5 @@ class SearchController extends AbstractAction $this->echoJson($result); } } -} \ No newline at end of file + +} diff --git a/yohobuy/m.yohobuy.com/application/models/Category/Class.php b/yohobuy/m.yohobuy.com/application/models/Category/Class.php index 8e2d5d3..7b670e1 100644 --- a/yohobuy/m.yohobuy.com/application/models/Category/Class.php +++ b/yohobuy/m.yohobuy.com/application/models/Category/Class.php @@ -20,18 +20,18 @@ class ClassModel { /** - * 根据频道获取品牌一览数据 + * 根据频道获取品类数据 * - * @param int $channel 1表示男生频道, 2表示女生频道, 3表示潮童频道, 4表示创意生活频道 * @return array */ public static function getClassData() { - $classes = array(); + $result = array(); if (USE_CACHE) { + $key = CacheConfig::KEY_COMMON_CATEGORY_CLASSES; // 先尝试获取一级缓存(master), 有数据则直接返回. - $result = Cache::get(CacheConfig::KEY_CATEGORY_CLASSES_DATA, 'master'); + $result = Cache::get($key, 'master'); if (!empty($result)) { return $result; } @@ -49,6 +49,8 @@ class ClassModel break; } + $oneClass = array(); + $item = array(); foreach ($data['data'] as $k => $v) { $oneClass = array('name' => $k, 'ca' => array()); if ($num === 1) { @@ -64,9 +66,9 @@ class ClassModel $subitem['name'] = $value['category_name']; $subitem['id'] = $value['relation_parameter']['sort']; $subitem['url'] = Helpers::url('/', array( - 'sort' => $value['relation_parameter']['sort'], - 'sort_name' => $value['category_name'] - ), 'list'); + 'sort' => $value['relation_parameter']['sort'], + 'sort_name' => $value['category_name'] + ), 'list'); $item['sub'][] = $subitem; } @@ -75,80 +77,73 @@ class ClassModel } $num++; - $classes[] = $oneClass; + $result[] = $oneClass; } if (USE_CACHE) { // 接口调用异常时, 不害怕,从我们的二级缓存(slave)里再取数据. - if (empty($classes)) { - $classes = Cache::get(CacheConfig::KEY_CATEGORY_CLASSES_DATA, 'slave'); + if (empty($result)) { + $result = Cache::get($key, 'slave'); } // 接口调用正常,数据封装完成, 则设置一级(master)和二级(slave)数据缓存 else { - Cache::set(CacheConfig::KEY_CATEGORY_CLASSES_DATA, $classes); + Cache::set($key, $result); } } } while (false); - return $classes; + return $result; } /** - * 返回品类构成的数组 + * 根据频道获取所有品类名称 * - * @return array 键为品类查询sort参数,值为品类名称构成的数组 + * @return array( + * "first" => '一级品类', + * "second" => '二级品类', + * ) */ - public static function getClassesArr() + public static function getClassNames() { - $classes = array(); - $classesData = self::getClassData(); + $result = array('first' => array(), 'second' => array()); - foreach ($classesData as $val) { - foreach ($val['ca'] as $single) { - $classes[$single['id']] = $single['name']; - $classes += self::array_column($single['sub'], 'name', 'id'); + if (USE_CACHE) { + $key = CacheConfig::KEY_COMMON_CATEGORY_CLASSES_NAMES; + // 先尝试获取一级缓存(master), 有数据则直接返回. + $result = Cache::get($key, 'master'); + if (!empty($result)) { + return $result; } } + + $classes= ClassData::getClassesData(); + if (!empty($classes['data'])) { + $id = 0; + foreach ($classes['data'] as $data) { + foreach ($data as $item) { + $id = $item['category_id']; + $result['first'][$id] = $item['category_name']; + foreach ($item['sub'] as $sub) { + $id = $sub['category_id']; + $result['second'][$id] = $sub['category_name']; + } + } + } + } + $classes = array(); - return $classes; - } - - /** - * 自定义array_column函数 - * - * @return array 返回数组中指定的一列组成的数组 - */ - - /** - * 自定义array_column函数 - * @param array $input 需要取出数组咧的多维数组 - * @param string $columnKey 需要返回的列 - * @param mixed $indexKey 作为返回数组的索引值 - * @return array 从多维数组中返回单列数组 - */ - private static function array_column(array $input, $columnKey, $indexKey = null) - { - $array = array(); - foreach ($input as $value) { - if (!isset($value[$columnKey])) { - trigger_error("Key \"$columnKey\" does not exist in array"); - return false; + if (USE_CACHE) { + // 接口调用异常时, 不害怕,从我们的二级缓存(slave)里再取数据. + if (empty($result)) { + $result = Cache::get($key, 'slave'); } - if (is_null($indexKey)) { - $array[] = $value[$columnKey]; - } else { - if (!isset($value[$indexKey])) { - trigger_error("Key \"$indexKey\" does not exist in array"); - return false; - } - if (!is_scalar($value[$indexKey])) { - trigger_error("Key \"$indexKey\" does not contain scalar value"); - return false; - } - $array[$value[$indexKey]] = $value[$columnKey]; + // 接口调用正常,数据封装完成, 则设置一级(master)和二级(slave)数据缓存 + else { + Cache::set($key, $result); } } - return $array; + + return $result; } } diff --git a/yohobuy/m.yohobuy.com/application/models/Product/List.php b/yohobuy/m.yohobuy.com/application/models/Product/List.php index f01ad7d..44b87c9 100644 --- a/yohobuy/m.yohobuy.com/application/models/Product/List.php +++ b/yohobuy/m.yohobuy.com/application/models/Product/List.php @@ -44,7 +44,7 @@ class ListModel } // 调用接口查询数据 - $listData = ClassData::filterClassData($condition); + $listData = ClassData::filterClassData($condition); // 处理返回的数据 if (isset($listData['code']) && $listData['code'] === 200) { $result = ListProcess::getListData($listData['data']); @@ -63,16 +63,19 @@ class ListModel return $result; } - + /** - * 获取品牌商品列表数据 + * 获取品牌信息 * + * @param int $id 唯一的ID + * @param int $uid 用户ID + * @param string $title 网站标题 * @return array */ - public static function getBrandData($condition, $id, $uid, &$title) + public static function getBrandIntro($id, $uid, &$title) { $result = array(); - + // 获取品牌介绍信息, 有缓存1小时 $introData = BrandData::getBrandIntro($id, $uid); if (isset($introData['data']['brand_intro'])) { @@ -88,14 +91,28 @@ class ListModel $result['brandHome']['banner'] = Helpers::getImageUrl($bannerData['data']['banner'], 640, 75); } + return $result; + } + + /** + * 获取品牌商品列表数据 + * + * @param array $condition 条件参数 + * @param string $title 网站标题 + * @return array + */ + public static function getBrandData($condition, &$title) + { + $result = array(); + if (USE_CACHE) { $key = CacheConfig::KEY_ACTION_PRODUCT_BRAND; if (!empty($condition)) { $key .= http_build_query($condition, null, '&'); } // 先尝试获取一级缓存(master), 有数据则直接返回. - $result['goodList'] = Cache::get($key, 'master'); - if (!empty($result['goodList'])) { + $result = Cache::get($key, 'master'); + if (!empty($result)) { return $result; } } @@ -104,20 +121,28 @@ class ListModel $listData = BrandData::filterBrandData($condition); // 处理返回的数据 if (isset($listData['code']) && $listData['code'] === 200) { - $result['goodList'] = ListProcess::getListData($listData['data']); + $result = ListProcess::getListData($listData['data']); + if (!empty($listData['data']['brand'])) { + $result['brandWay'] = array( + 'url' => 'http://'. $listData['data']['brand_domain'] . SUB_DOMAIN, + 'thumb' => Helpers::getImageUrl($listData['data']['brand_ico'], 75, 40), + 'name' => $listData['data']['brand_name'] + ); + $title = $listData['data']['brand_name']; + } } if (USE_CACHE) { // 接口调用异常时, 不害怕,从我们的二级缓存(slave)里再取数据. - if (empty($result['goodList'])) { - $result['goodList'] = Cache::get($key, 'slave'); + if (empty($result)) { + $result = Cache::get($key, 'slave'); } // 接口调用正常,数据封装完成, 则设置一级(master)和二级(slave)数据缓存 else { - Cache::set($key, $result['goodList'], 600); // 缓存10分钟 + Cache::set($key, $result, 600); // 缓存10分钟 } } - + return $result; } @@ -125,7 +150,7 @@ class ListModel * 获取所有的品牌名称列表 * * @return array( - * 品牌ID => 品牌命名(domain) + * 品牌ID => 品牌域名(domain) * ) */ public static function getAllBrandDomains() @@ -133,7 +158,7 @@ class ListModel $result = array(); if (USE_CACHE) { - $key = CacheConfig::KEY_ACTION_PRODUCT_BRAND_ALLNAMES; + $key = CacheConfig::KEY_ACTION_PRODUCT_BRAND_DOMAINS; // 先尝试获取一级缓存(master), 有数据则直接返回. $result = Cache::get($key, 'master'); if (!empty($result)) { @@ -146,14 +171,14 @@ class ListModel if (!empty($brand['data']['brands'])) { foreach ($brand['data']['brands'] as $value) { foreach ($value as $row) { - $result[ $row['id'] ] = $row['brand_domain'] ; + $result[$row['id']] = $row['brand_domain']; } } } // 更多关联的品牌 if (!empty($brand['data']['morebrands'])) { foreach ($brand['data']['morebrands'] as $row) { - $result[ $row['id'] ] = $row['brand_domain']; + $result[$row['id']] = $row['brand_domain']; } } $brand = array(); @@ -165,7 +190,58 @@ class ListModel } // 接口调用正常,数据封装完成, 则设置一级(master)和二级(slave)数据缓存 else { - Cache::set($key, $result, 600); // 缓存10分钟 + Cache::set($key, $result); + } + } + + return $result; + } + + /** + * 获取所有的品牌名称列表 + * + * @return array( + * 品牌域名(domain) => 品牌名称(name) + * ) + */ + public static function getAllBrandNames() + { + $result = array(); + + if (USE_CACHE) { + $key = CacheConfig::KEY_ACTION_PRODUCT_BRAND_NAMES; + // 先尝试获取一级缓存(master), 有数据则直接返回. + $result = Cache::get($key, 'master'); + if (!empty($result)) { + return $result; + } + } + + $brand = BrandData::getBrandsData(null); + /* 按字母'A-Z'分组的品牌列表 */ + if (!empty($brand['data']['brands'])) { + foreach ($brand['data']['brands'] as $value) { + foreach ($value as $row) { + $result[$row['brand_domain']] = strtolower($row['brand_name']); + } + } + } + // 更多关联的品牌 + if (!empty($brand['data']['morebrands'])) { + foreach ($brand['data']['morebrands'] as $row) { + $result[$row['brand_domain']] = strtolower($row['brand_name']); + } + } + $brand = array(); + + if (USE_CACHE) { + // 接口调用异常时, 不害怕,从我们的二级缓存(slave)里再取数据. + if (empty($result)) { + $result = Cache::get($key, 'slave'); + } + // 接口调用正常,数据封装完成, 则设置一级(master)和二级(slave)数据缓存 + else { + Cache::set($key, $result); } } diff --git a/yohobuy/m.yohobuy.com/application/modules/Guang/controllers/Plusstar.php b/yohobuy/m.yohobuy.com/application/modules/Guang/controllers/Plusstar.php index b02b133..61734a5 100644 --- a/yohobuy/m.yohobuy.com/application/modules/Guang/controllers/Plusstar.php +++ b/yohobuy/m.yohobuy.com/application/modules/Guang/controllers/Plusstar.php @@ -11,26 +11,39 @@ class PlusstarController extends AbstractAction { /** - * 国际精选-品牌列表页 + * 国际优选-品牌列表页 + * 明星原创-品牌列表页 * * @param int gender "1,3"表示男, "2,3"表示女 + * @param int type 1表示国际优选, 2表示明星原创 */ public function indexAction() { - $this->setTitle('国际优选'); - $this->setNavHeader('国际优选', true, SITE_MAIN); - $gender = $this->get('gender', '1,3'); - - $data = Guang\PlusstarModel::getFirstBrands($gender); - $data['psList'] = true; // 控制模板中的JS使用 - - $this->_view->display('index', $data); + $type = $this->get('type', 1); + if ($type == '2') { + $this->setTitle('明星原创'); + $this->setNavHeader('明星原创', true, SITE_MAIN); + + $data = Guang\PlusstarModel::getBrands($gender); + $data['psList'] = true; // 控制模板中的JS使用 + + $this->_view->display('list', $data); + } else { + $this->setTitle('国际优选'); + $this->setNavHeader('国际优选', true, SITE_MAIN); + + $data = Guang\PlusstarModel::getFirstBrands($gender); + $data['psList'] = true; // 控制模板中的JS使用 + + $this->_view->display('index', $data); + } } /** * 明星原创-品牌列表页 * + * 备注:已不使用暂留着,可去掉 * @param int gender "1,3"表示男, "2,3"表示女 */ public function listAction() @@ -79,7 +92,7 @@ class PlusstarController extends AbstractAction $data['ps']['likeUrl'] = false; //"http://guang.m.yohobuy.com/plustar/brandinfo?id=285&openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":"http:\/\/guang.m.yohobuy.com\/plustar\/brandinfo","param":{"id":285}},"requesturl":{"url":"\/guang\/api\/v1\/favorite\/togglebrand","param":{"brand_id":"701"}},"priority":"Y"}}"; $data['ps']['intro'] = empty($brandInfo['getBrandInfo']['data']['brand_intro']) ? '' : strtr(strip_tags($brandInfo['getBrandInfo']['data']['brand_intro']), array(' ' => ' ')); $data['ps']['newArrival'] = array(); - $data['ps']['newArrival']['moreUrl'] = '/product/list/brand?brand='.$id; // @todo 品牌列表页面 + $data['ps']['newArrival']['moreUrl'] = '/product/list/brand?brand=' . $id; // @todo 品牌列表页面 $data['ps']['newArrival']['naList'] = $brandInfo['getNewProduct']; $data['ps']['infos'] = array(); diff --git a/yohobuy/m.yohobuy.com/application/modules/Product/controllers/Index.php b/yohobuy/m.yohobuy.com/application/modules/Product/controllers/Index.php index fcdeec7..fffdb4d 100644 --- a/yohobuy/m.yohobuy.com/application/modules/Product/controllers/Index.php +++ b/yohobuy/m.yohobuy.com/application/modules/Product/controllers/Index.php @@ -1,9 +1,6 @@ <?php use Action\AbstractAction; -use LibModels\Wap\Category\BrandData; -use LibModels\Wap\Category\ClassData; -use Plugin\DataProcess\ListProcess; use Plugin\Helpers; /** @@ -29,7 +26,7 @@ class IndexController extends AbstractAction // 过滤请求参数 $condition = filter_input_array(INPUT_GET, array( 'brand' => FILTER_VALIDATE_INT, - 'sort' => FILTER_VALIDATE_INT, + 'sort' => FILTER_DEFAULT, 'msort' => FILTER_VALIDATE_INT, 'misort' => FILTER_VALIDATE_INT, 'color' => FILTER_VALIDATE_INT, @@ -74,7 +71,7 @@ class IndexController extends AbstractAction */ public function brandAction() { - /* 品牌域名参数 @see Bootstrap.php */ + /* 品牌域名参数 @see Bootstrap.php */ $domain = $this->param('named'); if (empty($domain)) { $this->error(); @@ -86,12 +83,19 @@ class IndexController extends AbstractAction if (!isset($brandIds[0])) { $this->error(); } + // 当前的登录用户UID $uid = $this->getUid(); - + // 存标题信息 + $title = ''; + + /* 搜索框相关 */ + $from = $this->get('from'); + $query = $this->get('query'); + /* 过滤请求参数 */ $condition = filter_input_array(INPUT_GET, array( - 'sort' => FILTER_VALIDATE_INT, + 'sort' => FILTER_DEFAULT, 'msort' => FILTER_VALIDATE_INT, 'misort' => FILTER_VALIDATE_INT, 'color' => FILTER_VALIDATE_INT, @@ -101,16 +105,25 @@ class IndexController extends AbstractAction 'gender' => FILTER_DEFAULT, 'p_d' => FILTER_DEFAULT,), false); $condition['brand'] = $brandIds[0]; - - // 存标题信息 - $title = ''; - $data = Product\ListModel::getBrandData($condition, $brandIds[0], $uid, $title); - if (!empty($condition)) { - $data = array_merge($data, $condition); - } $data['goodListPage'] = true; + // 从搜索页过来的,显示搜索框, 和进入品牌引导信息 + if ($from === 'search') { + $data['goodList'] = Product\ListModel::getBrandData($condition, $title); + $data['goodList']['brandWay'] = false; + $data['goodList']['search']['default'] = $query; + $data['goodList']['search']['url'] = Helpers::url('', null, 'search'); + } + // 品牌一览过来的展示品牌介绍和LOGO + else { + $data['brandHome'] = Product\ListModel::getBrandIntro($brandIds[0], $uid, $title); + $data['goodList'] = Product\ListModel::getBrandData($condition, $title); + } + $data['goodList'] += $condition; + if ($title === '') { + $title = $domain; + } $this->setTitle($title); $this->setNavHeader($title, true, SITE_MAIN); diff --git a/yohobuy/m.yohobuy.com/application/modules/Product/controllers/Opt.php b/yohobuy/m.yohobuy.com/application/modules/Product/controllers/Opt.php index 0b88dea..240ea50 100644 --- a/yohobuy/m.yohobuy.com/application/modules/Product/controllers/Opt.php +++ b/yohobuy/m.yohobuy.com/application/modules/Product/controllers/Opt.php @@ -1,14 +1,62 @@ <?php +use Action\AbstractAction; +use LibModels\Wap\Product\BrandData; + /** + * 商品操作相关的控制器 * - * @name Opt - * @package + * @name OptController + * @package product * @copyright yoho.inc * @version 1.0 (2015-10-27 19:13:28) * @author fei.hong <fei.hong@yoho.cn> */ -class Opt +class OptController extends AbstractAction { + /** + * 品牌[店铺]收藏/取消收藏 + * + * @param int id 品牌ID + * @param string opt 操作标识("ok":表示收藏,"cancel":表示取消收藏) + * @return json + */ + public function favoriteBrandAction() + { + $result = array('code' => 400, 'message' => '未登录', 'data' => false); + + do { + /* 判断是否是AJAX请求 */ + if (!$this->isAjax()) { + break; + } + + /* 判断品牌ID是否有效 */ + $id = $this->post('id'); + if (!is_numeric($id)) { + break; + } + + /* 判断用户是否登录 */ + $uid = $this->getUdid(); + if (!$uid) { + break; + } + + /* 取消收藏 */ + $opt = $this->post('opt', 'ok'); + if ($opt !== 'ok') { + $result = BrandData::favoriteCancel($id, $uid); + break; + } + + /* 收藏 */ + $result = BrandData::favorite($id, $uid); + } + while (false); + + $this->echoJson($result); + } + } diff --git a/yohobuy/m.yohobuy.com/configs/routes.guang.ini b/yohobuy/m.yohobuy.com/configs/routes.guang.ini index 7efb1c3..f7d995b 100644 --- a/yohobuy/m.yohobuy.com/configs/routes.guang.ini +++ b/yohobuy/m.yohobuy.com/configs/routes.guang.ini @@ -12,3 +12,17 @@ routes.author.route.module = Guang routes.author.route.controller = Index routes.author.route.action = Editor +; 国际优选 +routes.author.type = "rewrite" +routes.author.match = "/plustar" +routes.author.route.module = Guang +routes.author.route.controller = Plusstar +routes.author.route.action = Index + +; 明星原创 +routes.author.type = "rewrite" +routes.author.match = "/(plustar|plustar/index)" +routes.author.route.module = Guang +routes.author.route.controller = Plusstar +routes.author.route.action = Index +