Authored by Rock Zhang

添加赠品和加价购页面

Code Review By Rock Zhang
@@ -560,10 +560,9 @@ class Helpers @@ -560,10 +560,9 @@ class Helpers
560 * 格式化购物车商品 560 * 格式化购物车商品
561 * 561 *
562 * @param array $cartGoods 购物车商品列表 562 * @param array $cartGoods 购物车商品列表
563 - * @param bool $haveLink 控制是否需要商品链接  
564 * @return array 处理之后的购物车商品数据 563 * @return array 处理之后的购物车商品数据
565 */ 564 */
566 - public static function formatCartGoods($cartGoods, $haveLink = false) 565 + public static function formatCartGoods($cartGoods)
567 { 566 {
568 $arr = array(); 567 $arr = array();
569 568
@@ -580,19 +579,19 @@ class Helpers @@ -580,19 +579,19 @@ class Helpers
580 $oneGoods['lowStocks'] = ($value['buy_number'] < $value['storage_number']); 579 $oneGoods['lowStocks'] = ($value['buy_number'] < $value['storage_number']);
581 //gift=>是否赠品,advanceBuy=>是否加价购,soldOut=>失效商品; 580 //gift=>是否赠品,advanceBuy=>是否加价购,soldOut=>失效商品;
582 if (!isset($value['goods_type'])) { 581 if (!isset($value['goods_type'])) {
583 - $oneGoods['soldOut'] = true; 582 + $oneGoods['isSoldOut'] = true;
584 } elseif ($value['goods_type'] == 'gift') { 583 } elseif ($value['goods_type'] == 'gift') {
585 - $oneGoods['gift'] = true; 584 + $oneGoods['isGift'] = true;
586 } elseif ($value['goods_type'] == 'price_gift') { 585 } elseif ($value['goods_type'] == 'price_gift') {
587 - $oneGoods['advanceBuy'] = true; 586 + $oneGoods['isAdvanceBuy'] = true;
588 } 587 }
589 // 上市期 588 // 上市期
590 if (!empty($value['expect_arrival_time'])) { 589 if (!empty($value['expect_arrival_time'])) {
591 $oneGoods['appearDate'] = $value['expect_arrival_time']; 590 $oneGoods['appearDate'] = $value['expect_arrival_time'];
592 } 591 }
593 // 商品链接 592 // 商品链接
594 - if ($haveLink && isset($value['product_id'])) {  
595 - $oneGoods['link'] = self::url('/product/pro_' . $value['product_id'] . '_' . $value['goods_id'] . '/' . $value['cn_alphabet'] . '.html'); 593 + if (isset($value['cn_alphabet']) ) {
  594 + $oneGoods['url'] = self::url('/product/pro_' . $value['product_id'] . '_' . $value['goods_id'] . '/' . $value['cn_alphabet'] . '.html');
596 } 595 }
597 596
598 $arr[$key] = $oneGoods; 597 $arr[$key] = $oneGoods;
@@ -29,6 +29,7 @@ class ShoppingCartController extends AbstractAction @@ -29,6 +29,7 @@ class ShoppingCartController extends AbstractAction
29 // 渲染模板 29 // 渲染模板
30 $this->_view->display('index', $data); 30 $this->_view->display('index', $data);
31 } 31 }
  32 +
32 /* 33 /*
33 * 异步获取购物车数据 34 * 异步获取购物车数据
34 */ 35 */
@@ -135,6 +136,47 @@ class ShoppingCartController extends AbstractAction @@ -135,6 +136,47 @@ class ShoppingCartController extends AbstractAction
135 } 136 }
136 137
137 /* 138 /*
  139 + * 赠品页面
  140 + */
  141 + public function giftAction()
  142 + {
  143 + $this->setTitle('赠品');
  144 + $this->setNavHeader('赠品');
  145 +
  146 + $shoppingKey = Helpers::getShoppingKeyByCookie();
  147 + $uid = $this->getUid(true);
  148 +
  149 + $data = array(
  150 + 'shoppingCartPage' => true,
  151 + 'shoppingCart' => CartModel::getCartData($uid, $shoppingKey, true)
  152 + );
  153 +
  154 + // 渲染模板
  155 + $this->_view->display('gift-advance-good', $data);
  156 + }
  157 +
  158 + /*
  159 + * 加价购页面
  160 + */
  161 + public function advanceBuyAction()
  162 + {
  163 + $this->setTitle('加价购');
  164 + $this->setNavHeader('加价购');
  165 +
  166 + $shoppingKey = Helpers::getShoppingKeyByCookie();
  167 + $uid = $this->getUid(true);
  168 +
  169 + $data = array(
  170 + 'shoppingCartPage' => true,
  171 + 'shoppingCart' => CartModel::getCartData($uid, $shoppingKey, false, true)
  172 + );
  173 + print_r($data);
  174 +
  175 + // 渲染模板
  176 + $this->_view->display('gift-advance-good', $data);
  177 + }
  178 +
  179 + /*
138 * 获取购物车加价购商品数据 180 * 获取购物车加价购商品数据
139 */ 181 */
140 public function giftinfoAction() 182 public function giftinfoAction()
@@ -43,9 +43,11 @@ class CartModel @@ -43,9 +43,11 @@ class CartModel
43 /** 43 /**
44 * @param integer $uid 用户ID 44 * @param integer $uid 用户ID
45 * @param string $shoppingKey 未登录用户唯一识别码 45 * @param string $shoppingKey 未登录用户唯一识别码
  46 + * @param bool $onlyGift 只获取赠品的商品数据
  47 + * @param bool $onlyAdvanceBuy 只获取加价购的商品数据
46 * @return array|mixed 处理之后的购物车数据 48 * @return array|mixed 处理之后的购物车数据
47 */ 49 */
48 - public static function getCartData($uid, $shoppingKey) 50 + public static function getCartData($uid, $shoppingKey, $onlyGift = false, $onlyAdvanceBuy = false)
49 { 51 {
50 $result = array('cartNav' => true); 52 $result = array('cartNav' => true);
51 53
@@ -64,13 +66,13 @@ class CartModel @@ -64,13 +66,13 @@ class CartModel
64 /* 普通购物车 */ 66 /* 普通购物车 */
65 if(isset($cart['ordinary_cart_data'])) { 67 if(isset($cart['ordinary_cart_data'])) {
66 $result['commonGoodsCount'] = $cart['ordinary_cart_data']['shopping_cart_data']['goods_count']; 68 $result['commonGoodsCount'] = $cart['ordinary_cart_data']['shopping_cart_data']['goods_count'];
67 - $result['commonCart'] = self::procCartData($cart['ordinary_cart_data']); 69 + $result['commonCart'] = self::procCartData($cart['ordinary_cart_data'], $onlyGift, $onlyAdvanceBuy);
68 } 70 }
69 71
70 /* 预售购物车 */ 72 /* 预售购物车 */
71 if(isset($cart['advance_cart_data'])) { 73 if(isset($cart['advance_cart_data'])) {
72 $result['presellGoodsCount'] = $cart['advance_cart_data']['shopping_cart_data']['goods_count']; 74 $result['presellGoodsCount'] = $cart['advance_cart_data']['shopping_cart_data']['goods_count'];
73 - $result['preSellCart'] = self::procCartData($cart['advance_cart_data']); 75 + $result['preSellCart'] = self::procCartData($cart['advance_cart_data'], $onlyGift, $onlyAdvanceBuy);
74 } 76 }
75 77
76 } 78 }
@@ -601,12 +603,27 @@ class CartModel @@ -601,12 +603,27 @@ class CartModel
601 * 处理不同类型的购物车数据 603 * 处理不同类型的购物车数据
602 * 604 *
603 * @param array $data 不同类型购物车数据 605 * @param array $data 不同类型购物车数据
  606 + * @param bool $onlyGift 只获取赠品的商品数据
  607 + * @param bool $onlyAdvanceBuy 只获取加价购的商品数据
604 * @return array $result 处理之后的不同类型购物车数据 608 * @return array $result 处理之后的不同类型购物车数据
605 */ 609 */
606 - private static function procCartData($data) 610 + private static function procCartData($data, $onlyGift = false, $onlyAdvanceBuy = false)
607 { 611 {
608 $result = array(); 612 $result = array();
609 613
  614 + if (!$onlyAdvanceBuy) {
  615 + // 赠品
  616 + $result['giftCount'] = 0;
  617 + $result['freebie'] = Helpers::formatAdvanceGoods($data['gift_list'], $result['giftCount']);
  618 + }
  619 +
  620 + if (!$onlyGift) {
  621 + // 加价购
  622 + $result['advanceBuyCount'] = 0;
  623 + $result['advanceBuy'] = Helpers::formatAdvanceGoods($data['price_gift'], $result['advanceBuyCount']);
  624 + }
  625 +
  626 + if (!$onlyGift && !$onlyAdvanceBuy) {
610 // 购买的可用商品列表 627 // 购买的可用商品列表
611 $validGoods = Helpers::formatCartGoods($data['goods_list']); 628 $validGoods = Helpers::formatCartGoods($data['goods_list']);
612 !empty($validGoods) && $result['goods'] = $validGoods; 629 !empty($validGoods) && $result['goods'] = $validGoods;
@@ -615,17 +632,15 @@ class CartModel @@ -615,17 +632,15 @@ class CartModel
615 $notValidGoods = Helpers::formatCartGoods($data['sold_out_goods_list']); 632 $notValidGoods = Helpers::formatCartGoods($data['sold_out_goods_list']);
616 !empty($notValidGoods) && $result['$notValidGoods'] = $notValidGoods; 633 !empty($notValidGoods) && $result['$notValidGoods'] = $notValidGoods;
617 634
618 - // 赠 635 + // 赠品和加价购商
619 (count($data['gift_list']) || count($data['price_gift'])) && $result['freebieOrAdvanceBuy'] = true; 636 (count($data['gift_list']) || count($data['price_gift'])) && $result['freebieOrAdvanceBuy'] = true;
620 - $result['freebie'] = $data['gift_list'];  
621 - // 加价购  
622 - $result['advanceBuyCount'] = 0;  
623 - $result['advanceBuy'] = Helpers::formatAdvanceGoods($data['price_gift'], $result['advanceBuyCount']); 637 +
624 // 结算数据 638 // 结算数据
625 $result['price'] = Helpers::transPrice($data['shopping_cart_data']['order_amount']); 639 $result['price'] = Helpers::transPrice($data['shopping_cart_data']['order_amount']);
626 $result['activityPrice'] = Helpers::transPrice($data['shopping_cart_data']['discount_amount']); 640 $result['activityPrice'] = Helpers::transPrice($data['shopping_cart_data']['discount_amount']);
627 $result['count'] = $data['shopping_cart_data']['goods_count']; 641 $result['count'] = $data['shopping_cart_data']['goods_count'];
628 $result['sumPrice'] = Helpers::transPrice($data['shopping_cart_data']['order_amount']); 642 $result['sumPrice'] = Helpers::transPrice($data['shopping_cart_data']['order_amount']);
  643 + }
629 644
630 return $result; 645 return $result;
631 } 646 }