Authored by Lynnic

code reviewed by liangzhifeng

1 <?php 1 <?php
2 2
3 use Action\AbstractAction; 3 use Action\AbstractAction;
  4 +use Plugin\Helpers;
  5 +use LibModels\Wap\Product\DetailData;
4 6
5 /** 7 /**
6 * 商品详情的控制器 8 * 商品详情的控制器
@@ -16,510 +18,185 @@ class DetailController extends AbstractAction @@ -16,510 +18,185 @@ class DetailController extends AbstractAction
16 */ 18 */
17 public function indexAction() 19 public function indexAction()
18 { 20 {
19 - $productId = $this->param('productId', 123);  
20 - $goodsId = $this->param('goodsId', 3241); 21 + $productId = $this->param('productId');
  22 + if (!is_numeric($productId)) {
  23 + $this->error();
  24 + }
  25 + $goodsId = $this->param('goodsId');
  26 + if (!is_numeric($goodsId)) {
  27 + $this->error();
  28 + }
21 $uid = $this->getUid(); 29 $uid = $this->getUid();
22 30
  31 + $vipLevel = 0;
  32 + if (isset($this->_vip)) {
  33 + $vipLevel = Helpers::getVipLevel($this->_vip);
  34 + }
23 35
  36 + $data = \Product\DetailModel::getBaseInfo($productId, $goodsId, $uid, $vipLevel);
  37 + if (array() === $data) {
  38 + $this->error();
  39 + }
  40 + $data['goodsDetailPage'] = true;
  41 + $data['pageFooter'] = true;
24 42
25 - // $data = \Product\DetailModel::getBaseInfo($productId, $goodsId, $uid);  
26 - // $data['goodsDetailPage'] = true;  
27 -  
28 - // if (isset($data['goodsName'])) {  
29 - // $this->setTitle($data['goodsName']);  
30 - // }  
31 - // $this->setNavHeader('商品详情');  
32 -  
33 - $data = array (  
34 - 'goodsDetailPage' => true,  
35 - 'pageHeader' => array (  
36 - 'navBack' => 'sss ',  
37 - 'navHome' => 'sss ',  
38 - 'navTitle' => '商品详情TEST'  
39 - ),  
40 - 'pageFooter' => true,  
41 - 'bannerTop' => array (  
42 - 'list' => array (  
43 - array (  
44 - 'url' => '',  
45 - 'img' => 'http://img13.static.yhbimg.com/goodsimg/2015/10/18/03/0250c3935f86dbd2baa7d45603d19fd637.jpg?imageMogr2/thumbnail/450x600/extent/450x600/background/d2hpdGU=/position/center/quality/90'  
46 - ),  
47 - array (  
48 - 'url' => '',  
49 - 'img' => 'http://img11.static.yhbimg.com/goodsimg/2015/10/12/03/01bf4cf4444035a1930d33a9d0f8bff4fa.jpg?imageMogr2/thumbnail/450x600/extent/450x600/background/d2hpdGU=/position/center/quality/90'  
50 - ),  
51 - array (  
52 - 'url' => '',  
53 - 'img' => 'http://img11.static.yhbimg.com/goodsimg/2015/10/12/03/01d7ef2f624eeea15e80bb374607aea317.jpg?imageMogr2/thumbnail/450x600/extent/450x600/background/d2hpdGU=/position/center/quality/90'  
54 - )  
55 - )  
56 - ),  
57 - 'goodsName' => 'Stussy No. 4 BOX TEE DC SPAR HIGH WC  
58 -SHOE BQT KEN BLOCK',  
59 - 'goodsSubtitle'=>'【全民拼抢购】经典印花T恤,满4件免一件!全场低至  
60 -9.9元,拼购时代High起来。【全民拼抢购】经典印花T恤,满4件免一件!全场低至  
61 -9.9元,拼购时代High起来。',  
62 -  
63 - 'goodsPrice' =>array(  
64 - 'currentPrice'=>'¥298.00',  
65 - 'previousPrice'=>'¥598.00'  
66 - ),  
67 - 'periodOfMarket'=>'11月',  
68 - 'goodsTitle' => '¥298.00',  
69 - 'vipLevel' => array (  
70 - 'list' => array (  
71 - array (  
72 - 'img'=>'http://static.dev.yohobuy.com/img/product/silver.png',  
73 - 'text' => '¥284.00'  
74 - ),  
75 - array (  
76 - 'img'=>'http://static.dev.yohobuy.com/img/product/golden.png',  
77 - 'text' => '¥269.00'  
78 - ),  
79 - array (  
80 - 'img'=>'http://static.dev.yohobuy.com/img/product/platinum.png',  
81 - 'text' => '¥263.00'  
82 - )  
83 - )  
84 - ),  
85 - 'goodsDiscount'=>array(  
86 - 'list'=>array(  
87 - array(  
88 - 'text' =>' 【summer final sale】满¥499立享6.8折'  
89 - ),  
90 - array(  
91 - 'text' =>' 【BACK TO SCHOOL】满¥499赠送Paul  
92 - Franke帽子一个,多买多送!'  
93 - ),  
94 - array(  
95 - 'text' =>' 【BACK TO SCHOOL】满¥499赠送Paul  
96 - Franke帽子一个,多买多送!'  
97 - )  
98 - )  
99 - ),  
100 - 'feedbacks'=>array(  
101 - 'commentsNum'=>0,  
102 - 'consultsNum'=>1,  
103 - // 'commentName'=>'商品评价',  
104 - // 'consultName' =>'购买咨询',  
105 - 'link'=>'',  
106 - 'comments'=>array(  
107 - array(  
108 - 'userName'=>'Lynnic',  
109 - 'desc'=>'购买了白色Mate7',  
110 - 'content'=>'活动时买的,挺超值。上身效果也不错。质量  
111 -很好,买送人的,很满意。而且物流相当给...',  
112 - 'time'=>'2014-08-12 10:24:26'  
113 - )  
114 - ),  
115 - 'consults'=>array(  
116 - array(  
117 - 'question' =>'您好 我一米七七 140斤 穿M的行吗',  
118 - 'time'=>'2014-08-12 10:24:26',  
119 - 'answer'=>'您好,建议您参考XL的款式,由于版型和个人穿衣风格不同,需要'  
120 - )  
121 - )  
122 - ),  
123 -  
124 - 'enterStore'=>array(  
125 - 'img'=>'http://static.dev.yohobuy.com/img/product/store.png',  
126 - 'storeName'=>'Stussy',  
127 - 'url'=>'http://stussy.m.yohobuy.com/'  
128 - ),  
129 -  
130 - 'goodsDescription'=>array(  
131 - 'title' =>'商品描述',  
132 - 'enTitle'=>'DESCRIPTON',  
133 -  
134 - 'detail'=>array(  
135 - 'list' =>array(  
136 - array(  
137 - 'param'=>'编号:100101'  
138 - ),  
139 - array(  
140 - 'param'=>'编号:100101'  
141 - ),  
142 - array(  
143 - 'param'=>'编号:100101'  
144 - )  
145 - )  
146 - ),  
147 -  
148 - 'desc'=>'fafdfafsafsafffffloremadfaffasfsfas 我fsadfasfasfsfdafasfffdasfasffa'  
149 - ),  
150 -  
151 - 'sizeInfo'=>array(  
152 - 'title' => '尺码信息',  
153 - 'enTitle' =>'xSIZE INFO',  
154 -  
155 - 'detail' =>array(  
156 - 'list'=>array(  
157 - array(  
158 - 'params'=>array(  
159 - array(  
160 - 'param' =>'M'  
161 - ),  
162 - array(  
163 - 'param' =>'XL'  
164 - ),  
165 - array(  
166 - 'param' =>'XXL'  
167 - )  
168 - )  
169 - ),  
170 - array(  
171 - 'params'=>array(  
172 - array(  
173 - 'param' =>'43'  
174 - ),  
175 - array(  
176 - 'param' =>'46'  
177 - ),  
178 - array(  
179 - 'param' =>'XXL'  
180 - )  
181 - )  
182 - ),  
183 - array(  
184 - 'params'=>array(  
185 - array(  
186 - 'param' =>'102'  
187 - ),  
188 - array(  
189 - 'param' =>'107'  
190 - ),  
191 - array(  
192 - 'param' =>'XXL'  
193 - )  
194 - )  
195 - ),  
196 - array(  
197 - 'params'=>array(  
198 - array(  
199 - 'param' =>'11'  
200 - ),  
201 - array(  
202 - 'param' =>'22'  
203 - ),  
204 - array(  
205 - 'param' =>'XXL'  
206 - )  
207 - )  
208 - ),  
209 - array(  
210 - 'params'=>array(  
211 - array(  
212 - 'param' =>'bb'  
213 - ),  
214 - array(  
215 - 'param' =>'cc'  
216 - ),  
217 - array(  
218 - 'param' =>'XXL'  
219 - )  
220 - )  
221 - ),  
222 - array(  
223 - 'params'=>array(  
224 - array(  
225 - 'param' =>'kk'  
226 - ),  
227 - array(  
228 - 'param' =>'bb'  
229 - ),  
230 - array(  
231 - 'param' =>'XXL'  
232 - )  
233 - )  
234 - )  
235 - )  
236 - )  
237 - ),  
238 -  
239 - 'measurementMethod'=>array(  
240 - 'title' => '测量方式',  
241 - 'enTitle' =>'MEASUREMENT METHOD',  
242 - 'img'=>'http://static.yohobuy.com/images/1.jpg'  
243 - ),  
244 -  
245 - 'reference' => array(  
246 - 'title' => '模特试穿',  
247 - 'enTitle' =>'REFERENCE',  
248 -  
249 - 'detail' =>array(  
250 - 'list'=>array(  
251 - array(  
252 - 'params'=>array(  
253 - array(  
254 - 'param' =>'M'  
255 - ),  
256 - array(  
257 - 'param' =>'http://static.dev.yohobuy.com/img/product/avatar1.png'  
258 - ),  
259 - array(  
260 - 'param' =>'http://static.dev.yohobuy.com/img/product/avatar2.png'  
261 - )  
262 - )  
263 - ),  
264 - array(  
265 - 'params'=>array(  
266 - array(  
267 - 'param' =>'模特'  
268 - ),  
269 - array(  
270 - 'param' =>'Oliver'  
271 - ),  
272 - array(  
273 - 'param' =>'http://static.dev.yohobuy.com/img/product/avatar2.png'  
274 - )  
275 - )  
276 - ),  
277 - array(  
278 - 'params'=>array(  
279 - array(  
280 - 'param' =>'102'  
281 - ),  
282 - array(  
283 - 'param' =>'107'  
284 - ),  
285 - array(  
286 - 'param' =>'XXL'  
287 - )  
288 - )  
289 - ),  
290 - array(  
291 - 'params'=>array(  
292 - array(  
293 - 'param' =>'11'  
294 - ),  
295 - array(  
296 - 'param' =>'22'  
297 - ),  
298 - array(  
299 - 'param' =>'XXL'  
300 - )  
301 - )  
302 - ),  
303 - array(  
304 - 'params'=>array(  
305 - array(  
306 - 'param' =>'bb'  
307 - ),  
308 - array(  
309 - 'param' =>'cc'  
310 - ),  
311 - array(  
312 - 'param' =>'XXL'  
313 - )  
314 - )  
315 - ),  
316 - array(  
317 - 'params'=>array(  
318 - array(  
319 - 'param' =>'kk'  
320 - ),  
321 - array(  
322 - 'param' =>'bb'  
323 - ),  
324 - array(  
325 - 'param' =>'XXL'  
326 - )  
327 - )  
328 - )  
329 - )  
330 - )  
331 - ),  
332 -  
333 - 'materials' => array(  
334 - 'title' => '商品材质',  
335 - 'enTitle' =>'MATERIALS',  
336 - 'list' => array(  
337 - array(  
338 - 'img' => 'http://static.dev.yohobuy.com/img/product/material.png',  
339 - 'desc' =>'用各种洗涤剂,可手洗机洗,但不宜氯漂,宜阴干,避免曝晒,以免深色衣物褪色,在日光下晾晒时,将里面朝外。浸泡时间不能太长,避免褪色,深色与浅色衣服最好请分开洗涤,避免染色。'  
340 - ),  
341 - array(  
342 - 'img' => 'http://static.dev.yohobuy.com/img/product/material.png',  
343 - 'desc' =>'用各种洗涤剂,可手洗机洗,但不宜氯漂,宜阴干,避免曝晒,以免深色衣物褪色,在日光下晾晒时,将里面朝外。浸泡时间不能太长,避免褪色,深色与浅色衣服最好请分开洗涤,避免染色。'  
344 - )  
345 -  
346 - )  
347 - ),  
348 -  
349 - 'washTips' => array(  
350 - 'list' => array(  
351 - array(  
352 - 'img' => 'http://static.dev.yohobuy.com/img/product/washtips/washtip-1.png',  
353 - 'caption'=>'不可干燥不可干洗'  
354 - ),  
355 - array(  
356 - 'img' => 'http://static.dev.yohobuy.com/img/product/washtips/washtip-1.png',  
357 - 'caption'=>'不可干燥不可干洗'  
358 - ),  
359 - array(  
360 - 'img' => 'http://static.dev.yohobuy.com/img/product/washtips/washtip-1.png',  
361 - 'caption'=>'不可干燥不可干洗'  
362 - ),  
363 - array(  
364 - 'img' => 'http://static.dev.yohobuy.com/img/product/washtips/washtip-1.png',  
365 - 'caption'=>'不可干燥不可干洗'  
366 - ),  
367 - array(  
368 - 'img' => 'http://static.dev.yohobuy.com/img/product/washtips/washtip-1.png',  
369 - 'caption'=>'不可干燥不可干洗'  
370 - ),  
371 - array(  
372 - 'img' => 'http://static.dev.yohobuy.com/img/product/washtips/washtip-1.png',  
373 - 'caption'=>'不可干燥不可干洗'  
374 - )  
375 - )  
376 - ),  
377 -  
378 - 'productDetail' =>array(  
379 - 'title' => '商品详情',  
380 - 'enTitle' =>'DETAILS',  
381 - 'desc' => 'Married to the MOB是由Leah McSweeney创立的女装品牌,一向标榜不羁、大胆的女性streetwear设计。喜欢恶搞的女生们,赶紧入手吧。',  
382 - 'list' => array (  
383 - array('img' =>'http://static.dev.yohobuy.com/img/product/product.png'),  
384 - array('img' =>'http://static.dev.yohobuy.com/img/product/product.png')  
385 - )  
386 - ),  
387 -  
388 - 'cartInfo' =>array(  
389 - 'numInCart' => 3,  
390 - 'notForSale'=>1  
391 - ) 43 + if (isset($data['goodsName'])) {
  44 + $this->setTitle($data['goodsName']);
  45 + }
  46 + $this->setNavHeader('商品详情');
392 47
393 - );  
394 // 渲染模板 48 // 渲染模板
395 $this->_view->display('index', $data); 49 $this->_view->display('index', $data);
396 } 50 }
397 51
  52 + /**
  53 + * 尺码描述信息
  54 + */
  55 + public function introAction()
  56 + {
  57 + $productSkn = $this->param('productSkn');
  58 + if (!is_numeric($productSkn)) {
  59 + $this->error();
  60 + }
  61 + $data = \Product\DetailModel::getSizeInfo($productSkn);
  62 + if (array() === $data) {
  63 + echo ' ';
  64 + exit();
  65 + }
  66 + $this->_view->display('intro', $data);
  67 + }
  68 +
  69 + /**
  70 + * 购买评价列表
  71 + *
  72 + * @param int productId
  73 + * @param int total
  74 + */
398 public function commentsAction() 75 public function commentsAction()
399 { 76 {
  77 + $productId = $this->get('product_id', 0);
  78 + $total = $this->get('total');
  79 + if (!is_numeric($total)) {
  80 + $total = 0;
  81 + }
  82 + if ($total) {
  83 + $this->setNavHeader('购买评价(' . $total . ')');
  84 + } else {
  85 + $this->setNavHeader('购买评价');
  86 + }
  87 + $this->setTitle('购买评价');
  88 +
400 $data = array( 89 $data = array(
401 'goodsCommentsPage' => true, 90 'goodsCommentsPage' => true,
402 - 'pageHeader' => array(  
403 - 'navBack' => 'sss ',  
404 - // 'navHome' => 'sss ',  
405 - 'navTitle' => '购买评价(6)'  
406 - ),  
407 'pageFooter' => true, 91 'pageFooter' => true,
408 'comments' => array( 92 'comments' => array(
409 - 'list' => array(  
410 - array(  
411 - 'userName' => 'Lynnic',  
412 - 'desc' => '购买了白色Mate7',  
413 - 'content' => '活动时买的,挺超值。上身效果也不错。质量  
414 - 很好,买送人的,很满意。而且物流相当给...',  
415 - 'time' => '2014-08-12 10:24:26'  
416 - ),  
417 - array(  
418 - 'userName' => 'Lynnic',  
419 - 'desc' => '购买了白色Mate7',  
420 - 'content' => '活动时买的,挺超值。上身效果也不错。质量  
421 - 很好,买送人的,很满意。而且物流相当给...',  
422 - 'time' => '2014-08-12 10:24:26'  
423 - ),  
424 - array(  
425 - 'userName' => 'Lynnic',  
426 - 'desc' => '购买了白色Mate7',  
427 - 'content' => '活动时买的,挺超值。上身效果也不错。质量  
428 - 很好,买送人的,很满意。而且物流相当给...',  
429 - 'time' => '2014-08-12 10:24:26'  
430 - )  
431 - ) 93 + 'list' => \Product\DetailModel::getConsults($productId),
432 ), 94 ),
433 ); 95 );
434 96
435 - $this->_view->assign('title', '购买评价');  
436 - //$this->_view->display('brand', compact('brands'));  
437 // 渲染模板 97 // 渲染模板
438 $this->_view->display('comments', $data); 98 $this->_view->display('comments', $data);
439 } 99 }
440 100
  101 + /**
  102 + * 购买咨询列表
  103 + *
  104 + * @param int productId
  105 + * @param int total
  106 + */
441 public function consultsAction() 107 public function consultsAction()
442 { 108 {
  109 + $productId = $this->get('product_id', 0);
  110 + $total = $this->get('total', 0);
  111 + if (!is_numeric($total)) {
  112 + $total = 0;
  113 + }
  114 + if ($total) {
  115 + $this->setNavHeader('购买咨询(' . $total . ')');
  116 + } else {
  117 + $this->setNavHeader('购买咨询');
  118 + }
  119 + $this->setTitle('购买咨询');
  120 +
443 $data = array( 121 $data = array(
444 'goodsConsultsPage' => true, 122 'goodsConsultsPage' => true,
445 - 'pageHeader' => array(  
446 - 'navBack' => 'sss ',  
447 - // 'navHome' => 'sss ',  
448 - 'navTitle' => '购买咨询(6)'  
449 - ),  
450 'pageFooter' => true, 123 'pageFooter' => true,
451 'consults' => array( 124 'consults' => array(
452 - 'list' => array(  
453 - array(  
454 - 'question' => '您好 我一米七七 140斤 穿M的行吗',  
455 - 'time' => '2014-08-12 10:24:26',  
456 - 'answer' => '您好,建议您参考XL的款式,由于版型和个人穿衣风格不同,需要'  
457 - ),  
458 - array(  
459 - 'question' => '您好 我一米七七 140斤 穿M的行吗',  
460 - 'time' => '2014-08-12 10:24:26',  
461 - 'answer' => '您好,建议您参考XL的款式,由于版型和个人穿衣风格不同,需要'  
462 - ),  
463 - array(  
464 - 'question' => '您好 我一米七七 140斤 穿M的行吗',  
465 - 'time' => '2014-08-12 10:24:26',  
466 - 'answer' => '您好,建议您参考XL的款式,由于版型和个人穿衣风格不同,需要'  
467 - ),  
468 - array(  
469 - 'question' => '您好 我一米七七 140斤 穿M的行吗',  
470 - 'time' => '2014-08-12 10:24:26',  
471 - 'answer' => '您好,建议您参考XL的款式,由于版型和个人穿衣风格不同,需要'  
472 - ),  
473 - array(  
474 - 'question' => '您好 我一米七七 140斤 穿M的行吗',  
475 - 'time' => '2014-08-12 10:24:26',  
476 - 'answer' => '您好,建议您参考XL的款式,由于版型和个人穿衣风格不同,需要'  
477 - ),  
478 - array(  
479 - 'question' => '您好 我一米七七 140斤 穿M的行吗',  
480 - 'time' => '2014-08-12 10:24:26',  
481 - 'answer' => '您好,建议您参考XL的款式,由于版型和个人穿衣风格不同,需要'  
482 - ),  
483 - array(  
484 - 'question' => '您好 我一米七七 140斤 穿M的行吗',  
485 - 'time' => '2014-08-12 10:24:26',  
486 - 'answer' => '您好,建议您参考XL的款式,由于版型和个人穿衣风格不同,需要'  
487 - ),  
488 - array(  
489 - 'question' => '您好 我一米七七 140斤 穿M的行吗',  
490 - 'time' => '2014-08-12 10:24:26',  
491 - 'answer' => '您好,建议您参考XL的款式,由于版型和个人穿衣风格不同,需要'  
492 - ),  
493 - array(  
494 - 'question' => '您好 我一米七七 140斤 穿M的行吗',  
495 - 'time' => '2014-08-12 10:24:26',  
496 - 'answer' => '您好,建议您参考XL的款式,由于版型和个人穿衣风格不同,需要'  
497 - )  
498 - ) 125 + 'list' => \Product\DetailModel::getConsults($productId),
499 ), 126 ),
  127 + 'link' => Helpers::url('/product/detail/consultform', array('product_id' => $productId)),
500 ); 128 );
501 129
502 - $this->_view->assign('title', '购买咨询');  
503 - //$this->_view->display('brand', compact('brands'));  
504 // 渲染模板 130 // 渲染模板
505 $this->_view->display('consults', $data); 131 $this->_view->display('consults', $data);
506 } 132 }
507 133
  134 + /**
  135 + * 我要咨询表单
  136 + */
508 public function consultformAction() 137 public function consultformAction()
509 { 138 {
510 - $data = array(  
511 - 'consultform' => true,  
512 - 'pageHeader' => array(  
513 - 'navBack' => 'sss ',  
514 - // 'navHome' => 'sss ',  
515 - 'navTitle' => '我要咨询'  
516 - )  
517 - ); 139 + $uid = $this->getUid();
  140 + if (!$uid) {
  141 + $this->go(Helpers::url('/signin.html', array('refer' => $this->server('HTTP_REFERER', '/'))));
  142 + }
  143 +
  144 + $this->setTitle('我要咨询');
  145 + $this->setNavHeader('我要咨询');
  146 +
  147 + $productId = $this->get('product_id', 0);
518 148
519 - $this->_view->assign('title', '我要咨询');  
520 - //$this->_view->display('brand', compact('brands'));  
521 // 渲染模板 149 // 渲染模板
522 - $this->_view->display('consultform', $data); 150 + $this->_view->display('consultform', array(
  151 + 'consultformPage' => true,
  152 + 'productId' => $productId,
  153 + 'formUrl' => Helpers::url('/product/detail/consultsubmit'),
  154 + ));
  155 + }
  156 +
  157 + /**
  158 + * 添加咨询操作
  159 + *
  160 + * @param int product_id 商品ID
  161 + * @param string content 咨询内容
  162 + * @return json
  163 + */
  164 + public function consultsubmitAction()
  165 + {
  166 + $result = array('code' => 400, 'message' => '请输入咨询内容', 'data' => '');
  167 +
  168 + if ($this->isAjax()) {
  169 + $uid = $this->getUid();
  170 + $productId = $this->post('product_id', 0);
  171 + $content = $this->post('content');
  172 + $result = DetailData::addConsult($uid, $productId, $content);
  173 + }
  174 +
  175 + $this->echoJson($result);
  176 + }
  177 +
  178 + /**
  179 + * 为你优选
  180 + *
  181 + * @param int productSkn 商品SKN号
  182 + * @return json
  183 + */
  184 + public function preferenceAction()
  185 + {
  186 + $result = array();
  187 +
  188 + if ($this->isAjax()) {
  189 + $productSkn = $this->get('productSkn');
  190 + $brandId = $this->get('brandId');
  191 + $channel = Helpers::getChannelByCookie();
  192 + $result = \Product\DetailModel::getPreference($productSkn, $channel, $brandId);
  193 + }
  194 +
  195 + if (empty($result)) {
  196 + echo ' ';
  197 + } else {
  198 + $this->_view->display('preference', $result);
  199 + }
523 } 200 }
524 201
525 } 202 }