Authored by hf

Merge branch 'develop' of http://git.dev.yoho.cn/web/yohobuy into develop

... ... @@ -29,9 +29,9 @@ class Yohobuy
const YOHOBUY_URL = 'http://www.yohobuy.com/';
// /* 测试环境 */
// const API_URL = 'http://testapi.yoho.cn:28078/';
// const SERVICE_URL = 'http://testservice.yoho.cn:28077/';
// const YOHOBUY_URL = 'http://www.yohobuy.com/';
// const API_URL = 'http://testapi.yoho.cn:28078/';
// const SERVICE_URL = 'http://testservice.yoho.cn:28077/';
// const YOHOBUY_URL = 'http://www.yohobuy.com/';
/**
* 私钥列表
... ...
... ... @@ -560,43 +560,48 @@ class Helpers
* 格式化购物车商品
*
* @param array $cartGoods 购物车商品列表
* @param boolean $isValid 是否是可用商品(非失效商品),默认是
* @return array 处理之后的购物车商品数据
*/
public static function formatCartGoods($cartGoods)
public static function formatCartGoods($cartGoods, $isValid = true)
{
$arr = array();
$oneGoods = array();
foreach ($cartGoods as $key => $value) {
$oneGoods['id'] = $value['product_sku'];
$oneGoods['skn'] = $value['product_skn'];
$oneGoods['name'] = $value['product_name'];
$oneGoods['thumb'] = !empty($value['goods_images']) ? Images::getImageUrl($value['goods_images'], 90, 100) : '';
$oneGoods['color'] = $value['color_name'];
$oneGoods['size'] = $value['size_name'];
$oneGoods = array();
foreach ($cartGoods as $key => $value) {
$oneGoods['id'] = $value['product_sku'];
$oneGoods['skn'] = $value['product_skn'];
$oneGoods['name'] = $value['product_name'];
$oneGoods['thumb'] = !empty($value['goods_images']) ? Images::getImageUrl($value['goods_images'], 90, 100) : '';
$oneGoods['color'] = $value['color_name'];
$oneGoods['size'] = $value['size_name'];
$oneGoods['isSelected'] = $value['selected'] === 'Y';
$oneGoods['price'] = self::transPrice($value['sales_price']);
$oneGoods['count'] = $value['buy_number'];
$oneGoods['lowStocks'] = ($value['buy_number'] < $value['storage_number']);
//gift=>是否赠品,advanceBuy=>是否加价购,soldOut=>失效商品;
if (!isset($value['goods_type'])) {
$oneGoods['isSoldOut'] = true;
} elseif ($value['goods_type'] == 'gift' && !isset($value['isAdvanceBuy'])) {
$oneGoods['isGift'] = true;
} elseif ($value['goods_type'] == 'price_gift') {
$oneGoods['isAdvanceBuy'] = true;
}
// 上市期
if (!empty($value['expect_arrival_time'])) {
$oneGoods['appearDate'] = $value['expect_arrival_time'];
}
// 商品链接
if (isset($value['cn_alphabet']) ) {
$oneGoods['url'] = self::url('/product/pro_' . $value['product_id'] . '_' . $value['goods_id'] . '/' . $value['cn_alphabet'] . '.html');
}
$arr[$key] = $oneGoods;
}
$oneGoods['price'] = self::transPrice($value['sales_price']);
$oneGoods['count'] = $value['buy_number'];
if ($isValid) {
$oneGoods['lowStocks'] = ($value['buy_number'] > $value['storage_number']);
}
//gift=>是否赠品,advanceBuy=>是否加价购,soldOut=>失效商品;
if (!isset($value['goods_type'])) {
$oneGoods['isSoldOut'] = true;
} elseif ($value['goods_type'] == 'gift' && !isset($value['isAdvanceBuy'])) {
$oneGoods['isGift'] = true;
} elseif ($value['goods_type'] == 'price_gift') {
$oneGoods['isAdvanceBuy'] = true;
}
// 上市期
if (!empty($value['expect_arrival_time'])) {
$oneGoods['appearDate'] = $value['expect_arrival_time'];
}
// 商品链接
if (isset($value['cn_alphabet'])) {
$oneGoods['url'] = self::url('/product/pro_' . $value['product_id'] . '_' . $value['goods_id'] . '/' . $value['cn_alphabet'] . '.html');
}
$arr[$key] = $oneGoods;
}
return $arr;
}
... ... @@ -612,30 +617,30 @@ class Helpers
{
$arr = array();
$gift = array();
$oneGoods = array();
foreach ($advanceGoods as $value) {
$gift = array();
$gift['promotionId'] = $value['promotion_id'];
$gift['promotionTitle'] = $value['promotion_title'];
foreach ($value['goods_list'] as $single) {
$oneGoods['id'] = $single['product_skn'];
$oneGoods['name'] = $single['product_name'];
$oneGoods['thumb'] = !empty($single['goods_images']) ? Images::getImageUrl($single['goods_images'], 120, 160) : '';
$oneGoods['appearDate'] = '12月'; // 目前app接口没有返回该数据
$oneGoods['price'] = self::transPrice($single['last_price']);
$oneGoods['marketPrice'] = self::transPrice($single['market_price']);
$oneGoods['count'] = $single['storage_number'];
$gift['goods'][] = $oneGoods;
}
$arr[] = $gift;
// 计算加价购商品数目
$count += $value['max_select_number'];
}
$gift = array();
$oneGoods = array();
foreach ($advanceGoods as $value) {
$gift = array();
$gift['promotionId'] = $value['promotion_id'];
$gift['promotionTitle'] = $value['promotion_title'];
foreach ($value['goods_list'] as $single) {
$oneGoods['id'] = $single['product_skn'];
$oneGoods['name'] = $single['product_name'];
$oneGoods['thumb'] = !empty($single['goods_images']) ? Images::getImageUrl($single['goods_images'], 120, 160) : '';
$oneGoods['appearDate'] = '12月'; // 目前app接口没有返回该数据
$oneGoods['price'] = self::transPrice($single['last_price']);
$oneGoods['marketPrice'] = self::transPrice($single['market_price']);
$oneGoods['count'] = $single['storage_number'];
$gift['goods'][] = $oneGoods;
}
$arr[] = $gift;
// 计算加价购商品数目
$count += $value['max_select_number'];
}
return $arr;
}
... ...
... ... @@ -191,7 +191,7 @@ class SaeTOAuthV2 {
$params['username'] = $keys['username'];
$params['password'] = $keys['password'];
} else {
throw new OAuthException("wrong auth type");
throw new \OAuthException("wrong auth type");
}
$response = $this->oAuthRequest($this->accessTokenURL(), 'POST', $params);
... ... @@ -200,7 +200,7 @@ class SaeTOAuthV2 {
$this->access_token = $token['access_token'];
//$this->refresh_token = $token['refresh_token'];
} else {
throw new OAuthException("get access token failed." . $token['error']);
throw new \OAuthException("get access token failed." . $token['error']);
}
return $token;
}
... ...
... ... @@ -8,43 +8,50 @@ var $ = require('jquery'),
lazyLoad = require('yoho.lazyload'),
Hammer = require('yoho.hammer');
var chosePanel = require('./chose-panel');
var chosePanel = require('./chose-panel'),
tip = require('../plugin/tip');
var $cartContent = $('.cart-content');
var navHammer,
cartType = 'ordinary';
cartType = $('#cartType').val();
require('./good');
lazyLoad($('img.lazy'));
navHammer = new Hammer(document.getElementsByClassName('cart-nav')[0]);
navHammer.on('tap', function(e) {
var $this = $(e.target).closest('li');
if ($('.cart-nav').length > 0) {
navHammer = new Hammer(document.getElementsByClassName('cart-nav')[0]);
navHammer.on('tap', function(e) {
var $this = $(e.target).closest('li');
if ($this.hasClass('active')) {
return;
}
if ($this.hasClass('active')) {
return;
}
if (cartType === 'ordinary') {
cartType = 'advance';
} else {
cartType = 'ordinary';
}
if (cartType === 'ordinary') {
cartType = 'advance';
} else {
cartType = 'ordinary';
}
$this.siblings('.active').removeClass('active');
$this.addClass('active');
$this.siblings('.active').removeClass('active');
$this.addClass('active');
//切换普通商品和预售商品购物车显示
$cartContent.toggleClass('hide');
//切换普通商品和预售商品购物车显示
$cartContent.toggleClass('hide');
//trigger lazyload
$(window).trigger('scroll');
});
//trigger lazyload
$(window).trigger('scroll');
});
}
$('.btn-balance').on('touchend', function() {
window.location.href = '/cart/index/orderEnsure?cartType=' + cartType;
if($('.balance span').hasClass('icon-cb-checked')){
window.location.href = '/cart/index/orderEnsure?cartType=' + cartType;
} else {
tip.show('请先勾选商品~');
}
});
$('.chose').on('touchend', function() {
... ...
... ... @@ -213,7 +213,7 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) {
$siblingBlock.find('.block').eq(i).addClass('zero-stock');
}
}
numArray = $siblingBlock.find('.chosed').data('numstr').split('/');
numArray = ($siblingBlock.find('.chosed').data('numstr') + '').split('/');
$that.find('.num .left-num').html('剩余' + numArray[index] + '件');
if (2 === $chosed.closest('.zero-stock').length) {
$('#chose-btn-sure').css('background-color', '#c0c0c0');
... ...
... ... @@ -13,9 +13,9 @@ var dialog = require('../me/dialog'),
tip = require('../plugin/tip');
var $names,
$selectAllBtn = $('.balance .iconfont');
var requesting = false;
$selectAllBtn = $('.balance .iconfont'),
cartType = $('#cartType').val(),
requesting = false;
ellipsis.init();
... ... @@ -29,20 +29,6 @@ if ($names.length > 0) {
$names[0].mlellipsis(2);
}
//获取当前购物车类型
function getCartType() {
var $navItem = $('.cart-nav ').find('li'),
type = 'ordinary';
if ($navItem.eq(0).hasClass('active')) {
type = 'ordinary';
} else {
type = 'advance';
}
return type;
}
//TIP:事件委托在.cart-goods,商品列表的容器统一需要有.cart-goods
$('.cart-goods').on('touchstart', '.checkbox', function() {
var $this = $(this),
... ... @@ -66,7 +52,7 @@ $('.cart-goods').on('touchstart', '.checkbox', function() {
this.selected = properties.selected;
}
goodInfo.goods_type = getCartType();
goodInfo.goods_type = cartType;
goodInfo.selected = isSelected ? 'N' : 'Y';
goodInfo.product_sku = id;
goodInfo.buy_number = $good.find('.count').eq(0).text().trim().replace('×', '');
... ... @@ -95,13 +81,24 @@ $('.cart-goods').on('touchstart', '.checkbox', function() {
},
success: function(data) {
if (data) {
$('#good-totalprice').html('¥' + data.commonCart.price);
$('#good-activityPrice').html('¥' + data.commonCart.activityPrice);
$('#good-total').html('总计:¥' + data.commonCart.sumPrice + ' (' + data.commonCart.count + '件)');
if (data.commonCart.isAllSelected) {
$('.balance span').removeClass('icon-checkbox').addClass('icon-cb-checked');
if (cartType === 'ordinary') {
$('#good-totalprice').html('¥' + data.commonCart.price);
$('#good-activityPrice').html('¥' + data.commonCart.activityPrice);
$('#good-total').html('总计:¥' + data.commonCart.sumPrice + ' (' + data.commonCart.count + '件)');
if (data.commonCart.isAllSelected) {
$('.balance span').removeClass('icon-checkbox').addClass('icon-cb-checked');
} else {
$('.balance span').removeClass('icon-cb-checked').addClass('icon-checkbox');
}
} else {
$('.balance span').removeClass('icon-cb-checked').addClass('icon-checkbox');
$('#good-totalprice').html('¥' + data.preSellCart.price);
$('#good-activityPrice').html('¥' + data.preSellCart.activityPrice);
$('#good-total').html('总计:¥' + data.preSellCart.sumPrice + ' (' + data.preSellCart.count + '件)');
if (data.preSellCart.isAllSelected) {
$('.balance span').removeClass('icon-checkbox').addClass('icon-cb-checked');
} else {
$('.balance span').removeClass('icon-cb-checked').addClass('icon-checkbox');
}
}
}
},
... ... @@ -115,26 +112,6 @@ $('.cart-goods').on('touchstart', '.checkbox', function() {
}).fail(function() {
tip.show('网络错误');
});
}).on('touchstart', '.icon-edit', function() {
//var $this = $(this);
//
//var $cartgood = $this.closest('.shopping-cart-good');
//
////var id = $this.closest('.shopping-cart-good').data('id');
//
//var $viewGood = $cartgood.find('.deps');
// $editGoot = $cartgood.find('.calculate-num');
//
//if ($viewGood.hasClass('show')) {
// $viewGood.removeClass('show').addClass('hide');
// $editGoot.removeClass('hide').addClass('show');
//} else {
// $viewGood.removeClass('hide').addClass('show');
// $editGoot.removeClass('show').addClass('hide');
//}
}).on('touchstart', '.icon-del', function(e) {
var $this = $(this);
... ... @@ -274,7 +251,7 @@ function willBeSelected($this) {
//全选按钮点击事件
$selectAllBtn.on('touchend', function() {
var $this = $(this);
bottomCheckBoxHandeler(willBeSelected($this), getCartType(), didUpdateAllGoodsCheckStatus);
bottomCheckBoxHandeler(willBeSelected($this), cartType, didUpdateAllGoodsCheckStatus);
});
$('.down').on('touchend', function() {
... ...
... ... @@ -12,20 +12,7 @@
{{^}}
<div id="mainCart" class="shopping-cart-page yoho-page">
{{#if cartNav}}
<ul class="cart-nav clearfix">
<li class="active">
<span>
普通商品({{commonGoodsCount}})
</span>
</li>
<li>
<span>
预售商品({{presellGoodsCount}})
</span>
</li>
</ul>
{{/if}}
{{#if showLoginInfo}}
<p class="login-info">
... ... @@ -34,6 +21,21 @@
<a class="btn btn-login" href="{{signurl}}">登录</a>
可以同步电脑和手机中的商品
</p>
{{^}}
{{#if cartNav}}
<ul class="cart-nav clearfix">
<li class="active">
<span>
普通商品({{commonGoodsCount}})
</span>
</li>
<li>
<span>
预售商品({{presellGoodsCount}})
</span>
</li>
</ul>
{{/if}}
{{/if}}
{{# commonCart}}
... ... @@ -56,8 +58,7 @@
</div>
{{/if}}
<input id="cartType" type="hidden" value="{{cartType}}">
{{/ shoppingCart}}
{{> cart/chose-panel}}
... ...
... ... @@ -130,9 +130,9 @@
<ul class="pay-mode">
{{# paymentWay}}
<li class="{{#if default}}default{{/if}}" data-pay-type="{{paymentType}}" data-pay-id="{{id}}">
<li class="{{#if recommend}}default{{/if}}" data-pay-type="{{paymentType}}" data-pay-id="{{id}}">
<span class="iconfont">
{{#if default}}
{{#if recommend}}
&#xe62f;
{{else}}
&#xe62e;
... ...
... ... @@ -52,7 +52,7 @@ class CartModel
*/
public static function getCartData($uid, $shoppingKey, $cartType = 'all', $onlyGift = false, $onlyAdvanceBuy = false)
{
$result = array('cartNav' => true, 'commonGoodsCount' => '0', 'presellGoodsCount' => '0');
$result = array('cartNav' => false, 'commonGoodsCount' => '0', 'presellGoodsCount' => '0');
// 用户是否登录
if (empty($uid)) {
... ... @@ -65,15 +65,13 @@ class CartModel
// 处理普通购物车和预售购物车的数据
do {
if (!isset($cartData['data']) || empty($cartData['data'])) {
// $result['isEmptyCart'] = true;
if (empty($cartData['data'])) {
$result['isEmptyCart'] = true;
break;
}
$cart = $cartData['data'];
$result['cartNav'] = true;
if ($cartType !== 'all') { // 加价购或者赠品数据
$result = self::procCartData($cart['ordinary_cart_data'], $onlyGift, $onlyAdvanceBuy);
break;
... ... @@ -87,12 +85,29 @@ class CartModel
break;
}
// 普通购物车空,则显示预售购物车
if ($ordinaryCount === '0') {
$result['cartNav'] = false;
$result['cartType'] = 'advance';
}
// 预售购物车空,则显示普通购物车
elseif ($advanceCount === '0') {
$result['cartNav'] = false;
$result['cartType'] = 'ordinary';
}
// 以上两个购物车中都有数据, 默认显示普通购物车
else {
$result['cartNav'] = true;
$result['cartType'] = 'ordinary';
}
/* 普通购物车 */
$result['commonGoodsCount'] = $ordinaryCount;
$result['commonCart'] = self::procCartData($cart['ordinary_cart_data'], $onlyGift, $onlyAdvanceBuy);
/* 预售购物车 */
$result['presellGoodsCount'] = $advanceCount;
$result['preSellCart'] = self::procCartData($cart['advance_cart_data'], $onlyGift, $onlyAdvanceBuy);
} while(false);
return $result;
... ... @@ -420,7 +435,10 @@ class CartModel
$onePay['id'] = $pay['payment_id'];
$onePay['paymentType'] = $pay['payment_type'];
$onePay['name'] = $pay['payment_type_name'];
$onePay['default'] = ($pay['default'] === 'Y');
// $onePay['default'] = ($pay['default'] === 'Y');
if ($onePay['paymentType'] == 1) {
$onePay['recommend'] = true;
}
$result['paymentWay'][] = $onePay;
}
... ... @@ -547,25 +565,20 @@ class CartModel
// 调用接口获取优惠券数据
$coupons = CartData::getCouponList($uid);
// 处理优惠券数据
if (isset($coupons['data'])) {
do {
if ($onlyTotal) {
$result['count'] = count($coupons['data']['couponList']);
} else {
$couponArr = array();
isset($coupons['data']['couponList']) && $couponArr = $coupons['data']['couponList'];
foreach ($couponArr as &$val) {
$notAvailableRes = self::searchCoupon($uid, $val['couponCode']);
// 处理可用的优惠券
if (isset($notAvailableRes['code']) && $notAvailableRes['code'] !== 200) {
$val['notAvailable'] = true;
}
break;
}
if (isset($coupons['data']['couponList'])) {
foreach ($coupons['data']['couponList'] as &$val) {
$val['notAvailable'] = $val['isValidity'] === 'N';
}
!empty($couponArr) && $result = $couponArr;
$result = $coupons['data']['couponList'];
}
}
}while(0);
return $result;
}
... ... @@ -682,7 +695,7 @@ class CartModel
$oneColor['colorNum'] = $colorNum;
$oneColor['sizeNumStr'] = rtrim($sizeStorageStr, '/');
$colors[] = $oneColor;
// 缩略图
foreach ($val['images_list'] as $image) {
$thumbImageList[] = array(
... ... @@ -739,7 +752,7 @@ class CartModel
}
// 失效商品列表
$notValidGoods = Helpers::formatCartGoods($data['sold_out_goods_list']);
$notValidGoods = Helpers::formatCartGoods($data['sold_out_goods_list'], false);
if (!empty($notValidGoods)) {
$result['notValidGoods'] = $notValidGoods;
}
... ...
... ... @@ -248,8 +248,8 @@ class DetailModel
$result['cartInfo']['productId'] = $productId;
$result['cartInfo']['thumbs'] = $thumbImageList;
$result['cartInfo']['name'] = isset($result['goodsName']) ? $result['goodsName'] : '';
$result['cartInfo']['price'] = isset($result['goodsPrice']['currentPrice']) ? $result['goodsPrice']['currentPrice'] : '';
$result['cartInfo']['salePrice'] = isset($result['goodsPrice']['previousPrice']) ? $result['goodsPrice']['previousPrice'] : '';
$result['cartInfo']['price'] = isset($result['goodsPrice']['previousPrice']) ? $result['goodsPrice']['previousPrice'] : '';
$result['cartInfo']['salePrice'] = isset($result['goodsPrice']['currentPrice']) ? $result['goodsPrice']['currentPrice'] : '';
$result['cartInfo']['totalNum'] = $totalStorageNum;
$result['cartInfo']['colors'] = $colorGroup;
$result['cartInfo']['sizes'] = $sizeGroup;
... ... @@ -474,6 +474,7 @@ class DetailModel
'</p>' => '',
'<img src=' => "<img class=\"lazy\" src=\"data:image/gif;base64,R0lGODlhAQABAJEAAAAAAP///93d3f///yH5BAEAAAMALAAAAAABAAEAAAICVAEAOw==\" data-original=",
'<img border="0" src=' => "<img border=\"0\" class=\"lazy\" src=\"data:image/gif;base64,R0lGODlhAQABAJEAAAAAAP///93d3f///yH5BAEAAAMALAAAAAABAAEAAAICVAEAOw==\" data-original=",
'.jpg' => '.jpg?imageMogr2/thumbnail/750x/quality/90',
)),
);
}
... ...
... ... @@ -268,8 +268,8 @@ class IndexController extends AbstractAction
// 审判跳转登录页
$this->auditJumpLogin();
$this->setTitle('购物车');
$this->setNavHeader('购物车');
$this->setTitle('确认订单');
$this->setNavHeader('确认订单');
// 购物车商品为空跳转到购物车页面
$shoppingKey = Helpers::getShoppingKeyByCookie();
... ...