Authored by Rock Zhang

修复购物车结算页选择优惠券中优惠券是否可用的判定逻辑(通过php去过滤掉不可用的优惠券)

但那种免邮券还是不能用

Code Review By Rock Zhang
@@ -95,12 +95,13 @@ function orderCompute() { @@ -95,12 +95,13 @@ function orderCompute() {
95 } 95 }
96 if (res.discount_amount) { 96 if (res.discount_amount) {
97 res.discount_amount = (+res.discount_amount).toFixed(2); 97 res.discount_amount = (+res.discount_amount).toFixed(2);
98 - } 98 + }*/
99 if (res.last_order_amount) { 99 if (res.last_order_amount) {
100 res.last_order_amount = (+res.last_order_amount).toFixed(2); 100 res.last_order_amount = (+res.last_order_amount).toFixed(2);
101 - }*/ 101 + }
102 priceHtml = priceTmpl({ 102 priceHtml = priceTmpl({
103 - cartPayData: res.promotion_formula_list 103 + cartPayData: res.promotion_formula_list,
  104 + price: res.last_order_amount
104 }); 105 });
105 106
106 $price.html(priceHtml); 107 $price.html(priceHtml);
@@ -104,6 +104,9 @@ @@ -104,6 +104,9 @@
104   {{promotion_amount}} 104   {{promotion_amount}}
105 </li> 105 </li>
106 {{/cartPayData}} 106 {{/cartPayData}}
  107 + <li class="cost">
  108 + 应付金额: <em>¥{{price}}</em>
  109 + </li>
107 </ul> 110 </ul>
108 </section> 111 </section>
109 112
@@ -131,6 +134,9 @@ @@ -131,6 +134,9 @@
131 &nbsp;&nbsp;\{{promotion_amount}} 134 &nbsp;&nbsp;\{{promotion_amount}}
132 </li> 135 </li>
133 \{{/cartPayData}} 136 \{{/cartPayData}}
  137 + <li class="cost">
  138 + 应付金额: <em>¥\{{price}}</em>
  139 + </li>
134 </ul> 140 </ul>
135 </script> 141 </script>
136 {{> layout/footer}} 142 {{> layout/footer}}
@@ -451,6 +451,8 @@ class CartModel @@ -451,6 +451,8 @@ class CartModel
451 // 订单数据 451 // 订单数据
452 if (isset($payReturn['shopping_cart_data']) && !empty($payReturn['shopping_cart_data'])) { 452 if (isset($payReturn['shopping_cart_data']) && !empty($payReturn['shopping_cart_data'])) {
453 $result['cartPayData'] = isset($orderCompute['promotion_formula_list']) ? $orderCompute['promotion_formula_list'] : $payReturn['shopping_cart_data']['promotion_formula_list']; 453 $result['cartPayData'] = isset($orderCompute['promotion_formula_list']) ? $orderCompute['promotion_formula_list'] : $payReturn['shopping_cart_data']['promotion_formula_list'];
  454 + $price = isset($orderCompute['last_order_amount']) ? $orderCompute['last_order_amount'] : $payReturn['shopping_cart_data']['last_order_amount'];
  455 + $result['price'] = Helpers::transPrice($price);
454 456
455 /*$sumPrice = isset($orderCompute['order_amount']) ? $orderCompute['order_amount'] : $payReturn['shopping_cart_data']['order_amount']; 457 /*$sumPrice = isset($orderCompute['order_amount']) ? $orderCompute['order_amount'] : $payReturn['shopping_cart_data']['order_amount'];
456 458
@@ -569,17 +571,21 @@ class CartModel @@ -569,17 +571,21 @@ class CartModel
569 $coupons = CartData::getCouponList($uid); 571 $coupons = CartData::getCouponList($uid);
570 572
571 do { 573 do {
572 - if ($onlyTotal) {  
573 - $result['count'] = count($coupons['data']['couponList']);  
574 - break;  
575 - }  
576 -  
577 if (isset($coupons['data']['couponList'])) { 574 if (isset($coupons['data']['couponList'])) {
578 - foreach ($coupons['data']['couponList'] as &$val) {  
579 - $val['notAvailable'] = $val['isValidity'] === 'N'; 575 + foreach ($coupons['data']['couponList'] as $val) {
  576 + $notAvailableRes = self::searchCoupon($uid, $val['couponCode']);
  577 + // 处理可用的优惠券
  578 + if ($val['isValidity'] === 'N' || (isset($notAvailableRes['code']) && $notAvailableRes['code'] !== 200)) {
  579 +// $val['notAvailable'] = true;
  580 + continue;
  581 + }
  582 + $result[] = $val;
580 } 583 }
  584 + }
581 585
582 - $result = $coupons['data']['couponList']; 586 + if ($onlyTotal) {
  587 + $count = count($result);
  588 + $result = array('count' => $count);
583 } 589 }
584 }while(0); 590 }while(0);
585 591