Authored by hf

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

  1 +<?php
  2 +
  3 +namespace Configs;
  4 +
  5 +/**
  6 + * 缓存配置文件
  7 + */
  8 +class WebCacheConfig
  9 +{
  10 +
  11 + const KEY_WEB_HOME_NAVBAR_DATA = 'key_web_home_navbar_data';//web的导航数据
  12 + const KEY_WEB_HOME_CHANNEL_DATA = 'key_web_home_channel_data';//web首页频道数据[boys, girls, kids, lifestyle]
  13 + const KEY_WEB_HOME_CHANNEL_NEWARRIVAL_DATA = 'key_web_home_newarrival_data';//web频道最新上架数据[boys, girls, kids, lifestyle]
  14 + const KEY_WEB_PRODUCT_SEARCH_DATA = 'key_web_product_search_data'; // web搜索的数据
  15 +
  16 +}
@@ -19,8 +19,11 @@ class IndexData @@ -19,8 +19,11 @@ class IndexData
19 */ 19 */
20 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') 20 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')
21 { 21 {
22 - $params = array('parent_id'=>'','platform'=>'web',  
23 - 'status'=> $status,'fields'=> $fields 22 + $params = array(
  23 + 'parent_id'=>'',
  24 + 'platform'=>'web',
  25 + 'status'=> $status,
  26 + 'fields'=> $fields
24 ); 27 );
25 return Yohobuy::yarClient(Yohobuy::SERVICE_URL . self::URL_OPERATIONS_CATEGORY,'getCategory', $params); 28 return Yohobuy::yarClient(Yohobuy::SERVICE_URL . self::URL_OPERATIONS_CATEGORY,'getCategory', $params);
26 } 29 }
1 <?php 1 <?php
  2 +
2 use Action\WebAction; 3 use Action\WebAction;
3 use Index\HomeModel; 4 use Index\HomeModel;
  5 +
4 /** 6 /**
5 - * 女 7 + * 女生首页
6 */ 8 */
7 class GirlsController extends WebAction 9 class GirlsController extends WebAction
8 { 10 {
9 11
10 public function indexAction() 12 public function indexAction()
11 { 13 {
  14 + // 设置客户端浏览器1分钟内不改变
  15 + $this->setLastModified(mktime(date('H'), date('i'), 0, date('n'), date('j'), date('Y')));
  16 + // 设置浏览器缓存1分钟
  17 + $this->setExpires(60);
  18 +
  19 + // 设置网站SEO信息
12 $this->setTitle('女生|时尚潮流女装,日韩女装,潮牌女装全球购|YOHO!BUY有货 100%正品保证', false); 20 $this->setTitle('女生|时尚潮流女装,日韩女装,潮牌女装全球购|YOHO!BUY有货 100%正品保证', false);
13 $this->setKeywords('女生服饰,时尚潮流女装,日韩女装,女装正品购物网站,女装全球购'); 21 $this->setKeywords('女生服饰,时尚潮流女装,日韩女装,女装正品购物网站,女装全球购');
14 $this->setDescription('YOHO!BUY有货官网女生频道汇集了全球女装潮流时尚,提供时尚潮流女装,日版女装,韩版女装,潮牌女装正品全球购。YOHO!BUY有货购物100%正品保证,支持货到付款。'); 22 $this->setDescription('YOHO!BUY有货官网女生频道汇集了全球女装潮流时尚,提供时尚潮流女装,日版女装,韩版女装,潮牌女装正品全球购。YOHO!BUY有货购物100%正品保证,支持货到付款。');
  23 +
  24 + // 传递模板数据,渲染模板
15 $this->setWebNavHeader(HomeModel::COOKIE_NAME_GIRLS); 25 $this->setWebNavHeader(HomeModel::COOKIE_NAME_GIRLS);
16 $data = array( 26 $data = array(
17 'boysHomePage' => true, 27 'boysHomePage' => true,
18 - 'footerTop'=> true, 28 + 'footerTop' => true,
19 'girls' => HomeModel::getChannelResource(HomeModel::COOKIE_NAME_GIRLS, HomeModel::CODE_GIRLS_CHANNEL) 29 'girls' => HomeModel::getChannelResource(HomeModel::COOKIE_NAME_GIRLS, HomeModel::CODE_GIRLS_CHANNEL)
20 ); 30 );
21 $this->_view->display('index', $data); 31 $this->_view->display('index', $data);
1 <?php 1 <?php
2 2
3 use Action\WebAction; 3 use Action\WebAction;
  4 +use Index\HomeModel;
4 5
5 /** 6 /**
6 * 默认控制器 7 * 默认控制器
@@ -15,7 +16,7 @@ class IndexController extends WebAction @@ -15,7 +16,7 @@ class IndexController extends WebAction
15 { 16 {
16 if (null !== $this->get('go')) { 17 if (null !== $this->get('go')) {
17 // 先检查COOKIE是否有访问过, 有则跳转到相应的频道页 18 // 先检查COOKIE是否有访问过, 有则跳转到相应的频道页
18 - \Index\HomeModel::goSwitchChannel(); 19 + HomeModel::goSwitchChannel();
19 } else { 20 } else {
20 // 设置客户端浏览器1分钟内不改变 21 // 设置客户端浏览器1分钟内不改变
21 $this->setLastModified(mktime(date('H'), date('i'), 0, date('n'), date('j'), date('Y'))); 22 $this->setLastModified(mktime(date('H'), date('i'), 0, date('n'), date('j'), date('Y')));
@@ -23,11 +24,12 @@ class IndexController extends WebAction @@ -23,11 +24,12 @@ class IndexController extends WebAction
23 $this->setExpires(60); 24 $this->setExpires(60);
24 } 25 }
25 26
26 - $this->setWebNavHeader(\Index\HomeModel::COOKIE_NAME_BOYS); 27 + // 传递模板数据,渲染模板
  28 + $this->setWebNavHeader(HomeModel::COOKIE_NAME_BOYS);
27 $data = array( 29 $data = array(
28 'boysHomePage' => true, 30 'boysHomePage' => true,
29 'footerTop'=> true, 31 'footerTop'=> true,
30 - 'boys' => \Index\HomeModel::getChannelResource(\Index\HomeModel::COOKIE_NAME_BOYS, \Index\HomeModel::CODE_BOYS_CHANNEL) 32 + 'boys' => HomeModel::getChannelResource(HomeModel::COOKIE_NAME_BOYS, HomeModel::CODE_BOYS_CHANNEL)
31 ); 33 );
32 $this->_view->display('index', $data); 34 $this->_view->display('index', $data);
33 } 35 }
1 <?php 1 <?php
  2 +
2 use Action\WebAction; 3 use Action\WebAction;
3 use Index\HomeModel; 4 use Index\HomeModel;
4 5
@@ -10,15 +11,23 @@ class KidsController extends WebAction @@ -10,15 +11,23 @@ class KidsController extends WebAction
10 11
11 public function indexAction() 12 public function indexAction()
12 { 13 {
  14 + // 设置客户端浏览器1分钟内不改变
  15 + $this->setLastModified(mktime(date('H'), date('i'), 0, date('n'), date('j'), date('Y')));
  16 + // 设置浏览器缓存1分钟
  17 + $this->setExpires(60);
  18 +
  19 + // 设置网站SEO信息
13 $this->setTitle('潮童|男童装,女童装,韩版童装,儿童服装服饰|YOHO!BUY有货 100%正品保证', false); 20 $this->setTitle('潮童|男童装,女童装,韩版童装,儿童服装服饰|YOHO!BUY有货 100%正品保证', false);
14 $this->setKeywords('潮童,男童装,女童装,韩版童装,儿童服装服饰'); 21 $this->setKeywords('潮童,男童装,女童装,韩版童装,儿童服装服饰');
15 $this->setDescription('YOHO!BUY有货官网潮童频道汇集了全球潮童潮流时尚,提供新款男童装,女童装,韩版童装,儿童服装服饰正品全球购。YOHO!BUY有货购物100%正品保证,支持货到付款。'); 22 $this->setDescription('YOHO!BUY有货官网潮童频道汇集了全球潮童潮流时尚,提供新款男童装,女童装,韩版童装,儿童服装服饰正品全球购。YOHO!BUY有货购物100%正品保证,支持货到付款。');
  23 +
16 $this->setWebNavHeader(HomeModel::COOKIE_NAME_KIDS); 24 $this->setWebNavHeader(HomeModel::COOKIE_NAME_KIDS);
17 $data = array( 25 $data = array(
18 'boysHomePage' => true, 26 'boysHomePage' => true,
19 - 'footerTop'=> true, 27 + 'footerTop' => true,
20 'kids' => HomeModel::getChannelResource(HomeModel::COOKIE_NAME_KIDS, HomeModel::CODE_KIDS_CHANNEL) 28 'kids' => HomeModel::getChannelResource(HomeModel::COOKIE_NAME_KIDS, HomeModel::CODE_KIDS_CHANNEL)
21 ); 29 );
22 $this->_view->display('index', $data); 30 $this->_view->display('index', $data);
23 } 31 }
  32 +
24 } 33 }
1 <?php 1 <?php
  2 +
2 use Action\WebAction; 3 use Action\WebAction;
3 use Index\HomeModel; 4 use Index\HomeModel;
4 5
@@ -10,15 +11,24 @@ class LifestyleController extends WebAction @@ -10,15 +11,24 @@ class LifestyleController extends WebAction
10 11
11 public function indexAction() 12 public function indexAction()
12 { 13 {
  14 + // 设置客户端浏览器1分钟内不改变
  15 + $this->setLastModified(mktime(date('H'), date('i'), 0, date('n'), date('j'), date('Y')));
  16 + // 设置浏览器缓存1分钟
  17 + $this->setExpires(60);
  18 +
  19 + // 设置网站的SEO信息
13 $this->setTitle('创意生活|创意生活馆,潮流创意家居,家居生活用品|YOHO!BUY有货 100%正品保证', false); 20 $this->setTitle('创意生活|创意生活馆,潮流创意家居,家居生活用品|YOHO!BUY有货 100%正品保证', false);
14 $this->setKeywords('创意生活,创意生活馆,潮流家居,潮流创意家居,家居生活用品,YOHO!有货'); 21 $this->setKeywords('创意生活,创意生活馆,潮流家居,潮流创意家居,家居生活用品,YOHO!有货');
15 $this->setDescription('YOHO!BUY有货官网创意生活频道汇集了创意生活馆,潮流创意家居,家居生活用品等正品网购,给您的生活带来更多创意。YOHO!BUY有货购物100%正品保证,支持货到付款。'); 22 $this->setDescription('YOHO!BUY有货官网创意生活频道汇集了创意生活馆,潮流创意家居,家居生活用品等正品网购,给您的生活带来更多创意。YOHO!BUY有货购物100%正品保证,支持货到付款。');
  23 +
  24 + // 传递模板数据,渲染模板
16 $this->setWebNavHeader(HomeModel::COOKIE_NAME_LIFESTYLE); 25 $this->setWebNavHeader(HomeModel::COOKIE_NAME_LIFESTYLE);
17 $data = array( 26 $data = array(
18 'boysHomePage' => true, 27 'boysHomePage' => true,
19 - 'footerTop'=> true, 28 + 'footerTop' => true,
20 'lifestyle' => HomeModel::getChannelResource(HomeModel::COOKIE_NAME_LIFESTYLE, HomeModel::CODE_LIFESTYLE_CHANNEL) 29 'lifestyle' => HomeModel::getChannelResource(HomeModel::COOKIE_NAME_LIFESTYLE, HomeModel::CODE_LIFESTYLE_CHANNEL)
21 ); 30 );
22 $this->_view->display('index', $data); 31 $this->_view->display('index', $data);
23 } 32 }
  33 +
24 } 34 }
1 <?php 1 <?php
2 namespace Index; 2 namespace Index;
3 3
4 -use Configs\CacheConfig; 4 +use Configs\WebCacheConfig;
5 use Configs\ChannelConfig; 5 use Configs\ChannelConfig;
6 use WebPlugin\Helpers; 6 use WebPlugin\Helpers;
7 use WebPlugin\Cache; 7 use WebPlugin\Cache;
@@ -58,17 +58,18 @@ class HomeModel @@ -58,17 +58,18 @@ class HomeModel
58 */ 58 */
59 public static function getNavBars($channel = 'boys') 59 public static function getNavBars($channel = 'boys')
60 { 60 {
61 - $menu = array();  
62 - $key = CacheConfig::KEY_WEB_HOME_NAVBAR_DATA.'_'.$channel; 61 + $key = WebCacheConfig::KEY_WEB_HOME_NAVBAR_DATA . '_' . $channel;
63 $menu = Cache::get($key); 62 $menu = Cache::get($key);
64 - $data = array();  
65 - if(empty($menu)) {//数据缓存不存在 63 + //数据缓存不存在
  64 + if(empty($menu)) {
66 $data = IndexData::getNavData(); 65 $data = IndexData::getNavData();
67 -  
68 //接口存在数据 66 //接口存在数据
69 if(!empty($data['data'])) { 67 if(!empty($data['data'])) {
70 $item = array(); 68 $item = array();
71 - $index_main = 0; 69 + $subnav = array();
  70 + $thirdnav = array();
  71 + $indexMain = 0;
  72 + $indexSub = 0;
72 foreach ($data['data'] as $val) { 73 foreach ($data['data'] as $val) {
73 $item = array( 74 $item = array(
74 'name_cn' => $val['sort_name'], // 父级 75 'name_cn' => $val['sort_name'], // 父级
@@ -76,13 +77,13 @@ class HomeModel @@ -76,13 +77,13 @@ class HomeModel
76 'link' => $val['sort_url'], 77 'link' => $val['sort_url'],
77 'icon' => $val['sort_ico'], 78 'icon' => $val['sort_ico'],
78 'classname' => str_replace(' ', '', strtolower($val['sort_name_en'])) == $channel ? $channel : '', 79 'classname' => str_replace(' ', '', strtolower($val['sort_name_en'])) == $channel ? $channel : '',
79 - 'index_main' => $index_main ++, 80 + 'index_main' => $indexMain ++,
80 'content_code' => $val['content_code'], 81 'content_code' => $val['content_code'],
81 'is_hot' => $val['is_hot'] == 'Y' ? true : false, 82 'is_hot' => $val['is_hot'] == 'Y' ? true : false,
82 'is_new' => $val['is_new'] == 'Y' ? true : false, 83 'is_new' => $val['is_new'] == 'Y' ? true : false,
83 // 'subnav' => array() 84 // 'subnav' => array()
84 ); 85 );
85 - $index_sub = 0; 86 + $indexSub = 0;
86 foreach ($val['sub'] as $sub) { // 二级 87 foreach ($val['sub'] as $sub) { // 二级
87 $subnav = array( 88 $subnav = array(
88 'name' => $sub['sort_name'], 89 'name' => $sub['sort_name'],
@@ -92,9 +93,10 @@ class HomeModel @@ -92,9 +93,10 @@ class HomeModel
92 'is_new' => $sub['is_new'] == 'Y' ? true : false, 93 'is_new' => $sub['is_new'] == 'Y' ? true : false,
93 'content_code' => $sub['content_code'], 94 'content_code' => $sub['content_code'],
94 // 'thirdnav' => array(), 95 // 'thirdnav' => array(),
95 - 'index_sub' => $index_sub ++ 96 + 'index_sub' => $indexSub ++
96 ); 97 );
97 if (isset($sub['sub'])) { 98 if (isset($sub['sub'])) {
  99 + $thirdnav = array();
98 foreach ($sub['sub'] as $thirdsub) { // 三级 100 foreach ($sub['sub'] as $thirdsub) { // 三级
99 $thirdnav = array( 101 $thirdnav = array(
100 'title' => $thirdsub['sort_name'], 102 'title' => $thirdsub['sort_name'],
@@ -123,8 +125,9 @@ class HomeModel @@ -123,8 +125,9 @@ class HomeModel
123 Cache::set($key, $menu, 3600); 125 Cache::set($key, $menu, 3600);
124 } 126 }
125 } 127 }
  128 +
126 //数据缓存和接口都空的,取二级数据 129 //数据缓存和接口都空的,取二级数据
127 - if(empty($menu) && empty($data)) { 130 + if(empty($menu)) {
128 $menu = Cache::get($key,'slave'); 131 $menu = Cache::get($key,'slave');
129 } 132 }
130 133
@@ -176,25 +179,27 @@ class HomeModel @@ -176,25 +179,27 @@ class HomeModel
176 /** 179 /**
177 * 获取频道资源 180 * 获取频道资源
178 * 181 *
179 - * @param string $channel  
180 - * @param string $content_code 182 + * @param string $channel 频道标识(boys,girls,kids,lifestyle)
  183 + * @param string $contentCode 资源码
181 * @return array 184 * @return array
182 */ 185 */
183 - public static function getChannelResource($channel, $content_code) 186 + public static function getChannelResource($channel, $contentCode)
184 { 187 {
185 - $key = CacheConfig::KEY_WEB_HOME_CHANNEL_DATA.'_'.$content_code; 188 + $key = WebCacheConfig::KEY_WEB_HOME_CHANNEL_DATA . '_' . $contentCode;
186 $data = Cache::get($key); 189 $data = Cache::get($key);
187 - $resource = array();  
188 if(empty($data)) { 190 if(empty($data)) {
189 - $resource = IndexData::getResourceData($content_code);  
190 - if(isset($resource['data']) && !empty($resource['data']) && $resource['code'] == 200) { 191 + $resource = IndexData::getResourceData($contentCode);
  192 + if (isset($resource['data']) && !empty($resource['data']) && $resource['code'] == 200) {
191 //格式化数据 193 //格式化数据
192 $data = ChannelProcess::getFormat($channel, $resource['data']); 194 $data = ChannelProcess::getFormat($channel, $resource['data']);
193 - Cache::set($key, $data, 3600);//设置master,slave 195 + //设置master,slave
  196 + Cache::set($key, $data, 3600);
  197 + //清空变量
  198 + $resource = array();
194 } 199 }
195 } 200 }
196 //master没有数据,资源位没有数据, 取二层缓存 201 //master没有数据,资源位没有数据, 取二层缓存
197 - if(empty($data) && (empty($resource) || !isset($resource['data']))) { 202 + if(empty($data)) {
198 $data = Cache::get($key, 'slave'); 203 $data = Cache::get($key, 'slave');
199 } 204 }
200 return $data; 205 return $data;