Authored by hf

code review by fei.hong: do add guang brand and goods info for yoho boys and girls

@@ -147,6 +147,36 @@ class DetailData @@ -147,6 +147,36 @@ class DetailData
147 } 147 }
148 148
149 /** 149 /**
  150 + * 逛资讯数据封装 (专为YOHO!男女生资讯站提供)
  151 + *
  152 + * @param int $id 内容ID
  153 + * @param bool $isApp 标识是否是APP访问
  154 + * @return array
  155 + */
  156 + public static function packageForYoho($id, $isApp = false)
  157 + {
  158 + $result = array();
  159 +
  160 + // 客户端类型
  161 + $clientType = $isApp ? 'iphone' : 'h5';
  162 +
  163 + // 获取资讯内容
  164 + Yohobuy::yarConcurrentCall(Yohobuy::SERVICE_URL . self::URI_PACKAGE_ARTICLE, 'getArticleContent', array($id, $clientType), function ($retval) use (&$result) {
  165 + $result['getArticleContent'] = empty($retval) ? array() : $retval;
  166 + });
  167 +
  168 + // 获取资讯相关的品牌
  169 + Yohobuy::yarConcurrentCall(Yohobuy::SERVICE_URL . self::URI_PACKAGE_ARTICLE, 'getBrand', array($id, $clientType), function ($retval) use (&$result) {
  170 + $result['getBrand'] = empty($retval) ? array() : $retval;
  171 + });
  172 +
  173 + // 调用发起请求
  174 + Yohobuy::yarConcurrentLoop();
  175 +
  176 + return $result;
  177 + }
  178 +
  179 + /**
150 * 获取详情信息 180 * 获取详情信息
151 */ 181 */
152 public static function intro($id) 182 public static function intro($id)
@@ -343,4 +343,90 @@ class InfoController extends AbstractAction @@ -343,4 +343,90 @@ class InfoController extends AbstractAction
343 $data = array(); 343 $data = array();
344 } 344 }
345 345
  346 + /**
  347 + * 提供给YOHO资讯站调用的接口
  348 + *
  349 + * @param int id 逛内容ID
  350 + * @return json
  351 + */
  352 + public function foryohoAction()
  353 + {
  354 + $result = array();
  355 +
  356 + do {
  357 + /* 判断参数是否有效 */
  358 + $id = $this->get('id');
  359 + if (!is_numeric($id)) {
  360 + break;
  361 + }
  362 +
  363 + /* 判断是否有内容 */
  364 + $detail = DetailData::packageForYoho($id, true);
  365 + if (empty($detail['getArticleContent'])) {
  366 + break;
  367 + }
  368 +
  369 + /* 品牌信息 */
  370 + $result['brand'] = $detail['getBrand'];
  371 +
  372 + $build = array();
  373 + $good = array();
  374 + $skns = array();
  375 + $product = array();
  376 +
  377 + /* 商品信息 */
  378 + foreach ($detail['getArticleContent'] as $value) {
  379 + $build = array();
  380 + if (isset($value['goods']['data'])) {
  381 + $good = array();
  382 + // 遍历取得SKN
  383 + $skns = array();
  384 + foreach ($value['goods']['data'] as $goods) {
  385 + $skns[] = $goods['id'];
  386 + }
  387 + // 通过SKN获取商品信息
  388 + $product = ListData::productInfoBySkns($skns);
  389 + if (!empty($product['data']['product_list'])) {
  390 + foreach ($product['data']['product_list'] as $i => $goods) {
  391 + // 最多显示4个
  392 + if ($i > 3) {
  393 + break;
  394 + }
  395 + $good[] = Helpers::formatProduct($goods, false, true, true, 235, 314, true);
  396 + }
  397 + }
  398 + // 没有商品
  399 + if (!isset($i)) {
  400 + continue;
  401 + }
  402 + $result['goods'] = $good;
  403 + }
  404 + // 悬停浮动商品
  405 + elseif (isset($value['goodsGroup']['data'])) {
  406 + foreach ($value['goodsGroup']['data'] as $goods) {
  407 + $good = array();
  408 + $good['img'] = Helpers::getImageUrl($goods['cover']['cover'], 235, 314);
  409 + $good['icon'] = Helpers::getProductIcon($goods['cover']['maxSortId']);
  410 + $good['goods'] = array();
  411 + $skns = array();
  412 + foreach ($goods['list'] as $mini) {
  413 + $skns[] = $mini['id'];
  414 + }
  415 + // 通过SKN获取商品信息
  416 + $product = ListData::productInfoBySkns($skns);
  417 + if (!empty($product['data']['product_list'])) {
  418 + foreach ($product['data']['product_list'] as $i => $goods) {
  419 + $good['goods'][] = Helpers::formatProduct($goods, false, true, true, 235, 314, true);
  420 + }
  421 + $result['group'][] = $good;
  422 + }
  423 + }
  424 + }
  425 + }
  426 + }
  427 + while (false);
  428 +
  429 + $this->echoJson($result);
  430 + }
  431 +
346 } 432 }