添加格式化购物车商品,格式化加价购商品辅助函数,添加对商品的数据格式处理
Code Review By Rock Zhang
Showing
2 changed files
with
92 additions
and
18 deletions
@@ -556,6 +556,86 @@ class Helpers | @@ -556,6 +556,86 @@ class Helpers | ||
556 | } | 556 | } |
557 | 557 | ||
558 | /** | 558 | /** |
559 | + * 格式化购物车商品 | ||
560 | + * | ||
561 | + * @param array $cartGoods 购物车商品列表 | ||
562 | + * @param bool $haveLink 控制是否需要商品链接 | ||
563 | + */ | ||
564 | + public static function formatCartGoods($cartGoods, $haveLink = false) | ||
565 | + { | ||
566 | + $arr = array(); | ||
567 | + | ||
568 | + $oneGoods = array(); | ||
569 | + foreach ($cartGoods as $key => $value) { | ||
570 | + $oneGoods['id'] = $value['product_sku']; | ||
571 | + $oneGoods['skn'] = $value['product_skn']; | ||
572 | + $oneGoods['name'] = $value['product_name']; | ||
573 | + $oneGoods['thumb'] = !empty($value['goods_images']) ? Images::getImageUrl($value['goods_images'], 120, 120) : ''; | ||
574 | + $oneGoods['color'] = $value['color_name']; | ||
575 | + $oneGoods['size'] = $value['size_name']; | ||
576 | + $oneGoods['appearDate'] = '12月'; // 目前app接口没有返回该数据 | ||
577 | + $oneGoods['price'] = $value['real_price']; | ||
578 | + $oneGoods['count'] = $value['buy_number']; | ||
579 | + $oneGoods['lowStocks'] = ($value['buy_number'] < $value['storage_number']); | ||
580 | + //gift=>是否赠品,advanceBuy=>是否加价购,soldOut=>失效商品; | ||
581 | + if (!isset($value['goods_type'])) { | ||
582 | + $oneGoods['soldOut'] = true; | ||
583 | + } elseif ($value['goods_type'] == 'gift') { | ||
584 | + $oneGoods['gift'] = true; | ||
585 | + } elseif ($value['goods_type'] == 'price_gift') { | ||
586 | + $oneGoods['advanceBuy'] = true; | ||
587 | + } | ||
588 | + // 上市期 | ||
589 | + if (!empty($value['expect_arrival_time'])) { | ||
590 | + $oneGoods['appearDate'] = $value['expect_arrival_time']; | ||
591 | + } | ||
592 | + // 商品链接 | ||
593 | + if ($haveLink && isset($value['product_id'])) { | ||
594 | + $oneGoods['link'] = self::url('/product/pro_' . $value['product_id'] . '_' . $value['goods_id'] . '/' . $value['cn_alphabet'] . '.html'); | ||
595 | + } | ||
596 | + | ||
597 | + $arr[$key] = $oneGoods; | ||
598 | + } | ||
599 | + | ||
600 | + return $arr; | ||
601 | + } | ||
602 | + | ||
603 | + /** | ||
604 | + * 格式化加价购商品 | ||
605 | + * | ||
606 | + * @param array $advanceGoods 加价购商品列表 | ||
607 | + * @param bool $haveLink 控制是否需要商品链接 | ||
608 | + */ | ||
609 | + public static function formatAdvanceGoods($advanceGoods) | ||
610 | + { | ||
611 | + $arr = array(); | ||
612 | + | ||
613 | + | ||
614 | + $gift = array(); | ||
615 | + $oneGoods = array(); | ||
616 | + foreach ($advanceGoods as $value) { | ||
617 | + $gift = array(); | ||
618 | + $gift['promotionTitle'] = $value['promotion_title']; | ||
619 | + | ||
620 | + foreach ($value['goods_list'] as $single) { | ||
621 | + $oneGoods['id'] = $single['product_skn']; | ||
622 | + $oneGoods['name'] = $single['product_name']; | ||
623 | + $oneGoods['thumb'] = !empty($single['goods_images']) ? Images::getImageUrl($single['goods_images'], 120, 120) : ''; | ||
624 | + $oneGoods['appearDate'] = '12月'; // 目前app接口没有返回该数据 | ||
625 | + $oneGoods['price'] = $single['last_price']; | ||
626 | + $oneGoods['marketPrice'] = $single['market_price']; | ||
627 | + $oneGoods['count'] = $single['storage_number']; | ||
628 | + | ||
629 | + $gift['goods'][] = $oneGoods; | ||
630 | + } | ||
631 | + | ||
632 | + $arr[] = $gift; | ||
633 | + } | ||
634 | + | ||
635 | + return $arr; | ||
636 | + } | ||
637 | + | ||
638 | + /** | ||
559 | * 订单状态,按订单支付类型和订单状态 | 639 | * 订单状态,按订单支付类型和订单状态 |
560 | * @var array | 640 | * @var array |
561 | */ | 641 | */ |
@@ -63,13 +63,13 @@ class CartModel | @@ -63,13 +63,13 @@ class CartModel | ||
63 | 63 | ||
64 | /* 普通购物车 */ | 64 | /* 普通购物车 */ |
65 | if(isset($cart['ordinary_cart_data'])) { | 65 | if(isset($cart['ordinary_cart_data'])) { |
66 | - $result['commonGoodsCount'] = count($cart['ordinary_cart_data']['goods_list']); | 66 | + $result['commonGoodsCount'] = $cart['ordinary_cart_data']['shopping_cart_data']['goods_count']; |
67 | $result['commonCart'] = self::procCartData($cart['ordinary_cart_data']); | 67 | $result['commonCart'] = self::procCartData($cart['ordinary_cart_data']); |
68 | } | 68 | } |
69 | 69 | ||
70 | /* 预售购物车 */ | 70 | /* 预售购物车 */ |
71 | if(isset($cart['advance_cart_data'])) { | 71 | if(isset($cart['advance_cart_data'])) { |
72 | - $result['presellGoodsCount'] = count($cart['advance_cart_data']['goods_list']); | 72 | + $result['presellGoodsCount'] = $cart['advance_cart_data']['shopping_cart_data']['goods_count']; |
73 | $result['preSellCart'] = self::procCartData($cart['advance_cart_data']); | 73 | $result['preSellCart'] = self::procCartData($cart['advance_cart_data']); |
74 | } | 74 | } |
75 | 75 | ||
@@ -583,31 +583,25 @@ class CartModel | @@ -583,31 +583,25 @@ class CartModel | ||
583 | $result = array(); | 583 | $result = array(); |
584 | 584 | ||
585 | $oneGoods = array(); | 585 | $oneGoods = array(); |
586 | - // 购买的商品列表 | ||
587 | - foreach ($data['goods_list'] as $value) { | ||
588 | - $oneGoods['id'] = $value['product_sku']; | ||
589 | - $oneGoods['skn'] = $value['product_skn']; | ||
590 | - $oneGoods['name'] = $value['product_name']; | ||
591 | - $oneGoods['thumb'] = Images::getImageUrl($value['goods_images'], 120, 120); | ||
592 | - $oneGoods['color'] = $value['color_name']; | ||
593 | - $oneGoods['size'] = $value['size_name']; | ||
594 | - $oneGoods['appearDate'] = '12月'; // 目前app接口没有返回该数据 | ||
595 | - $oneGoods['price'] = $value['real_price']; | ||
596 | - $oneGoods['count'] = $value['buy_number']; | ||
597 | - $oneGoods['lowStocks'] = true; | ||
598 | - | ||
599 | - $result['goods'][] = $oneGoods; | ||
600 | - } | 586 | + // 购买的可用商品列表 |
587 | + $validGoods = Helpers::formatCartGoods($data['goods_list']); | ||
588 | + !empty($validGoods) && $result['goods'] = $validGoods; | ||
589 | + | ||
590 | + // 失效商品列表 | ||
591 | + $notValidGoods = Helpers::formatCartGoods($data['sold_out_goods_list']); | ||
592 | + !empty($notValidGoods) && $result['$notValidGoods'] = $notValidGoods; | ||
593 | + | ||
601 | // 赠品 | 594 | // 赠品 |
602 | (count($data['gift_list']) || count($data['price_gift'])) && $result['freebieOrAdvanceBuy'] = true; | 595 | (count($data['gift_list']) || count($data['price_gift'])) && $result['freebieOrAdvanceBuy'] = true; |
603 | $result['freebie'] = $data['gift_list']; | 596 | $result['freebie'] = $data['gift_list']; |
604 | // 加价购 | 597 | // 加价购 |
605 | - $result['advanceBuy'] = $data['price_gift']; | 598 | + $result['advanceBuy'] = Helpers::formatAdvanceGoods($data['price_gift']); |
606 | // 结算数据 | 599 | // 结算数据 |
607 | $result['price'] = $data['shopping_cart_data']['order_amount']; | 600 | $result['price'] = $data['shopping_cart_data']['order_amount']; |
608 | $result['activityPrice'] = $data['shopping_cart_data']['discount_amount']; | 601 | $result['activityPrice'] = $data['shopping_cart_data']['discount_amount']; |
609 | $result['count'] = $data['shopping_cart_data']['goods_count']; | 602 | $result['count'] = $data['shopping_cart_data']['goods_count']; |
610 | $result['sumPrice'] = $data['shopping_cart_data']['order_amount']; | 603 | $result['sumPrice'] = $data['shopping_cart_data']['order_amount']; |
604 | + print_r($result); | ||
611 | 605 | ||
612 | return $result; | 606 | return $result; |
613 | } | 607 | } |
-
Please register or login to post a comment