Authored by Rock Zhang

去除结算页面请求的单地址查询,优惠券可用性验证等接口,从而优化性能

Code Review By Rock Zhang
@@ -11,7 +11,16 @@ var $confim = $('.confim-mask'), @@ -11,7 +11,16 @@ var $confim = $('.confim-mask'),
11 deleteId; 11 deleteId;
12 12
13 $('.address-item').on('touchend', function() { 13 $('.address-item').on('touchend', function() {
14 - orderInfo('addressId', $(this).data('address-id')); 14 + var $this = $(this);
  15 + var addressId = $this.data('address-id');
  16 + var address = {
  17 + address_id: $this.data('address-id'),
  18 + consignee: $this.find('.name').text(),
  19 + mobile: $this.find('.tel').text(),
  20 + address_info: $this.find('.address-info').text()
  21 + };
  22 + orderInfo('addressId', addressId);
  23 + orderInfo('address', address);
15 }).on('touchend', '.edit', function() { 24 }).on('touchend', '.edit', function() {
16 window.location.href = $(this).data('href'); 25 window.location.href = $(this).data('href');
17 return false; 26 return false;
@@ -22,5 +31,6 @@ $('.address-item').on('touchend', function() { @@ -22,5 +31,6 @@ $('.address-item').on('touchend', function() {
22 $confim.on('touchend', '.confim', function() { 31 $confim.on('touchend', '.confim', function() {
23 if (orderInfo('addressId') === deleteId) { 32 if (orderInfo('addressId') === deleteId) {
24 orderInfo('addressId', null); 33 orderInfo('addressId', null);
  34 + orderInfo('address', null);
25 } 35 }
26 }); 36 });
@@ -5,7 +5,7 @@ @@ -5,7 +5,7 @@
5 <p class="infos"> 5 <p class="infos">
6 收货地址 6 收货地址
7 <span class="per-info">{{name}} {{phoneNum}}</span> 7 <span class="per-info">{{name}} {{phoneNum}}</span>
8 - <span class="address">{{area}} {{address}}</span> 8 + <span class="address">{{addressInfo}}</span>
9 </p> 9 </p>
10 <span class="iconfont">&#xe614;</span> 10 <span class="iconfont">&#xe614;</span>
11 </a> 11 </a>
@@ -324,6 +324,12 @@ class CartModel @@ -324,6 +324,12 @@ class CartModel
324 324
325 $pay = CartData::cartPay($uid, $cartType); 325 $pay = CartData::cartPay($uid, $cartType);
326 326
  327 + // 商品为空返回
  328 + if (!$pay || (isset($pay['data']['goods_list']) && empty($pay['data']['goods_list']))) {
  329 + $result['cartUrl'] = Helpers::url('/cart/index/index');
  330 + return $result;
  331 + }
  332 +
327 if ($pay && isset($pay['code']) && $pay['code'] === 200) { 333 if ($pay && isset($pay['code']) && $pay['code'] === 200) {
328 $payReturn = $pay['data']; 334 $payReturn = $pay['data'];
329 $address = array(); 335 $address = array();
@@ -335,8 +341,8 @@ class CartModel @@ -335,8 +341,8 @@ class CartModel
335 } 341 }
336 342
337 // 根据地址id查询地址信息 343 // 根据地址id查询地址信息
338 - if (isset($orderInfo['addressId'])) {  
339 - $address = UserModel::getAddressDataById($uid, $orderInfo['addressId']); 344 + if (isset($orderInfo['address'])) {
  345 + $address = $orderInfo['address'];
340 } 346 }
341 347
342 // 收货人有关信息 348 // 收货人有关信息
@@ -344,8 +350,8 @@ class CartModel @@ -344,8 +350,8 @@ class CartModel
344 $result['addressId'] = isset($address['address_id']) ? $address['address_id'] : $payReturn['delivery_address']['address_id']; 350 $result['addressId'] = isset($address['address_id']) ? $address['address_id'] : $payReturn['delivery_address']['address_id'];
345 $result['name'] = isset($address['consignee']) ? $address['consignee'] : $payReturn['delivery_address']['consignee']; 351 $result['name'] = isset($address['consignee']) ? $address['consignee'] : $payReturn['delivery_address']['consignee'];
346 $result['phoneNum'] = isset($address['mobile']) ? $address['mobile'] : $payReturn['delivery_address']['mobile']; 352 $result['phoneNum'] = isset($address['mobile']) ? $address['mobile'] : $payReturn['delivery_address']['mobile'];
347 - $result['area'] = isset($address['area']) ? $address['area'] : $payReturn['delivery_address']['area'];  
348 - $result['address'] = isset($address['address']) ? $address['address'] : $payReturn['delivery_address']['address']; 353 +// $result['area'] = isset($address['area']) ? $address['area'] : $payReturn['delivery_address']['area'];
  354 + $result['addressInfo'] = isset($address['address_info']) ? $address['address_info'] : $payReturn['delivery_address']['area'] . ' ' . $payReturn['delivery_address']['address'];
349 $isSupport = isset($address['is_support']) ? $address['is_support'] : $payReturn['delivery_address']['is_support']; 355 $isSupport = isset($address['is_support']) ? $address['is_support'] : $payReturn['delivery_address']['is_support'];
350 $result['isSupport'] = $isSupport === 'Y'; 356 $result['isSupport'] = $isSupport === 'Y';
351 } 357 }
@@ -477,9 +483,10 @@ class CartModel @@ -477,9 +483,10 @@ class CartModel
477 isset($orderInfo['msg']) && $result['msg'] = $orderInfo['msg']; 483 isset($orderInfo['msg']) && $result['msg'] = $orderInfo['msg'];
478 484
479 // 优惠券数据 485 // 优惠券数据
480 - $coupons = array();  
481 - !empty($orderCompute['coupon_amount']) && $coupons['couponName'] = $orderInfo['couponName'];  
482 - $coupons += self::getCouponList($uid, true); 486 + $coupons = array('couponName' => '');
  487 + if (!empty($orderCompute['coupon_amount'])) {
  488 + $coupons['couponName'] = $orderCompute['coupon_amount'];
  489 + }
483 $result['coupon'] = $coupons; 490 $result['coupon'] = $coupons;
484 } 491 }
485 492
@@ -553,11 +560,10 @@ class CartModel @@ -553,11 +560,10 @@ class CartModel
553 do { 560 do {
554 if (isset($coupons['data']['couponList'])) { 561 if (isset($coupons['data']['couponList'])) {
555 foreach ($coupons['data']['couponList'] as $val) { 562 foreach ($coupons['data']['couponList'] as $val) {
556 - $notAvailableRes = self::searchCoupon($uid, $val['couponCode']); 563 + // $notAvailableRes = self::searchCoupon($uid, $val['couponCode']);
557 // 处理可用的优惠券 564 // 处理可用的优惠券
558 - if ($val['isValidity'] === 'N' || (isset($notAvailableRes['code']) && $notAvailableRes['code'] !== 200)) { 565 + if ($val['isValidity'] === 'N') {
559 $val['notAvailable'] = true; 566 $val['notAvailable'] = true;
560 - // continue;  
561 } 567 }
562 $result[] = $val; 568 $result[] = $val;
563 } 569 }
@@ -283,22 +283,17 @@ class IndexController extends AbstractAction @@ -283,22 +283,17 @@ class IndexController extends AbstractAction
283 $orderInfo = json_decode($cookieData, true); 283 $orderInfo = json_decode($cookieData, true);
284 $cartType = $orderInfo['cartType']; 284 $cartType = $orderInfo['cartType'];
285 } 285 }
286 - $cartKey = 'commonCart';  
287 - if ($cartType === 'advance') {  
288 - $cartKey = 'preSellCart';  
289 - }  
290 286
291 - $shoppingKey = Helpers::getShoppingKeyByCookie();  
292 $uid = $this->getUid(true); 287 $uid = $this->getUid(true);
293 - $cartGoods = CartModel::getCartData($uid, $shoppingKey);  
294 - if (isset($cartGoods['isEmptyCart']) || empty($cartGoods[$cartKey])) {  
295 - $this->go(Helpers::url('/cart/index/index')); 288 + $order = CartModel::cartPay($uid, $cartType, $orderInfo);
  289 + if (isset($order['cartUrl'])) {
  290 + $this->go($order['cartUrl']);
296 } 291 }
297 292
298 $data = array( 293 $data = array(
299 'orderEnsurePage' => true, 294 'orderEnsurePage' => true,
300 'isOrdinaryCart' => ($cartType !== 'advance'), 295 'isOrdinaryCart' => ($cartType !== 'advance'),
301 - 'orderEnsure' => CartModel::cartPay($uid, $cartType, $orderInfo) 296 + 'orderEnsure' => $order
302 ); 297 );
303 298
304 $this->_view->display('order-ensure', $data); 299 $this->_view->display('order-ensure', $data);