Authored by hf

Merge branch 'guang' into beta

@@ -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,93 @@ class InfoController extends AbstractAction @@ -343,4 +343,93 @@ 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 + $app = $this->get('app');
  364 + $isApp = empty($app) ? false : true;
  365 +
  366 + /* 判断是否有内容 */
  367 + $detail = DetailData::package($id, $isApp);
  368 + if (empty($detail['getArticleContent'])) {
  369 + break;
  370 + }
  371 +
  372 + /* 品牌信息 */
  373 + $result['brand'] = $detail['getBrand'];
  374 +
  375 + $build = array();
  376 + $good = array();
  377 + $skns = array();
  378 + $product = array();
  379 +
  380 + /* 商品信息 */
  381 + foreach ($detail['getArticleContent'] as $value) {
  382 + $build = array();
  383 + if (isset($value['goods']['data'])) {
  384 + $good = array();
  385 + // 遍历取得SKN
  386 + $skns = array();
  387 + foreach ($value['goods']['data'] as $goods) {
  388 + $skns[] = $goods['id'];
  389 + }
  390 + // 通过SKN获取商品信息
  391 + $product = ListData::productInfoBySkns($skns);
  392 + if (!empty($product['data']['product_list'])) {
  393 + foreach ($product['data']['product_list'] as $i => $goods) {
  394 + // 最多显示4个
  395 + if ($i > 3) {
  396 + break;
  397 + }
  398 + $good[] = Helpers::formatProduct($goods, false, true, true, 235, 314, true);
  399 + }
  400 + }
  401 + // 没有商品
  402 + if (!isset($i)) {
  403 + continue;
  404 + }
  405 + $result['goods'] = $good;
  406 + }
  407 + // 悬停浮动商品
  408 + elseif (isset($value['goodsGroup']['data'])) {
  409 + foreach ($value['goodsGroup']['data'] as $goods) {
  410 + $good = array();
  411 + $good['img'] = Helpers::getImageUrl($goods['cover']['cover'], 235, 314);
  412 + $good['icon'] = Helpers::getProductIcon($goods['cover']['maxSortId']);
  413 + $good['goods'] = array();
  414 + $skns = array();
  415 + foreach ($goods['list'] as $mini) {
  416 + $skns[] = $mini['id'];
  417 + }
  418 + // 通过SKN获取商品信息
  419 + $product = ListData::productInfoBySkns($skns);
  420 + if (!empty($product['data']['product_list'])) {
  421 + foreach ($product['data']['product_list'] as $i => $goods) {
  422 + $good['goods'][] = Helpers::formatProduct($goods, false, true, true, 235, 314, true);
  423 + }
  424 + $result['group'][] = $good;
  425 + }
  426 + }
  427 + }
  428 + }
  429 + }
  430 + while (false);
  431 +
  432 + $this->echoJson($result);
  433 + }
  434 +
346 } 435 }