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
}
/**
* 逛资讯数据封装 (专为YOHO!男女生资讯站提供)
*
* @param int $id 内容ID
* @param bool $isApp 标识是否是APP访问
* @return array
*/
public static function packageForYoho($id, $isApp = false)
{
$result = array();
// 客户端类型
$clientType = $isApp ? 'iphone' : 'h5';
// 获取资讯内容
Yohobuy::yarConcurrentCall(Yohobuy::SERVICE_URL . self::URI_PACKAGE_ARTICLE, 'getArticleContent', array($id, $clientType), function ($retval) use (&$result) {
$result['getArticleContent'] = empty($retval) ? array() : $retval;
});
// 获取资讯相关的品牌
Yohobuy::yarConcurrentCall(Yohobuy::SERVICE_URL . self::URI_PACKAGE_ARTICLE, 'getBrand', array($id, $clientType), function ($retval) use (&$result) {
$result['getBrand'] = empty($retval) ? array() : $retval;
});
// 调用发起请求
Yohobuy::yarConcurrentLoop();
return $result;
}
/**
* 获取详情信息
*/
public static function intro($id)
... ...
... ... @@ -343,4 +343,90 @@ class InfoController extends AbstractAction
$data = array();
}
/**
* 提供给YOHO资讯站调用的接口
*
* @param int id 逛内容ID
* @return json
*/
public function foryohoAction()
{
$result = array();
do {
/* 判断参数是否有效 */
$id = $this->get('id');
if (!is_numeric($id)) {
break;
}
/* 判断是否有内容 */
$detail = DetailData::packageForYoho($id, true);
if (empty($detail['getArticleContent'])) {
break;
}
/* 品牌信息 */
$result['brand'] = $detail['getBrand'];
$build = array();
$good = array();
$skns = array();
$product = array();
/* 商品信息 */
foreach ($detail['getArticleContent'] as $value) {
$build = array();
if (isset($value['goods']['data'])) {
$good = array();
// 遍历取得SKN
$skns = array();
foreach ($value['goods']['data'] as $goods) {
$skns[] = $goods['id'];
}
// 通过SKN获取商品信息
$product = ListData::productInfoBySkns($skns);
if (!empty($product['data']['product_list'])) {
foreach ($product['data']['product_list'] as $i => $goods) {
// 最多显示4个
if ($i > 3) {
break;
}
$good[] = Helpers::formatProduct($goods, false, true, true, 235, 314, true);
}
}
// 没有商品
if (!isset($i)) {
continue;
}
$result['goods'] = $good;
}
// 悬停浮动商品
elseif (isset($value['goodsGroup']['data'])) {
foreach ($value['goodsGroup']['data'] as $goods) {
$good = array();
$good['img'] = Helpers::getImageUrl($goods['cover']['cover'], 235, 314);
$good['icon'] = Helpers::getProductIcon($goods['cover']['maxSortId']);
$good['goods'] = array();
$skns = array();
foreach ($goods['list'] as $mini) {
$skns[] = $mini['id'];
}
// 通过SKN获取商品信息
$product = ListData::productInfoBySkns($skns);
if (!empty($product['data']['product_list'])) {
foreach ($product['data']['product_list'] as $i => $goods) {
$good['goods'][] = Helpers::formatProduct($goods, false, true, true, 235, 314, true);
}
$result['group'][] = $good;
}
}
}
}
}
while (false);
$this->echoJson($result);
}
}
... ...