Authored by Rock Zhang

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

Code Review By Rock Zhang
... ... @@ -11,7 +11,16 @@ var $confim = $('.confim-mask'),
deleteId;
$('.address-item').on('touchend', function() {
orderInfo('addressId', $(this).data('address-id'));
var $this = $(this);
var addressId = $this.data('address-id');
var address = {
address_id: $this.data('address-id'),
consignee: $this.find('.name').text(),
mobile: $this.find('.tel').text(),
address_info: $this.find('.address-info').text()
};
orderInfo('addressId', addressId);
orderInfo('address', address);
}).on('touchend', '.edit', function() {
window.location.href = $(this).data('href');
return false;
... ... @@ -22,5 +31,6 @@ $('.address-item').on('touchend', function() {
$confim.on('touchend', '.confim', function() {
if (orderInfo('addressId') === deleteId) {
orderInfo('addressId', null);
orderInfo('address', null);
}
});
... ...
... ... @@ -5,7 +5,7 @@
<p class="infos">
收货地址
<span class="per-info">{{name}} {{phoneNum}}</span>
<span class="address">{{area}} {{address}}</span>
<span class="address">{{addressInfo}}</span>
</p>
<span class="iconfont">&#xe614;</span>
</a>
... ...
... ... @@ -324,6 +324,12 @@ class CartModel
$pay = CartData::cartPay($uid, $cartType);
// 商品为空返回
if (!$pay || (isset($pay['data']['goods_list']) && empty($pay['data']['goods_list']))) {
$result['cartUrl'] = Helpers::url('/cart/index/index');
return $result;
}
if ($pay && isset($pay['code']) && $pay['code'] === 200) {
$payReturn = $pay['data'];
$address = array();
... ... @@ -335,8 +341,8 @@ class CartModel
}
// 根据地址id查询地址信息
if (isset($orderInfo['addressId'])) {
$address = UserModel::getAddressDataById($uid, $orderInfo['addressId']);
if (isset($orderInfo['address'])) {
$address = $orderInfo['address'];
}
// 收货人有关信息
... ... @@ -344,8 +350,8 @@ class CartModel
$result['addressId'] = isset($address['address_id']) ? $address['address_id'] : $payReturn['delivery_address']['address_id'];
$result['name'] = isset($address['consignee']) ? $address['consignee'] : $payReturn['delivery_address']['consignee'];
$result['phoneNum'] = isset($address['mobile']) ? $address['mobile'] : $payReturn['delivery_address']['mobile'];
$result['area'] = isset($address['area']) ? $address['area'] : $payReturn['delivery_address']['area'];
$result['address'] = isset($address['address']) ? $address['address'] : $payReturn['delivery_address']['address'];
// $result['area'] = isset($address['area']) ? $address['area'] : $payReturn['delivery_address']['area'];
$result['addressInfo'] = isset($address['address_info']) ? $address['address_info'] : $payReturn['delivery_address']['area'] . ' ' . $payReturn['delivery_address']['address'];
$isSupport = isset($address['is_support']) ? $address['is_support'] : $payReturn['delivery_address']['is_support'];
$result['isSupport'] = $isSupport === 'Y';
}
... ... @@ -477,9 +483,10 @@ class CartModel
isset($orderInfo['msg']) && $result['msg'] = $orderInfo['msg'];
// 优惠券数据
$coupons = array();
!empty($orderCompute['coupon_amount']) && $coupons['couponName'] = $orderInfo['couponName'];
$coupons += self::getCouponList($uid, true);
$coupons = array('couponName' => '');
if (!empty($orderCompute['coupon_amount'])) {
$coupons['couponName'] = $orderCompute['coupon_amount'];
}
$result['coupon'] = $coupons;
}
... ... @@ -553,11 +560,10 @@ class CartModel
do {
if (isset($coupons['data']['couponList'])) {
foreach ($coupons['data']['couponList'] as $val) {
$notAvailableRes = self::searchCoupon($uid, $val['couponCode']);
// $notAvailableRes = self::searchCoupon($uid, $val['couponCode']);
// 处理可用的优惠券
if ($val['isValidity'] === 'N' || (isset($notAvailableRes['code']) && $notAvailableRes['code'] !== 200)) {
if ($val['isValidity'] === 'N') {
$val['notAvailable'] = true;
// continue;
}
$result[] = $val;
}
... ...
... ... @@ -283,22 +283,17 @@ class IndexController extends AbstractAction
$orderInfo = json_decode($cookieData, true);
$cartType = $orderInfo['cartType'];
}
$cartKey = 'commonCart';
if ($cartType === 'advance') {
$cartKey = 'preSellCart';
}
$shoppingKey = Helpers::getShoppingKeyByCookie();
$uid = $this->getUid(true);
$cartGoods = CartModel::getCartData($uid, $shoppingKey);
if (isset($cartGoods['isEmptyCart']) || empty($cartGoods[$cartKey])) {
$this->go(Helpers::url('/cart/index/index'));
$order = CartModel::cartPay($uid, $cartType, $orderInfo);
if (isset($order['cartUrl'])) {
$this->go($order['cartUrl']);
}
$data = array(
'orderEnsurePage' => true,
'isOrdinaryCart' => ($cartType !== 'advance'),
'orderEnsure' => CartModel::cartPay($uid, $cartType, $orderInfo)
'orderEnsure' => $order
);
$this->_view->display('order-ensure', $data);
... ...