DetailData.php
2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
namespace LibModels\Wap\Guang;
use Api\Yohobuy;
/**
* 逛资讯详情相关的数据模型
*
* @name DetailData
* @package LibModels/Wap/Guang
* @copyright yoho.inc
* @version 1.0 (2015-10-10 14:49:15)
* @author fei.hong <fei.hong@yoho.cn>
*/
class DetailData
{
const URI_PACKAGE_ARTICLE = 'guang/service/v2/article/';
const URI_PACKAGE_AUTHOR = 'guang/service/v1/author/';
/**
* 逛资讯详情页数据封装
*/
public static function package($id)
{
$result = array();
$result['getAuthor'] = array();
$result['getArticle'] = array();
$result['getArticleContent'] = array();
$result['getBrand'] = array();
$result['getOtherArticle'] = array();
// 获取资讯
$article = Yohobuy::yarClient(Yohobuy::SERVICE_URL . self::URI_PACKAGE_ARTICLE, 'getArticle', array($id));
if (!isset($article['tag'])) {
return $result;
}
else {
$result['getArticle'] = $article;
}
// 获取作者信息
Yohobuy::yarConcurrentCall(Yohobuy::SERVICE_URL . self::URI_PACKAGE_AUTHOR, 'getAuthor', array($article['author_id']), function ($retval) use (&$result) {
$result['getAuthor'] = empty($retval) ? array() : $retval;
});
// 获取资讯内容
Yohobuy::yarConcurrentCall(Yohobuy::SERVICE_URL . self::URI_PACKAGE_ARTICLE, 'getArticleContent', array($id), function ($retval) use (&$result) {
$result['getArticleContent'] = empty($retval) ? array() : $retval;
});
// 获取资讯相关的品牌
Yohobuy::yarConcurrentCall(Yohobuy::SERVICE_URL . self::URI_PACKAGE_ARTICLE, 'getBrand', array($id), function ($retval) use (&$result) {
$result['getBrand'] = empty($retval) ? array() : $retval;
});
// 获取资讯相关的其它资讯
Yohobuy::yarConcurrentCall(Yohobuy::SERVICE_URL . self::URI_PACKAGE_ARTICLE, 'getOtherArticle', array($article['tag'], $id, 0, 3), function ($retval) use (&$result) {
$result['getOtherArticle'] = empty($retval) ? array() : $retval;
});
// 调用发起请求
Yohobuy::yarConcurrentLoop();
return $result;
}
}