Authored by hf

do category brand page

framework @ 75bbc3b0
Subproject commit 119c247f5cf929aa1e059e40609bb16dd6b58f05
Subproject commit 75bbc3b075de19f239532f60c5995d06c5f814e2
... ...
... ... @@ -296,17 +296,17 @@ class AbstractAction extends Controller_Abstract
/**
* 设置网站导航头部信息
*
* @param string $backUrl 返回的链接
* @param string $title 头部标题
* @param string $backUrl 返回的链接
* @param string $homeUrl 返回首页的链接
* @return void
*/
protected function setNavHeader($backUrl, $title, $homeUrl)
protected function setNavHeader($title = '', $backUrl = true, $homeUrl = '/')
{
$header = array();
if (!empty($backUrl)) {
$header['navBack'] = $backUrl;
if ($backUrl) {
$header['navBack'] = true;
}
if (!empty($title)) {
$header['navTitle'] = $title;
... ...
... ... @@ -16,12 +16,43 @@ use Api\Sign;
*/
class BrandData
{
const URI_BRAND_TOPPOS = 'operations/api/v5/resource/get';
/**
* 封装获取品牌一览页面的数据
*
* @param string $contentCode 获取广告资源需要的位置码
* @param int $channel 频道标识 1:男,2:女,3:潮童,4:创意生活
* @return array(
* "brandTop": "顶部的轮翻广告及热门品牌数据",
* "brandList": "按字母'A-Z'分组的品牌列表数据"
* )
* @author fei.hong <fei.hong@yoho.cn>
*/
public static function package($contentCode, $channel)
{
$urlList = array();
/* 顶部的轮翻广告及热门品牌数据 */
$param = Yohobuy::param();
$param['content_code'] = $contentCode;
$param['client_secret'] = Sign::getSign($param);
$urlList['brandTop'] = Yohobuy::httpBuildQuery(Yohobuy::SERVICE_URL . self::URI_BRAND_TOPPOS, $param);
/* 按字母"A-Z"分组的品牌列表数据 */
$param = Yohobuy::param();
$param['method'] = 'app.brand.brandlist';
$param['yh_channel'] = $channel;
$param['client_secret'] = Sign::getSign($param);
$urlList['brandList'] = Yohobuy::httpBuildQuery(Yohobuy::API_URL, $param);
return Yohobuy::getMulti($urlList);
}
/**
* 获取品牌数据
*
* @param integer $channel 是否,默认1表示是,传值为空是app中用于品牌搜索的数据
*
* @return array 品牌数据
*/
public static function getBrandsData($channel = 1)
... ... @@ -38,16 +69,17 @@ class BrandData
/**
* 获取品牌页顶部楼层数据
*
* @param string $contentCode 位置码
* @return array 品牌也顶部楼层数据
*/
public static function getBrandTopData()
public static function getBrandTopData($contentCode)
{
// 构建必传参数
$param = Yohobuy::param();
$param['content_code'] = 'ce6ac059493ec26241a8cbe0bfa1b17a';
$param['content_code'] = $contentCode;
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(Yohobuy::SERVICE_URL . 'operations/api/v5/resource/get', $param);
return Yohobuy::get(Yohobuy::SERVICE_URL . self::URI_BRAND_TOPPOS, $param);
}
/**
... ...
... ... @@ -10,15 +10,26 @@ class Helpers
/**
* 根据尺寸获得图片url
* @param string $fileName 文件名
* @param string $url 路径
* @param integer $width 图片宽度
* @param integer $height 图片高度
* @param integer $mode 模式
* @return string 图片地址
*/
public static function getImageUrl($fileName, $width, $height, $mode = 2)
public static function getImageUrl($url, $width, $height, $mode = 2)
{
return strtr($fileName, array('{width}' => $width, '{height}' => $height, '{mode}' => $mode));
return strtr($url, array('{width}' => $width, '{height}' => $height, '{mode}' => $mode));
}
/**
* 获取过滤后的URL链接
*
* @param string $url 路径
* @return string 去除掉如&openby:yohobuy={"action":"go.brand"}这样的APP附加参数
*/
public static function getFilterUrl($url)
{
return strstr($url, '&openby:yohobuy=', true);
}
/**
... ...
... ... @@ -13,6 +13,9 @@ class BoysController extends AbstractAction
*/
public function indexAction()
{
// 设置COOKIE标识用户访问过该页面了
Index\HomeModel::setSwitchToCookie(Index\HomeModel::COOKIE_NAME_BOYS);
// 设置网站标题
$this->setTitle('男生首页');
// 显示侧边栏
... ...
... ... @@ -13,6 +13,9 @@ class GirlsController extends AbstractAction
*/
public function indexAction()
{
// 设置COOKIE标识用户访问过该页面了
Index\HomeModel::setSwitchToCookie(Index\HomeModel::COOKIE_NAME_GIRLS);
// 设置网站标题
$this->setTitle('女生首页');
// 显示侧边栏
... ... @@ -26,7 +29,6 @@ class GirlsController extends AbstractAction
'maybeLike' => true,
'content' => Index\HomeModel::getGirlsFloor()
));
}
}
... ...
... ... @@ -13,6 +13,10 @@ class IndexController extends AbstractAction
*/
public function indexAction()
{
// 先检查COOKIE是否有访问过, 有则跳转到相应的频道页
Index\HomeModel::goSwitchChannel();
// 渲染模板
$this->_view->display('index', array(
'background' => Index\HomeModel::getBgImage()
));
... ...
... ... @@ -13,6 +13,9 @@ class KidsController extends AbstractAction
*/
public function indexAction()
{
// 设置COOKIE标识用户访问过该页面了
Index\HomeModel::setSwitchToCookie(Index\HomeModel::COOKIE_NAME_KIDS);
// 设置网站标题
$this->setTitle('潮童首页');
// 显示侧边栏
... ... @@ -26,7 +29,6 @@ class KidsController extends AbstractAction
'maybeLike' => true,
'content' => Index\HomeModel::getKidsFloor()
));
}
}
... ...
... ... @@ -13,6 +13,9 @@ class LifestyleController extends AbstractAction
*/
public function indexAction()
{
// 设置COOKIE标识用户访问过该页面了
Index\HomeModel::setSwitchToCookie(Index\HomeModel::COOKIE_NAME_LIFESTYLE);
// 设置网站标题
$this->setTitle('创意生活首页');
// 显示侧边栏
... ... @@ -26,7 +29,6 @@ class LifestyleController extends AbstractAction
'maybeLike' => true,
'content' => Index\HomeModel::getLifestyleFloor()
));
}
}
... ...
<?php
namespace Category;
use LibModels\Wap\Category\BrandData;
use Configs\CacheConfig;
use Plugin\Helpers;
/**
* 品牌相关的模板数据模型
*
* @name BrandModel
* @package Models/Category
* @copyright yoho.inc
* @version 1.0 (2015-10-21 13:52:44)
* @author fei.hong <fei.hong@yoho.cn>
*/
class BrandModel
{
/* 男生频道取品牌广告及热门品牌数据的位置码 */
const CODE_TOPPOS_BOYS = 'ce6ac059493ec26241a8cbe0bfa1b17a';
/* 女生频道取品牌广告及热门品牌数据的位置码 */
const CODE_TOPPOS_GIRLS = 'dac99cdedc1f948e84c145aca561f7d2';
/* 潮童频道取品牌广告及热门品牌数据的位置码 */
const CODE_TOPPOS_KIDS = '713784f93f52bb1a7b93916b2bb15510';
/* 创意生活频道取品牌广告及热门品牌数据的位置码 */
const CODE_TOPPOS_LIFESTYLE = 'f1aa914fd23cbcda71a87de6f5416c75';
/**
* 根据频道获取品牌一览数据
*
* @param int $channel 1表示男生频道, 2表示女生频道, 3表示潮童频道, 4表示创意生活频道
* @return array
*/
public static function getBrandByChannel($channel)
{
$result = array();
$brand = array();
/* 根据频道调用接口 */
switch (intval($channel)) {
case 1: // 男生
$brand = BrandData::package(self::CODE_TOPPOS_BOYS, 1);
break;
case 2: // 女生
$brand = BrandData::package(self::CODE_TOPPOS_GIRLS, 2);
break;
case 3: // 潮童
$brand = BrandData::package(self::CODE_TOPPOS_KIDS, 3);
break;
case 4: // 创意生活
$brand = BrandData::package(self::CODE_TOPPOS_LIFESTYLE, 4);
break;
}
/* 顶部的轮翻广告列表 */
if (!empty($brand['brandTop'][0]['data'])) {
$build = array();
foreach ($brand['brandTop'][0]['data'] as $value) {
$build['url'] = Helpers::getFilterUrl($value['url']);
$build['img'] = Helpers::getImageUrl($value['src'], 640, 300);
$build['title'] = $value['title'];
$result['bannerTop']['list'][] = $build;
}
}
/* 顶部的热门品牌列表 */
if (!empty($brand['brandTop'][1]['data']['list'])) {
$build = array();
foreach ($brand['brandTop'][1]['data']['list'] as $value) {
$build['url'] = Helpers::getFilterUrl($value['url']);
$build['img'] = Helpers::getImageUrl($value['src'], 144, 144);
$build['name'] = $value['name'];
$result['hotBrand']['list'][] = $build;
}
}
/* 按字母'A-Z'分组的品牌列表 */
if (!empty($brand['brandList']['brands'])) {
$list = array();
$build = array();
foreach ($brand['brandList']['brands'] as $char => $value) {
$build['title'] = $char;
$build['list'] = array();
foreach ($value as $row) {
$list['name'] = $row['brand_name'];
$list['isHot'] = ($row['is_hot'] === 'Y') ? true : false;
$list['isNew'] = ($row['is_show_new'] === 'Y') ? true : false;
$list['url'] = $row['brand_domain'] . '.' . OLD_DOMAIN;
$build['list'][] = $list;
}
$result['brandList'][] = $build;
}
}
$brand = array();
return $result;
}
}
... ...
... ... @@ -19,7 +19,6 @@ use Configs\CacheConfig;
*/
class HomeModel
{
/* 频道选择页取背景图片的位置码 */
const CODE_BG = '7ba9118028f9b22090b57341487567eb';
... ... @@ -37,6 +36,44 @@ class HomeModel
/* 女生底部广告的位置码 */
const CODE_BANNER_BOTTOM_GIRLS = '8c8bd1b89a22e5895f05882e0825b493';
/* COOKIE标识访问的是男生频道 */
const COOKIE_NAME_BOYS = 'boys';
/* COOKIE标识访问的是女生频道 */
const COOKIE_NAME_GIRLS = 'girls';
/* COOKIE标识访问的是潮童频道 */
const COOKIE_NAME_KIDS = 'kids';
/* COOKIE标识访问的是创意生活频道 */
const COOKIE_NAME_LIFESTYLE = 'lifestyle';
/**
* 选择频道
*
* @return void
*/
public static function goSwitchChannel()
{
// 通过COOKIE检查是否已设置过首页频道时,跳转到对应的频道页
if (!empty($_COOKIE['_Channel'])) {
headers_sent() || header('Location: /' . $_COOKIE['_Channel']);
exit();
}
// 没有Cookie时, 设置默认访问的频道
else {
self::setSwitchToCookie(self::COOKIE_NAME_BOYS);
}
}
/**
* 设置选择的频道保存到浏览器COOKIE
*
* @param string $cookie
* @return void
*/
public static function setSwitchToCookie($cookie)
{
setcookie('_Channel', $cookie, time() + 86400 * 300, '/', '.' . SITE_DOMAIN);
}
/**
* 获取频道选择页的背景图片
*
... ... @@ -103,7 +140,7 @@ class HomeModel
Cache::set(CacheConfig::KEY_ACTION_BOYS_INDEX, $result);
}
}
return $result;
}
... ... @@ -136,7 +173,7 @@ class HomeModel
Cache::set(CacheConfig::KEY_ACTION_GIRLS_INDEX, $result);
}
}
return $result;
}
... ... @@ -169,7 +206,7 @@ class HomeModel
Cache::set(CacheConfig::KEY_ACTION_KIDS_INDEX, $result);
}
}
return $result;
}
... ... @@ -202,7 +239,7 @@ class HomeModel
Cache::set(CacheConfig::KEY_ACTION_LIFESTYLE_INDEX, $result);
}
}
return $result;
}
... ...
<?php
use Action\AbstractAction;
use LibModels\Wap\Category\BrandData;
/**
* 品牌
* 品牌相关的控制器
*/
class BrandController extends AbstractAction
{
/**
* 品牌一览
*
* @param int channel 1表示男生频道, 2表示女生频道, 3表示潮童频道, 4表示创意生活频道
*/
public function indexAction()
{
// 获取品牌数据
/*$brandTopData = BrandData::getBrandTopData();
$brandsData = BrandData::getBrandsData();
$this->setTitle('品牌一览');
$this->setNavHeader('品牌一览');
/* 判断参数是否有效 */
$channel = $this->get('channel', 1);
if (!is_numeric($channel) || intval($channel) > 4) {
$channel = 1;
}
/* 获取渲染模板需要的数据 */
$data = Category\BrandModel::getBrandByChannel($channel);
if (!is_array($data)) {
$data = array();
}
$data['brandPage'] = true;
$brandTop = array();
if($brandTopData['code'] == 200)
{
$brandTop = $brandTopData['data'];
}
$brands = array();
if($brandsData['code'] == 200)
{
$brands = $brandsData['data'];
}
echo '<pre>';
var_dump($brandTop, $brands);exit;*/
$data = array (
'brandPage' => true,
'bannerTop' => array (
'list' => array (
array (
'url' => '',
'img' => 'http://img10.static.yhbimg.com/adpic/2015/10/15/10/01c161398d3baec2868abe85e26ba1a71d.jpg?imageMogr2/thumbnail/640x300/extent/640x300/background/d2hpdGU=/position/center/quality/90'
),
array (
'url' => '',
'img' => 'http://img13.static.yhbimg.com/adpic/2015/10/15/10/027c45cdc03e23c367ec0ff3d29b7c3f79.jpg?imageMogr2/thumbnail/640x300/extent/640x300/background/d2hpdGU=/position/center/quality/90'
),
array (
'url' => '',
'img' => 'http://img13.static.yhbimg.com/adpic/2015/10/15/10/022e2ac6daa33fc3cb8a0f04025a35994f.jpg?imageMogr2/thumbnail/640x300/extent/640x300/background/d2hpdGU=/position/center/quality/90'
)
)
),
'hotBrand' => array (
'list' => array (
array (
'url' => '',
'img' => 'http://img13.static.yhbimg.com/brandLogo/2014/08/12/17/0233d54f34d2534c08271a8fc27090a6af.jpg?imageMogr2/thumbnail/144x144/extent/144x144/background/d2hpdGU=/position/center/quality/90'
),
array (
'url' => '',
'img' => 'http://img12.static.yhbimg.com/brandLogo/2014/01/27/11/020b17265b2103b49005c57395b8b154a9.jpg?imageMogr2/thumbnail/144x144/extent/144x144/background/d2hpdGU=/position/center/quality/90'
),
array (
'url' => '',
'img' => 'http://img13.static.yhbimg.com/brandLogo/2014/11/27/09/02b403bdcbfb965bdc632fea5c29816746.png?imageMogr2/thumbnail/144x144/extent/144x144/background/d2hpdGU=/position/center/quality/90'
),
array (
'url' => '',
'img' => 'http://img13.static.yhbimg.com/brandLogo/2013/11/01/14/027e68260ba30c01b165c17fe043f2ce2c.jpg?imageMogr2/thumbnail/144x144/extent/144x144/background/d2hpdGU=/position/center/quality/90'
),
array (
'url' => '',
'img' => 'http://img11.static.yhbimg.com/brandLogo/2014/04/25/14/0179fa8eacf51fd1a89ec6f7fdeab88fc2.jpg?imageMogr2/thumbnail/144x144/extent/144x144/background/d2hpdGU=/position/center/quality/90'
),
array (
'url' => '',
'img' => 'http://img12.static.yhbimg.com/brandLogo/2014/01/27/11/02608437f8d8b6b7b15786214b0a5ef502.jpg?imageMogr2/thumbnail/144x144/extent/144x144/background/d2hpdGU=/position/center/quality/90'
),
array (
'url' => '',
'img' => 'http://img12.static.yhbimg.com/brandLogo/2013/02/28/17/020aae69720d683a7962c9b7fd3a92c801.jpg?imageMogr2/thumbnail/144x144/extent/144x144/background/d2hpdGU=/position/center/quality/90'
),
array (
'url' => '',
'img' => 'http://img13.static.yhbimg.com/brandLogo/2014/01/27/11/02bca7ac6414c7475b4a337e28a0365590.jpg?imageMogr2/thumbnail/144x144/extent/144x144/background/d2hpdGU=/position/center/quality/90'
)
)
),
'brandList' => array (
array (
'title' => '0~9',
'list' => array(
array (
'name' => '004',
'isHot' => true
),
array (
'name' => '10*1',
'isNew' => true
),
array (
'name' => '2%'
)
)
),
array (
'title' => 'A',
'list' => array(
array (
'name' => 'Aape',
'isHot' => true
),
array (
'name' => 'Adfdfd',
'isNew' => true
),
array (
'name' => 'Acrwewwe'
)
)
),
array (
'title' => 'B',
'list' => array(
array (
'name' => 'Bape'
),
array (
'name' => 'Bdfdfd'
),
array (
'name' => 'Bcrwewwe'
)
)
)
)
);
$this->_view->assign('title', 'YOHO!有货');
//$this->_view->display('brand', compact('brands'));
$this->_view->display('index', $data);
}
}
\ No newline at end of file
... ...
... ... @@ -2,6 +2,7 @@
use Yaf\Application;
define('SITE_DOMAIN', 'm.dev.yohobuy.com'); // 网站主域名
define('OLD_DOMAIN', 'm.yohobuy.com'); // 网站旧域名
define('USE_CACHE', false); // 缓存的开关
define('APPLICATION_PATH', dirname(__DIR__));
define('ROOT_PATH', dirname(dirname(APPLICATION_PATH)));
... ...
... ... @@ -2,6 +2,7 @@
use Yaf\Application;
define('SITE_DOMAIN', 'buy.test.yoho.cn'); // 网站主域名
define('OLD_DOMAIN', 'm.yohobuy.com'); // 网站旧域名
define('USE_CACHE', true); // 缓存的开关
define('APPLICATION_PATH', dirname(__DIR__));
define('ROOT_PATH', dirname(dirname(APPLICATION_PATH)));
... ...
... ... @@ -2,6 +2,7 @@
use Yaf\Application;
define('SITE_DOMAIN', 'wap.yohobuy.com'); // 网站主域名
define('OLD_DOMAIN', 'm.yohobuy.com'); // 网站旧域名
define('USE_CACHE', true); // 缓存的开关
define('APPLICATION_PATH', dirname(__DIR__));
define('ROOT_PATH', dirname(dirname(APPLICATION_PATH)));
... ...