Authored by 梁志锋

Merge branch 'develop' of git.dev.yoho.cn:web/yohobuy into develop

@@ -351,7 +351,7 @@ @@ -351,7 +351,7 @@
351 { 351 {
352 //onlyOne 352 //onlyOne
353 relatedReco: { 353 relatedReco: {
354 - onlyOne: true, //若只有一个商品,传此字段为true 354 + id: 1, //必须字段
355 thumb: '', 355 thumb: '',
356 name: '', 356 name: '',
357 salePrice: 123, 357 salePrice: 123,
framework @ 75bbc3b0
1 -Subproject commit 119c247f5cf929aa1e059e40609bb16dd6b58f05 1 +Subproject commit 75bbc3b075de19f239532f60c5995d06c5f814e2
@@ -189,6 +189,32 @@ class AbstractAction extends Controller_Abstract @@ -189,6 +189,32 @@ class AbstractAction extends Controller_Abstract
189 return Cache::get($key, 'slave'); 189 return Cache::get($key, 'slave');
190 } 190 }
191 } 191 }
  192 +
  193 + /**
  194 + * 获取当前登录的用户ID
  195 + *
  196 + * @return int
  197 + * @todo
  198 + */
  199 + protected function getUid()
  200 + {
  201 + return 0;
  202 + }
  203 +
  204 + /**
  205 + * 获取客户端唯一标识
  206 + *
  207 + * @return string
  208 + */
  209 + protected function getUdid()
  210 + {
  211 + $udid = '';
  212 + $ip = $this->_request->getServer('REMOTE_ADDR');
  213 + if ($ip) {
  214 + $udid = ip2long($ip);
  215 + }
  216 + return $udid;
  217 + }
192 218
193 /* 219 /*
194 * 设置网站SEO的标题 220 * 设置网站SEO的标题
@@ -11,6 +11,8 @@ @@ -11,6 +11,8 @@
11 */ 11 */
12 namespace Api; 12 namespace Api;
13 13
  14 +use Plugin\Cache;
  15 +
14 class Yohobuy 16 class Yohobuy
15 { 17 {
16 18
@@ -93,12 +95,25 @@ class Yohobuy @@ -93,12 +95,25 @@ class Yohobuy
93 * 95 *
94 * @param string $url 接口URL 96 * @param string $url 接口URL
95 * @param array $data 参数列表 97 * @param array $data 参数列表
  98 + * @param mixed $cache 控制是否启用接口数据的缓存 如3600表示缓存1小时, false表示不缓存
96 * @param bool $returnJson 控制是否返回json格式数据 99 * @param bool $returnJson 控制是否返回json格式数据
97 * @param int $timeout 超时时间 100 * @param int $timeout 超时时间
98 * @return mixed 101 * @return mixed
99 */ 102 */
100 - public static function get($url, $data = array(), $returnJson = false, $timeout = 5) 103 + public static function get($url, $data = array(), $cache = false, $returnJson = false, $timeout = 5)
101 { 104 {
  105 + // 代表是否开启缓存
  106 + $useCache = $cache && isset($data['client_secret']);
  107 +
  108 + /* 先尝试获取一级缓存(master), 有数据则直接返回 */
  109 + if ($useCache) {
  110 + $key = md5($url . $data['client_secret']);
  111 + $result = Cache::get($key, 'master');
  112 + if (!empty($result)) {
  113 + return $result;
  114 + }
  115 + }
  116 +
102 // 销毁私钥参数 117 // 销毁私钥参数
103 if (isset($data['private_key'])) { 118 if (isset($data['private_key'])) {
104 unset($data['private_key']); 119 unset($data['private_key']);
@@ -117,6 +132,18 @@ class Yohobuy @@ -117,6 +132,18 @@ class Yohobuy
117 } 132 }
118 curl_close($ch); 133 curl_close($ch);
119 $data = array(); 134 $data = array();
  135 +
  136 + /* 设置一级二级缓存 或 获取二级缓存(slave) */
  137 + if ($useCache) {
  138 + // 如果接口异常没数据返回,则获取二级缓存
  139 + if (empty($result)) {
  140 + $result = Cache::get($key, 'slave');
  141 + }
  142 + // 如果接口正常有数据返回,则设置数据缓存
  143 + else {
  144 + Cache::set($key, $result);
  145 + }
  146 + }
120 147
121 return $result; 148 return $result;
122 } 149 }
@@ -176,9 +203,11 @@ class Yohobuy @@ -176,9 +203,11 @@ class Yohobuy
176 * 203 *
177 * @param array $urlList 接口列表 204 * @param array $urlList 接口列表
178 * @param array $options CURL设置项 205 * @param array $options CURL设置项
  206 + * @parma mixed $cache 控制是否启用接口数据的缓存 如3600表示缓存1小时, false表示不缓存
  207 + * @param int $timeout 超时时间,单位是秒
179 * @return array 208 * @return array
180 */ 209 */
181 - public static function getMulti($urlList = array(), $options = array()) 210 + public static function getMulti($urlList = array(), $options = array(), $cache = false, $timeout = 3)
182 { 211 {
183 $result = array(); 212 $result = array();
184 $response = array(); 213 $response = array();
@@ -188,8 +217,8 @@ class Yohobuy @@ -188,8 +217,8 @@ class Yohobuy
188 $defaultOptions = array( 217 $defaultOptions = array(
189 CURLOPT_HEADER => 0, 218 CURLOPT_HEADER => 0,
190 CURLOPT_RETURNTRANSFER => 1, 219 CURLOPT_RETURNTRANSFER => 1,
191 - CURLOPT_CONNECTTIMEOUT => 3,  
192 - CURLOPT_TIMEOUT => 3, 220 + CURLOPT_CONNECTTIMEOUT => $timeout,
  221 + CURLOPT_TIMEOUT => $timeout,
193 CURLOPT_NOSIGNAL => 1, //忽略所有的curl传递给php的信号,减少并发crash 222 CURLOPT_NOSIGNAL => 1, //忽略所有的curl传递给php的信号,减少并发crash
194 ); 223 );
195 $mh = curl_multi_init(); 224 $mh = curl_multi_init();
@@ -269,14 +298,11 @@ class Yohobuy @@ -269,14 +298,11 @@ class Yohobuy
269 try { 298 try {
270 $result = call_user_func_array(array($client, $method), $parameters); 299 $result = call_user_func_array(array($client, $method), $parameters);
271 } catch (\Exception $e) { 300 } catch (\Exception $e) {
  301 + var_dump($e);
272 $result = array(); 302 $result = array();
273 } 303 }
274 304
275 - if (!empty($result['data'])) {  
276 - return $result['data'];  
277 - } else {  
278 - return array();  
279 - } 305 + return $result;
280 } 306 }
281 307
282 /** 308 /**
@@ -34,27 +34,28 @@ class DetailData @@ -34,27 +34,28 @@ class DetailData
34 $article = Yohobuy::yarClient(Yohobuy::SERVICE_URL . self::URI_PACKAGE_ARTICLE, 'getArticle', array($id)); 34 $article = Yohobuy::yarClient(Yohobuy::SERVICE_URL . self::URI_PACKAGE_ARTICLE, 'getArticle', array($id));
35 if (!isset($article['tag'])) { 35 if (!isset($article['tag'])) {
36 return $result; 36 return $result;
37 - } else { 37 + }
  38 + else {
38 $result['getArticle'] = $article; 39 $result['getArticle'] = $article;
39 } 40 }
40 41
41 // 获取作者信息 42 // 获取作者信息
42 - Yohobuy::yarConcurrentCall(Yohobuy::SERVICE_URL . self::URI_PACKAGE_AUTHOR, 'getAuthor', array($id), function ($retval) use (&$result) { 43 + Yohobuy::yarConcurrentCall(Yohobuy::SERVICE_URL . self::URI_PACKAGE_AUTHOR, 'getAuthor', array($article['author_id']), function ($retval) use (&$result) {
43 $result['getAuthor'] = empty($retval) ? array() : $retval; 44 $result['getAuthor'] = empty($retval) ? array() : $retval;
44 }); 45 });
45 46
46 // 获取资讯内容 47 // 获取资讯内容
47 - Yohobuy::yarConcurrentCall(Yohobuy::SERVICE_URL . self::API_URI_ARTICLE, 'getArticleContent', array($id), function ($retval) use (&$result) { 48 + Yohobuy::yarConcurrentCall(Yohobuy::SERVICE_URL . self::URI_PACKAGE_ARTICLE, 'getArticleContent', array($id), function ($retval) use (&$result) {
48 $result['getArticleContent'] = empty($retval) ? array() : $retval; 49 $result['getArticleContent'] = empty($retval) ? array() : $retval;
49 }); 50 });
50 51
51 // 获取资讯相关的品牌 52 // 获取资讯相关的品牌
52 - Yohobuy::yarConcurrentCall(Yohobuy::SERVICE_URL . self::API_URI_ARTICLE, 'getBrand', array($id), function ($retval) use (&$result) { 53 + Yohobuy::yarConcurrentCall(Yohobuy::SERVICE_URL . self::URI_PACKAGE_ARTICLE, 'getBrand', array($id), function ($retval) use (&$result) {
53 $result['getBrand'] = empty($retval) ? array() : $retval; 54 $result['getBrand'] = empty($retval) ? array() : $retval;
54 }); 55 });
55 56
56 // 获取资讯相关的其它资讯 57 // 获取资讯相关的其它资讯
57 - Yohobuy::yarConcurrentCall(Yohobuy::SERVICE_URL . self::API_URI_ARTICLE, 'getOtherArticle', array($article['tag'], $id, 0, 3), function ($retval) use (&$result) { 58 + Yohobuy::yarConcurrentCall(Yohobuy::SERVICE_URL . self::URI_PACKAGE_ARTICLE, 'getOtherArticle', array($article['tag'], $id, 0, 3), function ($retval) use (&$result) {
58 $result['getOtherArticle'] = empty($retval) ? array() : $retval; 59 $result['getOtherArticle'] = empty($retval) ? array() : $retval;
59 }); 60 });
60 61
@@ -4,6 +4,7 @@ namespace LibModels\Wap\Guang; @@ -4,6 +4,7 @@ namespace LibModels\Wap\Guang;
4 4
5 use Api\Sign; 5 use Api\Sign;
6 use Api\Yohobuy; 6 use Api\Yohobuy;
  7 +use Plugin\Cache;
7 8
8 /** 9 /**
9 * 逛首页列表相关的数据模型 10 * 逛首页列表相关的数据模型
@@ -16,6 +17,10 @@ use Api\Yohobuy; @@ -16,6 +17,10 @@ use Api\Yohobuy;
16 */ 17 */
17 class ListData 18 class ListData
18 { 19 {
  20 + const URI_CATEGORY = 'guang/api/v1/category/get';
  21 + const URI_ARTICLELIST = 'guang/api/v2/article/getList';
  22 + const URI_AUTHOR = 'guang/service/v1/author/';
  23 +
19 /** 24 /**
20 * 逛分类 25 * 逛分类
21 * 26 *
@@ -25,39 +30,90 @@ class ListData @@ -25,39 +30,90 @@ class ListData
25 */ 30 */
26 public static function category() 31 public static function category()
27 { 32 {
28 - return Yohobuy::get(Yohobuy::SERVICE_URL . 'guang/api/v1/category/get'); 33 + $param = Yohobuy::param();
  34 + $param['client_secret'] = Sign::getSign($param);
  35 +
  36 + return Yohobuy::get(Yohobuy::SERVICE_URL . self::URI_CATEGORY, $param);
  37 + }
  38 +
  39 + /**
  40 + * 逛内容列表
  41 + *
  42 + * @param string $gender "1,3"表示男, "2,3"表示女, "1,2,3"表示所有
  43 + * @param int $sortId 分类ID
  44 + * @param int $uid 用户ID
  45 + * @param string $udid 客户端唯一标识
  46 + * @param int $page 分页第几页, 默认第1页
  47 + * @param string $tag 标签
  48 + * @param int $authorId 作者ID
  49 + * @return array
  50 + */
  51 + public static function article($gender, $sortId, $uid = 0, $udid = '', $page = 1, $tag = null, $authorId = null)
  52 + {
  53 + $param = Yohobuy::param();
  54 + $param['gender'] = $gender;
  55 + $param['page'] = $page;
  56 + $param['uid'] = $uid;
  57 + $param['udid'] = $udid;
  58 + if (isset($sortId)) {
  59 + $param['sort_id'] = $sortId;
  60 + }
  61 + if (isset($tag)) {
  62 + $param['tag'] = $tag;
  63 + }
  64 + if (isset($authorId) && is_numeric($authorId)) {
  65 + $param['author_id'] = $authorId;
  66 + }
  67 + $param['client_secret'] = Sign::getSign($param);
  68 +
  69 + return Yohobuy::get(Yohobuy::SERVICE_URL . self::URI_ARTICLELIST, $param);
29 } 70 }
30 - 71 +
31 /** 72 /**
32 * 根据分类进行分组的逛内容列表 73 * 根据分类进行分组的逛内容列表
33 * 74 *
34 * @param array $category 分类 75 * @param array $category 分类
35 * @param string $gender "1,3"表示男, "2,3"表示女 76 * @param string $gender "1,3"表示男, "2,3"表示女
36 - * @param int $page 分页第几页, 默认第1页  
37 - * @param int $channel 1表示男, 2表示女  
38 * @param int $uid 用户ID 77 * @param int $uid 用户ID
39 - * @param string $udid 客户端cookie唯一标识 78 + * @param string $udid 客户端唯一标识
  79 + * @param int $page 分页第几页, 默认第1页
40 * @return array 80 * @return array
41 */ 81 */
42 - public static function articleGroup($category, $gender, $channel, $uid = 0, $udid, $page = 1) 82 + public static function articleGroup($category, $gender, $uid = 0, $udid, $page = 1)
43 { 83 {
44 $urlList = array(); 84 $urlList = array();
45 $param = array(); 85 $param = array();
46 - 86 +
47 foreach ($category as $value) { 87 foreach ($category as $value) {
48 $param = Yohobuy::param(); 88 $param = Yohobuy::param();
49 $param['gender'] = $gender; 89 $param['gender'] = $gender;
50 $param['page'] = $page; 90 $param['page'] = $page;
51 - $param['yh_channel'] = $channel;  
52 $param['sort_id'] = $value['id']; 91 $param['sort_id'] = $value['id'];
53 $param['uid'] = $uid; 92 $param['uid'] = $uid;
54 $param['udid'] = $udid; 93 $param['udid'] = $udid;
55 $param['client_secret'] = Sign::getSign($param); 94 $param['client_secret'] = Sign::getSign($param);
56 -  
57 - $urlList[ $value['id'] ] = Yohobuy::httpBuildQuery(Yohobuy::SERVICE_URL . 'guang/api/v2/article/getList', $param);  
58 - }  
59 - 95 +
  96 + $urlList[$value['id']] = Yohobuy::httpBuildQuery(Yohobuy::SERVICE_URL . self::URI_ARTICLELIST, $param);
  97 + }
  98 +
60 return Yohobuy::getMulti($urlList); 99 return Yohobuy::getMulti($urlList);
61 } 100 }
62 - 101 +
  102 + /**
  103 + * 获取作者信息
  104 + *
  105 + * @param int $id 作者ID
  106 + * @return array
  107 + */
  108 + public static function author($id)
  109 + {
  110 + $result = array();
  111 +
  112 + if (is_numeric($id)) {
  113 + $result = Yohobuy::yarClient(Yohobuy::SERVICE_URL . self::URI_AUTHOR, 'getAuthor', array($id));
  114 + }
  115 +
  116 + return $result;
  117 + }
  118 +
63 } 119 }
@@ -87,7 +87,7 @@ class PlusstarData @@ -87,7 +87,7 @@ class PlusstarData
87 87
88 // 品牌详情信息 88 // 品牌详情信息
89 $brandInfo = Yohobuy::yarClient(Yohobuy::SERVICE_URL . self::URI_BRANDINFO_PLUSSTAR, 'getBrandInfo', array(array('id' => $id)) ); 89 $brandInfo = Yohobuy::yarClient(Yohobuy::SERVICE_URL . self::URI_BRANDINFO_PLUSSTAR, 'getBrandInfo', array(array('id' => $id)) );
90 - if (!isset($brandInfo['brand_id'])) { 90 + if (!isset($brandInfo['data']['brand_id'])) {
91 return $result; 91 return $result;
92 } else { 92 } else {
93 $result['getBrandInfo'] = $brandInfo; 93 $result['getBrandInfo'] = $brandInfo;
@@ -103,7 +103,7 @@ class PlusstarData @@ -103,7 +103,7 @@ class PlusstarData
103 103
104 // 相关资讯列表 (3篇) 104 // 相关资讯列表 (3篇)
105 $result['getArticleByBrand'] = array(); 105 $result['getArticleByBrand'] = array();
106 - Yohobuy::yarConcurrentCall(Yohobuy::SERVICE_URL . self::URI_BRANDINFO_ARTICLE, 'getArticleByBrand', array($brandInfo['brand_id'], 3, $udid), function($retval) use(&$result) { 106 + Yohobuy::yarConcurrentCall(Yohobuy::SERVICE_URL . self::URI_BRANDINFO_ARTICLE, 'getArticleByBrand', array($brandInfo['data']['brand_id'], 3, $udid), function($retval) use(&$result) {
107 $result['getArticleByBrand'] = empty($retval) ? array() : $retval; 107 $result['getArticleByBrand'] = empty($retval) ? array() : $retval;
108 }); 108 });
109 109
@@ -115,7 +115,7 @@ class PlusstarData @@ -115,7 +115,7 @@ class PlusstarData
115 // 调用搜索接口 115 // 调用搜索接口
116 $param = Yohobuy::param(); 116 $param = Yohobuy::param();
117 $param['method'] = 'app.search.li'; 117 $param['method'] = 'app.search.li';
118 - $param['brand'] = $brandInfo['brand_id']; 118 + $param['brand'] = $brandInfo['data']['brand_id'];
119 $param['page'] = '0'; 119 $param['page'] = '0';
120 $param['limit'] = '6'; 120 $param['limit'] = '6';
121 $param['gender'] = $gender; 121 $param['gender'] = $gender;
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\Yohobuy;
  6 +use Api\Sign;
  7 +
  8 +/**
  9 + * 商品列表相关的数据模型
  10 + *
  11 + * @name ListData
  12 + * @package LibModels/Wap/Product
  13 + * @copyright yoho.inc
  14 + * @version 1.0 (2015-10-15 20:15:02)
  15 + * @author fei.hong <fei.hong@yoho.cn>
7 */ 16 */
  17 +class ListData
  18 +{
  19 + const URI_PRODUCT = 'shops/service/v1/product';
  20 +
  21 + /**
  22 + * 根据商品SKN获取商品的简要信息
  23 + *
  24 + * @param array $skns
  25 + * @return array
  26 + */
  27 + public static function productInfoBySkns($skns)
  28 + {
  29 + //return Yohobuy::yarClient(Yohobuy::SERVICE_URL . self::URI_PRODUCT, 'getLessInfoByProductSkns', array());
  30 +
  31 + // 调用搜索接口
  32 + $param = Yohobuy::param();
  33 + $param['method'] = 'app.search.li';
  34 + $param['query'] = implode(' ', $skns);
  35 + $param['limit'] = count($skns);
  36 + $param['order'] = 's_t_desc';
  37 + $param['client_secret'] = Sign::getSign($param);
  38 +
  39 + return Yohobuy::get(Yohobuy::API_URL, $param);
  40 + }
  41 +
  42 + /**
  43 + * 根据商品SKC获取商品的简要信息
  44 + *
  45 + * @param array $skcs
  46 + * @return array
  47 + */
  48 + public static function productInfoBySkcs($skcs)
  49 + {
  50 + return Yohobuy::yarClient(Yohobuy::SERVICE_URL . self::URI_PRODUCT, 'getLessInfoByProductSkcs', array(array('productSkcs' => $skcs)));
  51 + }
8 52
  53 +}
1 -<?php  
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.  
7 - */  
8 1
@@ -16,7 +16,7 @@ class Helpers @@ -16,7 +16,7 @@ class Helpers
16 * @param integer $mode 模式 16 * @param integer $mode 模式
17 * @return string 图片地址 17 * @return string 图片地址
18 */ 18 */
19 - public static function getImageUrl($fileName, $width, $height, $mode = 1) 19 + public static function getImageUrl($fileName, $width, $height, $mode = 2)
20 { 20 {
21 return strtr($fileName, array('{width}' => $width, '{height}' => $height, '{mode}' => $mode)); 21 return strtr($fileName, array('{width}' => $width, '{height}' => $height, '{mode}' => $mode));
22 } 22 }
@@ -27,7 +27,7 @@ class Helpers @@ -27,7 +27,7 @@ class Helpers
27 * @param array $productData 需要格式化的商品数据 27 * @param array $productData 需要格式化的商品数据
28 * @return array | false 28 * @return array | false
29 */ 29 */
30 - public static function formatProduct($productData) 30 + public static function formatProduct($productData, $showTags = true)
31 { 31 {
32 // 商品信息有问题,则不显示 32 // 商品信息有问题,则不显示
33 if (!isset($productData['product_skn'])) { 33 if (!isset($productData['product_skn'])) {
@@ -42,21 +42,85 @@ class Helpers @@ -42,21 +42,85 @@ class Helpers
42 $result = array(); 42 $result = array();
43 $result['id'] = $productData['product_skn']; 43 $result['id'] = $productData['product_skn'];
44 $result['product_id'] = $productData['product_id']; 44 $result['product_id'] = $productData['product_id'];
45 - $result['thumb'] = Helpers::getImageUrl($productData['default_images'], 235, 314); 45 + $result['thumb'] = self::getImageUrl($productData['default_images'], 235, 314);
46 $result['name'] = $productData['product_name']; 46 $result['name'] = $productData['product_name'];
47 $result['price'] = $productData['market_price']; 47 $result['price'] = $productData['market_price'];
48 $result['salePrice'] = $productData['sales_price']; 48 $result['salePrice'] = $productData['sales_price'];
49 $result['isFew'] = ($productData['is_soon_sold_out'] === 'Y'); 49 $result['isFew'] = ($productData['is_soon_sold_out'] === 'Y');
50 $result['url'] = ''; // @todo 50 $result['url'] = ''; // @todo
51 - $result['tags'] = array();  
52 - $result['tags']['isNew'] = isset($productData['is_new']) && $productData['is_new'] === 'Y'; // 新品  
53 - $result['tags']['isSale'] = isset($productData['is_discount']) && $productData['is_discount'] === 'Y'; // 在售  
54 - $result['tags']['isLimit'] = isset($productData['is_limited']) && $productData['is_limited'] === 'Y'; // 限量  
55 - $result['tags']['isYohood'] = isset($productData['is_yohood']) && $productData['is_yohood'] === 'Y'; // YOHOOD  
56 - $result['tags']['midYear'] = isset($productData['mid-year']) && $productData['mid-year'] === 'Y'; // 年中  
57 - $result['tags']['yearEnd'] = isset($productData['year-end']) && $productData['year-end'] === 'Y'; // 年末  
58 - $result['tags']['isReNew'] = false; // 再到着  
59 - $result['tags']['isNewFestival'] = false; // 新品节 51 +
  52 + if ($showTags) {
  53 + $result['tags'] = array();
  54 + $result['tags']['isNew'] = isset($productData['is_new']) && $productData['is_new'] === 'Y'; // 新品
  55 + $result['tags']['isSale'] = isset($productData['is_discount']) && $productData['is_discount'] === 'Y'; // 在售
  56 + $result['tags']['isLimit'] = isset($productData['is_limited']) && $productData['is_limited'] === 'Y'; // 限量
  57 + $result['tags']['isYohood'] = isset($productData['is_yohood']) && $productData['is_yohood'] === 'Y'; // YOHOOD
  58 + $result['tags']['midYear'] = isset($productData['mid-year']) && $productData['mid-year'] === 'Y'; // 年中
  59 + $result['tags']['yearEnd'] = isset($productData['year-end']) && $productData['year-end'] === 'Y'; // 年末
  60 + $result['tags']['isReNew'] = false; // 再到着
  61 + $result['tags']['isNewFestival'] = false; // 新品节
  62 + }
  63 +
  64 + return $result;
  65 + }
  66 +
  67 + /**
  68 + * 格式化资讯文章
  69 + *
  70 + * @param array $articleData 需要格式化的资讯数据
  71 + * @param bool $showTag 是否显示左上角标签
  72 + * @param mixed $share 是否显示分享,在APP客户端里嵌入需要传url链接
  73 + * @param bool $showAuthor 控制是否显示作者信息
  74 + * @return array | false
  75 + */
  76 + public static function formatArticle($articleData, $showTag = true, $share = false, $showAuthor = true)
  77 + {
  78 + // 资讯ID不存在,则不显示
  79 + if (!isset($articleData['id'])) {
  80 + return false;
  81 + }
  82 +
  83 + $result = array();
  84 + $result['id'] = $articleData['id'];
  85 + $result['showTag'] = $showTag;
  86 + $result['img'] = self::getImageUrl($articleData['src'], 640, 640);
  87 + $result['url'] = $articleData['url']; // @todo
  88 + $result['title'] = $articleData['title'];
  89 + $result['text'] = $articleData['intro'];
  90 + $result['publishTime'] = $articleData['publish_time'];
  91 + $result['pageView'] = $articleData['views_num'];
  92 + $result['like'] = array();
  93 + $result['like']['count'] = $articleData['praise_num'];
  94 + $result['like']['isLiked'] = isset($articleData['isPraise']) && $articleData['isPraise'] === 'Y';
  95 + $result['collect'] = array();
  96 + $result['collect']['isCollected'] = isset($articleData['isFavor']) && $articleData['isFavor'] === 'Y';
  97 + $result['share'] = $share;
  98 +
  99 + // 判断是否显示作者信息
  100 + if ($showAuthor) {
  101 + $result['author'] = $articleData['author'];
  102 + }
  103 +
  104 + // 模板中需要的标签标识
  105 + if ($showTag) {
  106 + switch (strval($articleData['category_id'])) {
  107 + case '1': // 话题
  108 + $result['isTopic'] = true;
  109 + break;
  110 + case '2': // 搭配
  111 + $result['isCollocation'] = true;
  112 + break;
  113 + case '3': // 潮人
  114 + $result['isFashionMan'] = true;
  115 + break;
  116 + case '4': // 潮品
  117 + $result['isFashionGood'] = true;
  118 + break;
  119 + case '5': // 小贴士
  120 + $result['isTip'] = true;
  121 + break;
  122 + }
  123 + }
60 124
61 return $result; 125 return $result;
62 } 126 }
@@ -210,4 +274,29 @@ class Helpers @@ -210,4 +274,29 @@ class Helpers
210 return false; 274 return false;
211 } 275 }
212 276
  277 + /**
  278 + * 获取商品的ICON
  279 + *
  280 + * @param int $type
  281 + * @return array
  282 + */
  283 + public static function getProductIcon($type)
  284 + {
  285 + static $icons = array(
  286 + 1 => 'cloth',
  287 + 3 => 'pants',
  288 + 4 => 'dress',
  289 + 6 => 'shoe',
  290 + 7 => 'bag',
  291 + 10 => 'lamp',
  292 + 241 => 'headset',
  293 + 8 => 'watch',
  294 + 360 => 'swim-suit',
  295 + 308 => 'under'
  296 + );
  297 + $type = intval($type);
  298 +
  299 + return isset($icons[$type]) ? $icons[$type] : '';
  300 + }
  301 +
213 } 302 }
@@ -66,7 +66,7 @@ @@ -66,7 +66,7 @@
66 {{#if relatedReco}} 66 {{#if relatedReco}}
67 <div class="post-block related-reco-block clearfix"> 67 <div class="post-block related-reco-block clearfix">
68 <h2>相关推荐</h2> 68 <h2>相关推荐</h2>
69 - {{#if relatedReco.onlyOne}} 69 + {{#if relatedReco.id}}
70 {{#with relatedReco}} 70 {{#with relatedReco}}
71 <div class="one-good"> 71 <div class="one-good">
72 <img class="thumb lazy" data-original={{thumb}}> 72 <img class="thumb lazy" data-original={{thumb}}>
  1 +{{# infos}}
  2 + {{> guang/info}}
  3 +{{/ infos}}
1 <?php 1 <?php
  2 +
2 use Action\AbstractAction; 3 use Action\AbstractAction;
  4 +use LibModels\Wap\Guang\DetailData;
  5 +use LibModels\Wap\Product\ListData;
  6 +use Plugin\Helpers;
3 7
  8 +/**
  9 + * 逛详情页
  10 + */
4 class DetailController extends AbstractAction 11 class DetailController extends AbstractAction
5 { 12 {
6 13
  14 + /**
  15 + * 详情页
  16 + *
  17 + * @param int id 内容ID
  18 + */
7 public function indexAction() 19 public function indexAction()
8 { 20 {
9 - $data = array(  
10 - 'id' => 1,  
11 - 'author' => array(  
12 - 'avatar' => 'http://7xidk0.com1.z0.glb.clouddn.com/avater.png',  
13 - 'name' => '山本耀司',  
14 - 'intro' => '日本设计界一代宗师,分享一些个人区委分享内容不求有用但求有趣区委分享内容不求有用但求有趣区委分享内容不求有用但求有趣区委分享内容不求有用但求有趣',  
15 - 'url' => ''  
16 - ),  
17 - 'detail' => array(  
18 - 'title' => 'Skin Art Series INN 2015新品',  
19 - 'publishTime' => '2月13日 12:34',  
20 - 'pageView' => 3445,  
21 - 'content' => array(  
22 - array(  
23 - 'text' => '复古风劲吹,在各路复古跑鞋嚣张跋扈的当下,历史悠久的Onitsuka也动作频频'  
24 - ),  
25 - array(  
26 - 'bigImage' => 'http://img10.static.yhbimg.com/yhb-img01/2015/06/11/15/017b3fa0478e26a3ded2ac75d341fe3ab6.jpg?imageView/2/w/640/h/640'  
27 - ),  
28 - array(  
29 - 'relatedReco' => array(  
30 - 'onlyOne' => true,  
31 - 'id' => 1,  
32 - 'thumb' => 'http://img11.static.yhbimg.com/goodsimg/2015/03/02/07/01ebfb219e22770ffb0c2c3a2cbb2b4bef.jpg?imageMogr2/thumbnail/235x314/extent/235x314/background/d2hpdGU=/position/center/quality/90',  
33 - 'name' => 'GAWS DIGI 丛林数码印花拼接卫衣看看两行文字以上能不能切字啦,样式应该不会乱的吧',  
34 - 'isLike' => false,  
35 - 'price' => 1268,  
36 - 'salePrice' => 589,  
37 - 'url' => ''  
38 - )  
39 - ),  
40 - array(  
41 - 'collocation' => array(  
42 - array(  
43 - 'thumb' => 'http://7xidk0.com1.z0.glb.clouddn.com/clothe.png',  
44 - 'type' => 'pants',  
45 - 'goods' => array(  
46 - 'id' => 1,  
47 - 'thumb' => 'http://img11.static.yhbimg.com/goodsimg/2015/03/02/07/01ebfb219e22770ffb0c2c3a2cbb2b4bef.jpg?imageMogr2/thumbnail/235x314/extent/235x314/background/d2hpdGU=/position/center/quality/90',  
48 - 'name' => 'GAWS DIGI 丛林数码印花拼接卫衣',  
49 - 'price' => 1268,  
50 - 'salePrice' => 589,  
51 - 'tags' => array(  
52 - array(  
53 - 'isNew' => true  
54 - )  
55 - ),  
56 - 'isFew' => true,  
57 - 'url' => ''  
58 - )  
59 - ),  
60 - array(  
61 - 'thumb' => 'http://7xidk0.com1.z0.glb.clouddn.com/clothe.png',  
62 - 'type' => 'cloth',  
63 - 'goods' => array(  
64 - 'id' => 1,  
65 - 'thumb' => 'http://img11.static.yhbimg.com/goodsimg/2015/03/02/07/01ebfb219e22770ffb0c2c3a2cbb2b4bef.jpg?imageMogr2/thumbnail/235x314/extent/235x314/background/d2hpdGU=/position/center/quality/90',  
66 - 'name' => 'GAWS DIGI 丛林数码印花拼接卫衣',  
67 - 'price' => 1268,  
68 - 'salePrice' => 589,  
69 - 'tags' => array(  
70 - array(  
71 - 'isNew' => true  
72 - )  
73 - ),  
74 - 'isFew' => true,  
75 - 'url' => ''  
76 - )  
77 - )  
78 - )  
79 - )  
80 - )  
81 - ),  
82 - 'relatedBrand' => array(  
83 - array(  
84 - 'thumb' => 'http://7xidk0.com1.z0.glb.clouddn.com/logo.png',  
85 - 'name' => 'HALFGIRL测试名字长的情况',  
86 - 'url' => ''  
87 - ),  
88 - array(  
89 - 'thumb' => 'http://7xidk0.com1.z0.glb.clouddn.com/logo.png',  
90 - 'name' => '黄伟文Wyman',  
91 - 'url' => ''  
92 - ),  
93 - array(  
94 - 'thumb' => 'http://7xidk0.com1.z0.glb.clouddn.com/logo.png',  
95 - 'name' => 'HIPANDA',  
96 - 'url' => ''  
97 - )  
98 - ),  
99 - 'relatedTag' => array(  
100 - array(  
101 - 'name' => '棒球服',  
102 - 'url' => ''  
103 - )  
104 - ),  
105 - 'relatedInfo' => array(  
106 - array(  
107 - 'thumb' => 'http://7xidk0.com1.z0.glb.clouddn.com/pant.png',  
108 - 'title' => '复古风劲吹,在各路复古跑鞋嚣张跋扈的当下,历史悠久的Onitsuka',  
109 - 'url' => '',  
110 - 'publishTime' => '2月13日 12:34'  
111 - )  
112 - )  
113 - );  
114 - $this->_view->assign('title', 'YOHO!有货');  
115 - $this->_view->display('index', array('modulePath' => 'guang/detail', 'guang' => $data)); 21 + $id = $this->get('id');
  22 +
  23 + // 判断参数是否有效, 无效会跳转到错误页面
  24 + if (!is_numeric($id)) {
  25 + $this->error();
  26 + }
  27 +
  28 + // 获取详情内容信息, 异常则跳到错误页面
  29 + $detail = DetailData::package($id);
  30 + if (empty($detail['getArticle'])) {
  31 + $this->error();
  32 + }
  33 +
  34 + $data = array();
  35 + $data['guangDetail'] = true; // 模板中使用JS的标识
  36 + $data['guang']['id'] = $id;
  37 +
  38 + // 作者信息数据
  39 + if (isset($detail['getAuthor']['name'])) {
  40 + $data['guang']['author'] = array();
  41 + $data['guang']['author']['avatar'] = $detail['getAuthor']['avatar'];
  42 + $data['guang']['author']['name'] = $detail['getAuthor']['name'];
  43 + $data['guang']['author']['intro'] = $detail['getAuthor']['author_desc'];
  44 + $data['guang']['author']['url'] = '/guang/list/editor?id=' . $detail['getArticle']['author_id'];
  45 + }
  46 +
  47 + $data['detail'] = array();
  48 + $data['detail']['title'] = $detail['getArticle']['article_title'];
  49 + $data['detail']['publishTime'] = $detail['getArticle']['publishTime'];
  50 + $data['detail']['pageView'] = $detail['getArticle']['pageViews'];
  51 + $data['detail']['content'] = array();
  52 +
  53 + if (!empty($detail['getArticleContent'])) {
  54 + $build = array();
  55 + $good = array();
  56 + $skns = array();
  57 + $product = array();
  58 + foreach ($detail['getArticleContent'] as $value) {
  59 + $build = array();
  60 + // 文字
  61 + if (isset($value['text'])) {
  62 + $build['text'] = $value['text']['data']['text'];
  63 + $data['detail']['content'][] = $build;
  64 + }
  65 + // 单张图
  66 + elseif (isset($value['singleImage'])) {
  67 + $build['bigImage'] = Helpers::getImageUrl($value['singleImage']['data'][0]['src'], 640, 640);
  68 + $data['detail']['content'][] = $build;
  69 + }
  70 + // 相关推荐
  71 + elseif (isset($value['goods']['data'])) {
  72 + $good = array();
  73 + // 遍历取得SKN
  74 + $skns = array();
  75 + foreach ($value['goods']['data'] as $goods) {
  76 + $skns[] = $goods['id'];
  77 + }
  78 + // 通过SKN获取商品信息
  79 + $product = ListData::productInfoBySkns($skns);
  80 + foreach ($product['data']['product_list'] as $i => $goods) {
  81 + // 最多显示4个
  82 + if ($i > 3) {
  83 + break;
  84 + }
  85 + $good[] = Helpers::formatProduct($goods, false);
  86 + }
  87 + // 单个商品
  88 + if ($i === 0) {
  89 + $build['relatedReco'] = $good[0];
  90 + }
  91 + // 多个商品
  92 + else {
  93 + $build['relatedReco'] = $good;
  94 + }
  95 + }
  96 + // 悬停浮动商品
  97 + elseif (isset($value['goodsGroup']['data'])) {
  98 + foreach ($value['goodsGroup']['data'] as $goods) {
  99 + $good = array();
  100 + $good['thumb'] = Helpers::getImageUrl($goods['cover']['cover'], 235, 314);
  101 + $good['type'] = Helpers::getProductIcon($goods['cover']['maxSortId']);
  102 + $good['goods'] = array();
  103 + $skns = array();
  104 + foreach ($goods['list'] as $mini) {
  105 + $skns[] = $mini['id'];
  106 + }
  107 + // 通过SKN获取商品信息
  108 + $product = ListData::productInfoBySkns($skns);
  109 + foreach ($product['data']['product_list'] as $i => $goods) {
  110 + $good['goods'][] = Helpers::formatProduct($goods, false);
  111 + }
  112 + $build['collocation'][] = $good;
  113 + }
  114 + }
  115 +
  116 + $data['detail']['content'][] = $build;
  117 + }
  118 + }
  119 +
  120 + // 相关品牌
  121 + if (!empty($detail['getBrand'])) {
  122 + $data['relatedBrand'] = $detail['getBrand'];
  123 + }
  124 +
  125 + // 相关标签
  126 + if (!empty($detail['getArticle']['tags'])) {
  127 + foreach ($detail['getArticle']['tags'] as $value) {
  128 + $value['url'] = '/guang/list/tag?query=' . $value['name'];
  129 + $data['relatedTag'][] = $value;
  130 + }
  131 + }
  132 +
  133 + // 相关文章
  134 + if (!empty($detail['getOtherArticle'])) {
  135 + foreach ($detail['getOtherArticle'] as $value) {
  136 + $value['url'] = '/guang/detail/index?id=' . $value['id'];
  137 + $data['relatedInfo'][] = $value;
  138 + }
  139 + }
  140 +
  141 + $this->_view->display('index', $data);
  142 +
  143 + $detail = array();
  144 + $data = array();
116 } 145 }
117 } 146 }
1 <?php 1 <?php
  2 +
2 use Action\AbstractAction; 3 use Action\AbstractAction;
  4 +use LibModels\Wap\Guang\ListData;
  5 +use Plugin\Helpers;
3 6
4 /** 7 /**
5 * 逛首页、列表页、编辑页 8 * 逛首页、列表页、编辑页
@@ -8,351 +11,113 @@ class ListController extends AbstractAction @@ -8,351 +11,113 @@ class ListController extends AbstractAction
8 { 11 {
9 /** 12 /**
10 * 首页 13 * 首页
  14 + *
  15 + * @param int type 分类ID 0:最新,1:话题,2:搭配,3:潮人,4:潮品,5:小贴士
  16 + * @param string gender '1,3'表示男,'2,3'表示女
11 */ 17 */
12 public function indexAction() 18 public function indexAction()
13 { 19 {
14 - $data = array(  
15 - 'swiper' => array(  
16 - array(  
17 - 'url' => '',  
18 - 'img' => 'http://img11.static.yhbimg.com/yhb-img01/2015/07/06/10/014fd517e2fe3f3e0dc3cbc3007d8093af.jpg?imageView/2/w/640/h/640'  
19 - ),  
20 - array(  
21 - 'url' => '',  
22 - 'img' => 'http://img10.static.yhbimg.com/yhb-img01/2015/07/03/13/01a165dd33db8488edc741241950a596a8.jpg?imageView/2/w/640/h/640'  
23 - )  
24 - ),  
25 - 'navs' => array(  
26 - array(  
27 - 'typeId' => 1,  
28 - 'type' => '最新'  
29 - ),  
30 - array(  
31 - 'typeId' => 2,  
32 - 'type' => '话题',  
33 - 'focus' => true  
34 - ),  
35 - array(  
36 - 'typeId' => 3,  
37 - 'type' => '搭配'  
38 - ),  
39 - array(  
40 - 'typeId' => 4,  
41 - 'type' => '潮人'  
42 - ),  
43 - array(  
44 - 'typeId' => 5,  
45 - 'type' => '潮物'  
46 - ),  
47 - array(  
48 - 'typeId' => 6,  
49 - 'type' => '小贴士'  
50 - )  
51 - ),  
52 - 'infos' => array(  
53 - array(  
54 - 'info' => array(  
55 - array(  
56 - 'id' => 1,  
57 - 'img' => 'http://7xidk0.com1.z0.glb.clouddn.com/bg.png',  
58 - 'title' => '1.副线不知为何总是好看点',  
59 - 'text' => '具有绅士气质的英伦风格是永走前沿的经典,在众多的Made ' .  
60 - 'In England中Panul Smith缔造了一个传奇',  
61 - 'showTags' => true,  
62 - 'publishTime' => '2月13日 12:34',  
63 - 'pageView' => 3445,  
64 - 'like' => array(  
65 - 'count' => 459,  
66 - 'isLiked' => true  
67 - ),  
68 - 'share' => true,  
69 - 'url' => '',  
70 - 'likeUrl' => '',  
71 - 'isFashionMan' => true,  
72 - 'author' => array(  
73 - 'url' => '',  
74 - 'name' => 'LEO_LU',  
75 - 'avatar' => 'http://img11.static.yhbimg.com/yhb-img02/2015/09/07/02/01a050445c64825eed381c4e049030c692.jpg?imageView/0/w/100/h/100'  
76 - )  
77 - ),  
78 - array(  
79 - 'id' => 1,  
80 - 'img' => 'http://7xidk0.com1.z0.glb.clouddn.com/bg.png',  
81 - 'title' => '1.副线不知为何总是好看点',  
82 - 'text' => '具有绅士气质的英伦风格是永走前沿的经典,在众多的Made ' .  
83 - 'In England中Panul Smith缔造了一个传奇',  
84 - 'showTags' => true,  
85 - 'publishTime' => '2月13日 12:34',  
86 - 'pageView' => 3445,  
87 - 'collect' => array(  
88 - 'isCollected' => true  
89 - ),  
90 - 'share' => true,  
91 - 'url' => '',  
92 - 'likeUrl' => '',  
93 - 'isTip' => true,  
94 - 'author' => array(  
95 - 'url' => '',  
96 - 'name' => 'Kishi',  
97 - 'avatar' => 'http://img13.static.yhbimg.com/yhb-img02/2015/06/12/10/0256020c504fb08a176c5457599bdf5b49.jpg?imageView/0/w/100/h/100'  
98 - )  
99 - )  
100 - )  
101 - ),  
102 - array(  
103 - 'show' => true,  
104 - 'info' => array(  
105 - array(  
106 - 'id' => 2,  
107 - 'img' => 'http://7xidk0.com1.z0.glb.clouddn.com/bg.png',  
108 - 'title' => '2.副线不知为何总是好看点测试长度是否会被截取塞真的很恶心啊',  
109 - 'text' => '具有绅士气质的英伦风格是永走前沿的经典,在众多的Made ' .  
110 - 'In England中Panul Smith缔造了一个传奇',  
111 - 'showTags' => false,  
112 - 'publishTime' => '2月13日 12:34',  
113 - 'pageView' => 3445,  
114 - 'like' => array(  
115 - 'count' => 100,  
116 - 'isLiked' => false  
117 - ),  
118 - 'share' => true,  
119 - 'url' => '',  
120 - 'likeUrl' => '',  
121 - 'isFashionGood' => true  
122 - )  
123 - )  
124 - ),  
125 - array(  
126 - 'info' => array(  
127 - array(  
128 - 'id' => 2,  
129 - 'img' => 'http://7xidk0.com1.z0.glb.clouddn.com/bg.png',  
130 - 'title' => '2.副线不知为何总是好看点测试长度是否会被截取塞真的很恶心啊',  
131 - 'text' => '具有绅士气质的英伦风格是永走前沿的经典,在众多的Made ' .  
132 - 'In England中Panul Smith缔造了一个传奇',  
133 - 'showTags' => false,  
134 - 'publishTime' => '2月13日 12:34',  
135 - 'pageView' => 3445,  
136 - 'like' => array(  
137 - 'count' => 100,  
138 - 'isLiked' => false  
139 - ),  
140 - 'share' => true,  
141 - 'url' => '',  
142 - 'likeUrl' => '',  
143 - 'isFashionGood' => true  
144 - ),  
145 - array(  
146 - 'id' => 1,  
147 - 'img' => 'http://7xidk0.com1.z0.glb.clouddn.com/bg.png',  
148 - 'title' => '1.副线不知为何总是好看点',  
149 - 'text' => '具有绅士气质的英伦风格是永走前沿的经典,在众多的Made ' .  
150 - 'In England中Panul Smith缔造了一个传奇',  
151 - 'showTags' => true,  
152 - 'publishTime' => '2月13日 12:34',  
153 - 'pageView' => 3445,  
154 - 'like' => array(  
155 - 'count' => 459,  
156 - 'isLiked' => true  
157 - ),  
158 - 'share' => true,  
159 - 'url' => '',  
160 - 'likeUrl' => '',  
161 - 'isTip' => true  
162 - )  
163 - )  
164 - ),  
165 - array(  
166 - 'info' => array(  
167 - array(  
168 - 'id' => 2,  
169 - 'img' => 'http://7xidk0.com1.z0.glb.clouddn.com/bg.png',  
170 - 'title' => '2.副线不知为何总是好看点测试长度是否会被截取塞真的很恶心啊',  
171 - 'text' => '具有绅士气质的英伦风格是永走前沿的经典,在众多的Made ' .  
172 - 'In England中Panul Smith缔造了一个传奇',  
173 - 'showTags' => false,  
174 - 'publishTime' => '2月13日 12:34',  
175 - 'pageView' => 3445,  
176 - 'like' => array(  
177 - 'count' => 100,  
178 - 'isLiked' => false  
179 - ),  
180 - 'share' => true,  
181 - 'url' => '',  
182 - 'likeUrl' => '',  
183 - 'isFashionGood' => true  
184 - ),  
185 - array(  
186 - 'id' => 1,  
187 - 'img' => 'http://7xidk0.com1.z0.glb.clouddn.com/bg.png',  
188 - 'title' => '1.副线不知为何总是好看点',  
189 - 'text' => '具有绅士气质的英伦风格是永走前沿的经典,在众多的Made ' .  
190 - 'In England中Panul Smith缔造了一个传奇',  
191 - 'showTags' => true,  
192 - 'publishTime' => '2月13日 12:34',  
193 - 'pageView' => 3445,  
194 - 'like' => array(  
195 - 'count' => 459,  
196 - 'isLiked' => true  
197 - ),  
198 - 'share' => true,  
199 - 'url' => '',  
200 - 'likeUrl' => '',  
201 - 'isTip' => true  
202 - )  
203 - )  
204 - ),  
205 - array(  
206 - 'info' => array(  
207 - array(  
208 - 'id' => 2,  
209 - 'img' => 'http://7xidk0.com1.z0.glb.clouddn.com/bg.png',  
210 - 'title' => '2.副线不知为何总是好看点测试长度是否会被截取塞真的很恶心啊',  
211 - 'text' => '具有绅士气质的英伦风格是永走前沿的经典,在众多的Made ' .  
212 - 'In England中Panul Smith缔造了一个传奇',  
213 - 'showTags' => false,  
214 - 'publishTime' => '2月13日 12:34',  
215 - 'pageView' => 3445,  
216 - 'like' => array(  
217 - 'count' => 100,  
218 - 'isLiked' => false  
219 - ),  
220 - 'share' => true,  
221 - 'url' => '',  
222 - 'likeUrl' => '',  
223 - 'isFashionGood' => true  
224 - ),  
225 - array(  
226 - 'id' => 1,  
227 - 'img' => 'http://7xidk0.com1.z0.glb.clouddn.com/bg.png',  
228 - 'title' => '1.副线不知为何总是好看点',  
229 - 'text' => '具有绅士气质的英伦风格是永走前沿的经典,在众多的Made ' .  
230 - 'In England中Panul Smith缔造了一个传奇',  
231 - 'showTags' => true,  
232 - 'publishTime' => '2月13日 12:34',  
233 - 'pageView' => 3445,  
234 - 'like' => array(  
235 - 'count' => 459,  
236 - 'isLiked' => true  
237 - ),  
238 - 'share' => true,  
239 - 'url' => '',  
240 - 'likeUrl' => '',  
241 - 'isTip' => true  
242 - )  
243 - )  
244 - ),  
245 - array(  
246 - 'info' => array(  
247 - array(  
248 - 'id' => 2,  
249 - 'img' => 'http://7xidk0.com1.z0.glb.clouddn.com/bg.png',  
250 - 'title' => '2.副线不知为何总是好看点测试长度是否会被截取塞真的很恶心啊',  
251 - 'text' => '具有绅士气质的英伦风格是永走前沿的经典,在众多的Made ' .  
252 - 'In England中Panul Smith缔造了一个传奇',  
253 - 'showTags' => false,  
254 - 'publishTime' => '2月13日 12:34',  
255 - 'pageView' => 3445,  
256 - 'like' => array(  
257 - 'count' => 100,  
258 - 'isLiked' => false  
259 - ),  
260 - 'share' => true,  
261 - 'url' => '',  
262 - 'likeUrl' => '',  
263 - 'isFashionGood' => true  
264 - ),  
265 - array(  
266 - 'id' => 1,  
267 - 'img' => 'http://7xidk0.com1.z0.glb.clouddn.com/bg.png',  
268 - 'title' => '1.副线不知为何总是好看点',  
269 - 'text' => '具有绅士气质的英伦风格是永走前沿的经典,在众多的Made ' .  
270 - 'In England中Panul Smith缔造了一个传奇',  
271 - 'showTags' => true,  
272 - 'publishTime' => '2月13日 12:34',  
273 - 'pageView' => 3445,  
274 - 'like' => array(  
275 - 'count' => 459,  
276 - 'isLiked' => true  
277 - ),  
278 - 'share' => true,  
279 - 'url' => '',  
280 - 'likeUrl' => '',  
281 - 'isTip' => true  
282 - )  
283 - )  
284 - )  
285 - )  
286 - );  
287 - $this->_view->assign('title', 'YOHO!有货');  
288 - $this->_view->display('index', array('guangHome' => true, 'guang' => $data)); 20 + $this->setTitle('逛');
  21 +
  22 + $category = ListData::category();
  23 + $articleGroup = array();
  24 +
  25 + $uid = $this->getUid();
  26 + $udid = $this->getUdid();
  27 + $type = $this->get('type', 0);
  28 + $gender = $this->get('gender');
  29 +
  30 + // 男
  31 + if ($gender === '1,3') {
  32 + $articleGroup = ListData::articleGroup($category['data'], '1,3', $uid, $udid);
  33 + }
  34 + // 女
  35 + elseif ($gender === '2,3') {
  36 + $articleGroup = ListData::articleGroup($category['data'], '2,3', $uid, $udid);
  37 + }
  38 + // 所有
  39 + else {
  40 + $articleGroup = ListData::articleGroup($category['data'], '1,2,3', $uid, $udid);
  41 + }
  42 +
  43 + $data = array();
  44 + $build = array();
  45 +
  46 + // 模板中使用JS的标识
  47 + $data['guangHome'] = true;
  48 +
  49 + // 顶部的分类列表
  50 + foreach ($category['data'] as $value) {
  51 + $build = array();
  52 + $build['typeId'] = $value['id'];
  53 + $build['type'] = $value['name'];
  54 + $build['focus'] = ($value['id'] == $type);
  55 + $data['navs'][] = $build;
  56 + }
  57 +
  58 + $data['guang']['swiper'] = array();
  59 + $data['guang']['infos'] = array();
  60 + foreach ($articleGroup as $id => $value) {
  61 + // 轮番广告
  62 + if ($id == 0) {
  63 + $build = array();
  64 + foreach ($value['list']['adlist'] as $banner) {
  65 + $build['url'] = $banner['url'];
  66 + $build['img'] = Helpers::getImageUrl($banner['src'], 830, 327);
  67 + $data['guang']['swiper'][] = $build;
  68 + }
  69 + }
  70 +
  71 + // 内容列表
  72 + $build = array();
  73 + $build['show'] = ($id == $type);
  74 + foreach ($value['list']['artList'] as $article) {
  75 + $build['info'][] = Helpers::formatArticle($article, true, false);
  76 + }
  77 + $data['guang']['infos'][] = $build;
  78 + }
  79 +
  80 + // 分页需要参数
  81 + $data['guang']['gender'] = $gender;
  82 +
  83 + $this->_view->display('index', $data);
289 } 84 }
290 85
291 /** 86 /**
292 * 列表页 87 * 列表页
  88 + *
  89 + * @param string tag 标签名称
293 */ 90 */
294 - public function listAction() 91 + public function tagAction()
295 { 92 {
296 - $data = array(  
297 - 'infos' => array(  
298 - array(  
299 - 'id' => 1,  
300 - 'img' => 'http://7xidk0.com1.z0.glb.clouddn.com/bg.png',  
301 - 'title' => '1.副线不知为何总是好看点',  
302 - 'text' => '具有绅士气质的英伦风格是永走前沿的经典,在众多的Made ' .  
303 - 'In England中Panul Smith缔造了一个传奇',  
304 - 'showTags' => true,  
305 - 'publishTime' => '2月13日 12:34',  
306 - 'pageView' => 3445,  
307 - 'like' => array(  
308 - 'count' => 459,  
309 - 'isLiked' => true  
310 - ),  
311 - 'share' => true,  
312 - 'url' => '',  
313 - 'likeUrl' => '',  
314 - 'isFashionMan' => true  
315 - ),  
316 - array(  
317 - 'id' => 1,  
318 - 'img' => 'http://7xidk0.com1.z0.glb.clouddn.com/bg.png',  
319 - 'title' => '1.副线不知为何总是好看点',  
320 - 'text' => '具有绅士气质的英伦风格是永走前沿的经典,在众多的Made ' .  
321 - 'In England中Panul Smith缔造了一个传奇',  
322 - 'showTags' => true,  
323 - 'publishTime' => '2月13日 12:34',  
324 - 'pageView' => 3445,  
325 - 'like' => array(  
326 - 'count' => 459,  
327 - 'isLiked' => true  
328 - ),  
329 - 'share' => true,  
330 - 'url' => '',  
331 - 'likeUrl' => '',  
332 - 'isTip' => true  
333 - ),  
334 - array(  
335 - 'id' => 2,  
336 - 'img' => 'http://7xidk0.com1.z0.glb.clouddn.com/bg.png',  
337 - 'title' => '2.副线不知为何总是好看点测试长度是否会被截取塞真的很恶心啊',  
338 - 'text' => '具有绅士气质的英伦风格是永走前沿的经典,在众多的Made ' .  
339 - 'In England中Panul Smith缔造了一个传奇',  
340 - 'showTags' => false,  
341 - 'publishTime' => '2月13日 12:34',  
342 - 'pageView' => 3445,  
343 - 'like' => array(  
344 - 'count' => 100,  
345 - 'isLiked' => false  
346 - ),  
347 - 'share' => true,  
348 - 'url' => '',  
349 - 'likeUrl' => '',  
350 - 'isFashionGood' => true  
351 - )  
352 - )  
353 - );  
354 - $this->_view->assign('title', 'YOHO!有货');  
355 - $this->_view->display('list', array('modulePath' => 'guang/list', 'guang' => $data)); 93 + $tag = $this->get('query');
  94 + $uid = $this->getUid();
  95 + $udid = $this->getUdid();
  96 +
  97 + // 标签聚合内容列表
  98 + $article = ListData::article('', 0, $uid, $udid, 1, $tag);
  99 + // 标签聚合内容不存在, 跳到错误页面
  100 + if (empty($article['data']['list']['artList'])) {
  101 + $this->error();
  102 + }
  103 +
  104 + $data = array();
  105 + // 模板中使用JS的标识
  106 + $data['guangList'] = true;
  107 +
  108 + // 构建资讯文章内容
  109 + $build = array();
  110 + foreach ($article['data']['list']['artList'] as $article) {
  111 + $build[] = Helpers::formatArticle($article, true, false);
  112 + }
  113 + $data['guang']['infos'] = $build;
  114 +
  115 + // 分页需要的参数
  116 + $data['guang']['tag'] = $tag;
  117 +
  118 + $this->setTitle($tag);
  119 +
  120 + $this->_view->display('list', $data);
356 } 121 }
357 122
358 /** 123 /**
@@ -360,70 +125,104 @@ class ListController extends AbstractAction @@ -360,70 +125,104 @@ class ListController extends AbstractAction
360 */ 125 */
361 public function editorAction() 126 public function editorAction()
362 { 127 {
363 - $data = array(  
364 - 'author' => array(  
365 - 'avatar' => 'http://7xidk0.com1.z0.glb.clouddn.com/avater.png',  
366 - 'name' => '山本耀司',  
367 - 'info' => '设计理念:他以简洁而富有韵味,线条流畅,反时尚的设计风格而著称。'  
368 - ),  
369 - 'infos' => array(  
370 - array(  
371 - 'id' => 1,  
372 - 'img' => 'http://7xidk0.com1.z0.glb.clouddn.com/bg.png',  
373 - 'title' => '1.副线不知为何总是好看点',  
374 - 'text' => '具有绅士气质的英伦风格是永走前沿的经典,在众多的Made ' .  
375 - 'In England中Panul Smith缔造了一个传奇',  
376 - 'showTags' => true,  
377 - 'publishTime' => '2月13日 12:34',  
378 - 'pageView' => 3445,  
379 - 'like' => array(  
380 - 'count' => 459,  
381 - 'isLiked' => true  
382 - ),  
383 - 'share' => true,  
384 - 'url' => '',  
385 - 'likeUrl' => '',  
386 - 'isFashionMan' => true  
387 - ),  
388 - array(  
389 - 'id' => 1,  
390 - 'img' => 'http://7xidk0.com1.z0.glb.clouddn.com/bg.png',  
391 - 'title' => '1.副线不知为何总是好看点',  
392 - 'text' => '具有绅士气质的英伦风格是永走前沿的经典,在众多的Made ' .  
393 - 'In England中Panul Smith缔造了一个传奇',  
394 - 'showTags' => true,  
395 - 'publishTime' => '2月13日 12:34',  
396 - 'pageView' => 3445,  
397 - 'like' => array(  
398 - 'count' => 459,  
399 - 'isLiked' => true  
400 - ),  
401 - 'share' => true,  
402 - 'url' => '',  
403 - 'likeUrl' => '',  
404 - 'isTip' => true  
405 - ),  
406 - array(  
407 - 'id' => 2,  
408 - 'img' => 'http://7xidk0.com1.z0.glb.clouddn.com/bg.png',  
409 - 'title' => '2.副线不知为何总是好看点测试长度是否会被截取塞真的很恶心啊',  
410 - 'text' => '具有绅士气质的英伦风格是永走前沿的经典,在众多的Made ' .  
411 - 'In England中Panul Smith缔造了一个传奇',  
412 - 'showTags' => false,  
413 - 'publishTime' => '2月13日 12:34',  
414 - 'pageView' => 3445,  
415 - 'like' => array(  
416 - 'count' => 100,  
417 - 'isLiked' => false  
418 - ),  
419 - 'share' => true,  
420 - 'url' => '',  
421 - 'likeUrl' => '',  
422 - 'isFashionGood' => true  
423 - )  
424 - )  
425 - );  
426 - $this->_view->assign('title', 'YOHO!有货');  
427 - $this->_view->display('list', array('modulePath' => 'guang/list', 'guang' => $data)); 128 + $id = $this->get('id');
  129 + $uid = $this->getUid();
  130 + $udid = $this->getUdid();
  131 +
  132 + // 获取作者信息
  133 + $author = ListData::author($id);
  134 + // 作者信息不存在,则跳到错误页面
  135 + if (!isset($author['name'])) {
  136 + $this->error();
  137 + }
  138 +
  139 + $this->setTitle('编辑简介');
  140 +
  141 + $data = array();
  142 + // 模板中使用JS的标识
  143 + $data['guangList'] = true;
  144 +
  145 + // 作者信息
  146 + $data['author'] = array();
  147 + $data['author']['avatar'] = Helpers::getImageUrl($author['avatar'], 100, 100);
  148 + $data['author']['name'] = $author['name'];
  149 + $data['author']['info'] = $author['author_desc'];
  150 + $data['author']['id'] = $id;
  151 +
  152 + // 标签聚合内容列表
  153 + $article = ListData::article('', 0, $uid, $udid, 1, null, $id);
  154 + // 构建资讯文章内容
  155 + if (!empty($article['data']['list']['artList'])) {
  156 + $build = array();
  157 + foreach ($article['data']['list']['artList'] as $article) {
  158 + $build[] = Helpers::formatArticle($article, true, false, false);
  159 + }
  160 + $data['guang']['infos'] = $build;
  161 + }
  162 +
  163 + $this->_view->display('list', $data);
428 } 164 }
  165 +
  166 + /**
  167 + * 逛列表页面的资讯分页
  168 + *
  169 + * 逛首页、标签页、编辑页资讯列表
  170 + *
  171 + * @param string tag 标签名称, 没有传空或不传
  172 + * @param int type 逛首页的分类ID
  173 + * @param int page 分页的页码
  174 + * @param string gender "1,2,3"表示所有, "1,3"表示男, "2,3"表示女
  175 + * @param int authorId 作者ID
  176 + * @return html
  177 + */
  178 + public function pageAction()
  179 + {
  180 + do {
  181 + /* 判断是不是AJAX请求 */
  182 + if (!$this->isAjax()) {
  183 + break;
  184 + }
  185 +
  186 + /* 判断参数是否有效 */
  187 + $tag = $this->get('tag');
  188 + $sortId = $this->get('type');
  189 + $page = $this->get('page');
  190 + $gender = $this->get('gender');
  191 + $authorId = $this->get('authorId');
  192 + $showAuthor = true;
  193 + if (!empty($sortId) && !is_numeric($sortId)) {
  194 + break;
  195 + }
  196 + if (!empty($page) && !is_numeric($page)) {
  197 + break;
  198 + }
  199 + if (!empty($authorId) && is_numeric($authorId)) {
  200 + $showAuthor = false;
  201 + }
  202 +
  203 + /* 获取资讯文章列表 */
  204 + $uid = $this->getUid();
  205 + $udid = $this->getUdid();
  206 + $article = ListData::article($gender, 0, $uid, $udid, $page, $tag, $authorId);
  207 + if (empty($article['data']['list']['artList'])) {
  208 + break;
  209 + }
  210 +
  211 + /* 构建资讯文章内容 */
  212 + $data = array();
  213 + $build = array();
  214 + foreach ($article['data']['list']['artList'] as $article) {
  215 + $build[] = Helpers::formatArticle($article, true, false, $showAuthor);
  216 + }
  217 + $data['infos'] = $build;
  218 +
  219 + $this->_view->display('page', $data);
  220 +
  221 + exit();
  222 + }
  223 + while (false);
  224 +
  225 + echo ' ';
  226 + }
  227 +
429 } 228 }