Detail.php
5.37 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
<?php
use Action\AbstractAction;
use LibModels\Wap\Guang\DetailData;
use LibModels\Wap\Product\ListData;
use Plugin\Helpers;
/**
* 逛详情页
*/
class DetailController extends AbstractAction
{
/**
* 详情页
*
* @param int id 内容ID
*/
public function indexAction()
{
$id = $this->get('id');
// 判断参数是否有效, 无效会跳转到错误页面
if (!is_numeric($id)) {
$this->error();
}
// 获取详情内容信息, 异常则跳到错误页面
$detail = DetailData::package($id);
if (empty($detail['getArticle'])) {
$this->error();
}
$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'] = '/guang/list/editor?id=' . $detail['getArticle']['author_id'];
}
$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'];
$data['detail']['content'][] = $build;
}
// 单张图
elseif (isset($value['singleImage'])) {
$build['bigImage'] = Helpers::getImageUrl($value['singleImage']['data'][0]['src'], 640, 640);
$data['detail']['content'][] = $build;
}
// 相关推荐
elseif (isset($value['goods']['data'])) {
$good = array();
// 遍历取得SKN
$skns = array();
foreach ($value['goods']['data'] as $goods) {
$skns[] = $goods['id'];
}
// 通过SKN获取商品信息
$product = ListData::productInfoBySkns($skns);
foreach ($product['data']['product_list'] as $i => $goods) {
// 最多显示4个
if ($i > 3) {
break;
}
$good[] = Helpers::formatProduct($goods, false);
}
// 单个商品
if ($i === 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);
foreach ($product['data']['product_list'] as $i => $goods) {
$good['goods'][] = Helpers::formatProduct($goods, false);
}
$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) {
$value['url'] = '/guang/list/tag?query=' . $value['name'];
$data['relatedTag'][] = $value;
}
}
// 相关文章
if (!empty($detail['getOtherArticle'])) {
foreach ($detail['getOtherArticle'] as $value) {
$value['url'] = '/guang/detail/index?id=' . $value['id'];
$data['relatedInfo'][] = $value;
}
}
$this->_view->display('index', $data);
$detail = array();
$data = array();
}
}