Authored by hf

do add models to handle tempate data

@@ -13,22 +13,22 @@ @@ -13,22 +13,22 @@
13 price: 1000, 13 price: 1000,
14 tags: [ 14 tags: [
15 { 15 {
16 - isNew: true //NEW 16 + is_new: true //NEW
17 }, 17 },
18 { 18 {
19 - isSale: true //SALE 19 + is_discount: true //SALE
20 }, 20 },
21 { 21 {
22 - isLimit: false //限量商品 22 + is_limited: false //限量商品
23 }, 23 },
24 { 24 {
25 - isNewFestival: false //新品节 25 + is_yohood: // YOHOOD
26 }, 26 },
27 { 27 {
28 - isReNew: true //再到着 28 + is_advance: true //再到着
29 } 29 }
30 ], 30 ],
31 - isFew: true //即将售罄 31 + is_soon_sold_out: true //即将售罄
32 } 32 }
33 33
34 ### 侧栏导航 34 ### 侧栏导航
framework @ 75bbc3b0
1 -Subproject commit 119c247f5cf929aa1e059e40609bb16dd6b58f05 1 +Subproject commit 75bbc3b075de19f239532f60c5995d06c5f814e2
@@ -25,12 +25,19 @@ class AbstractAction extends Controller_Abstract @@ -25,12 +25,19 @@ class AbstractAction extends Controller_Abstract
25 * @var object 25 * @var object
26 */ 26 */
27 protected $_request; 27 protected $_request;
28 - 28 +
29 /** 29 /**
30 * 用户相关信息 30 * 用户相关信息
31 */ 31 */
32 - protected $_uid;  
33 - protected $_uname; 32 + protected $_uid = 0;
  33 + protected $_uname = '';
  34 +
  35 + /**
  36 + * 存放模板数据
  37 + *
  38 + * @var array
  39 + */
  40 + protected $_data;
34 41
35 /** 42 /**
36 * 初始化 43 * 初始化
@@ -38,7 +45,7 @@ class AbstractAction extends Controller_Abstract @@ -38,7 +45,7 @@ class AbstractAction extends Controller_Abstract
38 public function init() 45 public function init()
39 { 46 {
40 $this->_request = $this->getRequest(); 47 $this->_request = $this->getRequest();
41 - 48 +
42 // 设置环境变量 49 // 设置环境变量
43 switch (APPLICATION_ENV) { 50 switch (APPLICATION_ENV) {
44 case 'production': // 生产 51 case 'production': // 生产
@@ -166,7 +173,7 @@ class AbstractAction extends Controller_Abstract @@ -166,7 +173,7 @@ class AbstractAction extends Controller_Abstract
166 { 173 {
167 return $this->_request->getCookie($name, $default); 174 return $this->_request->getCookie($name, $default);
168 } 175 }
169 - 176 +
170 /** 177 /**
171 * 设置缓存 178 * 设置缓存
172 * 179 *
@@ -179,7 +186,7 @@ class AbstractAction extends Controller_Abstract @@ -179,7 +186,7 @@ class AbstractAction extends Controller_Abstract
179 { 186 {
180 Cache::set($key, $value, $expire); 187 Cache::set($key, $value, $expire);
181 } 188 }
182 - 189 +
183 /** 190 /**
184 * 获取缓存 191 * 获取缓存
185 * 192 *
@@ -195,7 +202,7 @@ class AbstractAction extends Controller_Abstract @@ -195,7 +202,7 @@ class AbstractAction extends Controller_Abstract
195 return Cache::get($key, 'slave'); 202 return Cache::get($key, 'slave');
196 } 203 }
197 } 204 }
198 - 205 +
199 /** 206 /**
200 * 获取当前登录的用户ID 207 * 获取当前登录的用户ID
201 * 208 *
@@ -216,7 +223,7 @@ class AbstractAction extends Controller_Abstract @@ -216,7 +223,7 @@ class AbstractAction extends Controller_Abstract
216 } 223 }
217 return $this->_uid; 224 return $this->_uid;
218 } 225 }
219 - 226 +
220 /** 227 /**
221 * 获取客户端唯一标识 228 * 获取客户端唯一标识
222 * 229 *
@@ -231,7 +238,7 @@ class AbstractAction extends Controller_Abstract @@ -231,7 +238,7 @@ class AbstractAction extends Controller_Abstract
231 } 238 }
232 return $udid; 239 return $udid;
233 } 240 }
234 - 241 +
235 /** 242 /**
236 * 获取当前登录的用户名字 243 * 获取当前登录的用户名字
237 * 244 *
@@ -258,6 +265,7 @@ class AbstractAction extends Controller_Abstract @@ -258,6 +265,7 @@ class AbstractAction extends Controller_Abstract
258 * @param string $title 标题 265 * @param string $title 标题
259 * @return void 266 * @return void
260 */ 267 */
  268 +
261 protected function setTitle($title) 269 protected function setTitle($title)
262 { 270 {
263 $this->_view->assign('title', $title . ' | '); 271 $this->_view->assign('title', $title . ' | ');
@@ -336,7 +344,7 @@ class AbstractAction extends Controller_Abstract @@ -336,7 +344,7 @@ class AbstractAction extends Controller_Abstract
336 344
337 $this->_view->assign('pageFooter', $footer); 345 $this->_view->assign('pageFooter', $footer);
338 } 346 }
339 - 347 +
340 /** 348 /**
341 * 设置侧边栏信息 349 * 设置侧边栏信息
342 * 350 *
@@ -368,7 +376,7 @@ class AbstractAction extends Controller_Abstract @@ -368,7 +376,7 @@ class AbstractAction extends Controller_Abstract
368 'textCn' => '创意生活', 376 'textCn' => '创意生活',
369 'textEn' => 'LIFE STYLE', 377 'textEn' => 'LIFE STYLE',
370 'styleClass' => 'life', 378 'styleClass' => 'life',
371 - 'url' => '/life', 379 + 'url' => '/lifestyle',
372 ), 380 ),
373 4 => array( 381 4 => array(
374 'textCn' => '逛', 382 'textCn' => '逛',
@@ -407,9 +415,8 @@ class AbstractAction extends Controller_Abstract @@ -407,9 +415,8 @@ class AbstractAction extends Controller_Abstract
407 ) 415 )
408 ), 416 ),
409 )); 417 ));
410 -  
411 } 418 }
412 - 419 +
413 /** 420 /**
414 * 返回顶部软件下载有关数据 421 * 返回顶部软件下载有关数据
415 * @return array 下载有关数据 422 * @return array 下载有关数据
@@ -418,7 +425,7 @@ class AbstractAction extends Controller_Abstract @@ -418,7 +425,7 @@ class AbstractAction extends Controller_Abstract
418 { 425 {
419 return array( 426 return array(
420 'img' => 'http://img11.static.yhbimg.com/adpic/2015/02/28/18/01d83bfad41c8fca8fd1ad334216d7d733.jpg?imageView/2/w/640/h/480', 427 'img' => 'http://img11.static.yhbimg.com/adpic/2015/02/28/18/01d83bfad41c8fca8fd1ad334216d7d733.jpg?imageView/2/w/640/h/480',
421 - 'url' => 'http://www.baidu.com' 428 + 'url' => 'http://www.baidu.com'
422 ); 429 );
423 } 430 }
424 431
@@ -442,7 +449,7 @@ class AbstractAction extends Controller_Abstract @@ -442,7 +449,7 @@ class AbstractAction extends Controller_Abstract
442 { 449 {
443 $download = array( 450 $download = array(
444 'img' => 'http://img11.static.yhbimg.com/adpic/2015/02/28/18/01d83bfad41c8fca8fd1ad334216d7d733.jpg?imageView/2/w/640/h/480', 451 'img' => 'http://img11.static.yhbimg.com/adpic/2015/02/28/18/01d83bfad41c8fca8fd1ad334216d7d733.jpg?imageView/2/w/640/h/480',
445 - 'url' => 'http://www.baidu.com' 452 + 'url' => 'http://www.baidu.com'
446 ); 453 );
447 454
448 $this->_view->assign('headerDownload', $download); 455 $this->_view->assign('headerDownload', $download);
@@ -12,6 +12,8 @@ @@ -12,6 +12,8 @@
12 12
13 namespace Api; 13 namespace Api;
14 14
  15 +use Plugin\Cache;
  16 +
15 class Yohobuy 17 class Yohobuy
16 { 18 {
17 19
@@ -100,11 +102,12 @@ class Yohobuy @@ -100,11 +102,12 @@ class Yohobuy
100 * 102 *
101 * @param string $url 接口URL 103 * @param string $url 接口URL
102 * @param array $data 参数列表 104 * @param array $data 参数列表
  105 + * @parma mixed $cache 控制是否启用接口数据的缓存(时间单位为秒). 如3600表示缓存1小时, false表示不缓存
103 * @param bool $returnJson 控制是否返回json格式数据 106 * @param bool $returnJson 控制是否返回json格式数据
104 * @param int $timeout 超时时间 107 * @param int $timeout 超时时间
105 * @return mixed 108 * @return mixed
106 */ 109 */
107 - public static function get($url, $data = array(), $returnJson = false, $timeout = 5) 110 + public static function get($url, $data = array(), $cache = false, $returnJson = false, $timeout = 5)
108 { 111 {
109 // 销毁私钥参数 112 // 销毁私钥参数
110 if (isset($data['private_key'])) { 113 if (isset($data['private_key'])) {
@@ -114,6 +117,15 @@ class Yohobuy @@ -114,6 +117,15 @@ class Yohobuy
114 $url = self::httpBuildQuery($url, $data); 117 $url = self::httpBuildQuery($url, $data);
115 } 118 }
116 119
  120 + /* 开启缓存的情况 */
  121 + if ($cache) {
  122 + // 先尝试获取一级缓存(master), 有数据则直接返回.
  123 + $result = Cache::get($url, 'master');
  124 + if (!empty($result)) {
  125 + return $result;
  126 + }
  127 + }
  128 +
117 $ch = curl_init($url); 129 $ch = curl_init($url);
118 curl_setopt($ch, CURLOPT_HEADER, 0); 130 curl_setopt($ch, CURLOPT_HEADER, 0);
119 curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); 131 curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
@@ -125,6 +137,18 @@ class Yohobuy @@ -125,6 +137,18 @@ class Yohobuy
125 curl_close($ch); 137 curl_close($ch);
126 $data = array(); 138 $data = array();
127 139
  140 + /* 开启缓存的情况 */
  141 + if ($cache) {
  142 + // 接口调用异常时, 不害怕,从我们的二级缓存(slave)里再取数据.
  143 + if (empty($result)) {
  144 + $result = Cache::get($url, 'slave');
  145 + }
  146 + // 接口调用成功时,这里会设置一级(master)和二级(slave)的缓存数据.
  147 + else {
  148 + Cache::set($url, $result, $cache);
  149 + }
  150 + }
  151 +
128 return $result; 152 return $result;
129 } 153 }
130 154
@@ -182,12 +206,22 @@ class Yohobuy @@ -182,12 +206,22 @@ class Yohobuy
182 * 206 *
183 * @param array $urlList 接口列表 207 * @param array $urlList 接口列表
184 * @param array $options CURL设置项 208 * @param array $options CURL设置项
185 - * @parma mixed $cache 控制是否启用接口数据的缓存 如3600表示缓存1小时, false表示不缓存 209 + * @parma mixed $cache 控制是否启用接口数据的缓存(时间单位为秒). 如3600表示缓存1小时, false表示不缓存
186 * @param int $timeout 超时时间,单位是秒 210 * @param int $timeout 超时时间,单位是秒
187 * @return array 211 * @return array
188 */ 212 */
189 public static function getMulti($urlList = array(), $options = array(), $cache = false, $timeout = 3) 213 public static function getMulti($urlList = array(), $options = array(), $cache = false, $timeout = 3)
190 { 214 {
  215 + /* 开启缓存的情况 */
  216 + if ($cache) {
  217 + $key = md5(implode(',', array_values($urlList)));
  218 + // 先尝试获取一级缓存(master), 有数据则直接返回.
  219 + $result = Cache::get($key, 'master');
  220 + if (!empty($result)) {
  221 + return $result;
  222 + }
  223 + }
  224 +
191 $result = array(); 225 $result = array();
192 $response = array(); 226 $response = array();
193 $running = 0; 227 $running = 0;
@@ -256,6 +290,18 @@ class Yohobuy @@ -256,6 +290,18 @@ class Yohobuy
256 } 290 }
257 curl_multi_close($mh); 291 curl_multi_close($mh);
258 292
  293 + /* 开启缓存的情况 */
  294 + if ($cache) {
  295 + // 接口调用异常时, 不害怕,从我们的二级缓存(slave)里再取数据.
  296 + if (empty($result)) {
  297 + $result = Cache::get($key, 'slave');
  298 + }
  299 + // 接口调用成功时,这里会设置一级(master)和二级(slave)的缓存数据.
  300 + else {
  301 + Cache::set($key, $result, $cache);
  302 + }
  303 + }
  304 +
259 return $result; 305 return $result;
260 } 306 }
261 307
@@ -263,10 +309,25 @@ class Yohobuy @@ -263,10 +309,25 @@ class Yohobuy
263 * rpc调用远程服务(YAR) 309 * rpc调用远程服务(YAR)
264 * 310 *
265 * @see http://php.net/manual/zh/yar-client.setopt.php 311 * @see http://php.net/manual/zh/yar-client.setopt.php
  312 + * @param string $uri
  313 + * @param string $method
  314 + * @param array $parameters
  315 + * @param mixed $cache 控制是否启用接口数据的缓存(时间单位为秒). 如3600表示缓存1小时, false表示不缓存
  316 + * @param int $timeout
266 * @return array 317 * @return array
267 */ 318 */
268 - public static function yarClient($uri, $method, $parameters = array(), $timeout = 3000) 319 + public static function yarClient($uri, $method, $parameters = array(), $cache = false, $timeout = 3000)
269 { 320 {
  321 + /* 开启缓存的情况 */
  322 + if ($cache) {
  323 + $key = self::httpBuildQuery($uri . $method, $parameters);
  324 + // 先尝试获取一级缓存(master), 有数据则直接返回.
  325 + $result = Cache::get($key, 'master');
  326 + if (!empty($result)) {
  327 + return $result;
  328 + }
  329 + }
  330 +
270 $client = new \Yar_Client($uri); 331 $client = new \Yar_Client($uri);
271 $client->SetOpt(YAR_OPT_PACKAGER, 'php'); 332 $client->SetOpt(YAR_OPT_PACKAGER, 'php');
272 $client->SetOpt(YAR_OPT_TIMEOUT, $timeout); 333 $client->SetOpt(YAR_OPT_TIMEOUT, $timeout);
@@ -278,6 +339,18 @@ class Yohobuy @@ -278,6 +339,18 @@ class Yohobuy
278 $result = array(); 339 $result = array();
279 } 340 }
280 341
  342 + /* 开启缓存的情况 */
  343 + if ($cache) {
  344 + // 接口调用异常时, 不害怕,从我们的二级缓存(slave)里再取数据.
  345 + if (empty($result)) {
  346 + $result = Cache::get($key, 'slave');
  347 + }
  348 + // 接口调用成功时,这里会设置一级(master)和二级(slave)的缓存数据.
  349 + else {
  350 + Cache::set($key, $result, $cache);
  351 + }
  352 + }
  353 +
281 return $result; 354 return $result;
282 } 355 }
283 356
@@ -7,7 +7,12 @@ namespace Configs; @@ -7,7 +7,12 @@ namespace Configs;
7 */ 7 */
8 class CacheConfig 8 class CacheConfig
9 { 9 {
10 -  
11 - const KEY_ACTION_INDEX_INDEX = 'key_action_index_index'; 10 +
  11 + /* 控制器方法中的数据缓存 */
  12 + const KEY_ACTION_INDEX_INDEX = 'key_action_index_index'; // 频道选择
  13 + const KEY_ACTION_BOYS_INDEX = 'key_action_boys_index'; // 男生首页
  14 + const KEY_ACTION_GIRLS_INDEX = 'key_action_girls_index'; // 女生首页
  15 + const KEY_ACTION_KIDS_INDEX = 'key_action_kids_index'; // 潮童首页
  16 + const KEY_ACTION_LIFESTYLE_INDEX = 'key_action_lifestyle_index'; // 创意生活首页
12 17
13 } 18 }
@@ -20,21 +20,17 @@ class IndexData @@ -20,21 +20,17 @@ class IndexData
20 /** 20 /**
21 * 获取启动轮播图 21 * 获取启动轮播图
22 * 22 *
  23 + * @param string $contentCode 内容位置码
23 * @return array 轮播图有关数据 24 * @return array 轮播图有关数据
24 */ 25 */
25 - public static function getBannerStart() 26 + public static function getBannerStart($contentCode)
26 { 27 {
27 // 构建必传参数 28 // 构建必传参数
28 $param = Yohobuy::param(); 29 $param = Yohobuy::param();
29 - $param['content_code'] = '7ba9118028f9b22090b57341487567eb'; 30 + $param['content_code'] = $contentCode;
30 $param['client_secret'] = Sign::getSign($param); 31 $param['client_secret'] = Sign::getSign($param);
31 - $response = Yohobuy::get(Yohobuy::SERVICE_URL . 'operations/api/v5/resource/get', $param);  
32 32
33 - $result = '';  
34 - if (isset($response['data'][0]['data']['list'][0]['src'])) {  
35 - $result = $response['data'][0]['data']['list'][0]['src'];  
36 - }  
37 - return $result; 33 + return Yohobuy::get(Yohobuy::SERVICE_URL . 'operations/api/v5/resource/get', $param);
38 } 34 }
39 35
40 /** 36 /**
@@ -53,42 +49,23 @@ class IndexData @@ -53,42 +49,23 @@ class IndexData
53 } 49 }
54 50
55 /** 51 /**
56 - * 获取用户个人信息  
57 - *  
58 - * @param integer $uid 用户ID  
59 - * @return array 用户个人信息数据  
60 - */  
61 - public static function getUserProfile($uid)  
62 - {  
63 - // 构建必传参数  
64 - $param = Yohobuy::param();  
65 - $param['method'] = 'app.passport.profile';  
66 - $param['uid'] = $uid;  
67 - $param['client_secret'] = Sign::getSign($param);  
68 -  
69 - return Yohobuy::get(Yohobuy::API_URL, $param);  
70 - }  
71 -  
72 - /**  
73 * 获取首页频道数据(除了可能喜欢的各楼层有关数据) 52 * 获取首页频道数据(除了可能喜欢的各楼层有关数据)
74 - * @param integer $uid 用户ID  
75 * @param string $gender 用户性别, "1,3"表示男, "2,3"表示女, "1,2,3"表示全部 53 * @param string $gender 用户性别, "1,3"表示男, "2,3"表示女, "1,2,3"表示全部
76 * @param string $contentCode 内容位置码 54 * @param string $contentCode 内容位置码
77 * @param integer $limit 查询返回的最大限字数,默认为20 55 * @param integer $limit 查询返回的最大限字数,默认为20
78 * @param integer $page 分页第几页,默认为第1页 56 * @param integer $page 分页第几页,默认为第1页
79 * @return array 首页频道数据 57 * @return array 首页频道数据
80 */ 58 */
81 - public static function getUserChannelData($uid, $gender, $contentCode, $limit = 20, $page = 1) 59 + public static function getResourceData($gender, $contentCode, $limit = 20, $page = 1)
82 { 60 {
83 $param = Yohobuy::param(); 61 $param = Yohobuy::param();
84 - $param['uid'] = $uid;  
85 $param['gender'] = $gender; 62 $param['gender'] = $gender;
86 $param['content_code'] = $contentCode; 63 $param['content_code'] = $contentCode;
87 $param['page'] = $page; 64 $param['page'] = $page;
88 $param['limit'] = $limit; 65 $param['limit'] = $limit;
89 $param['client_secret'] = Sign::getSign($param); 66 $param['client_secret'] = Sign::getSign($param);
90 -  
91 - return Yohobuy::get(Yohobuy::SERVICE_URL . 'operations/api/v5/resource/home', $param); 67 +
  68 + return Yohobuy::get(Yohobuy::SERVICE_URL . 'operations/api/v5/resource/home', $param);
92 } 69 }
93 70
94 } 71 }
1 <?php 1 <?php
2 2
3 -/*  
4 - * To change this license header, choose License Headers in Project Properties.  
5 - * To change this template file, choose Tools | Templates  
6 - * and open the template in the editor. 3 +namespace LibModels\Wap\Product;
  4 +
  5 +use Api\Sign;
  6 +use Api\Yohobuy;
  7 +
  8 +/**
  9 + * 商品详情相关的数据模型
  10 + *
  11 + * @name DetailData
  12 + * @package LibModels/Wap/Product
  13 + * @copyright yoho.inc
  14 + * @version 1.0 (2015-10-8 11:51:32)
  15 + * @author fei.hong <fei.hong@yoho.cn>
7 */ 16 */
  17 +class DetailData
  18 +{
8 19
  20 +}
@@ -8,7 +8,7 @@ use Api\Yohobuy; @@ -8,7 +8,7 @@ use Api\Yohobuy;
8 /** 8 /**
9 * 商品推荐相关的数据模型 9 * 商品推荐相关的数据模型
10 * 10 *
11 - * @name RecomModel 11 + * @name RecomData
12 * @package LibModels/Wap/Product 12 * @package LibModels/Wap/Product
13 * @copyright yoho.inc 13 * @copyright yoho.inc
14 * @version 1.0 (2015-10-8 11:51:32) 14 * @version 1.0 (2015-10-8 11:51:32)
@@ -35,15 +35,19 @@ class Cache @@ -35,15 +35,19 @@ class Cache
35 */ 35 */
36 public static function set($key, $value, $expire = 3600) 36 public static function set($key, $value, $expire = 3600)
37 { 37 {
38 - // WINDOWS  
39 - if (PATH_SEPARATOR === '\\') {  
40 - HoodCache::Memcache('master')->set(self::makeKey($key, 'master'), $value, $expire);  
41 - HoodCache::Memcache('slave')->set(self::makeKey($key, 'slave'), $value, 0);  
42 - }  
43 - // LINUX  
44 - else {  
45 - HoodCache::Memcached('master')->set(self::makeKey($key, 'master'), $value, $expire);  
46 - HoodCache::Memcached('slave')->set(self::makeKey($key, 'slave'), $value, 0); 38 + try {
  39 + // WINDOWS
  40 + if (DIRECTORY_SEPARATOR === '\\') {
  41 + HoodCache::Memcache('master')->set(self::makeKey($key, 'master'), $value, $expire);
  42 + HoodCache::Memcache('slave')->set(self::makeKey($key, 'slave'), $value, 0);
  43 + }
  44 + // LINUX
  45 + else {
  46 + HoodCache::Memcached('master')->set(self::makeKey($key, 'master'), $value, $expire);
  47 + HoodCache::Memcached('slave')->set(self::makeKey($key, 'slave'), $value, 0);
  48 + }
  49 + } catch (Exception $e) {
  50 + // do nothing
47 } 51 }
48 } 52 }
49 53
@@ -58,13 +62,17 @@ class Cache @@ -58,13 +62,17 @@ class Cache
58 { 62 {
59 $result = array(); 63 $result = array();
60 64
61 - // WINDOWS  
62 - if (PATH_SEPARATOR === '\\') {  
63 - $result = HoodCache::Memcache($node)->get(self::makeKey($key, $node));  
64 - }  
65 - // LINUX  
66 - else {  
67 - $result = HoodCache::Memcached($node)->get(self::makeKey($key, $node)); 65 + try {
  66 + // WINDOWS
  67 + if (DIRECTORY_SEPARATOR === '\\') {
  68 + $result = HoodCache::Memcache($node)->get(self::makeKey($key, $node));
  69 + }
  70 + // LINUX
  71 + else {
  72 + $result = HoodCache::Memcached($node)->get(self::makeKey($key, $node));
  73 + }
  74 + } catch (Exception $e) {
  75 + $result = array();
68 } 76 }
69 77
70 return $result; 78 return $result;
@@ -79,7 +87,7 @@ class Cache @@ -79,7 +87,7 @@ class Cache
79 public static function delete($key) 87 public static function delete($key)
80 { 88 {
81 // WINDOWS 89 // WINDOWS
82 - if (PATH_SEPARATOR === '\\') { 90 + if (DIRECTORY_SEPARATOR === '\\') {
83 HoodCache::Memcache('master')->delete(self::makeKey($key, 'master')); 91 HoodCache::Memcache('master')->delete(self::makeKey($key, 'master'));
84 HoodCache::Memcache('slave')->delete(self::makeKey($key, 'slave')); 92 HoodCache::Memcache('slave')->delete(self::makeKey($key, 'slave'));
85 } 93 }
@@ -19,16 +19,17 @@ class FloorProcess @@ -19,16 +19,17 @@ class FloorProcess
19 { 19 {
20 $result = array(); 20 $result = array();
21 if (!empty($data['list'])) { 21 if (!empty($data['list'])) {
  22 + $build = array();
22 foreach ($data['list'] as $v) { 23 foreach ($data['list'] as $v) {
23 $fun = $v['template_name']; 24 $fun = $v['template_name'];
24 if (!is_callable("self::$fun")) { 25 if (!is_callable("self::$fun")) {
25 continue; 26 continue;
26 } 27 }
27 - $data = self::$fun($v['data'], $type);  
28 - if (empty($data)) { 28 + $build = self::$fun($v['data'], $type);
  29 + if (empty($build)) {
29 continue; 30 continue;
30 } 31 }
31 - $result[] = $data; 32 + $result[] = $build;
32 } 33 }
33 } 34 }
34 return $result; 35 return $result;
@@ -83,6 +84,7 @@ class FloorProcess @@ -83,6 +84,7 @@ class FloorProcess
83 if (empty($data)) { 84 if (empty($data)) {
84 return array(); 85 return array();
85 } 86 }
  87 +
86 foreach ($data as &$one) { 88 foreach ($data as &$one) {
87 $one['img'] = Helpers::getImageUrl($one['src'], 750, 364, 1); 89 $one['img'] = Helpers::getImageUrl($one['src'], 750, 364, 1);
88 unset($one['src']); 90 unset($one['src']);
@@ -257,7 +259,6 @@ class FloorProcess @@ -257,7 +259,6 @@ class FloorProcess
257 */ 259 */
258 private static function single_name_image($data, $type) 260 private static function single_name_image($data, $type)
259 { 261 {
260 -  
261 if (empty($data)) { 262 if (empty($data)) {
262 return array(); 263 return array();
263 } 264 }
  1 +server
  2 +{
  3 + listen 80;
  4 + server_name wap.yohobuy.com;
  5 +
  6 + #access_log /Data/logs/access.wap.yohobuy.com.log combined;
  7 + error_log /Data/logs/error.wap.yohobuy.com.log warn;
  8 +
  9 + root /Data/code/git/yohobuy/yohobuy/m.yohobuy.com/public;
  10 +
  11 + location ~* \.html$ {
  12 + root /Data/PE/yohobuy/assets;
  13 + if (!-f $request_filename){
  14 + root /Data/PE/yohobuy/yohobuy/m.yohobuy.com/public;
  15 + rewrite ^/(.+)$ /index.php?$1& last;
  16 + }
  17 + expires 7d;
  18 + }
  19 +
  20 + location / {
  21 + index index.php;
  22 + if (!-f $request_filename){
  23 + rewrite ^/(.+)$ /index.php?$1& last;
  24 + }
  25 + }
  26 +
  27 + location ~* \.(ico|woff)$ {
  28 + expires 7d;
  29 + }
  30 +
  31 + location = /crossdomain.xml {
  32 + expires 7d;
  33 + }
  34 +
  35 + location ~ .*\.php?$ {
  36 + fastcgi_pass 127.0.0.1:9000;
  37 + fastcgi_index index.php;
  38 + #fastcgi_param PATH_INFO $fastcgi_script_name;
  39 + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  40 + include fastcgi_params;
  41 + }
  42 +
  43 + error_page 403 = http://wap.yohobuy.com;
  44 + error_page 404 = http://wap.yohobuy.com/error.html;
  45 +}
  46 +
  47 +server
  48 +{
  49 + listen 80;
  50 + server_name static.wap.yohobuy.com;
  51 +
  52 + #access_log /Data/logs/access.static.wap.yohobuy.com.log combined;
  53 + #error_log /Data/logs/error.static.wap.yohobuy.com.log warn;
  54 +
  55 + root /Data/PE/yohobuy/static;
  56 +
  57 + location / {
  58 + log_not_found off;
  59 + access_log off;
  60 + expires 30d;
  61 + }
  62 +
  63 + location ~* \.(svg|eot|ttf|woff|otf)$ {
  64 + add_header Access-Control-Allow-Origin *;
  65 + expires 30d;
  66 + }
  67 +
  68 +}
@@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
3 use Action\AbstractAction; 3 use Action\AbstractAction;
4 use LibModels\Wap\Home\IndexData; 4 use LibModels\Wap\Home\IndexData;
5 use Plugin\DataProcess\FloorProcess; 5 use Plugin\DataProcess\FloorProcess;
  6 +use Configs\CacheConfig;
6 7
7 /** 8 /**
8 * 男生首页 9 * 男生首页
@@ -10,6 +11,16 @@ use Plugin\DataProcess\FloorProcess; @@ -10,6 +11,16 @@ use Plugin\DataProcess\FloorProcess;
10 class BoysController extends AbstractAction 11 class BoysController extends AbstractAction
11 { 12 {
12 13
  14 + // 数据缓存时间
  15 + const DATA_EXPIRE = 3600;
  16 + // 楼层资源的位置码
  17 + const CODE_FLOOR = '8512bf0755cc549ac323f852c9fd945d';
  18 + // 底部广告的位置码
  19 + const CODE_BOTTOM_BANNER = 'a2ec977c027d0cd9cdccb356ddf16b08';
  20 +
  21 + /**
  22 + * 男生首页
  23 + */
13 public function indexAction() 24 public function indexAction()
14 { 25 {
15 // 设置网站标题 26 // 设置网站标题
@@ -19,17 +30,34 @@ class BoysController extends AbstractAction @@ -19,17 +30,34 @@ class BoysController extends AbstractAction
19 // 设置顶部信息(搜索) 30 // 设置顶部信息(搜索)
20 $this->setHomeChannelHeader(); 31 $this->setHomeChannelHeader();
21 32
22 - $data = array('boysHomePage' => true);  
23 - $uid = $this->getUid();  
24 -  
25 - // 频道数据  
26 - $channelData = IndexData::getUserChannelData($uid, '1,3', '201504091403001');  
27 - if (isset($channelData['code']) && $channelData['code'] == 200) {  
28 - $data['content'] = FloorProcess::getContent($channelData['data']);  
29 - }  
30 - 33 + $data = array();
  34 + $data['boysHomePage'] = true;
31 $data['maybeLike'] = true; 35 $data['maybeLike'] = true;
32 36
  37 + do {
  38 + // 先尝试获取一级缓存(master), 有数据则直接返回.
  39 + $data['content'] = $this->getCache(CacheConfig::KEY_ACTION_BOYS_INDEX, true);
  40 + if (!empty($data['content'])) {
  41 + break;
  42 + }
  43 +
  44 + // 调用接口获取楼层数据, 并封装成模板渲染需要的数据格式
  45 + $channelData = IndexData::getResourceData('1,3', self::CODE_FLOOR);
  46 + if (isset($channelData['code']) && $channelData['code'] == 200) {
  47 + $data['content'] = FloorProcess::getContent($channelData['data']);
  48 + }
  49 +
  50 + // 接口调用正常,数据封装完成, 则设置一级(master)和二级(slave)数据缓存
  51 + if (!empty($data['content'])) {
  52 + $this->setCache(CacheConfig::KEY_ACTION_BOYS_INDEX, $data['content'], self::DATA_EXPIRE); // 缓存1小时
  53 + break;
  54 + }
  55 +
  56 + // 接口调用异常时, 不害怕,从我们的二级缓存(slave)里再取数据.
  57 + $data['content'] = $this->getCache(CacheConfig::KEY_ACTION_BOYS_INDEX, false);
  58 +
  59 + } while (false);
  60 +
33 $this->_view->display('index', $data); 61 $this->_view->display('index', $data);
34 } 62 }
35 63
@@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
3 use Action\AbstractAction; 3 use Action\AbstractAction;
4 use LibModels\Wap\Home\IndexData; 4 use LibModels\Wap\Home\IndexData;
5 use Plugin\DataProcess\FloorProcess; 5 use Plugin\DataProcess\FloorProcess;
  6 +use Configs\CacheConfig;
6 7
7 /** 8 /**
8 * 女生首页 9 * 女生首页
@@ -10,6 +11,16 @@ use Plugin\DataProcess\FloorProcess; @@ -10,6 +11,16 @@ use Plugin\DataProcess\FloorProcess;
10 class GirlsController extends AbstractAction 11 class GirlsController extends AbstractAction
11 { 12 {
12 13
  14 + // 数据缓存时间
  15 + const DATA_EXPIRE = 3600;
  16 + // 楼层资源的位置码
  17 + const CODE_FLOOR = '189b6686065dbd6755dd6906cf03c002';
  18 + // 底部广告的位置码
  19 + const CODE_BOTTOM_BANNER = '8c8bd1b89a22e5895f05882e0825b493';
  20 +
  21 + /**
  22 + * 女生首页
  23 + */
13 public function indexAction() 24 public function indexAction()
14 { 25 {
15 // 设置网站标题 26 // 设置网站标题
@@ -19,14 +30,33 @@ class GirlsController extends AbstractAction @@ -19,14 +30,33 @@ class GirlsController extends AbstractAction
19 // 设置顶部信息(搜索) 30 // 设置顶部信息(搜索)
20 $this->setHomeChannelHeader(); 31 $this->setHomeChannelHeader();
21 32
22 - $data = array('grilsHomePage' => true);  
23 - $uid = $this->getUid(); 33 + $data = array();
  34 + $data['grilsHomePage'] = true;
  35 + $data['maybeLike'] = true;
  36 +
  37 + do {
  38 + // 先尝试获取一级缓存(master), 有数据则直接返回.
  39 + $data['content'] = $this->getCache(CacheConfig::KEY_ACTION_GIRLS_INDEX, true);
  40 + if (!empty($data['content'])) {
  41 + break;
  42 + }
  43 +
  44 + // 调用接口获取楼层数据, 并封装成模板渲染需要的数据格式
  45 + $channelData = IndexData::getResourceData('2,3', self::CODE_FLOOR);
  46 + if (isset($channelData['code']) && $channelData['code'] == 200) {
  47 + $data['content'] = FloorProcess::getContent($channelData['data']);
  48 + }
  49 +
  50 + // 接口调用正常,数据封装完成, 则设置一级(master)和二级(slave)数据缓存
  51 + if (!empty($data['content'])) {
  52 + $this->setCache(CacheConfig::KEY_ACTION_GIRLS_INDEX, $data['content'], self::DATA_EXPIRE); // 缓存1小时
  53 + break;
  54 + }
24 55
25 - // 频道数据  
26 - $channelData = IndexData::getUserChannelData($uid, '2,3', '201504091403002');  
27 - if (isset($channelData['code']) && $channelData['code'] == 200) {  
28 - $data['content'] = FloorProcess::getContent($channelData['data'], 2);  
29 - } 56 + // 接口调用异常时, 不害怕,从我们的二级缓存(slave)里再取数据.
  57 + $data['content'] = $this->getCache(CacheConfig::KEY_ACTION_GIRLS_INDEX, false);
  58 +
  59 + } while (false);
30 60
31 $this->_view->display('index', $data); 61 $this->_view->display('index', $data);
32 } 62 }
@@ -9,23 +9,23 @@ use Plugin\Helpers; @@ -9,23 +9,23 @@ use Plugin\Helpers;
9 */ 9 */
10 class IndexController extends AbstractAction 10 class IndexController extends AbstractAction
11 { 11 {
12 - 12 + const CODE_BANNER = '7ba9118028f9b22090b57341487567eb';
  13 +
13 /** 14 /**
14 * 启动首页频道选择 15 * 启动首页频道选择
15 */ 16 */
16 public function indexAction() 17 public function indexAction()
17 { 18 {
  19 + $data = array(
  20 + 'background' => '',
  21 + );
  22 +
18 // 背景图获取 23 // 背景图获取
19 - $banner = IndexData::getBannerStart();  
20 - if ($banner) {  
21 - $data['background'] = Helpers::getImageUrl($banner, 640, 800, 1); 24 + $banner = IndexData::getBannerStart(self::CODE_BANNER);
  25 + if (isset($banner['data'][0]['data']['list'][0]['src'])) {
  26 + $data['background'] = Helpers::getImageUrl($banner['data'][0]['data']['list'][0]['src'], 640, 800, 1);
22 } 27 }
23 -  
24 - // 设置底部导航信息  
25 - $this->setNavFooter();  
26 -  
27 - // 生成HTML (index.html)  
28 - $this->_view->html('index'); 28 + $banner = array();
29 29
30 // 渲染模板 30 // 渲染模板
31 $this->_view->display('index', $data); 31 $this->_view->display('index', $data);
@@ -3,13 +3,21 @@ @@ -3,13 +3,21 @@
3 use Action\AbstractAction; 3 use Action\AbstractAction;
4 use LibModels\Wap\Home\IndexData; 4 use LibModels\Wap\Home\IndexData;
5 use Plugin\DataProcess\FloorProcess; 5 use Plugin\DataProcess\FloorProcess;
  6 +use Configs\CacheConfig;
6 7
7 /** 8 /**
8 * 儿童首页 9 * 儿童首页
9 */ 10 */
10 class KidsController extends AbstractAction 11 class KidsController extends AbstractAction
11 { 12 {
  13 + // 数据缓存时间
  14 + const DATA_EXPIRE = 3600;
  15 + // 楼层资源的位置码
  16 + const CODE_FLOOR = 'b8c1bff53d4ea60f978926d538620636'; // '66cad79d93e055ad6fc5c8744086066d';
12 17
  18 + /**
  19 + * 潮童首页
  20 + */
13 public function indexAction() 21 public function indexAction()
14 { 22 {
15 // 设置网站标题 23 // 设置网站标题
@@ -19,17 +27,34 @@ class KidsController extends AbstractAction @@ -19,17 +27,34 @@ class KidsController extends AbstractAction
19 // 设置顶部信息(搜索) 27 // 设置顶部信息(搜索)
20 $this->setHomeChannelHeader(); 28 $this->setHomeChannelHeader();
21 29
22 - $data = array('kidsHomePage' => true);  
23 - $uid = $this->getUid(); 30 + $data = array();
  31 + $data['kidsHomePage'] = true;
  32 + $data['maybeLike'] = true;
24 33
25 - // 频道数据  
26 - $channelData = IndexData::getUserChannelData($uid, '', 'e9875682c1599a886bfbdb965b740022');  
27 - if (isset($channelData['code']) && $channelData['code'] == 200) {  
28 - $data['content'] = FloorProcess::getContent($channelData['data'], 3);  
29 - } 34 + do {
  35 + // 先尝试获取一级缓存(master), 有数据则直接返回.
  36 + $data['content'] = $this->getCache(CacheConfig::KEY_ACTION_KIDS_INDEX, true);
  37 + if (!empty($data['content'])) {
  38 + break;
  39 + }
  40 +
  41 + // 调用接口获取楼层数据, 并封装成模板渲染需要的数据格式
  42 + $channelData = IndexData::getResourceData('', self::CODE_FLOOR);
  43 + if (isset($channelData['code']) && $channelData['code'] == 200) {
  44 + $data['content'] = FloorProcess::getContent($channelData['data'], 3);
  45 + }
  46 +
  47 + // 接口调用正常,数据封装完成, 则设置一级(master)和二级(slave)数据缓存
  48 + if (!empty($data['content'])) {
  49 + $this->setCache(CacheConfig::KEY_ACTION_KIDS_INDEX, $data['content'], self::DATA_EXPIRE); // 缓存1小时
  50 + break;
  51 + }
  52 +
  53 + // 接口调用异常时, 不害怕,从我们的二级缓存(slave)里再取数据.
  54 + $data['content'] = $this->getCache(CacheConfig::KEY_ACTION_KIDS_INDEX, false);
  55 +
  56 + } while (false);
30 57
31 - $data['maybeLike'] = true;  
32 -  
33 $this->_view->display('index', $data); 58 $this->_view->display('index', $data);
34 } 59 }
35 60
@@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
3 use Action\AbstractAction; 3 use Action\AbstractAction;
4 use LibModels\Wap\Home\IndexData; 4 use LibModels\Wap\Home\IndexData;
5 use Plugin\DataProcess\FloorProcess; 5 use Plugin\DataProcess\FloorProcess;
  6 +use Configs\CacheConfig;
6 7
7 /** 8 /**
8 * 创意生活首页 9 * 创意生活首页
@@ -10,6 +11,14 @@ use Plugin\DataProcess\FloorProcess; @@ -10,6 +11,14 @@ use Plugin\DataProcess\FloorProcess;
10 class LifestyleController extends AbstractAction 11 class LifestyleController extends AbstractAction
11 { 12 {
12 13
  14 + // 数据缓存时间
  15 + const DATA_EXPIRE = 3600;
  16 + // 楼层资源的位置码
  17 + const CODE_FLOOR = '61cd852c6afcf60660196154f66a3a62';
  18 +
  19 + /**
  20 + * 创意生活首页
  21 + */
13 public function indexAction() 22 public function indexAction()
14 { 23 {
15 // 设置网站标题 24 // 设置网站标题
@@ -19,17 +28,34 @@ class LifestyleController extends AbstractAction @@ -19,17 +28,34 @@ class LifestyleController extends AbstractAction
19 // 设置顶部信息(搜索) 28 // 设置顶部信息(搜索)
20 $this->setHomeChannelHeader(); 29 $this->setHomeChannelHeader();
21 30
22 - $data = array('lifestyleHomePage' => true);  
23 - $uid = $this->getUid();  
24 -  
25 - // 频道数据  
26 - $channelData = IndexData::getUserChannelData($uid, '', '9aa25f5133f011ec96c2045eb15ae425');  
27 - if (isset($channelData['code']) && $channelData['code'] == 200) {  
28 - $data['content'] = FloorProcess::getContent($channelData['data'], 4);  
29 - }  
30 - 31 + $data = array();
  32 + $data['lifestyleHomePage'] = true;
31 $data['maybeLike'] = true; 33 $data['maybeLike'] = true;
32 34
  35 + do {
  36 + // 先尝试获取一级缓存(master), 有数据则直接返回.
  37 + $data['content'] = $this->getCache(CacheConfig::KEY_ACTION_LIFESTYLE_INDEX, true);
  38 + if (!empty($data['content'])) {
  39 + break;
  40 + }
  41 +
  42 + // 调用接口获取楼层数据, 并封装成模板渲染需要的数据格式
  43 + $channelData = IndexData::getResourceData('', '61cd852c6afcf60660196154f66a3a62');
  44 + if (isset($channelData['code']) && $channelData['code'] == 200) {
  45 + $data['content'] = FloorProcess::getContent($channelData['data'], 4);
  46 + }
  47 +
  48 + // 接口调用正常,数据封装完成, 则设置一级(master)和二级(slave)数据缓存
  49 + if (!empty($data['content'])) {
  50 + $this->setCache(CacheConfig::KEY_ACTION_LIFESTYLE_INDEX, $data['content'], self::DATA_EXPIRE); // 缓存1小时
  51 + break;
  52 + }
  53 +
  54 + // 接口调用异常时, 不害怕,从我们的二级缓存(slave)里再取数据.
  55 + $data['content'] = $this->getCache(CacheConfig::KEY_ACTION_LIFESTYLE_INDEX, false);
  56 +
  57 + } while (false);
  58 +
33 $this->_view->display('index', $data); 59 $this->_view->display('index', $data);
34 } 60 }
35 61
  1 +<?php
  2 +
  3 +use LibModels\Wap\Home\IndexData;
  4 +use Plugin\Helpers;
  5 +
  6 +/**
  7 + * 首页相关的模板数据模型
  8 + *
  9 + * @author fei.hong
  10 + */
  11 +class IndexModel
  12 +{
  13 +
  14 + /* 频道选择页取背景图片的位置码 */
  15 + const CODE_BG = '7ba9118028f9b22090b57341487567eb';
  16 +
  17 + /**
  18 + * 获取频道选择页的背景图片
  19 + *
  20 + * @return string | false
  21 + */
  22 + public static function getBgImage()
  23 + {
  24 + $banner = IndexData::getBannerStart(self::CODE_BG);
  25 + if (isset($banner['data'][0]['data']['list'][0]['src'])) {
  26 + $result = Helpers::getImageUrl($banner['data'][0]['data']['list'][0]['src'], 640, 800, 1);
  27 + } else {
  28 + $result = false;
  29 + }
  30 +
  31 + return $result;
  32 + }
  33 +
  34 +}
1 -[common]  
2 -servers.host = 127.0.0.1:11211:90  
3 -[memcached:common]  
4 -servers.hosts = 127.0.0.1:11213 1 +[memcached]
  2 +master.hosts = 127.0.0.1:11212,127.0.0.1:11213
  3 +slave.hosts = 127.0.0.1:11212,127.0.0.1:11213
5 [redis] 4 [redis]
6 servers.hosts = 127.0.0.1:6379 5 servers.hosts = 127.0.0.1:6379
@@ -5,7 +5,7 @@ collation = utf8_unicode_ci @@ -5,7 +5,7 @@ collation = utf8_unicode_ci
5 timeout = 3 5 timeout = 3
6 6
7 [database] 7 [database]
8 -yhb_bill.username = yohodb  
9 -yhb_bill.passwd = yohonj_9646_mysql  
10 -yhb_bill.write = 123.56.86.219:5511  
11 -yhb_bill.read = 123.56.86.219:5511  
  8 +yhb_test.username = test
  9 +yhb_test.passwd = 123456
  10 +yhb_test.write = 127.0.0.1:5511
  11 +yhb_test.read = 127.0.0.1:5511
@@ -5,7 +5,7 @@ collation = utf8_unicode_ci @@ -5,7 +5,7 @@ collation = utf8_unicode_ci
5 timeout = 3 5 timeout = 3
6 6
7 [database] 7 [database]
8 -yhb_bill.username = yohodb  
9 -yhb_bill.passwd = yohonj_9646_mysql  
10 -yhb_bill.write = 123.56.86.219:5511  
11 -yhb_bill.read = 123.56.86.219:5511  
  8 +yhb_test.username = test
  9 +yhb_test.passwd = 123456
  10 +yhb_test.write = 127.0.0.1:5511
  11 +yhb_test.read = 127.0.0.1:5511
@@ -5,7 +5,7 @@ collation = utf8_unicode_ci @@ -5,7 +5,7 @@ collation = utf8_unicode_ci
5 timeout = 3 5 timeout = 3
6 6
7 [database] 7 [database]
8 -yhb_bill.username = yohodb  
9 -yhb_bill.passwd = yohonj_9646_mysql  
10 -yhb_bill.write = 10.170.183.158:5511  
11 -yhb_bill.read = 10.170.183.158:5511  
  8 +yhb_test.username = test
  9 +yhb_test.passwd = 123456
  10 +yhb_test.write = 127.0.0.1:5511
  11 +yhb_test.read = 127.0.0.1:5511
1 <?php 1 <?php
2 use Yaf\Application; 2 use Yaf\Application;
3 3
  4 +define('DOMAIN', 'm.dev.yohobuy.com');
4 define('APPLICATION_PATH', dirname(__DIR__)); 5 define('APPLICATION_PATH', dirname(__DIR__));
5 define('ROOT_PATH', dirname(dirname(APPLICATION_PATH))); 6 define('ROOT_PATH', dirname(dirname(APPLICATION_PATH)));
6 defined('APPLICATION_ENV') || define('APPLICATION_ENV', 'developer'); 7 defined('APPLICATION_ENV') || define('APPLICATION_ENV', 'developer');
1 <?php 1 <?php
2 use Yaf\Application; 2 use Yaf\Application;
3 3
  4 +define('DOMAIN', 'buy.test.yoho.cn');
4 define('APPLICATION_PATH', dirname(__DIR__)); 5 define('APPLICATION_PATH', dirname(__DIR__));
5 define('ROOT_PATH', dirname(dirname(APPLICATION_PATH))); 6 define('ROOT_PATH', dirname(dirname(APPLICATION_PATH)));
6 defined('APPLICATION_ENV') || define('APPLICATION_ENV', 'testing'); 7 defined('APPLICATION_ENV') || define('APPLICATION_ENV', 'testing');
1 <?php 1 <?php
2 use Yaf\Application; 2 use Yaf\Application;
3 3
  4 +define('DOMAIN', 'wap.yohobuy.com');
4 define('APPLICATION_PATH', dirname(__DIR__)); 5 define('APPLICATION_PATH', dirname(__DIR__));
5 define('ROOT_PATH', dirname(dirname(APPLICATION_PATH))); 6 define('ROOT_PATH', dirname(dirname(APPLICATION_PATH)));
6 defined('APPLICATION_ENV') || define('APPLICATION_ENV', 'production'); 7 defined('APPLICATION_ENV') || define('APPLICATION_ENV', 'production');