Detail.php
6.98 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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
<?php
use Action\AbstractAction;
use Plugin\Helpers;
use LibModels\Wap\Product\DetailData;
/**
* 商品详情的控制器
*/
class DetailController extends AbstractAction
{
/**
* 商品详情
*
* @param int productId
* @param int goodsId
*/
public function indexAction()
{
$productId = $this->param('productId');
if (!is_numeric($productId)) {
$this->error();
}
$goodsId = $this->param('goodsId');
if (!is_numeric($goodsId)) {
$this->error();
}
$uid = $this->getUid();
$vipLevel = 0;
if (isset($this->_vip)) {
$vipLevel = Helpers::getVipLevel($this->_vip);
}
$data = \Product\DetailModel::getBaseInfo($productId, $goodsId, $uid, $vipLevel);
if (array() === $data) {
$this->error();
}
$data['goodsDetailPage'] = true;
$data['pageFooter'] = true;
if (isset($data['goodsName'])) {
$this->setTitle($data['goodsName']);
}
$this->setNavHeader('商品详情');
// 渲染模板
$this->_view->display('index', $data);
}
/**
* 商品详情 (SKN)
*
* @param int productSkn
*/
public function showAction()
{
$productSkn = $this->param('productSkn');
if (!is_numeric($productSkn)) {
$this->error();
}
$uid = $this->getUid();
$vipLevel = 0;
if (isset($this->_vip)) {
$vipLevel = Helpers::getVipLevel($this->_vip);
}
$data = \Product\DetailModel::getBaseInfo(null, null, $uid, $vipLevel, $productSkn);
if (array() === $data) {
$this->error();
}
$data['goodsDetailPage'] = true;
$data['pageFooter'] = true;
if (isset($data['goodsName'])) {
$this->setTitle($data['goodsName']);
}
$this->setNavHeader('商品详情');
// 渲染模板
$this->_view->display('index', $data);
}
/**
* 尺码描述信息
*/
public function introAction()
{
$productSkn = $this->param('productSkn');
if (!is_numeric($productSkn)) {
echo ' ';
}
$data = \Product\DetailModel::getSizeInfo($productSkn);
if (array() === $data) {
echo ' ';
exit();
}
$this->_view->display('intro', $data);
}
/**
* 购买评价列表
*
* @param int productId
* @param int total
*/
public function commentsAction()
{
$productId = $this->get('product_id', 0);
$total = $this->get('total');
if (!is_numeric($total)) {
$total = 0;
}
if ($total) {
$this->setNavHeader('购买评价(' . $total . ')');
} else {
$this->setNavHeader('购买评价');
}
$this->setTitle('购买评价');
$data = array(
'goodsCommentsPage' => true,
'pageFooter' => true,
'comments' => array(
'list' => \Product\DetailModel::getComments($productId),
),
);
// 渲染模板
$this->_view->display('comments', $data);
}
/**
* 购买咨询列表
*
* @param int productId
* @param int total
*/
public function consultsAction()
{
$productId = $this->get('product_id', 0);
$total = $this->get('total', 0);
if (!is_numeric($total)) {
$total = 0;
}
if ($total) {
$this->setNavHeader('购买咨询(' . $total . ')');
} else {
$this->setNavHeader('购买咨询');
}
$this->setTitle('购买咨询');
$uid = $this->getUid();
$consults = \Product\DetailModel::getConsults($uid, $productId);
$data = array(
'goodsConsultsPage' => true,
'pageFooter' => true,
'consults' => array(
'list' => $consults
),
'faq' => \Product\DetailModel::getCommonConsults(),
'showReadMore' => count($consults) > 2,
'link' => Helpers::url('/product/detail/consultform', array('product_id' => $productId)),
);
// 渲染模板
$this->_view->display('consults', $data);
}
/*
* 咨询点赞
*/
public function consultupvoteAction()
{
$result = array();
if ($this->isAjax()) {
$productId = $this->post('productId', 0);
$total = $this->post('total', 0);
$uid = $this->getUid();
$id = $this->post('id');
$result = \Product\DetailModel::upvoteConsult($uid, $id, $productId, $total);
}
$this->echoJson($result);
}
/*
* 咨询有用
*/
public function consultusefulAction()
{
$result = array();
if ($this->isAjax()) {
$productId = $this->post('productId', 0);
$total = $this->post('total', 0);
$uid = $this->getUid();
$id = $this->post('id');
$result = \Product\DetailModel::usefulConsult($uid, $id, $productId, $total);
}
$this->echoJson($result);
}
/**
* 我要咨询表单
*/
public function consultformAction()
{
$uid = $this->getUid();
if (!$uid) {
$this->go(Helpers::url('/signin.html', array('refer' => $this->server('HTTP_REFERER', '/'))));
}
$this->setTitle('我要咨询');
$this->setNavHeader('我要咨询');
$productId = $this->get('product_id', 0);
// 渲染模板
$this->_view->display('consultform', array(
'consultformPage' => true,
'productId' => $productId,
'formUrl' => Helpers::url('/product/detail/consultsubmit'),
));
}
/**
* 添加咨询操作
*
* @param int product_id 商品ID
* @param string content 咨询内容
* @return json
*/
public function consultsubmitAction()
{
$result = array('code' => 400, 'message' => '请输入咨询内容', 'data' => '');
if ($this->isAjax()) {
$uid = $this->getUid();
$productId = $this->post('product_id', 0);
$content = $this->post('content');
$result = DetailData::addConsult($uid, $productId, $content);
}
$this->echoJson($result);
}
/**
* 为你优选
*
* @param int productSkn 商品SKN号
* @return json
*/
public function preferenceAction()
{
$result = array();
if ($this->isAjax()) {
$productSkn = $this->get('productSkn');
$brandId = $this->get('brandId');
$channel = Helpers::getChannelByCookie();
$result = \Product\DetailModel::getPreference($productSkn, $channel, $brandId);
}
if (empty($result)) {
echo ' ';
} else {
$this->_view->display('preference', $result);
}
}
}