Authored by Rock Zhang

修复加价购商品详情的bug

Code Review By Rock Zhang
framework @ e9d066dd
1 -Subproject commit 75bbc3b075de19f239532f60c5995d06c5f814e2 1 +Subproject commit e9d066dd88a8e7e37103021c427a205a5cfcdcec
@@ -69,7 +69,7 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) { @@ -69,7 +69,7 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) {
69 i; 69 i;
70 70
71 var $siblingBlock = $this.closest('.block-list').siblings(':first'), 71 var $siblingBlock = $this.closest('.block-list').siblings(':first'),
72 - currentNumArray = $this.data('numstr').split('/'); 72 + currentNumArray = ($this.data('numstr') + '').split('/');
73 73
74 $this.siblings('.chosed').removeClass('chosed'); 74 $this.siblings('.chosed').removeClass('chosed');
75 $this.toggleClass('chosed'); 75 $this.toggleClass('chosed');
@@ -96,7 +96,7 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) { @@ -96,7 +96,7 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) {
96 } 96 }
97 }); 97 });
98 } else if ($chosed.length === 1 && $this.hasClass('chosed')) { 98 } else if ($chosed.length === 1 && $this.hasClass('chosed')) {
99 - numArray = $chosed.data('numstr').split('/'); 99 + numArray = ($chosed.data('numstr') + '').split('/');
100 $siblingBlock.find('.block').removeClass('zero-stock'); 100 $siblingBlock.find('.block').removeClass('zero-stock');
101 for (i = 0; i < numArray.length; i++) { 101 for (i = 0; i < numArray.length; i++) {
102 if (0 === numArray[i] - 0) { 102 if (0 === numArray[i] - 0) {
@@ -582,18 +582,14 @@ class CartModel @@ -582,18 +582,14 @@ class CartModel
582 { 582 {
583 $data = array(); 583 $data = array();
584 584
585 - // 品牌信息  
586 - if (isset($productData['brand_info']) && !empty($productData['brand_info'])) {  
587 - $data['thumb'] = Helpers::getImageUrl($productData['brand_info']['brand_ico'], 120, 120);  
588 - }  
589 -  
590 $data['name'] = $productData['product_name']; 585 $data['name'] = $productData['product_name'];
591 - $data['price'] = $productData['market_price'];  
592 - $data['salePrice'] = $productData['sales_price']; 586 + $data['price'] = Helpers::transPrice($productData['market_price']);
  587 + $data['salePrice'] = Helpers::transPrice($productData['sales_price']);
593 588
594 if (isset($productData['storage_sum'])) { 589 if (isset($productData['storage_sum'])) {
595 $data['storage'] = $productData['storage_sum']; 590 $data['storage'] = $productData['storage_sum'];
596 } 591 }
  592 + $data['num'] = 1;
597 if ($num !== null) { 593 if ($num !== null) {
598 $data['num'] = $num; 594 $data['num'] = $num;
599 } 595 }
@@ -606,25 +602,62 @@ class CartModel @@ -606,25 +602,62 @@ class CartModel
606 $oneColor = array(); 602 $oneColor = array();
607 $sizes = array(); 603 $sizes = array();
608 $oneSize = array(); 604 $oneSize = array();
  605 + $thumbImageList = array();
  606 + $colorNum = 0;
  607 + $totalStorageNum = 0; // 总库存数
  608 + $colorStorageGroup = array(); // 颜色分组的库存总数集合, 多个之间用/分隔
609 foreach ($goodsList as $val) { 609 foreach ($goodsList as $val) {
610 - // 颜色  
611 - $oneColor = array();  
612 - $oneColor['id'] = $val['color_id'];  
613 - $oneColor['name'] = $val['color_name']; 610 + $colorNum = 0;
  611 + $sizeStorageStr = '';
614 612
615 // 尺码 613 // 尺码
616 foreach ($val['size_list'] as $one) { 614 foreach ($val['size_list'] as $one) {
617 $oneSize = array(); 615 $oneSize = array();
618 $oneSize['id'] = $one['size_id']; 616 $oneSize['id'] = $one['size_id'];
  617 + $oneSize['skuId'] = $one['product_sku'];
  618 + $oneSize['goodsId'] = $val['goods_id'];
  619 + $oneSize['colorId'] = $val['color_id'];
619 $oneSize['name'] = $one['size_name']; 620 $oneSize['name'] = $one['size_name'];
  621 + $oneSize['sizeNum'] = $one['storage_number'];
  622 +
  623 + $colorNum += $one['storage_number'];
  624 + $sizeStorageStr .= $one['storage_number'] . '/';
  625 +
  626 + $sizes[] = $oneSize;
  627 +
  628 + $colorStorageGroup[$one['size_name']][$val['color_name']] = $one['storage_number'];
620 } 629 }
621 - $sizes[] = $oneSize;  
622 630
623 - $oneColor['sizes'] = $sizes; 631 + // 统计尺码对应的各个颜色的库存量
  632 + foreach ($sizes as &$sizeArr) {
  633 + $sizeArr['colorNumStr'] = implode('/', array_values($colorStorageGroup[ $sizeArr['name'] ]) );
  634 + }
  635 +
  636 + // 颜色
  637 + $oneColor = array();
  638 + $oneColor['id'] = $val['color_id'];
  639 + $oneColor['skcId'] = $val['product_skc'];
  640 + $oneColor['name'] = $val['color_name'];
  641 + $oneColor['goodsName'] = $productData['product_name'];
  642 + $oneColor['colorNum'] = $colorNum;
  643 + $oneColor['sizeNumStr'] = rtrim($sizeStorageStr, '/');
624 $colors[] = $oneColor; 644 $colors[] = $oneColor;
  645 +
  646 + // 缩略图
  647 + foreach ($val['images_list'] as $image) {
  648 + $thumbImageList[] = array(
  649 + 'img' => Helpers::getImageUrl($image['image_url'], 60, 60)
  650 + );
  651 + }
  652 +
  653 + // 商品库存总数
  654 + $totalStorageNum += $colorNum;
625 } 655 }
626 656
  657 + $data['thumbs'] = $thumbImageList;
627 $data['colors'] = $colors; 658 $data['colors'] = $colors;
  659 + $data['sizes'] = $sizes;
  660 + $data['totalNum'] = $totalStorageNum;
628 } 661 }
629 662
630 return $data; 663 return $data;
@@ -668,7 +701,7 @@ class CartModel @@ -668,7 +701,7 @@ class CartModel
668 // 失效商品列表 701 // 失效商品列表
669 $notValidGoods = Helpers::formatCartGoods($data['sold_out_goods_list']); 702 $notValidGoods = Helpers::formatCartGoods($data['sold_out_goods_list']);
670 if (!empty($notValidGoods)) { 703 if (!empty($notValidGoods)) {
671 - $result['$notValidGoods'] = $notValidGoods; 704 + $result['notValidGoods'] = $notValidGoods;
672 } 705 }
673 706
674 // 赠品和加价购商品 707 // 赠品和加价购商品
@@ -207,11 +207,11 @@ class IndexController extends AbstractAction @@ -207,11 +207,11 @@ class IndexController extends AbstractAction
207 { 207 {
208 $result = array(); 208 $result = array();
209 209
210 - if ($this->isAjax()) { 210 +// if ($this->isAjax()) {
211 $skn = $this->get('skn', null); 211 $skn = $this->get('skn', null);
212 $promotionId = $this->get('promotionId', null); 212 $promotionId = $this->get('promotionId', null);
213 $result = CartModel::giftProductData($skn, $promotionId); 213 $result = CartModel::giftProductData($skn, $promotionId);
214 - } 214 +// }
215 215
216 if (empty($result)) { 216 if (empty($result)) {
217 echo ' '; 217 echo ' ';