Authored by hf

code review by fei.hong: do format channel page code and web cache config file

<?php
namespace Configs;
/**
* 缓存配置文件
*/
class WebCacheConfig
{
const KEY_WEB_HOME_NAVBAR_DATA = 'key_web_home_navbar_data';//web的导航数据
const KEY_WEB_HOME_CHANNEL_DATA = 'key_web_home_channel_data';//web首页频道数据[boys, girls, kids, lifestyle]
const KEY_WEB_HOME_CHANNEL_NEWARRIVAL_DATA = 'key_web_home_newarrival_data';//web频道最新上架数据[boys, girls, kids, lifestyle]
const KEY_WEB_PRODUCT_SEARCH_DATA = 'key_web_product_search_data'; // web搜索的数据
}
... ...
... ... @@ -19,8 +19,11 @@ class IndexData
*/
public static function getNavData($status = 1, $fields = 'id,sort_name,sort_name_en,parent_id,sort_url,sort_ico,content_code,is_new,is_hot,separative_sign')
{
$params = array('parent_id'=>'','platform'=>'web',
'status'=> $status,'fields'=> $fields
$params = array(
'parent_id'=>'',
'platform'=>'web',
'status'=> $status,
'fields'=> $fields
);
return Yohobuy::yarClient(Yohobuy::SERVICE_URL . self::URL_OPERATIONS_CATEGORY,'getCategory', $params);
}
... ...
<?php
use Action\WebAction;
use Action\WebAction;
use Index\HomeModel;
/**
* 女
* 女生首页
*/
class GirlsController extends WebAction
{
public function indexAction()
{
// 设置客户端浏览器1分钟内不改变
$this->setLastModified(mktime(date('H'), date('i'), 0, date('n'), date('j'), date('Y')));
// 设置浏览器缓存1分钟
$this->setExpires(60);
// 设置网站SEO信息
$this->setTitle('女生|时尚潮流女装,日韩女装,潮牌女装全球购|YOHO!BUY有货 100%正品保证', false);
$this->setKeywords('女生服饰,时尚潮流女装,日韩女装,女装正品购物网站,女装全球购');
$this->setDescription('YOHO!BUY有货官网女生频道汇集了全球女装潮流时尚,提供时尚潮流女装,日版女装,韩版女装,潮牌女装正品全球购。YOHO!BUY有货购物100%正品保证,支持货到付款。');
// 传递模板数据,渲染模板
$this->setWebNavHeader(HomeModel::COOKIE_NAME_GIRLS);
$data = array(
'boysHomePage' => true,
'footerTop'=> true,
'footerTop' => true,
'girls' => HomeModel::getChannelResource(HomeModel::COOKIE_NAME_GIRLS, HomeModel::CODE_GIRLS_CHANNEL)
);
$this->_view->display('index', $data);
}
}
\ No newline at end of file
}
... ...
<?php
use Action\WebAction;
use Index\HomeModel;
/**
* 默认控制器
... ... @@ -15,7 +16,7 @@ class IndexController extends WebAction
{
if (null !== $this->get('go')) {
// 先检查COOKIE是否有访问过, 有则跳转到相应的频道页
\Index\HomeModel::goSwitchChannel();
HomeModel::goSwitchChannel();
} else {
// 设置客户端浏览器1分钟内不改变
$this->setLastModified(mktime(date('H'), date('i'), 0, date('n'), date('j'), date('Y')));
... ... @@ -23,11 +24,12 @@ class IndexController extends WebAction
$this->setExpires(60);
}
$this->setWebNavHeader(\Index\HomeModel::COOKIE_NAME_BOYS);
// 传递模板数据,渲染模板
$this->setWebNavHeader(HomeModel::COOKIE_NAME_BOYS);
$data = array(
'boysHomePage' => true,
'footerTop'=> true,
'boys' => \Index\HomeModel::getChannelResource(\Index\HomeModel::COOKIE_NAME_BOYS, \Index\HomeModel::CODE_BOYS_CHANNEL)
'boys' => HomeModel::getChannelResource(HomeModel::COOKIE_NAME_BOYS, HomeModel::CODE_BOYS_CHANNEL)
);
$this->_view->display('index', $data);
}
... ...
<?php
use Action\WebAction;
use Index\HomeModel;
... ... @@ -10,15 +11,23 @@ class KidsController extends WebAction
public function indexAction()
{
// 设置客户端浏览器1分钟内不改变
$this->setLastModified(mktime(date('H'), date('i'), 0, date('n'), date('j'), date('Y')));
// 设置浏览器缓存1分钟
$this->setExpires(60);
// 设置网站SEO信息
$this->setTitle('潮童|男童装,女童装,韩版童装,儿童服装服饰|YOHO!BUY有货 100%正品保证', false);
$this->setKeywords('潮童,男童装,女童装,韩版童装,儿童服装服饰');
$this->setDescription('YOHO!BUY有货官网潮童频道汇集了全球潮童潮流时尚,提供新款男童装,女童装,韩版童装,儿童服装服饰正品全球购。YOHO!BUY有货购物100%正品保证,支持货到付款。');
$this->setWebNavHeader(HomeModel::COOKIE_NAME_KIDS);
$data = array(
'boysHomePage' => true,
'footerTop'=> true,
'footerTop' => true,
'kids' => HomeModel::getChannelResource(HomeModel::COOKIE_NAME_KIDS, HomeModel::CODE_KIDS_CHANNEL)
);
$this->_view->display('index', $data);
}
}
\ No newline at end of file
}
... ...
<?php
use Action\WebAction;
use Index\HomeModel;
... ... @@ -10,15 +11,24 @@ class LifestyleController extends WebAction
public function indexAction()
{
// 设置客户端浏览器1分钟内不改变
$this->setLastModified(mktime(date('H'), date('i'), 0, date('n'), date('j'), date('Y')));
// 设置浏览器缓存1分钟
$this->setExpires(60);
// 设置网站的SEO信息
$this->setTitle('创意生活|创意生活馆,潮流创意家居,家居生活用品|YOHO!BUY有货 100%正品保证', false);
$this->setKeywords('创意生活,创意生活馆,潮流家居,潮流创意家居,家居生活用品,YOHO!有货');
$this->setDescription('YOHO!BUY有货官网创意生活频道汇集了创意生活馆,潮流创意家居,家居生活用品等正品网购,给您的生活带来更多创意。YOHO!BUY有货购物100%正品保证,支持货到付款。');
// 传递模板数据,渲染模板
$this->setWebNavHeader(HomeModel::COOKIE_NAME_LIFESTYLE);
$data = array(
'boysHomePage' => true,
'footerTop'=> true,
'footerTop' => true,
'lifestyle' => HomeModel::getChannelResource(HomeModel::COOKIE_NAME_LIFESTYLE, HomeModel::CODE_LIFESTYLE_CHANNEL)
);
$this->_view->display('index', $data);
}
}
... ...
<?php
namespace Index;
use Configs\CacheConfig;
use Configs\WebCacheConfig;
use Configs\ChannelConfig;
use WebPlugin\Helpers;
use WebPlugin\Cache;
... ... @@ -58,17 +58,18 @@ class HomeModel
*/
public static function getNavBars($channel = 'boys')
{
$menu = array();
$key = CacheConfig::KEY_WEB_HOME_NAVBAR_DATA.'_'.$channel;
$key = WebCacheConfig::KEY_WEB_HOME_NAVBAR_DATA . '_' . $channel;
$menu = Cache::get($key);
$data = array();
if(empty($menu)) {//数据缓存不存在
//数据缓存不存在
if(empty($menu)) {
$data = IndexData::getNavData();
//接口存在数据
if(!empty($data['data'])) {
$item = array();
$index_main = 0;
$subnav = array();
$thirdnav = array();
$indexMain = 0;
$indexSub = 0;
foreach ($data['data'] as $val) {
$item = array(
'name_cn' => $val['sort_name'], // 父级
... ... @@ -76,13 +77,13 @@ class HomeModel
'link' => $val['sort_url'],
'icon' => $val['sort_ico'],
'classname' => str_replace(' ', '', strtolower($val['sort_name_en'])) == $channel ? $channel : '',
'index_main' => $index_main ++,
'index_main' => $indexMain ++,
'content_code' => $val['content_code'],
'is_hot' => $val['is_hot'] == 'Y' ? true : false,
'is_new' => $val['is_new'] == 'Y' ? true : false,
// 'subnav' => array()
);
$index_sub = 0;
$indexSub = 0;
foreach ($val['sub'] as $sub) { // 二级
$subnav = array(
'name' => $sub['sort_name'],
... ... @@ -92,9 +93,10 @@ class HomeModel
'is_new' => $sub['is_new'] == 'Y' ? true : false,
'content_code' => $sub['content_code'],
// 'thirdnav' => array(),
'index_sub' => $index_sub ++
'index_sub' => $indexSub ++
);
if (isset($sub['sub'])) {
$thirdnav = array();
foreach ($sub['sub'] as $thirdsub) { // 三级
$thirdnav = array(
'title' => $thirdsub['sort_name'],
... ... @@ -123,8 +125,9 @@ class HomeModel
Cache::set($key, $menu, 3600);
}
}
//数据缓存和接口都空的,取二级数据
if(empty($menu) && empty($data)) {
if(empty($menu)) {
$menu = Cache::get($key,'slave');
}
... ... @@ -176,25 +179,27 @@ class HomeModel
/**
* 获取频道资源
*
* @param string $channel
* @param string $content_code
* @param string $channel 频道标识(boys,girls,kids,lifestyle)
* @param string $contentCode 资源码
* @return array
*/
public static function getChannelResource($channel, $content_code)
public static function getChannelResource($channel, $contentCode)
{
$key = CacheConfig::KEY_WEB_HOME_CHANNEL_DATA.'_'.$content_code;
$key = WebCacheConfig::KEY_WEB_HOME_CHANNEL_DATA . '_' . $contentCode;
$data = Cache::get($key);
$resource = array();
if(empty($data)) {
$resource = IndexData::getResourceData($content_code);
if(isset($resource['data']) && !empty($resource['data']) && $resource['code'] == 200) {
$resource = IndexData::getResourceData($contentCode);
if (isset($resource['data']) && !empty($resource['data']) && $resource['code'] == 200) {
//格式化数据
$data = ChannelProcess::getFormat($channel, $resource['data']);
Cache::set($key, $data, 3600);//设置master,slave
//设置master,slave
Cache::set($key, $data, 3600);
//清空变量
$resource = array();
}
}
//master没有数据,资源位没有数据, 取二层缓存
if(empty($data) && (empty($resource) || !isset($resource['data']))) {
if(empty($data)) {
$data = Cache::get($key, 'slave');
}
return $data;
... ...