Info.php
7.29 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
<?php
use Action\AbstractAction;
use LibModels\Wap\Guang\DetailData;
use LibModels\Wap\Product\ListData;
use Plugin\Helpers;
/**
* 逛详情页
*/
class InfoController extends AbstractAction
{
/**
* 详情页
*
* @param int id 内容ID
*/
public function indexAction()
{
$id = $this->get('id');
// 判断参数是否有效, 无效会跳转到错误页面
if (!is_numeric($id)) {
$this->error();
}
// 标识是不是APP访问的
$isApp = null !== $this->get('app_version', null);
// 获取详情内容信息, 异常则跳到错误页面
$detail = DetailData::package($id, $isApp);
if (empty($detail['getArticle'])) {
$this->error();
}
// WAP上设置头部导航
if (!$isApp) {
$this->setNavHeader('逛', true, SITE_MAIN);
}
$data = array();
$data['guangDetail'] = true; // 模板中使用JS的标识
$data['guang']['id'] = $id;
// 作者信息数据
if (isset($detail['getAuthor']['name'])) {
$data['guang']['author'] = array();
$data['guang']['author']['avatar'] = $detail['getAuthor']['avatar'];
$data['guang']['author']['name'] = $detail['getAuthor']['name'];
$data['guang']['author']['intro'] = $detail['getAuthor']['author_desc'];
$data['guang']['author']['url'] = $isApp ? $detail['getAuthor']['url'] : Helpers::url('/author/index', array('id' => $detail['getArticle']['author_id']), 'guang');
}
$data['detail'] = array();
$data['detail']['title'] = $detail['getArticle']['article_title'];
$data['detail']['publishTime'] = $detail['getArticle']['publishTime'];
$data['detail']['pageView'] = $detail['getArticle']['pageViews'];
$data['detail']['content'] = array();
if (!empty($detail['getArticleContent'])) {
$build = array();
$good = array();
$skns = array();
$product = array();
foreach ($detail['getArticleContent'] as $value) {
$build = array();
// 文字
if (isset($value['text'])) {
$build['text'] = $value['text']['data']['text'];
}
// 单张图
elseif (isset($value['singleImage'])) {
$build['bigImage'] = Helpers::getImageUrl($value['singleImage']['data'][0]['src'], 640, 640);
} elseif (isset($value['smallPic']['data'])) {
$imgs = $value['smallPic']['data'];
$build['smallImage'] = array(
array(
'src' => Helpers::getImageUrl($imgs[0]['src'], 315, 420)
),
array(
'src' => Helpers::getImageUrl($imgs[1]['src'], 315, 420)
)
);
}
// 相关推荐
elseif (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);
}
}
// 没有商品
if (!isset($i)) {
continue;
}
// 单个商品
elseif ($i === 0 && isset($good[0])) {
$build['relatedReco'] = $good[0];
}
// 多个商品
else {
$build['relatedReco'] = $good;
}
}
// 悬停浮动商品
elseif (isset($value['goodsGroup']['data'])) {
foreach ($value['goodsGroup']['data'] as $goods) {
$good = array();
$good['thumb'] = Helpers::getImageUrl($goods['cover']['cover'], 235, 314);
$good['type'] = 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);
}
$build['collocation'][] = $good;
}
}
}
$data['detail']['content'][] = $build;
}
}
// 相关品牌
if (!empty($detail['getBrand'])) {
$data['relatedBrand'] = $detail['getBrand'];
}
// 相关标签
if (!empty($detail['getArticle']['tags'])) {
foreach ($detail['getArticle']['tags'] as $value) {
if (!$isApp) {
$value['url'] = Helpers::url('/tags/index', array('query=' => $value['name']), 'guang');
}
$data['relatedTag'][] = $value;
}
}
// 相关文章
if (!empty($detail['getOtherArticle'])) {
foreach ($detail['getOtherArticle'] as $value) {
if (!$isApp) {
$value['url'] = Helpers::url('/info/index', array('id' => $value['id']), 'guang');
}
$value['thumb'] = Helpers::getImageUrl($value['thumb'], 279, 175);
$data['relatedInfo'][] = $value;
}
}
// 分享参数
if (isset($detail['getArticle']['cover_image'])) {
$data['shareLink'] = Helpers::url('/info/index', array('id' => $id), 'guang');
$data['shareTitle'] = $detail['getArticle']['article_title'];
$data['shareDesc'] = $detail['getArticle']['article_summary'];
if ($detail['getArticle']['cover_image_type'] == 1) {
$data['shareImg'] = Helpers::getImageUrl($detail['getArticle']['cover_image'], 640, 640);
} else {
$data['shareImg'] = Helpers::getImageUrl($detail['getArticle']['cover_image'], 640, 320);
}
}
// 标识有微信分享
$data['hasWxShare'] = true;
$this->_view->display('index', $data);
$detail = array();
$data = array();
}
}