Authored by Rock Zhang

修复购物车结算页面一些样式显示以及数据交互的问题

Code Review By Rock Zhang
framework @ e9d066dd
1 -Subproject commit 75bbc3b075de19f239532f60c5995d06c5f814e2 1 +Subproject commit e9d066dd88a8e7e37103021c427a205a5cfcdcec
@@ -190,7 +190,7 @@ class Helpers @@ -190,7 +190,7 @@ class Helpers
190 */ 190 */
191 public static function transPrice($price) 191 public static function transPrice($price)
192 { 192 {
193 - return (!empty($price) && !is_float($price)) ? $price . '.00' : $price; 193 + return (!empty($price) && !is_float($price)) ? $price . '.00' : number_format($price, 2, '.', '');
194 } 194 }
195 195
196 /** 196 /**
@@ -80,6 +80,7 @@ function orderCompute() { @@ -80,6 +80,7 @@ function orderCompute() {
80 sumPrice: res.order_amount, 80 sumPrice: res.order_amount,
81 salePrice: res.discount_amount, 81 salePrice: res.discount_amount,
82 freight: res.promotion_formula_list[1].promotion_amount, 82 freight: res.promotion_formula_list[1].promotion_amount,
  83 + couponPrice: res.coupon_amount,
83 yohoCoin: res.use_yoho_coin, 84 yohoCoin: res.use_yoho_coin,
84 price: res.last_order_amount 85 price: res.last_order_amount
85 }); 86 });
@@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
3 * @author: bikai<kai.bi@yoho.cn> 3 * @author: bikai<kai.bi@yoho.cn>
4 * @date: 2015/12/14 4 * @date: 2015/12/14
5 */ 5 */
  6 +var $ = require('jquery');
6 var info = window.cookie('order-info'); 7 var info = window.cookie('order-info');
7 8
8 // info 必须是 JSON 字符串 9 // info 必须是 JSON 字符串
@@ -10,10 +11,10 @@ try { @@ -10,10 +11,10 @@ try {
10 info = JSON.parse(info); 11 info = JSON.parse(info);
11 } catch (e) { 12 } catch (e) {
12 info = { 13 info = {
13 - deliveryId: null,  
14 - deliveryTimeId: null,  
15 - paymentTypeId: null,  
16 - yohoCoin: null, 14 + deliveryId: 1,
  15 + deliveryTimeId: 1,
  16 + paymentTypeId: 1,
  17 + yohoCoin: $('.coin').data('yoho-coin') || 0,
17 addressId: null, 18 addressId: null,
18 couponCode: null, 19 couponCode: null,
19 couponValue: null, 20 couponValue: null,
@@ -41,7 +41,7 @@ @@ -41,7 +41,7 @@
41 41
42 <section class="block"> 42 <section class="block">
43 <ul class="sale-invoice"> 43 <ul class="sale-invoice">
44 - {{#if coupon}} 44 + {{# coupon}}
45 <li class="coupon"> 45 <li class="coupon">
46 <a href="/shoppingCart/selectCoupon"> 46 <a href="/shoppingCart/selectCoupon">
47 <!-- <a href="{{url}}"> --> 47 <!-- <a href="{{url}}"> -->
@@ -65,7 +65,7 @@ @@ -65,7 +65,7 @@
65 {{/if}} 65 {{/if}}
66 </a> 66 </a>
67 </li> 67 </li>
68 - {{/if}} 68 + {{/coupon}}
69 69
70 {{# yohoCoin}} 70 {{# yohoCoin}}
71 <li class="coin" data-yoho-coin="{{.}}"> 71 <li class="coin" data-yoho-coin="{{.}}">
@@ -114,11 +114,17 @@ @@ -114,11 +114,17 @@
114 </li> 114 </li>
115 <li> 115 <li>
116 <span>运费</span> 116 <span>运费</span>
117 - + ¥{{freight}} 117 + + {{freight}}
  118 + </li>
  119 + {{#couponPrice}}
  120 + <li>
  121 + <span>优惠券</span>
  122 + - ¥{{.}}
118 </li> 123 </li>
  124 + {{/couponPrice}}
119 <li> 125 <li>
120 <span>YOHO币</span> 126 <span>YOHO币</span>
121 - - ¥{{yohoCoin}} 127 + - {{yohoCoin}}
122 </li> 128 </li>
123 <li class="cost"> 129 <li class="cost">
124 应付金额: <em>¥{{price}}</em> 130 应付金额: <em>¥{{price}}</em>
@@ -156,6 +162,12 @@ @@ -156,6 +162,12 @@
156 <span>运费</span> 162 <span>运费</span>
157 + \{{freight}} 163 + \{{freight}}
158 </li> 164 </li>
  165 + \{{#couponPrice}}
  166 + <li>
  167 + <span>优惠券</span>
  168 + - ¥\{{.}}
  169 + </li>
  170 + \{{/couponPrice}}
159 <li> 171 <li>
160 <span>YOHO币</span> 172 <span>YOHO币</span>
161 - ¥\{{yohoCoin}} 173 - ¥\{{yohoCoin}}
@@ -23,7 +23,7 @@ class CartModel @@ -23,7 +23,7 @@ class CartModel
23 * @param int $productSku 商品SKU 23 * @param int $productSku 商品SKU
24 * @param int $buyNumber 购买数量 24 * @param int $buyNumber 购买数量
25 * @param int $goodsType 商品类型,0表示普通商品,1表示加价购商品 25 * @param int $goodsType 商品类型,0表示普通商品,1表示加价购商品
26 - * @param int int $isEdit 是否是编辑商品SKU,0表示不是编辑 26 + * @param int $isEdit 是否是编辑商品SKU,0表示不是编辑
27 * @param null|int $promotionId 促销id,默认null(加价购有关) 27 * @param null|int $promotionId 促销id,默认null(加价购有关)
28 * @param null|int $uid 用户UID,可以不传 28 * @param null|int $uid 用户UID,可以不传
29 * @return array 加入购物车接口返回的数据 29 * @return array 加入购物车接口返回的数据
@@ -406,7 +406,7 @@ class CartModel @@ -406,7 +406,7 @@ class CartModel
406 $oneGoods['name'] = $single['product_name']; 406 $oneGoods['name'] = $single['product_name'];
407 $oneGoods['color'] = $single['color_name']; 407 $oneGoods['color'] = $single['color_name'];
408 $oneGoods['size'] = $single['size_name']; 408 $oneGoods['size'] = $single['size_name'];
409 - $oneGoods['price'] = Helpers::transPrice($single['real_price']); // last_price有些带.00,有些不带,real_price都不带.00 409 + $oneGoods['price'] = Helpers::transPrice($single['sales_price']);
410 $oneGoods['count'] = $single['buy_number']; 410 $oneGoods['count'] = $single['buy_number'];
411 411
412 $result['goods'][] = $oneGoods; 412 $result['goods'][] = $oneGoods;
@@ -428,18 +428,20 @@ class CartModel @@ -428,18 +428,20 @@ class CartModel
428 } 428 }
429 429
430 // 有货币 430 // 有货币
431 - $result['yohoCoin'] = isset($orderCompute['use_yoho_coin']) ? isset($orderCompute['use_yoho_coin']) : $payReturn['yoho_coin']; 431 + $result['yohoCoin'] = (isset($orderCompute['use_yoho_coin']) && !empty($orderCompute['use_yoho_coin'])) ? $orderCompute['use_yoho_coin'] : $payReturn['yoho_coin'];
432 432
433 // 订单数据 433 // 订单数据
434 if (isset($payReturn['shopping_cart_data']) && !empty($payReturn['shopping_cart_data'])) { 434 if (isset($payReturn['shopping_cart_data']) && !empty($payReturn['shopping_cart_data'])) {
435 $sumPrice = isset($orderCompute['order_amount']) ? $orderCompute['order_amount'] : $payReturn['shopping_cart_data']['order_amount']; 435 $sumPrice = isset($orderCompute['order_amount']) ? $orderCompute['order_amount'] : $payReturn['shopping_cart_data']['order_amount'];
436 - $salePrice = isset($orderCompute['discount_amount']) ? $orderCompute['discount_amount'] : $payReturn['shopping_cart_data']['discount_amount']; 436 + $freight = isset($orderCompute['promotion_formula_list']['promotion_amount']) ? $orderCompute['promotion_formula_list'][1]['promotion_amount'] : $payReturn['shopping_cart_data']['promotion_formula_list'][1]['promotion_amount'];
  437 + $couponPrice = isset($orderCompute['coupon_amount']) ? $orderCompute['coupon_amount'] : false;
  438 + $salePrice = isset($orderCompute['discount_amount']) ? $orderCompute['discount_amount'] : $payReturn['shopping_cart_data']['promotion_formula_list'][3]['promotion_amount'];
437 $price = isset($orderCompute['last_order_amount']) ? $orderCompute['last_order_amount'] : $payReturn['shopping_cart_data']['last_order_amount']; 439 $price = isset($orderCompute['last_order_amount']) ? $orderCompute['last_order_amount'] : $payReturn['shopping_cart_data']['last_order_amount'];
438 - $freight = isset($orderCompute['promotion_formula_list']['promotion_amount']) ? $orderCompute['promotion_formula_list']['promotion_amount'] : $payReturn['shopping_cart_data']['promotion_formula_list'][1]['promotion_amount'];  
439 $result['sumPrice'] = Helpers::transPrice($sumPrice); 440 $result['sumPrice'] = Helpers::transPrice($sumPrice);
440 $result['salePrice'] = Helpers::transPrice($salePrice); 441 $result['salePrice'] = Helpers::transPrice($salePrice);
441 $result['price'] = Helpers::transPrice($price); 442 $result['price'] = Helpers::transPrice($price);
442 - $result['freight'] = strtr($freight, array('¥'=>'','¥'=>'')) . '.00'; 443 + $result['freight'] = $freight;
  444 + $result['couponPrice'] = $couponPrice;
443 } 445 }
444 446
445 // 发票有关数据 447 // 发票有关数据
@@ -468,7 +470,7 @@ class CartModel @@ -468,7 +470,7 @@ class CartModel
468 // 优惠券数据 470 // 优惠券数据
469 $coupons = array(); 471 $coupons = array();
470 !empty($orderCompute['coupon_amount']) && $coupons['value'] = $orderInfo['couponValue']; 472 !empty($orderCompute['coupon_amount']) && $coupons['value'] = $orderInfo['couponValue'];
471 - $coupons += self::getCouponList($uid, 0, 1, true); 473 + $coupons += self::getCouponList($uid, true);
472 $result['coupon'] = $coupons; 474 $result['coupon'] = $coupons;
473 } 475 }
474 476
@@ -535,7 +537,7 @@ class CartModel @@ -535,7 +537,7 @@ class CartModel
535 if (isset($coupons['data'])) { 537 if (isset($coupons['data'])) {
536 538
537 if ($onlyTotal) { 539 if ($onlyTotal) {
538 - $result['count'] = $coupons['data']['total']; 540 + $result['count'] = count($coupons['data']['couponList']);
539 } else { 541 } else {
540 $couponArr = array(); 542 $couponArr = array();
541 isset($coupons['data']['couponList']) && $couponArr = $coupons['data']['couponList']; 543 isset($coupons['data']['couponList']) && $couponArr = $coupons['data']['couponList'];
@@ -605,7 +607,6 @@ class CartModel @@ -605,7 +607,6 @@ class CartModel
605 { 607 {
606 $result = array(); 608 $result = array();
607 609
608 - $oneGoods = array();  
609 // 购买的可用商品列表 610 // 购买的可用商品列表
610 $validGoods = Helpers::formatCartGoods($data['goods_list']); 611 $validGoods = Helpers::formatCartGoods($data['goods_list']);
611 !empty($validGoods) && $result['goods'] = $validGoods; 612 !empty($validGoods) && $result['goods'] = $validGoods;