diff --git a/library/Action/AbstractAction.php b/library/Action/AbstractAction.php index 5521e8f..708ebe6 100644 --- a/library/Action/AbstractAction.php +++ b/library/Action/AbstractAction.php @@ -89,6 +89,18 @@ class AbstractAction extends Controller_Abstract } /** + * 封装一下获取YAF内部的参数 + * + * @param String $key + * @param mixed $default + * @return mixed + */ + protected function param($key, $default = null) + { + return $this->_request->getParam($key, $default); + } + + /** * 关闭模板自动渲染 * * @return void diff --git a/library/Configs/CacheConfig.php b/library/Configs/CacheConfig.php index 73292a7..e9f1aae 100644 --- a/library/Configs/CacheConfig.php +++ b/library/Configs/CacheConfig.php @@ -30,5 +30,9 @@ class CacheConfig const KEY_ACTION_PRODUCT_NEWSALE_DISCOUNT_GIRLS = 'key_action_product_newsale_discount_girls'; // 女生折扣专区 const KEY_ACTION_PRODUCT_NEWSALE_DISCOUNT_KIDS = 'key_action_product_newsale_discount_kids'; // 潮童折扣专区 const KEY_ACTION_PRODUCT_NEWSALE_DISCOUNT_LIFESTYLE = 'key_action_product_newsale_discount_lifestyle'; // 创意生活折扣专区 + + 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'; // 所有品牌域名列表 } diff --git a/library/LibModels/Wap/Category/BrandData.php b/library/LibModels/Wap/Category/BrandData.php index 89ab77b..07675fb 100644 --- a/library/LibModels/Wap/Category/BrandData.php +++ b/library/LibModels/Wap/Category/BrandData.php @@ -60,7 +60,9 @@ class BrandData // 构建必传参数 $param = Yohobuy::param(); $param['method'] = 'app.brand.brandlist'; - $param['yh_channel'] = $channel; + if (is_numeric($channel)) { + $param['yh_channel'] = $channel; + } $param['client_secret'] = Sign::getSign($param); return Yohobuy::get(Yohobuy::API_URL, $param); @@ -88,15 +90,18 @@ class BrandData * @param integer $brandId 品牌ID * @return array 品牌介绍信息 */ - public static function getBrandIntro($brandId) + public static function getBrandIntro($brandId, $uid) { // 构建必传参数 $param = Yohobuy::param(); $param['brand_id'] = $brandId; + $param['uid'] = $uid; $param['method'] = 'app.brand.getBrandIntro'; $param['client_secret'] = Sign::getSign($param); + + $cache = empty($uid) ? 3600 : false; - return Yohobuy::get(Yohobuy::API_URL, $param); + return Yohobuy::get(Yohobuy::API_URL, $param, $cache); // 有缓存1小时 } /** @@ -105,16 +110,15 @@ class BrandData * @param integer $uid 用户id * @return array banner数据 */ - public static function getBrandBanner($brandId, $uid) + public static function getBrandBanner($brandId) { // 构建必传参数 $param = Yohobuy::param(); $param['brand_id'] = $brandId; - $param['uid'] = $uid; $param['method'] = 'app.brand.banner'; $param['client_secret'] = Sign::getSign($param); - return Yohobuy::get(Yohobuy::API_URL, $param); + return Yohobuy::get(Yohobuy::API_URL, $param, 3600); // 有缓存1小时 } /** @@ -161,5 +165,34 @@ class BrandData return Yohobuy::get(Yohobuy::API_URL, $param); } + + /** + * 查询商品数据 + * + * @param string $gender "1,3"表示男, "2,3"表示女, "1,2,3"表示全部 + * @param integer $brand 品牌Id + * @param integer $sort 品类查询sort参数 + * @param integer $color 颜色Id + * @param integer $size 尺码Id + * @param string $price 价格 + * @param string $p_d 折扣 + * @param string $order 排序方式,默认s_t_desc + * @param integer $limit 限制查询的数目,默认为60 + * @param integer $page 查询第几页,默认为第1页 + * @param integer $channel 表示频道号,1位男生,2为女生 + * @return array 品类商品数据 + */ + public static function filterBrandData($condition, $order = 's_t_desc', $limit = 60, $page = 1) + { + $param = Yohobuy::param(); + $param['method'] = 'app.search.brand'; + $param['page'] = $page; + $param['limit'] = $limit; + $param['order'] = $order; + $param += $condition; + $param['client_secret'] = Sign::getSign($param); + + return Yohobuy::get(Yohobuy::API_URL, $param); + } } diff --git a/library/LibModels/Wap/Category/ClassData.php b/library/LibModels/Wap/Category/ClassData.php index 41c9290..47917ae 100644 --- a/library/LibModels/Wap/Category/ClassData.php +++ b/library/LibModels/Wap/Category/ClassData.php @@ -1,4 +1,5 @@ <?php + namespace LibModels\Wap\Category; use Api\Yohobuy; @@ -15,62 +16,93 @@ use Api\Sign; */ class ClassData { - /** - * 获取品类数据 - * - * @return array 品类数据 - */ + + /** + * 获取品类数据 + * + * @return array 品类数据 + */ public static function getClassesData() { - // 构建必传参数 - $param = Yohobuy::param(); + // 构建必传参数 + $param = Yohobuy::param(); - $param['method'] = 'app.sort.get'; + $param['method'] = 'app.sort.get'; $param['client_secret'] = Sign::getSign($param); - + return Yohobuy::get(Yohobuy::API_URL, $param); } - /** - * 查询品类商品数据 - * - * @param string $gender "1,3"表示男, "2,3"表示女, "1,2,3"表示全部 - * @param integer $brand 品牌Id - * @param integer $sort 品类查询sort参数 - * @param integer $color 颜色Id - * @param integer $size 尺码Id - * @param string $price 价格 - * @param string $p_d 折扣 - * @param string $order 排序方式,默认s_t_desc - * @param integer $limit 限制查询的数目,默认为60 - * @param integer $page 查询第几页,默认为第1页 - * @param integer $channel 表示频道号,1位男生,2为女生 - * @return array 品类商品数据 - */ - public static function selectClassDetail($gender, $brand, $sort, $color, $size, $price, $p_d, $channel = 1, $order = 's_t_desc', $limit = 60, $page = 1) - { - // 构建必传参数 - $param = Yohobuy::param(); + /** + * 查询品类商品数据 + * + * @param string $gender "1,3"表示男, "2,3"表示女, "1,2,3"表示全部 + * @param integer $brand 品牌Id + * @param integer $sort 品类查询sort参数 + * @param integer $color 颜色Id + * @param integer $size 尺码Id + * @param string $price 价格 + * @param string $p_d 折扣 + * @param string $order 排序方式,默认s_t_desc + * @param integer $limit 限制查询的数目,默认为60 + * @param integer $page 查询第几页,默认为第1页 + * @param integer $channel 表示频道号,1位男生,2为女生 + * @return array 品类商品数据 + */ + public static function selectClassDetail($gender, $brand, $sort, $color, $size, $price, $p_d, $order = 's_t_desc', $limit = 60, $page = 1) + { + // 构建必传参数 + $param = Yohobuy::param(); - $selectItems = array( - 'gender' => $gender, - 'brand' => $brand, - 'sort' => $sort, - 'color' => $color, - 'size' => $size, - 'price' => $price, - 'p_d' => $p_d - ); - // 拉取筛选参数 - $queriedParams = array_filter($selectItems, function($v) {return $v !== null;}); + $selectItems = array( + 'gender' => $gender, + 'brand' => $brand, + 'sort' => $sort, + 'color' => $color, + 'size' => $size, + 'price' => $price, + 'p_d' => $p_d + ); + // 拉取筛选参数 + $queriedParams = array_filter($selectItems); $param += $queriedParams; - $param['method'] = 'app.search.category'; - $param['page'] = $page; - $param['limit'] = $limit; - $param['yh_channel'] = $channel; - $param['client_secret'] = Sign::getSign($param); - - return Yohobuy::get(Yohobuy::API_URL, $param); - } + $param['method'] = 'app.search.category'; + $param['page'] = $page; + $param['limit'] = $limit; + $param['gender'] = $gender; + $param['client_secret'] = Sign::getSign($param); + + return Yohobuy::get(Yohobuy::API_URL, $param); + } + + /** + * 查询商品数据 + * + * @param string $gender "1,3"表示男, "2,3"表示女, "1,2,3"表示全部 + * @param integer $brand 品牌Id + * @param integer $sort 品类查询sort参数 + * @param integer $color 颜色Id + * @param integer $size 尺码Id + * @param string $price 价格 + * @param string $p_d 折扣 + * @param string $order 排序方式,默认s_t_desc + * @param integer $limit 限制查询的数目,默认为60 + * @param integer $page 查询第几页,默认为第1页 + * @param integer $channel 表示频道号,1位男生,2为女生 + * @return array 品类商品数据 + */ + public static function filterClassData($condition, $order = 's_t_desc', $limit = 60, $page = 1) + { + $param = Yohobuy::param(); + $param['method'] = 'app.search.category'; + $param['page'] = $page; + $param['limit'] = $limit; + $param['order'] = $order; + $param += $condition; + $param['client_secret'] = Sign::getSign($param); + + return Yohobuy::get(Yohobuy::API_URL, $param); + } + } diff --git a/library/Plugin/Helpers.php b/library/Plugin/Helpers.php index f6d4c6b..7baf925 100644 --- a/library/Plugin/Helpers.php +++ b/library/Plugin/Helpers.php @@ -9,6 +9,36 @@ class Helpers { /** + * 构建网站的URL + * + * 备注:所有的URL构建都尽量使用该方法,便于以后维护. + * + * @param string $uri 如 "/passport/reg/index" + * @param array $param 参数项 array(key1 => value1, key2 => value2,) + * @param string $module 模块名 如"index"表示默认, "guang"表示逛,"list"表示商品列表,"search"表示搜索 + * @return string + */ + public static function url($uri, $param, $module = 'index') + { + $url = ''; + + switch ($module) { + case 'guang': // 逛 + $url = 'http://guang' . SUB_DOMAIN; + break; + case 'list': // 商品列表 + $url = 'http://list' . SUB_DOMAIN; + break; + case 'search': // 搜索 + $url = 'http://search' . SUB_DOMAIN; + break; + } + $url .= $uri . '?' . http_build_query($param, null, '&'); + + return $url; + } + + /** * 根据尺寸获得图片url * @param string $url 路径 * @param integer $width 图片宽度 @@ -29,13 +59,31 @@ class Helpers */ public static function getFilterUrl($url) { - $filter = strstr($url, 'openby:yohobuy=', true); + $filter = strtr(strstr($url, 'openby:yohobuy=', true), array('m.yohobuy.com' => SUB_DOMAIN)); if ($filter) { return rtrim(rtrim($filter, '?'), '&'); } else { return $url; } } + + /** + * 根据用户访问的COOKIE判断出性别 + * + * @return string + */ + public static function getGenderByCookie() + { + $cookie = isset($_COOKIE['_Channel']) ? $_COOKIE['_Channel'] : 'boys'; + switch (strval($cookie)) { + case 'boys': // 男 + return '1,3'; + case 'girls': // 女 + return '2,3'; + default: // 其它 + return '1,2,3'; + } + } /** * 格式化商品信息 @@ -87,11 +135,11 @@ class Helpers * * @param array $articleData 需要格式化的资讯数据 * @param bool $showTag 是否显示左上角标签 - * @param mixed $share 是否显示分享,在APP客户端里嵌入需要传url链接 + * @param mixed $isApp 是否显示分享,在APP客户端里嵌入需要传url链接 * @param bool $showAuthor 控制是否显示作者信息 * @return array | false */ - public static function formatArticle($articleData, $showTag = true, $share = false, $showAuthor = true) + public static function formatArticle($articleData, $showTag = true, $isApp = false, $showAuthor = true) { // 资讯ID不存在,则不显示 if (!isset($articleData['id'])) { @@ -102,7 +150,7 @@ class Helpers $result['id'] = $articleData['id']; $result['showTags'] = $showTag; $result['img'] = self::getImageUrl($articleData['src'], 640, 640); - $result['url'] = '/guang/detail/index?id=' . $articleData['id']; // @todo + $result['url'] = $isApp && !empty($articleData['url']) ? $articleData['url'] : '/info/index?id=' . $articleData['id']; $result['title'] = $articleData['title']; $result['text'] = $articleData['intro']; $result['publishTime'] = $articleData['publish_time']; @@ -113,7 +161,7 @@ class Helpers // 收藏 // $result['collect'] = array(); // $result['collect']['isCollected'] = isset($articleData['isFavor']) && $articleData['isFavor'] === 'Y'; - $result['share'] = $share; + $result['share'] = $isApp && isset($articleData['share']['url']) ? $articleData['share']['url'] : false; // 判断是否显示作者信息 if ($showAuthor) { diff --git a/script/nginx/conf/vhosts/yohobuy.conf b/script/nginx/conf/vhosts/yohobuy.conf index c177e00..4b27395 100644 --- a/script/nginx/conf/vhosts/yohobuy.conf +++ b/script/nginx/conf/vhosts/yohobuy.conf @@ -1,7 +1,7 @@ server { listen 80; - server_name m.dev.yohobuy.com; + server_name m.dev.yohobuy.com *.dev.yohobuy.com; #access_log /nginx/logs/access_test_yoho_cn.log combined; error_log /nginx/logs/error_test_yoho_cn.log warn; diff --git a/static/js/guang/info.js b/static/js/guang/info.js index 860cf3b..24b2bc2 100644 --- a/static/js/guang/info.js +++ b/static/js/guang/info.js @@ -95,7 +95,7 @@ function loadMore($container, opt) { loading = true; $.ajax({ type: 'GET', - url: ' /guang/list/page', + url: ' /guang/index/page', data: opt, success: function(data) { if (data === ' ') { diff --git a/template/m.yohobuy.com/actions/guang/index/index.phtml b/template/m.yohobuy.com/actions/guang/index/index.phtml new file mode 100644 index 0000000..11f7395 --- /dev/null +++ b/template/m.yohobuy.com/actions/guang/index/index.phtml @@ -0,0 +1,57 @@ +{{> layout/header}} +<div class="guang-list-page guang-page yoho-page"> + {{# guang}} + <div class="swiper-container"> + <div class="swiper-wrapper"> + {{# swiper}} + <div class="swiper-slide"> + <a href="{{url}}"> + <img class="swiper-lazy" data-src="{{img}}"> + </a> + <div class="swiper-lazy-preloader"></div> + </div> + {{/ swiper}} + </div> + <div class="swiper-pagination"></div> + </div> + + {{# author}} + <div id="author-infos" class="editor-header clearfix" data-id={{id}}> + <div class="avatar"> + <img src="{{avatar}}"> + </div> + <div class="text"> + <p class="name">{{name}}</p> + <p class="info">{{info}}</p> + </div> + </div> + {{/ author}} + + <ul id="guang-nav" class="guang-nav clearfix"> + {{# navs}} + <li class="guang-nav-item {{#focus}}focus{{/focus}}" data-type={{typeId}}> + {{type}} + </li> + {{/ navs}} + </ul> + + <div id="info-list" class="info-list-container"> + {{# infos}} + <div class="info-list {{^show}}hide{{/show}}"> + {{# info}} + {{> guang/info}} + {{/ info}} + </div> + {{/ infos}} + </div> + + <div id="load-more-info" class="load-more-info"> + <div class="loading status"> + 正在加载... + </div> + <span class="no-more status hide">没有更多啦</span> + </div> + <input id="gender" type="hidden" value={{gender}}> + {{/ guang}} +</div> +{{> layout/footer}} \ No newline at end of file diff --git a/template/m.yohobuy.com/actions/guang/index/list.phtml b/template/m.yohobuy.com/actions/guang/index/list.phtml new file mode 100644 index 0000000..1aa0e1d --- /dev/null +++ b/template/m.yohobuy.com/actions/guang/index/list.phtml @@ -0,0 +1,33 @@ +{{> layout/header}} +<div class="guang-list-page guang-page yoho-page"> + {{# guang}} + {{# author}} + <div id="author-infos" class="editor-header clearfix" data-id={{id}}> + <div class="avatar"> + <img src="{{avatar}}"> + </div> + <div class="text"> + <p class="name">{{name}}</p> + <p class="info">{{info}}</p> + </div> + </div> + {{/ author}} + + <div id="info-list" class="info-list"> + {{# infos}} + {{> guang/info}} + {{/ infos}} + </div> + + <div id="load-more-info" class="load-more-info"> + <div class="loading status"> + 正在加载... + </div> + <span class="no-more status hide">没有更多啦</span> + </div> + {{#if tag}} + <input id="tag" type="hidden" value={{tag}}> + {{/if}} + {{/ guang}} +</div> +{{> layout/footer}} \ No newline at end of file diff --git a/template/m.yohobuy.com/actions/guang/index/page.phtml b/template/m.yohobuy.com/actions/guang/index/page.phtml new file mode 100644 index 0000000..e112697 --- /dev/null +++ b/template/m.yohobuy.com/actions/guang/index/page.phtml @@ -0,0 +1,3 @@ +{{# infos}} + {{> guang/info}} +{{/ infos}} \ No newline at end of file diff --git a/template/m.yohobuy.com/actions/guang/info/index.phtml b/template/m.yohobuy.com/actions/guang/info/index.phtml new file mode 100644 index 0000000..65e6b69 --- /dev/null +++ b/template/m.yohobuy.com/actions/guang/info/index.phtml @@ -0,0 +1,157 @@ +{{>layout/header}} +<div class="guang-detail-page guang-page yoho-page"> + {{# guang}} + <div id="wrapper"> + <div id="scroller"> + {{# author}} + <div class="author" data-id={{id}}> + <a class="clearfix" href={{url}}> + <img class="avatar" src={{avatar}}> + <span class="name">{{name}}</span> + <span class="intro">{{intro}}</span> + </a> + </div> + {{/ author}} + + {{# detail}} + <div class="detail"> + <div class="post-title"> + <p class="title">{{title}}</p> + {{> guang/tvls}} + </div> + <div class="post-content"> + {{# content}} + {{#if text}} + <div class="post-block text-block"> + {{text}} + </div> + {{/if}} + + {{#if bigImage}} + <div class="post-block big-img-block"> + <img class="lazy" data-original={{bigImage}}> + </div> + {{/if}} + + {{#if smallImage}} + <div class="post-block small-img-block clearfix"> + {{# smallImage}} + <img class="lazy" data-original={{src}}> + {{/ smallImage}} + </div> + {{/if}} + + {{#if collocation}} + <div class="post-block collocation-block"> + <ul class="thumb-container"> + {{#each collocation}} + <li class="thumb {{#if @first}}focus{{/if}}"> + <img class="thumb-img lazy" data-original={{thumb}}> + <span class="clothe-type {{type}}"></span> + </li> + {{/each}} + </ul> + <div class="good-list clearfix"> + {{#each collocation}} + <div class="prod {{#unless @first}}hide{{/unless}}"> + {{# goods}} + {{> good}} + {{/ goods}} + </div> + {{/each}} + </div> + </div> + {{/if}} + + {{#if relatedReco}} + <div class="post-block related-reco-block clearfix"> + <h2>相关推荐</h2> + {{#if relatedReco.id}} + {{#with relatedReco}} + <div class="one-good"> + <img class="thumb lazy" data-original={{thumb}}> + <div class="content-container"> + <p> + <span class="reco-name">{{name}}</span> + </p> + <p class="price"> + <span class="sale-price {{^price}}no-price{{/price}}">¥{{salePrice}}</span> + {{#price}} + <span class="market-price">¥{{.}}</span> + {{/price}} + <a class="check-detail" href={{url}}> + 查看详情 + </a> + </p> + </div> + </div> + {{/with}} + {{^}} + <div class="good-list clearfix"> + {{# relatedReco}} + {{> good}} + {{/ relatedReco}} + </div> + {{/if}} + </div> + {{/if}} + {{/ content}} + </div> + </div> + {{/ detail}} + + {{#if relatedBrand}} + <div class="related-brand"> + <h2>相关品牌</h2> + <ul class="brand-list clearfix"> + {{# relatedBrand}} + <li class="brand"> + <a href={{url}}> + <div class="brand-logo"> + <img class="lazy" data-original={{thumb}}> + </div> + <p class="brand-name">{{name}}</p> + </a> + </li> + {{/ relatedBrand}} + </ul> + </div> + {{/if}} + + {{#if relatedTag}} + <div class="related-tag"> + <div class="tag-bg"></div> + <ul class="tag-list clearfix"> + {{# relatedTag}} + <li> + <a href={{url}}>{{name}}</a> + </li> + {{/ relatedTag}} + </ul> + </div> + {{/if}} + + {{#if relatedInfo}} + <div class="related-info"> + <h2>相关文章</h2> + <ul class="info-list"> + {{# relatedInfo}} + <li> + <a class="clearfix" href={{url}}> + <img class="lazy {{#if squareThumb}}square{{/if}}" data-original={{thumb}}> + <span class="title">{{title}}</span> + <span class="publish-time"> + <i class="iconfont"></i> + {{publishTime}} + </span> + </a> + </li> + {{/ relatedInfo}} + </ul> + </div> + {{/if}} + </div> + </div> + {{/ guang}} +</div> +{{> layout/footer}} \ No newline at end of file diff --git a/template/m.yohobuy.com/actions/index/search/list.phtml b/template/m.yohobuy.com/actions/index/search/list.phtml new file mode 100644 index 0000000..e40873f --- /dev/null +++ b/template/m.yohobuy.com/actions/index/search/list.phtml @@ -0,0 +1,127 @@ +{{> layout/header}} +<div class="good-list-page yoho-page"> + {{# goodList}} + {{# search}} + <div id="search-input" class="search-input"> + <form action="/product/list/index" method="get"> + <i class="search-icon iconfont"></i> + <input type="text" value={{default}} name="query"> + <i class="clear-input iconfont hide"></i> + <button id="search" class="search" type="submit">搜索</button> + </form> + </div> + {{/ search}} + + {{# brandWay}} + <div class="brand-way"> + <a href={{url}}> + <img class="brand-thumb" src={{thumb}}> + <span>{{name}}</span> + <span class="entry"> + 进入品牌 + <i class="iconfont"></i> + </span> + </a> + </div> + {{/ brandWay}} + + {{# brandHome}} + <div id="brand-header" class="brand-header" data-id={{id}}> + <img class="lazy" data-original={{banner}}> + <a class="btn-intro" href="javascript:void(0);"> + 品牌介绍 + </a> + <a class="btn-col" href="javascript:void(0);"> + <span class="iconfont"></span> + 收藏 + </a> + </div> + <div id="intro-box" class="brand-intro-box hide"> + <div id="brand-intro" class="brand-intro"> + <h2>品牌介绍</h2> + <div class="con"> + {{{intro}}} + </div> + <p class="fo"> + <span></span> + 100%品牌授权正品 + </p> + <span class="iconfont close-intro"></span> + </div> + </div> + {{/ brandHome}} + + <ul id="list-nav" class="list-nav clearfix"> + <li class="new active"> + <a href="javascript:void(0);"> + 最新 + <span class="iconfont cur"></span> + </a> + </li> + <li class="price"> + <a href="javascript:void(0);"> + 价格 + <span class="icon"> + <i class="iconfont up"></i> + <i class="iconfont down cur"></i> + </span> + </a> + </li> + <li class="discount"> + <a href="javascript:void(0);"> + 折扣 + <span class="icon"> + <i class="iconfont up"></i> + <i class="iconfont down cur"></i> + </span> + </a> + </li> + <li class="filter"> + <a href="javascript:void(0);"> + 筛选 + <span class="iconfont"></span> + </a> + </li> + </ul> + <div id="goods-container" class="goods-container"> + <div class="new-goods container"> + {{# new}} + {{> good}} + {{/ new}} + </div> + <div class="price-goods container hide"></div> + <div class="discount-goods container hide"></div> + + {{> filter}} + </div> + + {{#if brand}} + <input id="brand" type="hidden" value={{brand}}> + {{/if}} + + {{#if gender}} + <input id="gender" type="hidden" value={{gender}}> + {{/if}} + + {{#if msort}} + <input id="msort" type="hidden" value={{msort}}> + {{/if}} + + {{#if color}} + <input id="color" type="hidden" value={{color}}> + {{/if}} + + {{#if size}} + <input id="size" type="hidden" value={{size}}> + {{/if}} + + {{#if price}} + <input id="price" type="hidden" value={{price}}> + {{/if}} + + {{#if discount}} + <input id="discount" type="hidden" value={{discount}}> + {{/if}} + {{/ goodList}} +</div> +{{> layout/footer}} \ No newline at end of file diff --git a/template/m.yohobuy.com/actions/index/search/page.phtml b/template/m.yohobuy.com/actions/index/search/page.phtml new file mode 100644 index 0000000..78c71c3 --- /dev/null +++ b/template/m.yohobuy.com/actions/index/search/page.phtml @@ -0,0 +1,3 @@ +{{# new}} + {{> good}} +{{/ new}} \ No newline at end of file diff --git a/template/m.yohobuy.com/actions/product/index/index.phtml b/template/m.yohobuy.com/actions/product/index/index.phtml new file mode 100644 index 0000000..f49f7f1 --- /dev/null +++ b/template/m.yohobuy.com/actions/product/index/index.phtml @@ -0,0 +1,127 @@ +{{> layout/header}} +<div class="good-list-page yoho-page"> + {{# goodList}} + {{# search}} + <div id="search-input" class="search-input"> + <form action="/product/list/index" method="get"> + <i class="search-icon iconfont"></i> + <input type="text" value={{default}} name="query"> + <i class="clear-input iconfont hide"></i> + <button id="search" class="search" type="submit">搜索</button> + </form> + </div> + {{/ search}} + + {{# brandWay}} + <div class="brand-way"> + <a href={{url}}> + <img class="brand-thumb" src={{thumb}}> + <span>{{name}}</span> + <span class="entry"> + 进入品牌 + <i class="iconfont"></i> + </span> + </a> + </div> + {{/ brandWay}} + + {{# brandHome}} + <div id="brand-header" class="brand-header" data-id={{id}}> + <img class="lazy" data-original={{banner}}> + <a class="btn-intro" href="javascript:void(0);"> + 品牌介绍 + </a> + <a class="btn-col" href="javascript:void(0);"> + <span class="iconfont"></span> + 收藏 + </a> + </div> + <div id="intro-box" class="brand-intro-box hide"> + <div id="brand-intro" class="brand-intro"> + <h2>品牌介绍</h2> + <div class="con"> + {{{intro}}} + </div> + <p class="fo"> + <span></span> + 100%品牌授权正品 + </p> + <span class="iconfont close-intro"></span> + </div> + </div> + {{/ brandHome}} + + <ul id="list-nav" class="list-nav clearfix"> + <li class="new active"> + <a href="javascript:void(0);"> + 最新 + <span class="iconfont cur"></span> + </a> + </li> + <li class="price"> + <a href="javascript:void(0);"> + 价格 + <span class="icon"> + <i class="iconfont up"></i> + <i class="iconfont down cur"></i> + </span> + </a> + </li> + <li class="discount"> + <a href="javascript:void(0);"> + 折扣 + <span class="icon"> + <i class="iconfont up"></i> + <i class="iconfont down cur"></i> + </span> + </a> + </li> + <li class="filter"> + <a href="javascript:void(0);"> + 筛选 + <span class="iconfont"></span> + </a> + </li> + </ul> + <div id="goods-container" class="goods-container"> + <div class="new-goods container"> + {{# new}} + {{> good}} + {{/ new}} + </div> + <div class="price-goods container hide"></div> + <div class="discount-goods container hide"></div> + + {{> filter}} + </div> + + {{#if brand}} + <input id="brand" type="hidden" value={{brand}}> + {{/if}} + + {{#if gender}} + <input id="gender" type="hidden" value={{gender}}> + {{/if}} + + {{#if msort}} + <input id="msort" type="hidden" value={{msort}}> + {{/if}} + + {{#if color}} + <input id="color" type="hidden" value={{color}}> + {{/if}} + + {{#if size}} + <input id="size" type="hidden" value={{size}}> + {{/if}} + + {{#if price}} + <input id="price" type="hidden" value={{price}}> + {{/if}} + + {{#if discount}} + <input id="discount" type="hidden" value={{discount}}> + {{/if}} + {{/ goodList}} +</div> +{{> layout/footer}} \ No newline at end of file diff --git a/template/m.yohobuy.com/actions/search/index/index.phtml b/template/m.yohobuy.com/actions/search/index/index.phtml new file mode 100644 index 0000000..f49f7f1 --- /dev/null +++ b/template/m.yohobuy.com/actions/search/index/index.phtml @@ -0,0 +1,127 @@ +{{> layout/header}} +<div class="good-list-page yoho-page"> + {{# goodList}} + {{# search}} + <div id="search-input" class="search-input"> + <form action="/product/list/index" method="get"> + <i class="search-icon iconfont"></i> + <input type="text" value={{default}} name="query"> + <i class="clear-input iconfont hide"></i> + <button id="search" class="search" type="submit">搜索</button> + </form> + </div> + {{/ search}} + + {{# brandWay}} + <div class="brand-way"> + <a href={{url}}> + <img class="brand-thumb" src={{thumb}}> + <span>{{name}}</span> + <span class="entry"> + 进入品牌 + <i class="iconfont"></i> + </span> + </a> + </div> + {{/ brandWay}} + + {{# brandHome}} + <div id="brand-header" class="brand-header" data-id={{id}}> + <img class="lazy" data-original={{banner}}> + <a class="btn-intro" href="javascript:void(0);"> + 品牌介绍 + </a> + <a class="btn-col" href="javascript:void(0);"> + <span class="iconfont"></span> + 收藏 + </a> + </div> + <div id="intro-box" class="brand-intro-box hide"> + <div id="brand-intro" class="brand-intro"> + <h2>品牌介绍</h2> + <div class="con"> + {{{intro}}} + </div> + <p class="fo"> + <span></span> + 100%品牌授权正品 + </p> + <span class="iconfont close-intro"></span> + </div> + </div> + {{/ brandHome}} + + <ul id="list-nav" class="list-nav clearfix"> + <li class="new active"> + <a href="javascript:void(0);"> + 最新 + <span class="iconfont cur"></span> + </a> + </li> + <li class="price"> + <a href="javascript:void(0);"> + 价格 + <span class="icon"> + <i class="iconfont up"></i> + <i class="iconfont down cur"></i> + </span> + </a> + </li> + <li class="discount"> + <a href="javascript:void(0);"> + 折扣 + <span class="icon"> + <i class="iconfont up"></i> + <i class="iconfont down cur"></i> + </span> + </a> + </li> + <li class="filter"> + <a href="javascript:void(0);"> + 筛选 + <span class="iconfont"></span> + </a> + </li> + </ul> + <div id="goods-container" class="goods-container"> + <div class="new-goods container"> + {{# new}} + {{> good}} + {{/ new}} + </div> + <div class="price-goods container hide"></div> + <div class="discount-goods container hide"></div> + + {{> filter}} + </div> + + {{#if brand}} + <input id="brand" type="hidden" value={{brand}}> + {{/if}} + + {{#if gender}} + <input id="gender" type="hidden" value={{gender}}> + {{/if}} + + {{#if msort}} + <input id="msort" type="hidden" value={{msort}}> + {{/if}} + + {{#if color}} + <input id="color" type="hidden" value={{color}}> + {{/if}} + + {{#if size}} + <input id="size" type="hidden" value={{size}}> + {{/if}} + + {{#if price}} + <input id="price" type="hidden" value={{price}}> + {{/if}} + + {{#if discount}} + <input id="discount" type="hidden" value={{discount}}> + {{/if}} + {{/ goodList}} +</div> +{{> layout/footer}} \ No newline at end of file diff --git a/template/m.yohobuy.com/actions/search/index/list.phtml b/template/m.yohobuy.com/actions/search/index/list.phtml new file mode 100644 index 0000000..78c71c3 --- /dev/null +++ b/template/m.yohobuy.com/actions/search/index/list.phtml @@ -0,0 +1,3 @@ +{{# new}} + {{> good}} +{{/ new}} \ No newline at end of file diff --git a/yohobuy/m.yohobuy.com/application/Bootstrap.php b/yohobuy/m.yohobuy.com/application/Bootstrap.php index 30dd73d..d4da7af 100644 --- a/yohobuy/m.yohobuy.com/application/Bootstrap.php +++ b/yohobuy/m.yohobuy.com/application/Bootstrap.php @@ -16,11 +16,11 @@ use Yaf\Application; use Yaf\Registry; use Yaf\Loader; use Yaf\Config; - use Plugin\TemplateLayout; class Bootstrap extends Bootstrap_Abstract { + private $_config; /** @@ -64,16 +64,25 @@ class Bootstrap extends Bootstrap_Abstract */ public function _initRoute(Dispatcher $dispatcher) { - /* 根据域名的级别,选择对应的模块 */ $hostParts = explode('.', $dispatcher->getRequest()->getServer('HTTP_HOST', '')); $level = count($hostParts) - 1; + + /* 根据域名的级别,设置默认的模块、控制器、方法 */ $module = 'Index'; + $controller = 'Index'; + $action = 'Index'; // 三级域名 - if ($level === 3) { - switch (strtolower(strval($hostParts[0]))) { - case 'm': - case 'new': // 默认 - $module = 'Index'; + if (3 === $level) { + $subDomain = strval($hostParts[0]); + switch (strtolower($subDomain)) { + case 'm': // 老版(到频道选择) + break; + case 'new': // 原新版(到男生首页) + $controller = 'Boys'; + break; + case 'search': // 搜索 + $controller = 'Search'; + $action = 'List'; break; case 'guang': // 逛 $module = 'Guang'; @@ -82,21 +91,24 @@ class Bootstrap extends Bootstrap_Abstract $module = 'Product'; break; default: // 其它(识别为品牌) - $module = 'Brand'; + $module = 'Product'; + $action = 'Brand'; + $dispatcher->getRequest()->setParam('named', $subDomain); break; } } $dispatcher->getRequest()->module = $module; - + $dispatcher->getRequest()->controller = $controller; + $dispatcher->getRequest()->action = $action; + /* 根据对应模块的配置,添加相应的路由规则 */ - $iniFile = APPLICATION_PATH . '/configs/routes.' . strtolower($module) . 'ini'; + $iniFile = APPLICATION_PATH . '/configs/routes.' . strtolower($module) . '.ini'; if (file_exists($iniFile)) { $config = new Config\Ini($iniFile); if (isset($config->routes)) { $dispatcher->getRouter()->addConfig($config->routes); } } - } /** @@ -107,15 +119,15 @@ class Bootstrap extends Bootstrap_Abstract { // 关闭自动渲染模板 $dispatcher->autoRender(false); - + // 判断到不是AJAX请求时, 使用自定义的模板渲染 (Mustache or Handlebars) //if (!$dispatcher->getRequest()->isXmlHttpRequest()) { - $layout = new TemplateLayout(); - $layout->setScriptPath($this->_config->application->template->path); - $dispatcher->setView($layout); + $layout = new TemplateLayout(); + $layout->setScriptPath($this->_config->application->template->path); + $dispatcher->setView($layout); //} } - + // /** // * 初始化第三方包 // * @param Dispatcher $dispatcher @@ -126,5 +138,4 @@ class Bootstrap extends Bootstrap_Abstract // require $this->_config->composer->path . '/vendor/autoload.php'; // } // } - } diff --git a/yohobuy/m.yohobuy.com/application/controllers/Search.php b/yohobuy/m.yohobuy.com/application/controllers/Search.php index 37fa3ff..37b650b 100644 --- a/yohobuy/m.yohobuy.com/application/controllers/Search.php +++ b/yohobuy/m.yohobuy.com/application/controllers/Search.php @@ -7,6 +7,9 @@ use LibModels\Wap\Product\SearchData; */ class SearchController extends AbstractAction { + /** + * 搜索首页 + */ public function indexAction() { $data = array( @@ -41,7 +44,142 @@ class SearchController extends AbstractAction ) ) ); - $this->_view->display('index', array('search' => $data, 'searchPage' => true, 'pageFooter' => true)); + $this->_view->display('index', array( + '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; + } + + // 如果存在搜索字符串就显示搜索栏 + if(!is_null($query) && $classFlag === false) + { + $data['search'] = array( + 'default' => $query + ); + } + + // 转换性别 + $this->genderTrans($gender); + + // 查询数据 + $listData = SearchData::searchLiDatas($query, $brand, $gender, $p_d, $misort, $msort); + // 处理返回的数据 + 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); + } + + $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); + + // 转换排序方式 + $order = $this->get('order', null); + $type = $this->get('type', ''); + switch ($type) { + case 'price': + $order = ($order == 0) ? 's_p_desc' : 's_p_asc'; + break; + case 'discount': + $order = ($order == 0) ? 'p_d_desc' : 'p_d_asc'; + break; + case 'newest': + default: + $order = ($order == 0) ? 's_t_desc' : 's_t_asc'; + break; + } + + $data = array(); + // 查询数据 + $listData = SearchData::searchLiDatas($query, $brand, $gender, $color, $size, $price, $p_d, $sort, $order); + // 处理返回的数据 + if (isset($listData['code']) && $listData['code'] === 200) { + $tmpData = $listData['data']; + + unset($tmpData['filter']);// 不要筛选条件的数据 + $data = ListProcess::getListData($tmpData); + } + + if(empty($data)) + { + echo ' '; + } + else + { + $this->_view->display('page', $data); + } + } } /** diff --git a/yohobuy/m.yohobuy.com/application/models/Category/Brand.php b/yohobuy/m.yohobuy.com/application/models/Category/Brand.php index 0b79ecd..e079236 100644 --- a/yohobuy/m.yohobuy.com/application/models/Category/Brand.php +++ b/yohobuy/m.yohobuy.com/application/models/Category/Brand.php @@ -86,7 +86,7 @@ class BrandModel $list['name'] = $row['brand_name']; $list['isHot'] = ($row['is_hot'] === 'Y') ? true : false; $list['isNew'] = ($row['is_show_new'] === 'Y') ? true : false; - $list['url'] = 'http://' . $row['brand_domain'] . '.' . OLD_DOMAIN; + $list['url'] = 'http://' . $row['brand_domain'] . SUB_DOMAIN; $build['list'][] = $list; } $result['brandList'][] = $build; diff --git a/yohobuy/m.yohobuy.com/application/models/Category/Class.php b/yohobuy/m.yohobuy.com/application/models/Category/Class.php index 8f95e5b..ad1d135 100644 --- a/yohobuy/m.yohobuy.com/application/models/Category/Class.php +++ b/yohobuy/m.yohobuy.com/application/models/Category/Class.php @@ -18,7 +18,7 @@ use Plugin\Cache; */ class ClassModel { - + /** * 根据频道获取品牌一览数据 * @@ -41,20 +41,17 @@ class ClassModel $num = 1; $data = ClassData::getClassesData(); - if(!isset($data['code']) || $data['code'] !== 200) - { + if (!isset($data['code']) || $data['code'] !== 200) { break; } - if(!isset($data['data'])) - { + if (!isset($data['data'])) { break; } - foreach ($data['data'] as $k => $v){ - $oneClass = array('name'=>$k, 'ca'=>array()); - if($num === 1) - { + foreach ($data['data'] as $k => $v) { + $oneClass = array('name' => $k, 'ca' => array()); + if ($num === 1) { $oneClass['focus'] = true; } @@ -66,8 +63,8 @@ class ClassModel $subitem = array(); $subitem['name'] = $value['category_name']; $subitem['id'] = $value['relation_parameter']['sort']; - $subitem['url'] = '/product/list/class?sort='.$value['relation_parameter']['sort']; - + $subitem['url'] = '/product/list/class?sort=' . $value['relation_parameter']['sort']; + $item['sub'][] = $subitem; } @@ -88,13 +85,11 @@ class ClassModel Cache::set(CacheConfig::KEY_CATEGORY_CLASSES_DATA, $classes); } } - - }while(false); + } while (false); return $classes; } - /** * 返回品类构成的数组 * @@ -115,12 +110,12 @@ class ClassModel return $classes; } - /** * 自定义array_column函数 * * @return array 返回数组中指定的一列组成的数组 */ + /** * 自定义array_column函数 * @param array $input 需要取出数组咧的多维数组 @@ -132,19 +127,18 @@ class ClassModel { $array = array(); foreach ($input as $value) { - if ( ! isset($value[$columnKey])) { + if (!isset($value[$columnKey])) { trigger_error("Key \"$columnKey\" does not exist in array"); return false; } if (is_null($indexKey)) { $array[] = $value[$columnKey]; - } - else { - if ( ! isset($value[$indexKey])) { + } else { + if (!isset($value[$indexKey])) { trigger_error("Key \"$indexKey\" does not exist in array"); return false; } - if ( ! is_scalar($value[$indexKey])) { + if (!is_scalar($value[$indexKey])) { trigger_error("Key \"$indexKey\" does not contain scalar value"); return false; } @@ -152,7 +146,6 @@ class ClassModel } } return $array; - } - + } diff --git a/yohobuy/m.yohobuy.com/application/models/Guang/Index.php b/yohobuy/m.yohobuy.com/application/models/Guang/Index.php new file mode 100644 index 0000000..78a8e59 --- /dev/null +++ b/yohobuy/m.yohobuy.com/application/models/Guang/Index.php @@ -0,0 +1,98 @@ +<?php + +namespace Guang; + +use LibModels\Wap\Guang\ListData; +use Plugin\Helpers; + +/** + * + * @name IndexModel + * @package models/Guang + * @copyright yoho.inc + * @version 1.0 (2015-10-27 11:31:49) + * @author fei.hong <fei.hong@yoho.cn> + */ +class IndexModel +{ + + /** + * 获取逛首页分类内容列表 + * + * @param string $gender "1,3"表示男, "2,3"表示女 + * @param int channel APP客户端标识 1表示男,2:表示女,3:潮童,4:创意生活 + * @param int type 分类ID 0:最新,1:话题,2:搭配,3:潮人,4:潮品,5:小贴士 + * @param int $uid 用户ID + * @param string $udid 客户端唯一标识 + * @param int $page 分页第几页, 默认第1页 + * @return array + */ + public static function getArticleGroup($gender, $type, $uid, $udid, $page = 1) + { + // 逛首页的分类名称列表 + $category = ListData::category(); + $articleGroup = array(); + + switch ($gender) { + case '1,3': // 男 + $articleGroup = ListData::articleGroup($category['data'], '1,3', $uid, $udid, $page); + break; + case '2,3': // 女 + $articleGroup = ListData::articleGroup($category['data'], '2,3', $uid, $udid, $page); + break; + default: // 其它所有 + $articleGroup = ListData::articleGroup($category['data'], '1,2,3', $uid, $udid, $page); + break; + } + + $data = array(); + $build = array(); + + // 模板中使用JS的标识 + $data['guangHome'] = true; + + // 顶部的分类列表 + foreach ($category['data'] as $value) { + $build = array(); + $build['typeId'] = $value['id']; + $build['type'] = $value['name']; + $build['focus'] = ($value['id'] == $type); + $data['navs'][] = $build; + } + + $data['guang']['swiper'] = array(); + $data['guang']['infos'] = array(); + foreach ($articleGroup as $id => $value) { + // 判断是否有内容 + if (empty($value['list'])) { + continue; + } + + // 轮番广告 + if ($id == 0) { + $build = array(); + foreach ($value['list']['adlist'] as $banner) { + $build['url'] = Helpers::getFilterUrl($banner['url']); + $build['img'] = Helpers::getImageUrl($banner['src'], 830, 327); + $data['guang']['swiper'][] = $build; + } + } + + // 内容列表 + $build = array(); + $build['show'] = ($id == $type); + foreach ($value['list']['artList'] as $article) { + $build['info'][] = Helpers::formatArticle($article, true, false); + } + $data['guang']['infos'][] = $build; + } + + // 分页需要参数 + $data['guang']['gender'] = $gender; + + $category = array(); + + return $data; + } + +} diff --git a/yohobuy/m.yohobuy.com/application/models/Index/Side.php b/yohobuy/m.yohobuy.com/application/models/Index/Side.php index ec1c59f..4ed6443 100644 --- a/yohobuy/m.yohobuy.com/application/models/Index/Side.php +++ b/yohobuy/m.yohobuy.com/application/models/Index/Side.php @@ -47,7 +47,7 @@ class SideModel $result[$key]['textCn'] = $value['sort_name']; $result[$key]['textEn'] = $value['sort_name_en']; $result[$key]['styleClass'] = strtolower($value['sort_name_en']); - $result[$key]['url'] = $value['sort_url']; + $result[$key]['url'] = Helpers::getFilterUrl($value['sort_url']); $result[$key]['img'] = Helpers::getImageUrl($value['sort_ico'], 60, 60); } } diff --git a/yohobuy/m.yohobuy.com/application/models/Product/List.php b/yohobuy/m.yohobuy.com/application/models/Product/List.php new file mode 100644 index 0000000..f01ad7d --- /dev/null +++ b/yohobuy/m.yohobuy.com/application/models/Product/List.php @@ -0,0 +1,175 @@ +<?php + +namespace Product; + +use Configs\CacheConfig; +use LibModels\Wap\Category\ClassData; +use LibModels\Wap\Category\BrandData; +use Plugin\DataProcess\ListProcess; +use Plugin\Helpers; +use Plugin\Cache; + +/** + * 商品列表相关的模板数据模型 + * + * @name ListModel + * @package models/Product + * @copyright yoho.inc + * @version 1.0 (2015-10-27 16:27:54) + * @author fei.hong <fei.hong@yoho.cn> + */ +class ListModel +{ + + /** + * 获取品类商品列表数据 + * + * @param array $condition 条件 + * @return array | false + */ + public static function getClassData($condition) + { + $result = array(); + + if (USE_CACHE) { + $key = CacheConfig::KEY_ACTION_PRODUCT_INDEX; + if (!empty($condition)) { + $key .= http_build_query($condition, null, '&'); + } + // 先尝试获取一级缓存(master), 有数据则直接返回. + $result = Cache::get($key, 'master'); + if (!empty($result)) { + return $result; + } + } + + // 调用接口查询数据 + $listData = ClassData::filterClassData($condition); + // 处理返回的数据 + if (isset($listData['code']) && $listData['code'] === 200) { + $result = ListProcess::getListData($listData['data']); + } + + if (USE_CACHE) { + // 接口调用异常时, 不害怕,从我们的二级缓存(slave)里再取数据. + if (empty($result)) { + $result = Cache::get($key, 'slave'); + } + // 接口调用正常,数据封装完成, 则设置一级(master)和二级(slave)数据缓存 + else { + Cache::set($key, $result, 600); // 缓存10分钟 + } + } + + return $result; + } + + /** + * 获取品牌商品列表数据 + * + * @return array + */ + public static function getBrandData($condition, $id, $uid, &$title) + { + $result = array(); + + // 获取品牌介绍信息, 有缓存1小时 + $introData = BrandData::getBrandIntro($id, $uid); + if (isset($introData['data']['brand_intro'])) { + $result['brandHome']['id'] = $id; + $result['brandHome']['intro'] = $introData['data']['brand_intro']; + // 顶部导航的标题 + $title = isset($introData['data']['brand_name']) ? $introData['data']['brand_name'] : ''; + } + + // 获取品牌banner的数据, 有缓存1小时 + $bannerData = BrandData::getBrandBanner($id); + if (isset($bannerData['data']['banner'])) { + $result['brandHome']['banner'] = Helpers::getImageUrl($bannerData['data']['banner'], 640, 75); + } + + 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'])) { + return $result; + } + } + + // 调用接口查询数据 + $listData = BrandData::filterBrandData($condition); + // 处理返回的数据 + if (isset($listData['code']) && $listData['code'] === 200) { + $result['goodList'] = ListProcess::getListData($listData['data']); + } + + if (USE_CACHE) { + // 接口调用异常时, 不害怕,从我们的二级缓存(slave)里再取数据. + if (empty($result['goodList'])) { + $result['goodList'] = Cache::get($key, 'slave'); + } + // 接口调用正常,数据封装完成, 则设置一级(master)和二级(slave)数据缓存 + else { + Cache::set($key, $result['goodList'], 600); // 缓存10分钟 + } + } + + return $result; + } + + /** + * 获取所有的品牌名称列表 + * + * @return array( + * 品牌ID => 品牌命名(domain) + * ) + */ + public static function getAllBrandDomains() + { + $result = array(); + + if (USE_CACHE) { + $key = CacheConfig::KEY_ACTION_PRODUCT_BRAND_ALLNAMES; + // 先尝试获取一级缓存(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['id'] ] = $row['brand_domain'] ; + } + } + } + // 更多关联的品牌 + if (!empty($brand['data']['morebrands'])) { + foreach ($brand['data']['morebrands'] as $row) { + $result[ $row['id'] ] = $row['brand_domain']; + } + } + $brand = array(); + + if (USE_CACHE) { + // 接口调用异常时, 不害怕,从我们的二级缓存(slave)里再取数据. + if (empty($result)) { + $result = Cache::get($key, 'slave'); + } + // 接口调用正常,数据封装完成, 则设置一级(master)和二级(slave)数据缓存 + else { + Cache::set($key, $result, 600); // 缓存10分钟 + } + } + + return $result; + } + +} diff --git a/yohobuy/m.yohobuy.com/application/models/Product/Newsale.php b/yohobuy/m.yohobuy.com/application/models/Product/Newsale.php index 5621b7f..4e327dd 100644 --- a/yohobuy/m.yohobuy.com/application/models/Product/Newsale.php +++ b/yohobuy/m.yohobuy.com/application/models/Product/Newsale.php @@ -65,7 +65,7 @@ class NewsaleModel * * @return array */ - public static function getSaleFocus() + public static function getSaleFocus($channel) { $result = array(); diff --git a/yohobuy/m.yohobuy.com/application/modules/Category/controllers/Class.php b/yohobuy/m.yohobuy.com/application/modules/Category/controllers/Class.php index 081a10e..e3337cd 100644 --- a/yohobuy/m.yohobuy.com/application/modules/Category/controllers/Class.php +++ b/yohobuy/m.yohobuy.com/application/modules/Category/controllers/Class.php @@ -19,11 +19,12 @@ class ClassController extends AbstractAction 'navTitle' => '商品分类' ), 'category' => array( - "class" => $classes + 'class' => $classes ) ); - $this->_view->assign('title', 'YOHO!有货'); + $this->setTitle('商品分类'); + $this->_view->display('index', $data); } } \ No newline at end of file diff --git a/yohobuy/m.yohobuy.com/application/modules/Guang/controllers/Index.php b/yohobuy/m.yohobuy.com/application/modules/Guang/controllers/Index.php new file mode 100644 index 0000000..2b891b1 --- /dev/null +++ b/yohobuy/m.yohobuy.com/application/modules/Guang/controllers/Index.php @@ -0,0 +1,192 @@ +<?php + +use Action\AbstractAction; +use LibModels\Wap\Guang\ListData; +use Plugin\Helpers; + +/** + * 逛首页、列表页、编辑页 + */ +class IndexController extends AbstractAction +{ + + /** + * 首页 + * + * @param int id 分类ID 0:最新,1:话题,2:搭配,3:潮人,4:潮品,5:小贴士 + * @param string gender '1,3'表示男,'2,3'表示女, 默认为所有 + */ + public function indexAction() + { + $this->setTitle('逛'); + $this->setNavHeader('逛', true, SITE_MAIN); + + $uid = $this->getUid(); + $udid = $this->getUdid(); + $type = $this->get('id', 0); + $gender = $this->get('gender'); + + $this->_view->display('index', Guang\IndexModel::getArticleGroup($gender, $type, $uid, $udid)); + } + + /** + * 列表页 + * + * @param string tag 标签名称 + * @param int yh_channel APP客户端标识 1表示男,2:表示女,3:潮童,4:创意生活 + */ + public function tagAction() + { + $uid = $this->getUid(); + $udid = $this->getUdid(); + $tag = $this->get('query'); + $channel = $this->get('yh_channel'); + + // 标签聚合内容列表 + $article = ListData::article('', 0, $uid, $udid, 1, $tag); + // 标签聚合内容不存在, 跳到错误页面 + if (empty($article['data']['list']['artList'])) { + $this->error(); + } + // 标识是不是APP客户端 + $isApp = isset($channel); + + $this->setTitle($tag); + if (!$isApp) { + $this->setNavHeader($tag, true, SITE_MAIN); + } + + $data = array(); + // 模板中使用JS的标识 + $data['guangList'] = true; + + // 构建资讯文章内容 + $build = array(); + foreach ($article['data']['list']['artList'] as $article) { + $build[] = Helpers::formatArticle($article, true, $isApp); + } + $data['guang']['infos'] = $build; + + // 分页需要的参数 + $data['guang']['tag'] = $tag; + + $this->_view->display('list', $data); + } + + /** + * 编辑页 + * + * @param int id 作者ID + * @param int yh_channel APP客户端标识 1表示男,2:表示女,3:潮童,4:创意生活 + */ + public function editorAction() + { + $id = $this->get('id'); + $channel = $this->get('yh_channel'); + + // 获取作者信息 + $author = ListData::author($id); + // 作者信息不存在,则跳到错误页面 + if (!isset($author['name'])) { + $this->error(); + } + // 标识是不是APP客户端 + $isApp = isset($channel); + + $this->setTitle('编辑简介'); + if (!$isApp) { + $this->setNavHeader('编辑简介', true, SITE_MAIN); + } + + $uid = $this->getUid(); + $udid = $this->getUdid(); + + $data = array(); + // 模板中使用JS的标识 + $data['guangList'] = true; + + // 作者信息 + $data['author'] = array(); + $data['author']['avatar'] = Helpers::getImageUrl($author['avatar'], 100, 100); + $data['author']['name'] = $author['name']; + $data['author']['info'] = $author['author_desc']; + $data['author']['id'] = $id; + + // 标签聚合内容列表 + $article = ListData::article('', 0, $uid, $udid, 1, null, $id); + // 构建资讯文章内容 + if (!empty($article['data']['list']['artList'])) { + $build = array(); + foreach ($article['data']['list']['artList'] as $article) { + $build[] = Helpers::formatArticle($article, true, false, false); + } + $data['guang']['infos'] = $build; + } + + $this->_view->display('list', $data); + } + + /** + * 逛列表页面的资讯分页 + * + * 逛首页、标签页、编辑页资讯列表 + * + * @param string tag 标签名称, 没有传空或不传 + * @param int type 逛首页的分类ID + * @param int page 分页的页码 + * @param string gender "1,2,3"表示所有, "1,3"表示男, "2,3"表示女 + * @param int authorId 作者ID + * @return html + */ + public function pageAction() + { + do { + /* 判断是不是AJAX请求 */ + if (!$this->isAjax()) { + break; + } + + /* 判断参数是否有效 */ + $tag = $this->get('tag'); + $sortId = $this->get('type', 0); + $page = $this->get('page'); + $gender = $this->get('gender'); + $authorId = $this->get('authorId'); + $showAuthor = true; + if (!empty($sortId) && !is_numeric($sortId)) { + break; + } + if (!empty($page) && !is_numeric($page)) { + break; + } + if (!empty($authorId) && is_numeric($authorId)) { + $showAuthor = false; + } + + /* 获取资讯文章列表 */ + $uid = $this->getUid(); + $udid = $this->getUdid(); + $page = intval($page) + 1; + $article = ListData::article($gender, $sortId, $uid, $udid, $page, $tag, $authorId); + if (empty($article['data']['list']['artList'])) { + break; + } + + /* 构建资讯文章内容 */ + $data = array(); + $build = array(); + foreach ($article['data']['list']['artList'] as $article) { + $build[] = Helpers::formatArticle($article, true, false, $showAuthor); + } + $data['infos'] = $build; + + $this->_view->display('page', $data); + + exit(); + + } while (false); + + echo ' '; + } + +} diff --git a/yohobuy/m.yohobuy.com/application/modules/Guang/controllers/Info.php b/yohobuy/m.yohobuy.com/application/modules/Guang/controllers/Info.php new file mode 100644 index 0000000..49a302f --- /dev/null +++ b/yohobuy/m.yohobuy.com/application/modules/Guang/controllers/Info.php @@ -0,0 +1,154 @@ +<?php + +use Action\AbstractAction; +use LibModels\Wap\Guang\DetailData; +use LibModels\Wap\Product\ListData; +use Plugin\Helpers; + +/** + * 逛详情页 + */ +class InfoController extends AbstractAction +{ + + /** + * 详情页 + * + * @param int id 内容ID + */ + public function indexAction() + { + $id = $this->get('id'); + + // 判断参数是否有效, 无效会跳转到错误页面 + if (!is_numeric($id)) { + $this->error(); + } + + // 获取详情内容信息, 异常则跳到错误页面 + $detail = DetailData::package($id); + if (empty($detail['getArticle'])) { + $this->error(); + } + + $data = array(); + $data['guangDetail'] = true; // 模板中使用JS的标识 + $data['guang']['id'] = $id; + + // 作者信息数据 + if (isset($detail['getAuthor']['name'])) { + $data['guang']['author'] = array(); + $data['guang']['author']['avatar'] = $detail['getAuthor']['avatar']; + $data['guang']['author']['name'] = $detail['getAuthor']['name']; + $data['guang']['author']['intro'] = $detail['getAuthor']['author_desc']; + $data['guang']['author']['url'] = '/author/index?id=' . $detail['getArticle']['author_id']; + } + + $data['detail'] = array(); + $data['detail']['title'] = $detail['getArticle']['article_title']; + $data['detail']['publishTime'] = $detail['getArticle']['publishTime']; + $data['detail']['pageView'] = $detail['getArticle']['pageViews']; + $data['detail']['content'] = array(); + + if (!empty($detail['getArticleContent'])) { + $build = array(); + $good = array(); + $skns = array(); + $product = array(); + foreach ($detail['getArticleContent'] as $value) { + $build = array(); + // 文字 + if (isset($value['text'])) { + $build['text'] = $value['text']['data']['text']; + $data['detail']['content'][] = $build; + } + // 单张图 + elseif (isset($value['singleImage'])) { + $build['bigImage'] = Helpers::getImageUrl($value['singleImage']['data'][0]['src'], 640, 640); + $data['detail']['content'][] = $build; + } + // 相关推荐 + elseif (isset($value['goods']['data'])) { + $good = array(); + // 遍历取得SKN + $skns = array(); + foreach ($value['goods']['data'] as $goods) { + $skns[] = $goods['id']; + } + // 通过SKN获取商品信息 + $product = ListData::productInfoBySkns($skns); + if (!empty($product['data']['product_list'])) { + foreach ($product['data']['product_list'] as $i => $goods) { + // 最多显示4个 + if ($i > 3) { + break; + } + $good[] = Helpers::formatProduct($goods, false); + } + } + // 没有商品 + if (!isset($i)) { + continue; + } + // 单个商品 + elseif ($i === 0) { + $build['relatedReco'] = $good[0]; + } + // 多个商品 + else { + $build['relatedReco'] = $good; + } + } + // 悬停浮动商品 + elseif (isset($value['goodsGroup']['data'])) { + foreach ($value['goodsGroup']['data'] as $goods) { + $good = array(); + $good['thumb'] = Helpers::getImageUrl($goods['cover']['cover'], 235, 314); + $good['type'] = Helpers::getProductIcon($goods['cover']['maxSortId']); + $good['goods'] = array(); + $skns = array(); + foreach ($goods['list'] as $mini) { + $skns[] = $mini['id']; + } + // 通过SKN获取商品信息 + $product = ListData::productInfoBySkns($skns); + if (!empty($product['data']['product_list'])) { + foreach ($product['data']['product_list'] as $i => $goods) { + $good['goods'][] = Helpers::formatProduct($goods, false); + } + $build['collocation'][] = $good; + } + } + } + + $data['detail']['content'][] = $build; + } + } + + // 相关品牌 + if (!empty($detail['getBrand'])) { + $data['relatedBrand'] = $detail['getBrand']; + } + + // 相关标签 + if (!empty($detail['getArticle']['tags'])) { + foreach ($detail['getArticle']['tags'] as $value) { + $value['url'] = '/tags/index?query=' . $value['name']; + $data['relatedTag'][] = $value; + } + } + + // 相关文章 + if (!empty($detail['getOtherArticle'])) { + foreach ($detail['getOtherArticle'] as $value) { + $value['url'] = '/info/index?id=' . $value['id']; + $data['relatedInfo'][] = $value; + } + } + + $this->_view->display('index', $data); + + $detail = array(); + $data = array(); + } +} \ No newline at end of file diff --git a/yohobuy/m.yohobuy.com/application/modules/Product/controllers/Index.php b/yohobuy/m.yohobuy.com/application/modules/Product/controllers/Index.php new file mode 100644 index 0000000..fcdeec7 --- /dev/null +++ b/yohobuy/m.yohobuy.com/application/modules/Product/controllers/Index.php @@ -0,0 +1,120 @@ +<?php + +use Action\AbstractAction; +use LibModels\Wap\Category\BrandData; +use LibModels\Wap\Category\ClassData; +use Plugin\DataProcess\ListProcess; +use Plugin\Helpers; + +/** + * 商品列表相关的控制器 + * + */ +class IndexController extends AbstractAction +{ + + /** + * 品类商品列表页 + * + * @param string $gender "1,3"表示男, "2,3"表示女, "1,2,3"表示全部 + * @param integer $brand 品牌Id + * @param integer $sort 品类查询sort参数 + * @param integer $color 颜色Id + * @param integer $size 尺码Id + * @param string $price 价格 + * @param string $p_d 折扣 + */ + public function indexAction() + { + // 过滤请求参数 + $condition = filter_input_array(INPUT_GET, array( + '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_VALIDATE_INT, + 'gender' => FILTER_DEFAULT, + 'p_d' => FILTER_DEFAULT,), false); + + // 性别参数,不传则从COOKIE获取 + if (!isset($condition['gender'])) { + $condition['gender'] = Helpers::getGenderByCookie(); + } + + // 品类名称参数, 不传则默认为全部 + $name = $this->get('sort_name'); + if (empty($name)) { + $name = $this->get('title', '全部'); + } + $this->setTitle($name); + $this->setNavHeader($name, true, SITE_MAIN); + + $goodList = Product\ListModel::getClassData($condition); + if (!empty($condition)) { + $goodList = array_merge($goodList, $condition); + } + $this->_view->display('index', array( + 'goodListPage' => true, + 'goodList' => $goodList, + )); + } + + /** + * 品牌商品列表页 + * + * @param string $gender "1,3"表示男, "2,3"表示女, "1,2,3"表示全部 + * @param integer $sort 品类查询sort参数 + * @param integer $color 颜色Id + * @param integer $size 尺码Id + * @param string $price 价格 + * @param string $p_d 折扣 + */ + public function brandAction() + { + /* 品牌域名参数 @see Bootstrap.php */ + $domain = $this->param('named'); + if (empty($domain)) { + $this->error(); + } + + /* 通过品牌域名找到对应的品牌ID */ + $domainList = Product\ListModel::getAllBrandDomains(); + $brandIds = array_keys($domainList, $domain); + if (!isset($brandIds[0])) { + $this->error(); + } + // 当前的登录用户UID + $uid = $this->getUid(); + + /* 过滤请求参数 */ + $condition = filter_input_array(INPUT_GET, array( + '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_VALIDATE_INT, + '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; + + $this->setTitle($title); + $this->setNavHeader($title, true, SITE_MAIN); + + $this->_view->display('index', $data); + } + +} diff --git a/yohobuy/m.yohobuy.com/application/modules/Product/controllers/Opt.php b/yohobuy/m.yohobuy.com/application/modules/Product/controllers/Opt.php new file mode 100644 index 0000000..0b88dea --- /dev/null +++ b/yohobuy/m.yohobuy.com/application/modules/Product/controllers/Opt.php @@ -0,0 +1,14 @@ +<?php + +/** + * + * @name Opt + * @package + * @copyright yoho.inc + * @version 1.0 (2015-10-27 19:13:28) + * @author fei.hong <fei.hong@yoho.cn> + */ +class Opt +{ + +} diff --git a/yohobuy/m.yohobuy.com/configs/routes.guang.ini b/yohobuy/m.yohobuy.com/configs/routes.guang.ini new file mode 100644 index 0000000..7efb1c3 --- /dev/null +++ b/yohobuy/m.yohobuy.com/configs/routes.guang.ini @@ -0,0 +1,14 @@ +; 标签聚合列表 +routes.tag.type = "rewrite" +routes.tag.match = "/tags/index" +routes.tag.route.module = Guang +routes.tag.route.controller = Index +routes.tag.route.action = Tag + +; 作者聚合列表 +routes.author.type = "rewrite" +routes.author.match = "/author/index" +routes.author.route.module = Guang +routes.author.route.controller = Index +routes.author.route.action = Editor + diff --git a/yohobuy/m.yohobuy.com/configs/routes.index.ini b/yohobuy/m.yohobuy.com/configs/routes.index.ini new file mode 100644 index 0000000..da328b9 --- /dev/null +++ b/yohobuy/m.yohobuy.com/configs/routes.index.ini @@ -0,0 +1,64 @@ +; 默认页 +routes.index.type = "rewrite" +routes.index.match = "/index.html" +routes.index.route.module = Index +routes.index.route.controller = Index +routes.index.route.action = Index + +; 错误页 +routes.error.type = "rewrite" +routes.error.match = "/error.html" +routes.error.route.module = Index +routes.error.route.controller = Error +routes.error.route.action = Index + +; 搜索页 +routes.reg.type = "rewrite" +routes.reg.match = "/search.html" +routes.reg.route.module = Index +routes.reg.route.controller = Search +routes.reg.route.action = Index + +; 注册页 +routes.reg.type = "rewrite" +routes.reg.match = "/reg.html" +routes.reg.route.module = Passport +routes.reg.route.controller = Reg +routes.reg.route.action = Index + +; 登录页 +routes.login.type = "rewrite" +routes.login.match = "/signin.html" +routes.login.route.module = Passport +routes.login.route.controller = Login +routes.login.route.action = Index + +; 登录页(国际账号) +routes.interational.type = "rewrite" +routes.interational.match = "/login.html" +routes.interational.route.module = Passport +routes.interational.route.controller = Login +routes.interational.route.action = International + +; 找回密码(手机号) +routes.phoneback.type = "rewrite" +routes.phoneback.match = "/phoneback.html" +routes.phoneback.route.module = Passport +routes.phoneback.route.controller = Back +routes.phoneback.route.action = Mobile + +; 找回密码(邮箱) +routes.emailback.type = "rewrite" +routes.emailback.match = "/emailback.html" +routes.emailback.route.module = Passport +routes.emailback.route.controller = Back +routes.emailback.route.action = Email + +; 所有品类 +routes.reg.type = "rewrite" +routes.reg.match = "/cate" +routes.reg.route.module = Category +routes.reg.route.controller = Class +routes.reg.route.action = Index + + diff --git a/yohobuy/m.yohobuy.com/public/index-dev.php b/yohobuy/m.yohobuy.com/public/index-dev.php index 6147ec4..7b1cd47 100644 --- a/yohobuy/m.yohobuy.com/public/index-dev.php +++ b/yohobuy/m.yohobuy.com/public/index-dev.php @@ -4,6 +4,7 @@ use Yaf\Application; define('SITE_MAIN', 'http://m.dev.yohobuy.com'); // 网站主域名 define('OLD_MAIN', 'http://m.yohobuy.com'); // 网站旧域名 define('COOKIE_DOMAIN', '.m.dev.yohobuy.com'); // COOKIE作用域 +define('SUB_DOMAIN', '.dev.yohobuy.com'); // 子域名后缀 define('USE_CACHE', false); // 缓存的开关 define('APPLICATION_PATH', dirname(__DIR__)); // 应用目录 define('ROOT_PATH', dirname(dirname(APPLICATION_PATH))); // 根目录 diff --git a/yohobuy/m.yohobuy.com/public/index-test.php b/yohobuy/m.yohobuy.com/public/index-test.php index 846af7e..d9f2f1c 100644 --- a/yohobuy/m.yohobuy.com/public/index-test.php +++ b/yohobuy/m.yohobuy.com/public/index-test.php @@ -4,6 +4,7 @@ use Yaf\Application; define('SITE_MAIN', 'http://buy.test.yoho.cn'); // 网站主域名 define('OLD_MAIN', 'http://m.yohobuy.com'); // 网站旧域名 define('COOKIE_DOMAIN', '.test.yoho.cn'); // COOKIE作用域 +define('SUB_DOMAIN', '.test.yoho.cn'); // 子域名后缀 define('USE_CACHE', false); // 缓存的开关 define('APPLICATION_PATH', dirname(__DIR__)); // 应用目录 define('ROOT_PATH', dirname(dirname(APPLICATION_PATH))); // 根目录 diff --git a/yohobuy/m.yohobuy.com/public/index.php b/yohobuy/m.yohobuy.com/public/index.php index 0f20fab..24fb9b8 100644 --- a/yohobuy/m.yohobuy.com/public/index.php +++ b/yohobuy/m.yohobuy.com/public/index.php @@ -4,6 +4,7 @@ use Yaf\Application; define('SITE_MAIN', 'http://mtesth5.yohobuy.com'); // 网站主域名 define('OLD_MAIN', 'http://m.yohobuy.com'); // 网站旧域名 define('COOKIE_DOMAIN', '.yohobuy.com'); // COOKIE作用域 +define('SUB_DOMAIN', '.m.yohobuy.com'); // 子域名后缀 define('USE_CACHE', true); // 缓存的开关 define('APPLICATION_PATH', dirname(__DIR__)); // 应用目录 define('ROOT_PATH', dirname(dirname(APPLICATION_PATH))); // 根目录