Authored by hf

do guang plusstar data model

@@ -264,9 +264,13 @@ class Yohobuy @@ -264,9 +264,13 @@ 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 - $result = $client->$method($parameters);  
268 -  
269 - return $result; 267 + $result = call_user_func_array(array($client, $method), $parameters);
  268 +
  269 + if (!empty($result['data'])) {
  270 + return $result['data'];
  271 + } else {
  272 + return array();
  273 + }
270 } 274 }
271 275
272 /** 276 /**
@@ -282,7 +286,7 @@ class Yohobuy @@ -282,7 +286,7 @@ class Yohobuy
282 */ 286 */
283 public static function yarConcurrentCall($uri, $method, $parameters, $callback, $timeout = 3000) 287 public static function yarConcurrentCall($uri, $method, $parameters, $callback, $timeout = 3000)
284 { 288 {
285 - \Yar_Concurrent_Client::call($uri, $method, array($parameters), $callback, null, array( 289 + \Yar_Concurrent_Client::call($uri, $method, $parameters, $callback, null, array(
286 YAR_OPT_PACKAGER => 'php', 290 YAR_OPT_PACKAGER => 'php',
287 YAR_OPT_TIMEOUT => $timeout, 291 YAR_OPT_TIMEOUT => $timeout,
288 YAR_OPT_CONNECT_TIMEOUT => $timeout 292 YAR_OPT_CONNECT_TIMEOUT => $timeout
@@ -57,20 +57,198 @@ class PlusstarData @@ -57,20 +57,198 @@ class PlusstarData
57 57
58 /** 58 /**
59 * 品牌介绍 59 * 品牌介绍
  60 + *
  61 + * @param int $id 唯一的ID
  62 + * @param string $gender $gender "1,3"表示男, "2,3"表示女
  63 + * @param int $uid 用户ID
  64 + * @param string $udid cookie记录唯一标识
  65 + * @return array(
  66 + * "getBrandInfo" => array(品牌详情信息),
  67 + * "getUidBrandFav" => false,
  68 + * "getArticleByBrand" => array(3篇相关资讯),
  69 + * "getNewProduct" => array(6篇新品到着),
  70 + * "getUidProductFav" => array(用户是否收藏新品)
  71 + * )
60 */ 72 */
61 - public static function brandInfo($id) 73 + public static function brandInfo($id, $gender, $uid, $udid = null)
62 { 74 {
  75 + $isUidOk = $uid && is_numeric($uid);
  76 +
  77 + // 品牌详情信息
63 $result = array(); 78 $result = array();
  79 + $result['getBrandInfo'] = Yohobuy::yarClient(Yohobuy::SERVICE_URL . 'guang/service/v1/plustar/', 'getBrandInfo', array(array('id' => $id)) );
  80 + $result['getUidBrandFav'] = false;
  81 + $result['getNewProduct'] = array();
  82 + $result['getUidProductFav'] = array();
  83 + $result['getArticleByBrand'] = array();
64 84
65 - Yohobuy::yarConcurrentCall('http://service.api.yohobuy.com/guang/service/v1/plustar/', 'getBrandInfo', array('id' => 289), function($retval, $callinfo) use(&$result) {  
66 - $result[ $callinfo['method'] ] = empty($retval['data']) ? array() : $retval['data'];  
67 - });  
68 - Yohobuy::yarConcurrentCall('http://service.api.yohobuy.com/guang/service/v1/plustar/', 'getList', array('id' => 289), function($retval, $callinfo) use(&$result) {  
69 - $result[ $callinfo['method'] ] = empty($retval['data']) ? array() : $retval['data']; 85 + // 判断
  86 + if (!isset($result['getBrandInfo']['brand_id'])) {
  87 + return $result;
  88 + }
  89 +
  90 + // 是否收藏店铺
  91 + if ($isUidOk) {
  92 + 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 + });
  95 + }
  96 +
  97 + // 相关资讯列表 (3篇)
  98 + $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 + $result['getArticleByBrand'] = empty($retval) ? array() : $retval;
70 }); 101 });
71 - Yohobuy::yarConcurrentLoop();  
72 102
  103 + // 新品到着列表 (6篇)
  104 + $result['getNewProduct'] = array();
  105 + $result['getUidProductFav'] = array();
  106 +
  107 + do {
  108 + // 调用搜索接口
  109 + $param = Yohobuy::param();
  110 + $param['method'] = 'app.search.li';
  111 + $param['brand'] = $result['getBrandInfo']['brand_id'];
  112 + $param['page'] = '0';
  113 + $param['limit'] = '6';
  114 + $param['gender'] = $gender;
  115 + $param['order'] = 's_t_desc';
  116 + $param['client_secret'] = Sign::getSign($param);
  117 + $newProduct = Yohobuy::get(Yohobuy::API_URL, $param);
  118 + if (empty($newProduct['data']['product_list'])) {
  119 + break;
  120 + }
  121 +
  122 + //$result['getNewProduct'] = $newProduct['data']['product_list'];
  123 +
  124 + $skn = '';
  125 + foreach ($newProduct['data']['product_list'] as $value) {
  126 + if (empty($value['goods_list'])) {
  127 + continue;
  128 + }
  129 +
  130 + // 用户是否收藏该商品
  131 + $skn = $value['product_skn'];
  132 + $result['getUidProductFav'][ $skn ] = false;
  133 + if ($isUidOk) {
  134 + Yohobuy::yarConcurrentCall(Yohobuy::SERVICE_URL . 'shops/service/v1/favorite/', 'getUidProductFav', array($uid, $value['product_skn']), function($retval) use(&$result,&$skn) {
  135 + $result['getUidProductFav'][ $skn ] = empty($retval['data']) ? false : $retval['data'];
  136 + });
  137 + }
  138 +
  139 + // @todo 需要根据页面结构封装返回数据
  140 + }
  141 + } while (false);
  142 +
  143 + // 调用发起请求
  144 + Yohobuy::yarConcurrentLoop();
  145 +
73 return $result; 146 return $result;
  147 +
  148 +
  149 + // @todo 根据页面展示数据封装
  150 +// $url = '';
  151 +// if($uid > 0){
  152 +// $isLike = Favorite::getUidProductFav($uid, $new_goods_info['product_skn']);
  153 +// }
  154 +// if($client_type == 'web'){
  155 +// $baseUrl = QUtilsConfig::$websiteRoot['yohobuy'];
  156 +// }else{
  157 +// $baseUrl = QUtilsConfig::$websiteRoot['h5'];
  158 +// }
  159 +// $goods_url = MakeUrl::h5ProductDetailUrl($baseUrl,$new_goods_info['product_id'],$new_goods_info['goods_list'][0]['goods_id'],$new_goods_info['cn_alphabet']);
  160 +// $url = MakeUrl::makeUrl('go.productDetail',$goods_url, array('product_skn'=>$new_goods_info['product_skn']),$client_type);
  161 +// if((int)$new_goods_info['market_price'] == (int)$new_goods_info['sales_price'])
  162 +// {
  163 +// $new_goods_info['market_price'] = '';
  164 +// }
  165 +// $tags = array(
  166 +// 'isNew' => false,
  167 +// 'isSale' => false,
  168 +// 'isLimit' => false,
  169 +// 'isYohood' => false,
  170 +// 'midYear' => false,
  171 +// 'yearEnd' => false,
  172 +// );
  173 +// foreach ($new_goods_info['tags'] as $v){
  174 +// if($v == 'is_new'){
  175 +// $tags['isNew'] = true;
  176 +// }elseif($v == 'is_discount'){
  177 +// $tags['isSale'] = true;
  178 +// }elseif($v == 'is_limited'){
  179 +// $tags['isLimit'] = true;
  180 +// }elseif($v == 'is_yohood'){
  181 +// $tags['isYohood'] = true;
  182 +// }elseif($v == 'mid-year'){
  183 +// $tags['midYear'] = true;
  184 +// }elseif($v == 'year-end'){
  185 +// $tags['yearEnd'] = true;
  186 +// }
  187 +// }
  188 +// $newPatterns[$new_goods_info['product_skn']]= array (
  189 +// 'id'=>$new_goods_info['product_skn'],
  190 +// 'product_id'=>$new_goods_info['product_id'],
  191 +// 'product_skn'=>$new_goods_info['product_skn'],
  192 +// 'thumb' => $new_goods_info['default_images'],
  193 +// 'name' => $new_goods_info['product_name'],
  194 +// 'isLike' => $isLike,
  195 +// 'price' => $new_goods_info['market_price'],
  196 +// 'salePrice' => $new_goods_info['sales_price'],
  197 +// 'isSale' => $new_goods_info['is_discount'] == 'Y' ? true : false,
  198 +// 'isFew' => $new_goods_info['is_soon_sold_out'] == 'Y' ? true : false,
  199 +// 'isNew' => $new_goods_info['is_new'] == 'Y' ? true : false,
  200 +// 'url' => $url,
  201 +// 'tags' => $tags
  202 +// );
  203 +
  204 +
  205 + }
  206 +
  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 + }
74 } 252 }
75 253
76 } 254 }
@@ -11,8 +11,5 @@ class IndexController extends AbstractAction @@ -11,8 +11,5 @@ class IndexController extends AbstractAction
11 { 11 {
12 $this->_view->assign('title', 'YOHO!有货'); 12 $this->_view->assign('title', 'YOHO!有货');
13 $this->_view->display('index', array('test' => 'hello world')); 13 $this->_view->display('index', array('test' => 'hello world'));
14 -  
15 - $test = PlusstarData::brandInfo();  
16 - var_dump($test);  
17 } 14 }
18 } 15 }
1 <?php 1 <?php
2 use Action\AbstractAction; 2 use Action\AbstractAction;
  3 +use LibModels\Wap\Guang\PlusstarData;
  4 +
3 /** 5 /**
4 * 明星品牌和原创品牌 6 * 明星品牌和原创品牌
5 */ 7 */
@@ -13,6 +15,9 @@ class PlusstarController extends AbstractAction @@ -13,6 +15,9 @@ class PlusstarController extends AbstractAction
13 { 15 {
14 $this->_view->assign('title', 'YOHO!有货'); 16 $this->_view->assign('title', 'YOHO!有货');
15 $this->_view->display('list', array('test' => 'hello world')); 17 $this->_view->display('list', array('test' => 'hello world'));
  18 +
  19 + $test = PlusstarData::brandList("1,3", 1);
  20 + var_dump($test);
16 } 21 }
17 22
18 /** 23 /**
@@ -20,7 +25,8 @@ class PlusstarController extends AbstractAction @@ -20,7 +25,8 @@ class PlusstarController extends AbstractAction
20 */ 25 */
21 public function detailAction() 26 public function detailAction()
22 { 27 {
23 - 28 + $test = PlusstarData::brandInfo(67, '1,3', 123456);
  29 + var_dump($test);
24 } 30 }
25 31
26 } 32 }