Authored by hf

do guang list and detail data model

@@ -264,7 +264,12 @@ class Yohobuy @@ -264,7 +264,12 @@ class Yohobuy
264 $client->SetOpt(YAR_OPT_PACKAGER, 'php'); 264 $client->SetOpt(YAR_OPT_PACKAGER, 'php');
265 $client->SetOpt(YAR_OPT_TIMEOUT, $timeout); 265 $client->SetOpt(YAR_OPT_TIMEOUT, $timeout);
266 $client->SetOpt(YAR_OPT_CONNECT_TIMEOUT, $timeout); 266 $client->SetOpt(YAR_OPT_CONNECT_TIMEOUT, $timeout);
  267 +
  268 + try {
267 $result = call_user_func_array(array($client, $method), $parameters); 269 $result = call_user_func_array(array($client, $method), $parameters);
  270 + } catch (\Exception $e) {
  271 + $result = array();
  272 + }
268 273
269 if (!empty($result['data'])) { 274 if (!empty($result['data'])) {
270 return $result['data']; 275 return $result['data'];
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\Guang;
  4 +
  5 +use Api\Yohobuy;
  6 +
  7 +/**
  8 + * 逛资讯详情相关的数据模型
  9 + *
  10 + * @name DetailData
  11 + * @package LibModels/Wap/Guang
  12 + * @copyright yoho.inc
  13 + * @version 1.0 (2015-10-10 14:49:15)
  14 + * @author fei.hong <fei.hong@yoho.cn>
  15 + */
  16 +class DetailData
  17 +{
  18 + const API_URI_ARTICLE = 'guang/service/v2/article/';
  19 + const API_URI_AUTHOR = 'guang/service/v1/author/';
  20 +
  21 + /**
  22 + * 逛资讯详情页数据封装
7 */ 23 */
  24 + public static function package($id)
  25 + {
  26 + $result = array();
  27 + $result['getAuthor'] = array();
  28 + $result['getArticle'] = array();
  29 + $result['getArticleContent'] = array();
  30 + $result['getBrand'] = array();
  31 + $result['getOtherArticle'] = array();
  32 +
  33 + // 获取资讯
  34 + $article = Yohobuy::yarClient(Yohobuy::SERVICE_URL . self::API_URI_ARTICLE, 'getArticle', array($id));
  35 + if (!isset($article['tag'])) {
  36 + return $result;
  37 + } else {
  38 + $result['getArticle'] = $article;
  39 + }
  40 +
  41 + // 获取作者信息
  42 + Yohobuy::yarConcurrentCall(Yohobuy::SERVICE_URL . self::API_URI_AUTHOR, 'getAuthor', array($id), function ($retval) use (&$result) {
  43 + $result['getAuthor'] = empty($retval) ? array() : $retval;
  44 + });
  45 +
  46 + // 获取资讯内容
  47 + Yohobuy::yarConcurrentCall(Yohobuy::SERVICE_URL . self::API_URI_ARTICLE, 'getArticleContent', array($id), function ($retval) use (&$result) {
  48 + $result['getArticleContent'] = empty($retval) ? array() : $retval;
  49 + });
  50 +
  51 + // 获取资讯相关的品牌
  52 + Yohobuy::yarConcurrentCall(Yohobuy::SERVICE_URL . self::API_URI_ARTICLE, 'getBrand', array($id), function ($retval) use (&$result) {
  53 + $result['getBrand'] = empty($retval) ? array() : $retval;
  54 + });
  55 +
  56 + // 获取资讯相关的其它资讯
  57 + Yohobuy::yarConcurrentCall(Yohobuy::SERVICE_URL . self::API_URI_ARTICLE, 'getOtherArticle', array($article['tag'], $id, 0, 3), function ($retval) use (&$result) {
  58 + $result['getOtherArticle'] = empty($retval) ? array() : $retval;
  59 + });
  60 +
  61 + // 调用发起请求
  62 + Yohobuy::yarConcurrentLoop();
  63 +
  64 + return $result;
  65 + }
8 66
  67 +}
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\Guang;
  4 +
  5 +use Api\Sign;
  6 +use Api\Yohobuy;
  7 +use Hood\Cache;
  8 +
  9 +/**
  10 + * 逛首页列表相关的数据模型
  11 + *
  12 + * @name ListData
  13 + * @package LibModels/Wap/Guang
  14 + * @copyright yoho.inc
  15 + * @version 1.0 (2015-10-10 9:54:07)
  16 + * @author fei.hong <fei.hong@yoho.cn>
  17 + */
  18 +class ListData
  19 +{
  20 + /**
  21 + * 逛分类
  22 + *
  23 + * 备注: id (0:最新,1:话题,2:搭配,3:潮人,4:潮品,5:小贴士)
  24 + *
  25 + * @return array
  26 + */
  27 + public static function category()
  28 + {
  29 + return Yohobuy::get(Yohobuy::SERVICE_URL . 'guang/api/v1/category/get');
  30 + }
  31 +
  32 + /**
  33 + * 根据分类进行分组的逛内容列表
  34 + *
  35 + * @param array $category 分类
  36 + * @param string $gender "1,3"表示男, "2,3"表示女
  37 + * @param int $page 分页第几页, 默认第1页
  38 + * @param int $channel 1表示男, 2表示女
  39 + * @param int $uid 用户ID
  40 + * @param string $udid 客户端cookie唯一标识
  41 + * @return array
7 */ 42 */
  43 + public static function articleGroup($category, $gender, $channel, $uid = 0, $udid, $page = 1)
  44 + {
  45 + $urlList = array();
  46 + $param = array();
  47 +
  48 + foreach ($category as $value) {
  49 + $param = Yohobuy::param();
  50 + $param['gender'] = $gender;
  51 + $param['page'] = $page;
  52 + $param['yh_channel'] = $channel;
  53 + $param['sort_id'] = $value['id'];
  54 + $param['uid'] = $uid;
  55 + $param['udid'] = $udid;
  56 + $param['client_secret'] = Sign::getSign($param);
  57 +
  58 + $urlList[ $value['id'] ] = Yohobuy::httpBuildQuery(Yohobuy::SERVICE_URL . 'guang/api/v2/article/getList', $param);
  59 + }
  60 +
  61 + return Yohobuy::getMulti($urlList);
  62 + }
8 63
  64 +}
  1 +<?php
  2 +
  3 +namespace LibModels\Wap\Guang;
  4 +
  5 +use Api\Sign;
  6 +use Api\Yohobuy;
  7 +
  8 +/**
  9 + * 逛操作相关的数据模型
  10 + *
  11 + * @name OptData
  12 + * @package LibModels/Wap/Guang
  13 + * @copyright yoho.inc
  14 + * @version 1.0 (2015-10-10 11:51:16)
  15 + * @author fei.hong <fei.hong@yoho.cn>
  16 + */
  17 +class OptData
  18 +{
  19 +
  20 + /**
  21 + * 品牌收藏/取消收藏
  22 + *
  23 + * @param int $uid 用户ID
  24 + * @param int $id 唯一的ID
  25 + * @param string $opt 操作(ok:表示确定,cancel:表示取消)
  26 + * @return array
  27 + */
  28 + public static function favoriteBrand($uid, $id, $opt = 'ok')
  29 + {
  30 + return Yohobuy::yarClient(Yohobuy::SERVICE_URL . 'shops/service/v1/favorite/', 'toggleBrandFav', array($uid, $id));
  31 + }
  32 +
  33 + /**
  34 + * 商品收藏/取消收藏
  35 + *
  36 + * @param int $uid 用户ID
  37 + * @param int $skn 商品标识
  38 + * @param string $opt 操作(ok:表示确定,cancel:表示取消)
  39 + * @return array
  40 + */
  41 + public static function favoriteProduct($uid, $skn, $opt = 'ok')
  42 + {
  43 + if ($opt === 'cancel') {
  44 + return Yohobuy::yarClient(Yohobuy::SERVICE_URL . 'shops/service/v1/favorite/', 'addUidProductFav', array($uid, $skn));
  45 + } else {
  46 + return Yohobuy::yarClient(Yohobuy::SERVICE_URL . 'shops/service/v1/favorite/', 'delUidProductFav', array($uid, $skn));
  47 + }
  48 + }
  49 +
  50 + /**
  51 + * 品牌相关资讯点赞/取消赞
  52 + *
  53 + * @param int $uid 用户ID
  54 + * @param int $id 唯一的ID
  55 + * @param string $opt 操作(ok:表示确定,cancel:表示取消)
  56 + * @return array
  57 + */
  58 + public static function praiseBrandArticle($uid, $id, $opt = 'ok')
  59 + {
  60 + if ($opt === 'cancel') {
  61 + return Yohobuy::yarClient(Yohobuy::SERVICE_URL . 'guang/service/v1/favorite/', 'cancelPraise', array($id, $uid));
  62 + } else {
  63 + return Yohobuy::yarClient(Yohobuy::SERVICE_URL . 'guang/service/v1/favorite/', 'setPraise', array($id, $uid));
  64 + }
  65 + }
  66 +
  67 + /**
  68 + * 逛资讯点赞/取消赞
  69 + *
  70 + * @param int $udid 唯一客户端cookie标识
  71 + * @param int $id 唯一资讯的ID
  72 + * @param string $opt 操作(ok:表示确定,cancel:表示取消)
  73 + * @return array
  74 + */
  75 + public static function praiseArticle($udid, $id, $opt = 'ok')
  76 + {
  77 + $param = Yohobuy::param();
  78 + $param['udid'] = $udid;
  79 + $param['article_id'] = $id;
  80 + $param['client_secret'] = Sign::getSign($param);
  81 +
  82 + if ($opt === 'cancel') {
  83 + return Yohobuy::get(Yohobuy::SERVICE_URL . 'guang/api/v2/praise/setPraise', $param);
  84 + } else {
  85 + return Yohobuy::get(Yohobuy::SERVICE_URL . 'guang/api/v2/praise/cancel', $param);
  86 + }
  87 + }
  88 +
  89 +}
@@ -72,22 +72,23 @@ class PlusstarData @@ -72,22 +72,23 @@ class PlusstarData
72 */ 72 */
73 public static function brandInfo($id, $gender, $uid, $udid = null) 73 public static function brandInfo($id, $gender, $uid, $udid = null)
74 { 74 {
75 - $isUidOk = $uid && is_numeric($uid);  
76 -  
77 - // 品牌详情信息  
78 $result = array(); 75 $result = array();
79 - $result['getBrandInfo'] = Yohobuy::yarClient(Yohobuy::SERVICE_URL . 'guang/service/v1/plustar/', 'getBrandInfo', array(array('id' => $id)) ); 76 + $result['getBrandInfo'] = array();
80 $result['getUidBrandFav'] = false; 77 $result['getUidBrandFav'] = false;
81 $result['getNewProduct'] = array(); 78 $result['getNewProduct'] = array();
82 $result['getUidProductFav'] = array(); 79 $result['getUidProductFav'] = array();
83 $result['getArticleByBrand'] = array(); 80 $result['getArticleByBrand'] = array();
84 81
85 - // 判断  
86 - if (!isset($result['getBrandInfo']['brand_id'])) { 82 + // 品牌详情信息
  83 + $brandInfo = Yohobuy::yarClient(Yohobuy::SERVICE_URL . 'guang/service/v1/plustar/', 'getBrandInfo', array(array('id' => $id)) );
  84 + if (!isset($brandInfo['brand_id'])) {
87 return $result; 85 return $result;
  86 + } else {
  87 + $result['getBrandInfo'] = $brandInfo;
88 } 88 }
89 89
90 // 是否收藏店铺 90 // 是否收藏店铺
  91 + $isUidOk = $uid && is_numeric($uid);
91 if ($isUidOk) { 92 if ($isUidOk) {
92 Yohobuy::yarConcurrentCall(Yohobuy::SERVICE_URL . 'shops/service/v1/favorite/', 'getUidBrandFav', array($uid, $id), function($retval) use(&$result) { 93 Yohobuy::yarConcurrentCall(Yohobuy::SERVICE_URL . 'shops/service/v1/favorite/', 'getUidBrandFav', array($uid, $id), function($retval) use(&$result) {
93 $result['getUidBrandFav'] = empty($retval['data']) ? false : $retval['data']; 94 $result['getUidBrandFav'] = empty($retval['data']) ? false : $retval['data'];
@@ -96,7 +97,7 @@ class PlusstarData @@ -96,7 +97,7 @@ class PlusstarData
96 97
97 // 相关资讯列表 (3篇) 98 // 相关资讯列表 (3篇)
98 $result['getArticleByBrand'] = array(); 99 $result['getArticleByBrand'] = array();
99 - Yohobuy::yarConcurrentCall(Yohobuy::SERVICE_URL . 'guang/service/v1/article/', 'getArticleByBrand', array($result['getBrandInfo']['brand_id'], 3, $udid), function($retval) use(&$result) { 100 + Yohobuy::yarConcurrentCall(Yohobuy::SERVICE_URL . 'guang/service/v1/article/', 'getArticleByBrand', array($brandInfo['brand_id'], 3, $udid), function($retval) use(&$result) {
100 $result['getArticleByBrand'] = empty($retval) ? array() : $retval; 101 $result['getArticleByBrand'] = empty($retval) ? array() : $retval;
101 }); 102 });
102 103
@@ -108,7 +109,7 @@ class PlusstarData @@ -108,7 +109,7 @@ class PlusstarData
108 // 调用搜索接口 109 // 调用搜索接口
109 $param = Yohobuy::param(); 110 $param = Yohobuy::param();
110 $param['method'] = 'app.search.li'; 111 $param['method'] = 'app.search.li';
111 - $param['brand'] = $result['getBrandInfo']['brand_id']; 112 + $param['brand'] = $brandInfo['brand_id'];
112 $param['page'] = '0'; 113 $param['page'] = '0';
113 $param['limit'] = '6'; 114 $param['limit'] = '6';
114 $param['gender'] = $gender; 115 $param['gender'] = $gender;
@@ -204,51 +205,4 @@ class PlusstarData @@ -204,51 +205,4 @@ class PlusstarData
204 205
205 } 206 }
206 207
207 - /**  
208 - * 品牌收藏/取消收藏  
209 - *  
210 - * @param int $uid 用户ID  
211 - * @param int $id 唯一的ID  
212 - * @param string $opt 操作(ok:表示确定,cancel:表示取消)  
213 - * @return array  
214 - */  
215 - public static function favoriteBrand($uid, $id, $opt = 'ok')  
216 - {  
217 - return Yohobuy::yarClient(Yohobuy::SERVICE_URL . 'shops/service/v1/favorite/', 'toggleBrandFav', array($uid, $id));  
218 - }  
219 -  
220 - /**  
221 - * 商品收藏/取消收藏  
222 - *  
223 - * @param int $uid 用户ID  
224 - * @param int $skn 商品标识  
225 - * @param string $opt 操作(ok:表示确定,cancel:表示取消)  
226 - * @return array  
227 - */  
228 - public static function favoriteProduct($uid, $skn, $opt = 'ok')  
229 - {  
230 - if ($opt === 'cancel') {  
231 - return Yohobuy::yarClient(Yohobuy::SERVICE_URL . 'shops/service/v1/favorite/', 'addUidProductFav', array($uid, $skn));  
232 - } else {  
233 - return Yohobuy::yarClient(Yohobuy::SERVICE_URL . 'shops/service/v1/favorite/', 'delUidProductFav', array($uid, $skn));  
234 - }  
235 - }  
236 -  
237 - /**  
238 - * 资讯点赞/取消赞  
239 - *  
240 - * @param int $uid 用户ID  
241 - * @param int $id 唯一的ID  
242 - * @param string $opt 操作(ok:表示确定,cancel:表示取消)  
243 - * @return array  
244 - */  
245 - public static function praiseArticle($uid, $id, $opt = 'ok')  
246 - {  
247 - if ($opt === 'cancel') {  
248 - return Yohobuy::yarClient(Yohobuy::SERVICE_URL . 'guang/service/v1/favorite/', 'cancelPraise', array($id, $uid));  
249 - } else {  
250 - return Yohobuy::yarClient(Yohobuy::SERVICE_URL . 'guang/service/v1/favorite/', 'setPraise', array($id, $uid));  
251 - }  
252 - }  
253 -  
254 } 208 }
  1 +<?php
  2 +
  3 +/**
  4 + *
  5 + * @name Cache
  6 + * @package
  7 + * @copyright yoho.inc
  8 + * @version 1.0 (2015-10-10 11:23:47)
  9 + * @author fei.hong <fei.hong@yoho.cn>
  10 + */
  11 +class Cache
  12 +{
  13 +
  14 +}
@@ -16,8 +16,9 @@ class Helpers @@ -16,8 +16,9 @@ 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){  
20 - return str_replace('{width}', $width, str_replace('{height}', $height, str_replace('{mode}', $mode, $fileName))); 19 + public static function getImageUrl($fileName, $width, $height, $mode = 1)
  20 + {
  21 + return strtr($fileName, array('{width}' => $width, '{height}' => $height, '{mode}' => $mode));
21 } 22 }
22 23
23 /** 24 /**
@@ -30,4 +31,7 @@ class Helpers @@ -30,4 +31,7 @@ class Helpers
30 { 31 {
31 return array_intersect_key($array, array_flip((array) $keys)); 32 return array_intersect_key($array, array_flip((array) $keys));
32 } 33 }
  34 +
  35 +
  36 +
33 } 37 }
@@ -45,4 +45,9 @@ server @@ -45,4 +45,9 @@ server
45 expires 1h; 45 expires 1h;
46 } 46 }
47 47
  48 + location ~* \.(svg|eot|ttf|woff|otf)$ {
  49 + add_header Access-Control-Allow-Origin *;
  50 + expires 30d;
  51 + }
  52 +
48 } 53 }